drivers/infiniband/hw/hfi1/affinity.c
Source file repositories/reference/linux-study-clean/drivers/infiniband/hw/hfi1/affinity.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/infiniband/hw/hfi1/affinity.c- Extension
.c- Size
- 30481 bytes
- Lines
- 1170
- Domain
- Driver Families
- Bucket
- drivers/infiniband
- 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.
- 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/topology.hlinux/cpumask.hlinux/interrupt.hlinux/numa.hhfi.haffinity.hsdma.htrace.h
Detected Declarations
function init_cpu_mask_setfunction _cpu_mask_set_gen_incfunction _cpu_mask_set_gen_decfunction cpu_mask_set_get_firstfunction cpu_mask_set_putfunction init_real_cpu_maskfunction node_affinity_initfunction node_affinity_destroyfunction node_affinity_destroy_allfunction node_affinity_add_tailfunction list_for_each_entryfunction per_cpu_affinity_getfunction per_cpu_affinity_put_maxfunction _dev_comp_vect_cpu_getfunction _dev_comp_vect_cpu_putfunction _dev_comp_vect_mappings_destroyfunction _dev_comp_vect_mappings_createfunction hfi1_comp_vectors_set_upfunction hfi1_comp_vectors_clean_upfunction hfi1_comp_vect_mappings_lookupfunction _dev_comp_vect_cpu_mask_initfunction _dev_comp_vect_cpu_mask_clean_upfunction hfi1_dev_affinity_initfunction hfi1_dev_affinity_clean_upfunction hfi1_update_sdma_affinityfunction hfi1_irq_notifier_notifyfunction hfi1_irq_notifier_releasefunction hfi1_cleanup_sdma_notifierfunction get_irq_affinityfunction hfi1_get_irq_affinityfunction hfi1_put_irq_affinityfunction find_hw_thread_maskfunction hfi1_get_proc_affinityfunction hfi1_put_proc_affinity
Annotated Snippet
while ((dev = pci_get_device(ids->vendor, ids->device, dev))) {
node = pcibus_to_node(dev->bus);
if (node < 0)
goto out;
hfi1_per_node_cntr[node]++;
}
ids++;
}
return 0;
out:
/*
* Invalid PCI NUMA node information found, note it, and populate
* our database 1:1.
*/
pr_err("HFI: Invalid PCI NUMA node. Performance may be affected\n");
pr_err("HFI: System BIOS may need to be upgraded\n");
for (node = 0; node < node_affinity.num_possible_nodes; node++)
hfi1_per_node_cntr[node] = 1;
pci_dev_put(dev);
return 0;
}
static void node_affinity_destroy(struct hfi1_affinity_node *entry)
{
free_percpu(entry->comp_vect_affinity);
kfree(entry);
}
void node_affinity_destroy_all(void)
{
struct list_head *pos, *q;
struct hfi1_affinity_node *entry;
mutex_lock(&node_affinity.lock);
list_for_each_safe(pos, q, &node_affinity.list) {
entry = list_entry(pos, struct hfi1_affinity_node,
list);
list_del(pos);
node_affinity_destroy(entry);
}
mutex_unlock(&node_affinity.lock);
kfree(hfi1_per_node_cntr);
}
static struct hfi1_affinity_node *node_affinity_allocate(int node)
{
struct hfi1_affinity_node *entry;
entry = kzalloc_obj(*entry);
if (!entry)
return NULL;
entry->node = node;
entry->comp_vect_affinity = alloc_percpu(u16);
INIT_LIST_HEAD(&entry->list);
return entry;
}
/*
* It appends an entry to the list.
* It *must* be called with node_affinity.lock held.
*/
static void node_affinity_add_tail(struct hfi1_affinity_node *entry)
{
list_add_tail(&entry->list, &node_affinity.list);
}
/* It must be called with node_affinity.lock held */
static struct hfi1_affinity_node *node_affinity_lookup(int node)
{
struct hfi1_affinity_node *entry;
list_for_each_entry(entry, &node_affinity.list, list) {
if (entry->node == node)
return entry;
}
return NULL;
}
static int per_cpu_affinity_get(cpumask_var_t possible_cpumask,
u16 __percpu *comp_vect_affinity)
{
int curr_cpu;
u16 cntr;
Annotation
- Immediate include surface: `linux/topology.h`, `linux/cpumask.h`, `linux/interrupt.h`, `linux/numa.h`, `hfi.h`, `affinity.h`, `sdma.h`, `trace.h`.
- Detected declarations: `function init_cpu_mask_set`, `function _cpu_mask_set_gen_inc`, `function _cpu_mask_set_gen_dec`, `function cpu_mask_set_get_first`, `function cpu_mask_set_put`, `function init_real_cpu_mask`, `function node_affinity_init`, `function node_affinity_destroy`, `function node_affinity_destroy_all`, `function node_affinity_add_tail`.
- Atlas domain: Driver Families / drivers/infiniband.
- Implementation status: source 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.