arch/x86/kernel/cpu/mce/genpool.c
Source file repositories/reference/linux-study-clean/arch/x86/kernel/cpu/mce/genpool.c
File Facts
- System
- Linux kernel
- Corpus path
arch/x86/kernel/cpu/mce/genpool.c- Extension
.c- Size
- 3708 bytes
- Lines
- 157
- Domain
- Architecture Layer
- Bucket
- arch/x86
- Inferred role
- Architecture Layer: implementation source
- Status
- source implementation candidate
Why This File Exists
CPU and platform-specific kernel glue: boot entry, traps, syscall entry, interrupts, page tables, context switch, and low-level barriers.
- CPU and platform-specific kernel glue: boot entry, traps, syscall entry, interrupts, page tables, context switch, and low-level barriers.
- 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/smp.hlinux/mm.hlinux/genalloc.hlinux/llist.hinternal.h
Detected Declarations
function is_duplicate_mce_recordfunction llist_for_each_entryfunction recordsfunction mce_gen_pool_processfunction mce_gen_pool_emptyfunction mce_gen_pool_addfunction mce_gen_pool_createfunction mce_gen_pool_init
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0-only
/*
* MCE event pool management in MCE context
*
* Copyright (C) 2015 Intel Corp.
* Author: Chen, Gong <gong.chen@linux.intel.com>
*/
#include <linux/smp.h>
#include <linux/mm.h>
#include <linux/genalloc.h>
#include <linux/llist.h>
#include "internal.h"
/*
* printk() is not safe in MCE context. This is a lock-less memory allocator
* used to save error information organized in a lock-less list.
*
* This memory pool is only to be used to save MCE records in MCE context.
* MCE events are rare, so a fixed size memory pool should be enough.
* Allocate on a sliding scale based on number of CPUs.
*/
#define MCE_MIN_ENTRIES 80
#define MCE_PER_CPU 2
static struct gen_pool *mce_evt_pool;
static LLIST_HEAD(mce_event_llist);
/*
* Compare the record "t" with each of the records on list "l" to see if
* an equivalent one is present in the list.
*/
static bool is_duplicate_mce_record(struct mce_evt_llist *t, struct mce_evt_llist *l)
{
struct mce_hw_err *err1, *err2;
struct mce_evt_llist *node;
err1 = &t->err;
llist_for_each_entry(node, &l->llnode, llnode) {
err2 = &node->err;
if (!mce_cmp(&err1->m, &err2->m))
return true;
}
return false;
}
/*
* The system has panicked - we'd like to peruse the list of MCE records
* that have been queued, but not seen by anyone yet. The list is in
* reverse time order, so we need to reverse it. While doing that we can
* also drop duplicate records (these were logged because some banks are
* shared between cores or by all threads on a socket).
*/
struct llist_node *mce_gen_pool_prepare_records(void)
{
struct llist_node *head;
LLIST_HEAD(new_head);
struct mce_evt_llist *node, *t;
head = llist_del_all(&mce_event_llist);
if (!head)
return NULL;
/* squeeze out duplicates while reversing order */
llist_for_each_entry_safe(node, t, head, llnode) {
if (!is_duplicate_mce_record(node, t))
llist_add(&node->llnode, &new_head);
}
return new_head.first;
}
void mce_gen_pool_process(struct work_struct *__unused)
{
struct mce_evt_llist *node, *tmp;
struct llist_node *head;
struct mce *mce;
head = llist_del_all(&mce_event_llist);
if (!head)
return;
head = llist_reverse_order(head);
llist_for_each_entry_safe(node, tmp, head, llnode) {
mce = &node->err.m;
blocking_notifier_call_chain(&x86_mce_decoder_chain, 0, mce);
gen_pool_free(mce_evt_pool, (unsigned long)node, sizeof(*node));
}
}
Annotation
- Immediate include surface: `linux/smp.h`, `linux/mm.h`, `linux/genalloc.h`, `linux/llist.h`, `internal.h`.
- Detected declarations: `function is_duplicate_mce_record`, `function llist_for_each_entry`, `function records`, `function mce_gen_pool_process`, `function mce_gen_pool_empty`, `function mce_gen_pool_add`, `function mce_gen_pool_create`, `function mce_gen_pool_init`.
- Atlas domain: Architecture Layer / arch/x86.
- Implementation status: source 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.