drivers/xen/cpu_hotplug.c
Source file repositories/reference/linux-study-clean/drivers/xen/cpu_hotplug.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/xen/cpu_hotplug.c- Extension
.c- Size
- 2344 bytes
- Lines
- 122
- Domain
- Driver Families
- Bucket
- drivers/xen
- Inferred role
- Driver Families: implementation source
- Status
- source implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/notifier.hxen/xen.hxen/xenbus.hasm/xen/hypervisor.hasm/cpu.h
Detected Declarations
function enable_hotplug_cpufunction disable_hotplug_cpufunction vcpu_onlinefunction vcpu_hotplugfunction handle_vcpu_hotplug_eventfunction setup_cpu_watcherfunction for_each_possible_cpufunction setup_vcpu_hotplug_event
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
#define pr_fmt(fmt) "xen:" KBUILD_MODNAME ": " fmt
#include <linux/notifier.h>
#include <xen/xen.h>
#include <xen/xenbus.h>
#include <asm/xen/hypervisor.h>
#include <asm/cpu.h>
static void enable_hotplug_cpu(int cpu)
{
if (!cpu_present(cpu))
xen_arch_register_cpu(cpu);
set_cpu_present(cpu, true);
}
static void disable_hotplug_cpu(int cpu)
{
if (!cpu_is_hotpluggable(cpu))
return;
lock_device_hotplug();
if (cpu_online(cpu))
device_offline(get_cpu_device(cpu));
if (!cpu_online(cpu) && cpu_present(cpu)) {
xen_arch_unregister_cpu(cpu);
set_cpu_present(cpu, false);
}
unlock_device_hotplug();
}
static int vcpu_online(unsigned int cpu)
{
int err;
char dir[16], state[16];
sprintf(dir, "cpu/%u", cpu);
err = xenbus_scanf(XBT_NIL, dir, "availability", "%15s", state);
if (err != 1) {
if (!xen_initial_domain())
pr_err("Unable to read cpu state\n");
return err;
}
if (strcmp(state, "online") == 0)
return 1;
else if (strcmp(state, "offline") == 0)
return 0;
pr_err("unknown state(%s) on CPU%d\n", state, cpu);
return -EINVAL;
}
static void vcpu_hotplug(unsigned int cpu)
{
if (cpu >= nr_cpu_ids || !cpu_possible(cpu))
return;
switch (vcpu_online(cpu)) {
case 1:
enable_hotplug_cpu(cpu);
break;
case 0:
disable_hotplug_cpu(cpu);
break;
default:
break;
}
}
static void handle_vcpu_hotplug_event(struct xenbus_watch *watch,
const char *path, const char *token)
{
unsigned int cpu;
char *cpustr;
cpustr = strstr(path, "cpu/");
if (cpustr != NULL) {
sscanf(cpustr, "cpu/%u", &cpu);
vcpu_hotplug(cpu);
}
}
static int setup_cpu_watcher(struct notifier_block *notifier,
unsigned long event, void *data)
{
int cpu;
static struct xenbus_watch cpu_watch = {
.node = "cpu",
Annotation
- Immediate include surface: `linux/notifier.h`, `xen/xen.h`, `xen/xenbus.h`, `asm/xen/hypervisor.h`, `asm/cpu.h`.
- Detected declarations: `function enable_hotplug_cpu`, `function disable_hotplug_cpu`, `function vcpu_online`, `function vcpu_hotplug`, `function handle_vcpu_hotplug_event`, `function setup_cpu_watcher`, `function for_each_possible_cpu`, `function setup_vcpu_hotplug_event`.
- Atlas domain: Driver Families / drivers/xen.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.