kernel/watchdog_perf.c
Source file repositories/reference/linux-study-clean/kernel/watchdog_perf.c
File Facts
- System
- Linux kernel
- Corpus path
kernel/watchdog_perf.c- Extension
.c- Size
- 7999 bytes
- Lines
- 315
- Domain
- Core OS
- Bucket
- Scheduler, Processes, Timers, Sync, And Syscalls
- Inferred role
- Core OS: implementation source
- Status
- source implementation candidate
Why This File Exists
Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- 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/panic.hlinux/nmi.hlinux/atomic.hlinux/module.hlinux/sched/debug.hasm/irq_regs.hlinux/perf_event.h
Detected Declarations
function watchdog_update_hrtimer_thresholdfunction watchdog_check_timestampfunction watchdog_init_timestampfunction watchdog_check_timestampfunction watchdog_init_timestampfunction watchdog_overflow_callbackfunction watchdog_hardlockup_enablefunction watchdog_hardlockup_disablefunction hardlockup_detector_perf_adjust_periodfunction hardlockup_detector_perf_stopfunction for_each_online_cpufunction hardlockup_detector_perf_restartfunction for_each_online_cpufunction arch_perf_nmi_is_availablefunction watchdog_hardlockup_probefunction hardlockup_config_perf_event
Annotated Snippet
static inline bool watchdog_check_timestamp(void) { return true; }
static inline void watchdog_init_timestamp(void) { }
#endif
static struct perf_event_attr wd_hw_attr = {
.type = PERF_TYPE_HARDWARE,
.config = PERF_COUNT_HW_CPU_CYCLES,
.size = sizeof(struct perf_event_attr),
.pinned = 1,
.disabled = 1,
};
static struct perf_event_attr fallback_wd_hw_attr = {
.type = PERF_TYPE_HARDWARE,
.config = PERF_COUNT_HW_CPU_CYCLES,
.size = sizeof(struct perf_event_attr),
.pinned = 1,
.disabled = 1,
};
/* Callback function for perf event subsystem */
static void watchdog_overflow_callback(struct perf_event *event,
struct perf_sample_data *data,
struct pt_regs *regs)
{
/* Ensure the watchdog never gets throttled */
event->hw.interrupts = 0;
if (panic_in_progress())
return;
if (!watchdog_check_timestamp())
return;
watchdog_hardlockup_check(smp_processor_id(), regs);
}
static struct perf_event *hardlockup_detector_event_create(unsigned int cpu)
{
struct perf_event_attr *wd_attr;
struct perf_event *evt;
wd_attr = &wd_hw_attr;
wd_attr->sample_period = hw_nmi_get_sample_period(watchdog_thresh);
/* Try to register using hardware perf events */
evt = perf_event_create_kernel_counter(wd_attr, cpu, NULL,
watchdog_overflow_callback, NULL);
if (IS_ERR(evt)) {
wd_attr = &fallback_wd_hw_attr;
wd_attr->sample_period = hw_nmi_get_sample_period(watchdog_thresh);
evt = perf_event_create_kernel_counter(wd_attr, cpu, NULL,
watchdog_overflow_callback, NULL);
}
return evt;
}
/**
* watchdog_hardlockup_enable - Enable the local event
* @cpu: The CPU to enable hard lockup on.
*/
void watchdog_hardlockup_enable(unsigned int cpu)
{
struct perf_event *evt;
WARN_ON_ONCE(cpu != smp_processor_id());
evt = hardlockup_detector_event_create(cpu);
if (IS_ERR(evt)) {
pr_debug("Perf event create on CPU %d failed with %ld\n", cpu,
PTR_ERR(evt));
return;
}
/* use original value for check */
if (!atomic_fetch_inc(&watchdog_cpus))
pr_info("Enabled. Permanently consumes one hw-PMU counter.\n");
WARN_ONCE(this_cpu_read(watchdog_ev), "unexpected watchdog_ev leak");
this_cpu_write(watchdog_ev, evt);
watchdog_init_timestamp();
perf_event_enable(evt);
}
/**
* watchdog_hardlockup_disable - Disable the local event
* @cpu: The CPU to enable hard lockup on.
*/
Annotation
- Immediate include surface: `linux/panic.h`, `linux/nmi.h`, `linux/atomic.h`, `linux/module.h`, `linux/sched/debug.h`, `asm/irq_regs.h`, `linux/perf_event.h`.
- Detected declarations: `function watchdog_update_hrtimer_threshold`, `function watchdog_check_timestamp`, `function watchdog_init_timestamp`, `function watchdog_check_timestamp`, `function watchdog_init_timestamp`, `function watchdog_overflow_callback`, `function watchdog_hardlockup_enable`, `function watchdog_hardlockup_disable`, `function hardlockup_detector_perf_adjust_period`, `function hardlockup_detector_perf_stop`.
- Atlas domain: Core OS / Scheduler, Processes, Timers, Sync, And Syscalls.
- 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.