drivers/ras/cec.c
Source file repositories/reference/linux-study-clean/drivers/ras/cec.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/ras/cec.c- Extension
.c- Size
- 14145 bytes
- Lines
- 609
- Domain
- Driver Families
- Bucket
- drivers/ras
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/mm.hlinux/gfp.hlinux/ras.hlinux/kernel.hlinux/workqueue.hasm/mce.hdebugfs.h
Detected Declarations
function do_spring_cleaningfunction cec_mod_workfunction cec_work_fnfunction __find_elemfunction find_elemfunction del_elemfunction del_lru_elem_unlockedfunction del_lru_elemfunction sanity_checkfunction cec_add_elemfunction u64_getfunction pfn_setfunction decay_interval_setfunction action_threshold_setfunction array_showfunction create_debugfs_nodesfunction cec_notifierfunction mce_is_correctablefunction cec_initfunction parse_cec_param
Annotated Snippet
else if (this_pfn == pfn) {
if (to)
*to = i;
return i;
}
}
/*
* When the loop terminates without finding @pfn, min has the index of
* the element slot where the new @pfn should be inserted. The loop
* terminates when min > max, which means the min index points to the
* bigger element while the max index to the smaller element, in-between
* which the new @pfn belongs to.
*
* For more details, see exercise 1, Section 6.2.1 in TAOCP, vol. 3.
*/
if (to)
*to = min;
return -ENOKEY;
}
static int find_elem(struct ce_array *ca, u64 pfn, unsigned int *to)
{
WARN_ON(!to);
if (!ca->n) {
*to = 0;
return -ENOKEY;
}
return __find_elem(ca, pfn, to);
}
static void del_elem(struct ce_array *ca, int idx)
{
/* Save us a function call when deleting the last element. */
if (ca->n - (idx + 1))
memmove((void *)&ca->array[idx],
(void *)&ca->array[idx + 1],
(ca->n - (idx + 1)) * sizeof(u64));
ca->n--;
}
static u64 del_lru_elem_unlocked(struct ce_array *ca)
{
unsigned int min = FULL_COUNT_MASK;
int i, min_idx = 0;
for (i = 0; i < ca->n; i++) {
unsigned int this = FULL_COUNT(ca->array[i]);
if (min > this) {
min = this;
min_idx = i;
}
}
del_elem(ca, min_idx);
return PFN(ca->array[min_idx]);
}
/*
* We return the 0th pfn in the error case under the assumption that it cannot
* be poisoned and excessive CEs in there are a serious deal anyway.
*/
static u64 __maybe_unused del_lru_elem(void)
{
struct ce_array *ca = &ce_arr;
u64 pfn;
if (!ca->n)
return 0;
mutex_lock(&ce_mutex);
pfn = del_lru_elem_unlocked(ca);
mutex_unlock(&ce_mutex);
return pfn;
}
static bool sanity_check(struct ce_array *ca)
{
bool ret = false;
u64 prev = 0;
int i;
for (i = 0; i < ca->n; i++) {
Annotation
- Immediate include surface: `linux/mm.h`, `linux/gfp.h`, `linux/ras.h`, `linux/kernel.h`, `linux/workqueue.h`, `asm/mce.h`, `debugfs.h`.
- Detected declarations: `function do_spring_cleaning`, `function cec_mod_work`, `function cec_work_fn`, `function __find_elem`, `function find_elem`, `function del_elem`, `function del_lru_elem_unlocked`, `function del_lru_elem`, `function sanity_check`, `function cec_add_elem`.
- Atlas domain: Driver Families / drivers/ras.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
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.