[PATCH 07/15] watchdog: Allow runtime toggle of lockup detector affinity

Qiliang Yuan posted 15 patches 1 week ago
[PATCH 07/15] watchdog: Allow runtime toggle of lockup detector affinity
Posted by Qiliang Yuan 1 week ago
The hardlockup detector threads are affined to CPUs based on the
HK_TYPE_TIMER housekeeping mask at boot. If this mask is updated at
runtime, these threads remain on their original CPUs, potentially
running on isolated cores.

Synchronize watchdog thread affinity with HK_TYPE_TIMER updates.

This ensures that hardlockup detector threads correctly follow the
dynamic housekeeping boundaries for timers.

Signed-off-by: Qiliang Yuan <realwujing@gmail.com>
---
 kernel/watchdog.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/kernel/watchdog.c b/kernel/watchdog.c
index 366122f4a0f87..ef93795729697 100644
--- a/kernel/watchdog.c
+++ b/kernel/watchdog.c
@@ -26,6 +26,7 @@
 #include <linux/sysctl.h>
 #include <linux/tick.h>
 #include <linux/sys_info.h>
+#include <linux/sched/isolation.h>
 
 #include <linux/sched/clock.h>
 #include <linux/sched/debug.h>
@@ -1359,6 +1360,29 @@ static int __init lockup_detector_check(void)
 }
 late_initcall_sync(lockup_detector_check);
 
+static int watchdog_housekeeping_reconfigure(struct notifier_block *nb,
+					    unsigned long action, void *data)
+{
+	if (action == HK_UPDATE_MASK) {
+		struct housekeeping_update *upd = data;
+		unsigned int type = upd->type;
+
+		if (type == HK_TYPE_TIMER) {
+			mutex_lock(&watchdog_mutex);
+			cpumask_copy(&watchdog_cpumask,
+				     housekeeping_cpumask(HK_TYPE_TIMER));
+			proc_watchdog_update(false);
+			mutex_unlock(&watchdog_mutex);
+		}
+	}
+
+	return NOTIFY_OK;
+}
+
+static struct notifier_block watchdog_housekeeping_nb = {
+	.notifier_call = watchdog_housekeeping_reconfigure,
+};
+
 void __init lockup_detector_init(void)
 {
 	if (tick_nohz_full_enabled())
@@ -1373,4 +1397,5 @@ void __init lockup_detector_init(void)
 		allow_lockup_detector_init_retry = true;
 
 	lockup_detector_setup();
+	housekeeping_register_notifier(&watchdog_housekeeping_nb);
 }

-- 
2.43.0
Re: [PATCH 07/15] watchdog: Allow runtime toggle of lockup detector affinity
Posted by Peter Zijlstra 1 week ago
On Wed, Mar 25, 2026 at 05:09:38PM +0800, Qiliang Yuan wrote:
> The hardlockup detector threads are affined to CPUs based on the
> HK_TYPE_TIMER housekeeping mask at boot. If this mask is updated at
> runtime, these threads remain on their original CPUs, potentially
> running on isolated cores.
> 
> Synchronize watchdog thread affinity with HK_TYPE_TIMER updates.

Doesn't the normal watchdog run off of perf, using NMIs? How is that
TIMER?

And again, why do you think you need more than _ONE_ mask?

In the end, NOHZ_FULL needs all the masks to be the same anyway. There
is absolutely no sane reason to have this much configuration space.
Re: [PATCH 07/15] watchdog: Allow runtime toggle of lockup detector affinity
Posted by Qiliang Yuan 2 days, 14 hours ago
On Wed, Mar 25, 2026 at 03:03:24PM +0100, Peter Zijlstra wrote:
> Why would we want to toggle the watchdog? It's linked to the 
> TIMER housekeeping type anyway, right?

Yes, it is. The original patch had an independent toggle that felt 
redundant to you, and I agree. The watchdog affinity follows the 
timer housekeeping state.

I'll simplify this by removing the custom toggle and making it a 
guaranteed side-effect of the global housekeeping state update. 
This keeps the configuration simple while still achieving the goal 
of keeping the isolated cores completely clean during dynamic changes.