drivers/base/topology.c
Source file repositories/reference/linux-study-clean/drivers/base/topology.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/base/topology.c- Extension
.c- Size
- 7172 bytes
- Lines
- 263
- Domain
- Driver Families
- Bucket
- drivers/base
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration 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.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/mm.hlinux/cpu.hlinux/module.hlinux/hardirq.hlinux/topology.h
Detected Declarations
function topology_is_visiblefunction topology_add_devfunction topology_remove_devfunction topology_sysfs_initfunction topology_set_cpu_scalefunction cpu_capacity_showfunction cpu_capacity_sysctl_addfunction cpu_capacity_sysctl_removefunction register_cpu_capacity_sysctlmodule init topology_sysfs_initmodule init register_cpu_capacity_sysctl
Annotated Snippet
device_initcall(topology_sysfs_init);
DEFINE_PER_CPU(unsigned long, cpu_scale) = SCHED_CAPACITY_SCALE;
EXPORT_PER_CPU_SYMBOL_GPL(cpu_scale);
void topology_set_cpu_scale(unsigned int cpu, unsigned long capacity)
{
per_cpu(cpu_scale, cpu) = capacity;
}
static ssize_t cpu_capacity_show(struct device *dev,
struct device_attribute *attr,
char *buf)
{
struct cpu *cpu = container_of(dev, struct cpu, dev);
return sysfs_emit(buf, "%lu\n", topology_get_cpu_scale(cpu->dev.id));
}
static DEVICE_ATTR_RO(cpu_capacity);
static int cpu_capacity_sysctl_add(unsigned int cpu)
{
struct device *cpu_dev = get_cpu_device(cpu);
if (!cpu_dev)
return -ENOENT;
device_create_file(cpu_dev, &dev_attr_cpu_capacity);
return 0;
}
static int cpu_capacity_sysctl_remove(unsigned int cpu)
{
struct device *cpu_dev = get_cpu_device(cpu);
if (!cpu_dev)
return -ENOENT;
device_remove_file(cpu_dev, &dev_attr_cpu_capacity);
return 0;
}
static int register_cpu_capacity_sysctl(void)
{
cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "topology/cpu-capacity",
cpu_capacity_sysctl_add, cpu_capacity_sysctl_remove);
return 0;
}
subsys_initcall(register_cpu_capacity_sysctl);
Annotation
- Immediate include surface: `linux/mm.h`, `linux/cpu.h`, `linux/module.h`, `linux/hardirq.h`, `linux/topology.h`.
- Detected declarations: `function topology_is_visible`, `function topology_add_dev`, `function topology_remove_dev`, `function topology_sysfs_init`, `function topology_set_cpu_scale`, `function cpu_capacity_show`, `function cpu_capacity_sysctl_add`, `function cpu_capacity_sysctl_remove`, `function register_cpu_capacity_sysctl`, `module init topology_sysfs_init`.
- Atlas domain: Driver Families / drivers/base.
- Implementation status: integration 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.