lib/cpu_rmap.c
Source file repositories/reference/linux-study-clean/lib/cpu_rmap.c
File Facts
- System
- Linux kernel
- Corpus path
lib/cpu_rmap.c- Extension
.c- Size
- 8356 bytes
- Lines
- 340
- Domain
- Kernel Services
- Bucket
- lib
- Inferred role
- Kernel Services: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
Shared kernel service surface used by multiple subsystems, including helpers, cryptography, virtualization support, and async I/O infrastructure.
- Shared kernel service surface used by multiple subsystems, including helpers, cryptography, virtualization support, and async I/O infrastructure.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- 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/cpu_rmap.hlinux/interrupt.hlinux/export.h
Detected Declarations
struct irq_gluefunction cpu_rmap_releasefunction cpu_rmap_getfunction cpu_rmap_putfunction cpu_rmap_copy_neighfunction for_each_cpufunction debug_print_rmapfunction for_each_possible_cpufunction debug_print_rmapfunction cpu_rmap_addfunction cpu_rmap_updatefunction free_irq_cpu_rmapfunction irq_cpu_rmap_notifyfunction irq_cpu_rmap_releasefunction irq_cpu_rmap_removefunction request_irqexport alloc_cpu_rmapexport cpu_rmap_putexport cpu_rmap_addexport cpu_rmap_updateexport free_irq_cpu_rmapexport irq_cpu_rmap_removeexport irq_cpu_rmap_add
Annotated Snippet
struct irq_glue {
struct irq_affinity_notify notify;
struct cpu_rmap *rmap;
u16 index;
};
/**
* free_irq_cpu_rmap - free a CPU affinity reverse-map used for IRQs
* @rmap: Reverse-map allocated with alloc_irq_cpu_map(), or %NULL
*
* Must be called in process context, before freeing the IRQs.
*/
void free_irq_cpu_rmap(struct cpu_rmap *rmap)
{
struct irq_glue *glue;
u16 index;
if (!rmap)
return;
for (index = 0; index < rmap->size; index++) {
glue = rmap->obj[index];
if (glue)
irq_set_affinity_notifier(glue->notify.irq, NULL);
}
cpu_rmap_put(rmap);
}
EXPORT_SYMBOL(free_irq_cpu_rmap);
/**
* irq_cpu_rmap_notify - callback for IRQ subsystem when IRQ affinity updated
* @notify: struct irq_affinity_notify passed by irq/manage.c
* @mask: cpu mask for new SMP affinity
*
* This is executed in workqueue context.
*/
static void
irq_cpu_rmap_notify(struct irq_affinity_notify *notify, const cpumask_t *mask)
{
struct irq_glue *glue =
container_of(notify, struct irq_glue, notify);
int rc;
rc = cpu_rmap_update(glue->rmap, glue->index, mask);
if (rc)
pr_warn("irq_cpu_rmap_notify: update failed: %d\n", rc);
}
/**
* irq_cpu_rmap_release - reclaiming callback for IRQ subsystem
* @ref: kref to struct irq_affinity_notify passed by irq/manage.c
*/
static void irq_cpu_rmap_release(struct kref *ref)
{
struct irq_glue *glue =
container_of(ref, struct irq_glue, notify.kref);
glue->rmap->obj[glue->index] = NULL;
cpu_rmap_put(glue->rmap);
kfree(glue);
}
/**
* irq_cpu_rmap_remove - remove an IRQ from a CPU affinity reverse-map
* @rmap: The reverse-map
* @irq: The IRQ number
*/
int irq_cpu_rmap_remove(struct cpu_rmap *rmap, int irq)
{
return irq_set_affinity_notifier(irq, NULL);
}
EXPORT_SYMBOL(irq_cpu_rmap_remove);
/**
* irq_cpu_rmap_add - add an IRQ to a CPU affinity reverse-map
* @rmap: The reverse-map
* @irq: The IRQ number
*
* This adds an IRQ affinity notifier that will update the reverse-map
* automatically.
*
* Must be called in process context, after the IRQ is allocated but
* before it is bound with request_irq().
*/
int irq_cpu_rmap_add(struct cpu_rmap *rmap, int irq)
{
struct irq_glue *glue = kzalloc_obj(*glue);
int rc;
Annotation
- Immediate include surface: `linux/cpu_rmap.h`, `linux/interrupt.h`, `linux/export.h`.
- Detected declarations: `struct irq_glue`, `function cpu_rmap_release`, `function cpu_rmap_get`, `function cpu_rmap_put`, `function cpu_rmap_copy_neigh`, `function for_each_cpu`, `function debug_print_rmap`, `function for_each_possible_cpu`, `function debug_print_rmap`, `function cpu_rmap_add`.
- Atlas domain: Kernel Services / lib.
- Implementation status: integration implementation candidate.
- 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.