drivers/xen/pcpu.c
Source file repositories/reference/linux-study-clean/drivers/xen/pcpu.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/xen/pcpu.c- Extension
.c- Size
- 9524 bytes
- Lines
- 426
- Domain
- Driver Families
- Bucket
- drivers/xen
- Inferred role
- Driver Families: operation-table or driver-model contract
- Status
- pattern 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 an operation table; this is where Linux turns generic core objects into subsystem-specific behavior.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/interrupt.hlinux/spinlock.hlinux/cpu.hlinux/stat.hlinux/capability.hxen/xen.hxen/acpi.hxen/xenbus.hxen/events.hxen/interface/platform.hasm/xen/hypervisor.hasm/xen/hypercall.hacpi/processor.h
Detected Declarations
struct pcpufunction xen_pcpu_downfunction xen_pcpu_upfunction online_showfunction online_storefunction pcpu_dev_is_visiblefunction xen_pcpu_onlinefunction pcpu_online_statusfunction xen_pcpu_onlinefunction list_for_each_entryfunction pcpu_releasefunction unregister_and_remove_pcpufunction register_pcpufunction sync_pcpufunction xen_sync_pcpusfunction xen_pcpu_work_fnfunction xen_pcpu_interruptfunction xen_pcpu_initfunction xen_processor_presentfunction xen_sanitize_proc_cap_bits
Annotated Snippet
static const struct bus_type xen_pcpu_subsys = {
.name = "xen_cpu",
.dev_name = "xen_cpu",
};
static DEFINE_MUTEX(xen_pcpu_lock);
static LIST_HEAD(xen_pcpus);
static int xen_pcpu_down(uint32_t cpu_id)
{
struct xen_platform_op op = {
.cmd = XENPF_cpu_offline,
.interface_version = XENPF_INTERFACE_VERSION,
.u.cpu_ol.cpuid = cpu_id,
};
return HYPERVISOR_platform_op(&op);
}
static int xen_pcpu_up(uint32_t cpu_id)
{
struct xen_platform_op op = {
.cmd = XENPF_cpu_online,
.interface_version = XENPF_INTERFACE_VERSION,
.u.cpu_ol.cpuid = cpu_id,
};
return HYPERVISOR_platform_op(&op);
}
static ssize_t online_show(struct device *dev,
struct device_attribute *attr,
char *buf)
{
struct pcpu *cpu = container_of(dev, struct pcpu, dev);
return sprintf(buf, "%u\n", !!(cpu->flags & XEN_PCPU_FLAGS_ONLINE));
}
static ssize_t online_store(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t count)
{
struct pcpu *pcpu = container_of(dev, struct pcpu, dev);
unsigned long long val;
ssize_t ret;
if (!capable(CAP_SYS_ADMIN))
return -EPERM;
if (kstrtoull(buf, 0, &val) < 0)
return -EINVAL;
switch (val) {
case 0:
ret = xen_pcpu_down(pcpu->cpu_id);
break;
case 1:
ret = xen_pcpu_up(pcpu->cpu_id);
break;
default:
ret = -EINVAL;
}
if (ret >= 0)
ret = count;
return ret;
}
static DEVICE_ATTR_RW(online);
static struct attribute *pcpu_dev_attrs[] = {
&dev_attr_online.attr,
NULL
};
static umode_t pcpu_dev_is_visible(struct kobject *kobj,
struct attribute *attr, int idx)
{
struct device *dev = kobj_to_dev(kobj);
/*
* Xen never offline cpu0 due to several restrictions
* and assumptions. This basically doesn't add a sys control
* to user, one cannot attempt to offline BSP.
*/
return dev->id ? attr->mode : 0;
}
static const struct attribute_group pcpu_dev_group = {
.attrs = pcpu_dev_attrs,
Annotation
- Immediate include surface: `linux/interrupt.h`, `linux/spinlock.h`, `linux/cpu.h`, `linux/stat.h`, `linux/capability.h`, `xen/xen.h`, `xen/acpi.h`, `xen/xenbus.h`.
- Detected declarations: `struct pcpu`, `function xen_pcpu_down`, `function xen_pcpu_up`, `function online_show`, `function online_store`, `function pcpu_dev_is_visible`, `function xen_pcpu_online`, `function pcpu_online_status`, `function xen_pcpu_online`, `function list_for_each_entry`.
- Atlas domain: Driver Families / drivers/xen.
- Implementation status: pattern implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
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.