kernel/watchdog_buddy.c
Source file repositories/reference/linux-study-clean/kernel/watchdog_buddy.c
File Facts
- System
- Linux kernel
- Corpus path
kernel/watchdog_buddy.c- Extension
.c- Size
- 2834 bytes
- Lines
- 104
- 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.
Dependency Surface
linux/cpu.hlinux/cpumask.hlinux/kernel.hlinux/nmi.hlinux/percpu-defs.h
Detected Declarations
function watchdog_next_cpufunction watchdog_hardlockup_probefunction watchdog_hardlockup_enablefunction watchdog_hardlockup_disablefunction watchdog_buddy_check_hardlockup
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
#include <linux/cpu.h>
#include <linux/cpumask.h>
#include <linux/kernel.h>
#include <linux/nmi.h>
#include <linux/percpu-defs.h>
static cpumask_t __read_mostly watchdog_cpus;
static unsigned int watchdog_next_cpu(unsigned int cpu)
{
unsigned int next_cpu;
next_cpu = cpumask_next_wrap(cpu, &watchdog_cpus);
if (next_cpu == cpu)
return nr_cpu_ids;
return next_cpu;
}
int __init watchdog_hardlockup_probe(void)
{
watchdog_hardlockup_miss_thresh = 3;
return 0;
}
void watchdog_hardlockup_enable(unsigned int cpu)
{
unsigned int next_cpu;
/*
* The new CPU will be marked online before the hrtimer interrupt
* gets a chance to run on it. If another CPU tests for a
* hardlockup on the new CPU before it has run its the hrtimer
* interrupt, it will get a false positive. Touch the watchdog on
* the new CPU to delay the check for at least 3 sampling periods
* to guarantee one hrtimer has run on the new CPU.
*/
watchdog_hardlockup_touch_cpu(cpu);
/*
* We are going to check the next CPU. Our watchdog_hrtimer
* need not be zero if the CPU has already been online earlier.
* Touch the watchdog on the next CPU to avoid false positive
* if we try to check it in less then 3 interrupts.
*/
next_cpu = watchdog_next_cpu(cpu);
if (next_cpu < nr_cpu_ids)
watchdog_hardlockup_touch_cpu(next_cpu);
/*
* Makes sure that watchdog is touched on this CPU before
* other CPUs could see it in watchdog_cpus. The counter
* part is in watchdog_buddy_check_hardlockup().
*/
smp_wmb();
cpumask_set_cpu(cpu, &watchdog_cpus);
}
void watchdog_hardlockup_disable(unsigned int cpu)
{
unsigned int next_cpu = watchdog_next_cpu(cpu);
/*
* Offlining this CPU will cause the CPU before this one to start
* checking the one after this one. If this CPU just finished checking
* the next CPU and updating hrtimer_interrupts_saved, and then the
* previous CPU checks it within one sample period, it will trigger a
* false positive. Touch the watchdog on the next CPU to prevent it.
*/
if (next_cpu < nr_cpu_ids)
watchdog_hardlockup_touch_cpu(next_cpu);
/*
* Makes sure that watchdog is touched on the next CPU before
* this CPU disappear in watchdog_cpus. The counter part is in
* watchdog_buddy_check_hardlockup().
*/
smp_wmb();
cpumask_clear_cpu(cpu, &watchdog_cpus);
}
void watchdog_buddy_check_hardlockup(int hrtimer_interrupts)
{
unsigned int next_cpu;
/* check for a hardlockup on the next CPU */
Annotation
- Immediate include surface: `linux/cpu.h`, `linux/cpumask.h`, `linux/kernel.h`, `linux/nmi.h`, `linux/percpu-defs.h`.
- Detected declarations: `function watchdog_next_cpu`, `function watchdog_hardlockup_probe`, `function watchdog_hardlockup_enable`, `function watchdog_hardlockup_disable`, `function watchdog_buddy_check_hardlockup`.
- Atlas domain: Core OS / Scheduler, Processes, Timers, Sync, And Syscalls.
- 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.