watchdog: Add ARM TWD (MPCore private) watchdog driver
PATCH v4 1/1 watchdog: Add ARM TWD (MPCore private) watchdog driver
ARM11 MPCore, Cortex-A5 and Cortex-A9 MPCore systems have a watchdog next to the local timer of every CPU, banked at the same address. The binding "arm,cortex-a9-twd-wdt" exists, but there has been no driver since mpcore_wdt was removed in v3.11, among other reasons because it only ever programmed the CPU that ran the ioctl.
Program, ping and stop the watchdogs of all online CPUs together with on_each_cpu(), and use a CPU hotplug state to arm the watchdog of a CPU coming online while the device is active and to stop it on a CPU going offline, which could not ping it any more. The watchdog is used in reset mode only, its interrupt is not needed.
Bootloaders such as the one of the Securifi Almond+ start the watchdog before booting the kernel. A watchdog found running on any CPU is marked WDOG_HW_RUNNING and taken over with the driver's timeout without being stopped, unless it runs with a different prescaler: the prescaler cannot be changed in watchdog mode. Once the watchdog mode is set it can only be left through the disable register sequence, which is what stop does.
The TWD clock follows the CPU clock on many systems, so rate changes are followed through a clock notifier. A CPU whose power domain went down in idle gets its watchdog set up again on CPU PM exit, and the boot CPU on resume from suspend.
The watchdog is also registered as a restart handler with the default priority, for systems that have no other way to restart: the CPU that restarts the system, the only one left running, lets its own watchdog expire right away.
---
ARM11 MPCore, Cortex-A5 and Cortex-A9 MPCore systems have a watchdog next to the local timer of every CPU. The binding "arm,cortex-a9-twd-wdt" (watchdog/arm,twd-wdt.yaml) exists and 15 dts/dtsi files describe the device, but there has been no driver since mpcore_wdt was removed in v3.11 ("watchdog: delete mpcore_wdt driver"). The reasons given then were that the watchdog is banked per CPU while the driver only programmed the CPU that happened to run the ioctl, that it used request_irq() for a per-CPU interrupt, and that it had no users.
This driver does not use the interrupt (the watchdog runs in reset mode) and programs, pings and stops the watchdogs of all online CPUs with on_each_cpu(). A CPU hotplug state arms the watchdog of a CPU coming online while the device is active and stops it on a CPU going offline. Clock rate changes are followed through a clock notifier, a CPU that lost its watchdog in a deep idle state gets it back on CPU PM exit, and the boot CPU on resume. A watchdog found running at probe time is reported as WDOG_HW_RUNNING and taken over.
The driver was written for the Cortina Systems CS75xx / Securifi Almond+, whose boot loader arms the watchdog: the board resets ~300 s after boot unless it is serviced. It was previously sent as part of a series with the CS75xx interrupt controller, GPIO and I2C drivers; as it is not specific to that SoC, it is now sent on its own. The driver also registers a restart handler with the default (last resort) priority, since the CS75xx platform has no other way to restart.
Tested on a Securifi Almond+ (Cortex-A9, two CPUs): the watchdog left running by the boot loader on both CPUs was taken over ("running on CPU0-1, taking over"); pinged from userspace for 60 s and then left alone, it reset the board when timeleft reached zero; reboot(2) issued from CPU1 restarted the board through the restart handler. Not tested:
CPU hotplug (the platform has no cpu_die yet), suspend and CPU PM.
Open questions:
1. The binding marks clocks as optional, the driver requires them (the rate is needed to compute the timeout). Should the binding be tightened, or should the driver fall back to something when there is
no clock? Several of the existing dts files have no clocks property; the driver does not probe there.
2. Is a separate MAINTAINERS entry for this driver the right thing, or should it only be covered by the watchdog subsystem entry?
---
Changes in v4:
- rebase on v7.4-rc1
- sent on its own, split out of "Cortina Systems CS75xx: interrupt controller, GPIO, I2C and TWD watchdog"
- do not take cpus_read_lock() in the clock notifier, which can be
called from CPU hotplug through cpufreq: publish the armed state and
the rate with WRITE_ONCE() and a full barrier first, then apply them with on_each_cpu(), so that a rate change racing with start is never missed (sashiko-bot)
- restore the watchdog of a CPU on CPU PM exit when its power domain
went down in idle (sashiko-bot)
- register the restart handler with the default priority instead of
128, so that it only runs when nothing else can restart the system
- print the timeout and the clock rate only as debug messages
- Link to v3: https://patch.msgid.link/[email protected]
Changes in v3:
- follow rate changes of the clock, which on many MPCore systems scales with the CPU clock, and restore the watchdog of the boot CPU on resume (sashiko-bot)
- Link to v2: https://patch.msgid.link/[email protected]
Changes in v2:
- do not include <linux/mod_devicetable.h> (Uwe)
- the prescaler cannot be changed in watchdog mode (verified on the board), so a watchdog left running by the boot loader with a different prescaler is stopped before it is reprogrammed (sashiko-bot)
- Link to v1: https://patch.msgid.link/[email protected]
To: Wim Van Sebroeck <[email protected]>
To: Guenter Roeck <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: Russell King <[email protected]>
Cc: [email protected]
--- MAINTAINERS | 6 + drivers/watchdog/Kconfig | 15 ++ drivers/watchdog/Makefile | 1 + drivers/watchdog/arm_twd_wdt.c | 508 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 530 insertions(+)
MAINTAINERS +6 -0
@@ -2544,6 +2544,12 @@ T: git git://git.kernel.org/pub/scm/linux/kernel/git/soc/soc.git F: arch/arm/mach-*/ F: arch/arm/plat-*/ +ARM TWD WATCHDOG DRIVER +M: Fil Dunsky <[email protected]> +L: [email protected] +S: Maintained +F: drivers/watchdog/arm_twd_wdt.c + ARM/ACTIONS SEMI ARCHITECTURE M: Andreas Färber <[email protected]> M: Manivannan Sadhasivam <[email protected]>
drivers/watchdog/Kconfig +15 -0
@@ -465,6 +465,21 @@ config ARM_SP805_WATCHDOG ARM Primecell SP805 Watchdog timer. This will reboot your system when the timeout is reached. +config ARM_TWD_WATCHDOG + tristate "ARM TWD (MPCore private) Watchdog" + depends on HAVE_ARM_TWD || COMPILE_TEST + depends on HAS_IOMEM + select WATCHDOG_CORE + help + Say Y here to include support for the private watchdog found next + to the local (TWD) timer of every CPU in ARM11 MPCore, Cortex-A5 + and Cortex-A9 MPCore systems. The watchdogs of all online CPUs are + driven together. A watchdog left running by the bootloader is + taken over. + + To compile this driver as a module, choose M here: the + module will be called arm_twd_wdt. + config ARM_SBSA_WATCHDOG tristate "ARM SBSA Generic Watchdog" depends on ARM64
drivers/watchdog/Makefile +1 -0
@@ -40,6 +40,7 @@ obj-$(CONFIG_USBPCWATCHDOG) += pcwd_usb.o # ARM Architecture obj-$(CONFIG_ARM_SP805_WATCHDOG) += sp805_wdt.o obj-$(CONFIG_ARM_SBSA_WATCHDOG) += sbsa_gwdt.o +obj-$(CONFIG_ARM_TWD_WATCHDOG) += arm_twd_wdt.o obj-$(CONFIG_ARMADA_37XX_WATCHDOG) += armada_37xx_wdt.o obj-$(CONFIG_AIROHA_WATCHDOG) += airoha_wdt.o obj-$(CONFIG_ASM9260_WATCHDOG) += asm9260_wdt.o
drivers/watchdog/arm_twd_wdt.c new file +508 -0
508 lines not on this page · raw message
---
base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
change-id: 20261015-arm-twd-wdt-71ff5cef355b
Best regards,
Signature · 1 line
Fil Dunsky <[email protected]>
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 6 potential issues to consider: - [Medium] watchdog: arm_twd_wdt: CPU hotplug race in twd_wdt_set_armed() - [Medium] watchdog: arm_twd_wdt…
Thank you for your contribution! Sashiko AI review found 6 potential issues to consider:
- [Medium] watchdog: arm_twd_wdt: CPU hotplug race in twd_wdt_set_armed()
- [Medium] watchdog: arm_twd_wdt: IRQ race in twd_wdt_cpu_online() and offline()
- [Medium] watchdog: arm_twd_wdt: watchdog left armed on probe error or unbind
- [Medium] watchdog: arm_twd_wdt: twd_wdt_clk_notify() resets full timeout on rate change
- [Low] watchdog: arm_twd_wdt: inaccurate suspend comment on CPU watchdog restore
- [Low] watchdog: arm_twd_wdt: full timeout reload on CPU_PM_EXIT in twd_wdt_cpu_pm_notify()
--
commit e14841698f0a4aae63c19877ba002e8fa6489c92
Author: Fil Dunsky <[email protected]>
watchdog: Add ARM TWD (MPCore private) watchdog driver
This commit adds a watchdog driver for the banked per-CPU private watchdog on ARM11 MPCore, Cortex-A5 and Cortex-A9 MPCore systems, managing all online CPUs together across CPU hotplug, clock rate changes, CPU PM and suspend/resume.
Quoted 6 lines
drivers/watchdog/arm_twd_wdt.c new file +0
-0@@ -0,0 +1,508 @@
[ ... ]
Quoted 41 lines
drivers/watchdog/arm_twd_wdt.c new file +41
-0+/* The following run on the CPU whose watchdog they access */ +static void twd_wdt_cpu_stop (void *data) +{ +struct twd_wdt *wdt = data; + +writel (TWD_WDT_DISABLE_KEY1 , wdt->base +TWD_WDT_DISABLE ); +writel (TWD_WDT_DISABLE_KEY2 , wdt->base +TWD_WDT_DISABLE ); +writel (0 , wdt->base +TWD_WDT_CONTROL ); +} + +static void twd_wdt_cpu_start (void *data) +{ +struct twd_wdt *wdt = data; +u32 ctrl =readl (wdt->base +TWD_WDT_CONTROL ); + +/* +* In watchdog mode the prescaler cannot be changed, so a watchdog +* started by the bootloader with a different one is stopped first. +*/ +if ((ctrl &TWD_WDT_CTRL_WD_MODE ) && +FIELD_GET (TWD_WDT_CTRL_PRESCALER , ctrl) !=TWD_WDT_PRESCALE ) +twd_wdt_cpu_stop (wdt); + +/* +* Load the counter before enabling, it may still be zero. A watchdog +* that is already running is reloaded and keeps running, the mode bit +* cannot be cleared by writing the control register. +*/ +writel (twd_wdt_ticks (wdt, wdt->wdd.timeout), wdt->base +TWD_WDT_LOAD ); +writel (FIELD_PREP (TWD_WDT_CTRL_PRESCALER ,TWD_WDT_PRESCALE ) | +TWD_WDT_CTRL_WD_MODE |TWD_WDT_CTRL_ENABLE , + wdt->base +TWD_WDT_CONTROL ); +} + +static void twd_wdt_cpu_ping (void *data) +{ +struct twd_wdt *wdt = data; + +/* In watchdog mode a write to the load register reloads the counter */ +writel (twd_wdt_ticks (wdt, wdt->wdd.timeout), wdt->base +TWD_WDT_LOAD ); +}
[ ... ]
Quoted 40 lines
drivers/watchdog/arm_twd_wdt.c new file +40
-0+static void twd_wdt_set_armed (struct twd_wdt *wdt,bool armed) +{ +WRITE_ONCE (wdt->armed, armed); +/* Pairs with the barrier in twd_wdt_clk_notify() */ +smp_mb (); + +on_each_cpu (armed ? twd_wdt_cpu_start : twd_wdt_cpu_stop, wdt,1 ); +} + +static int twd_wdt_start (struct watchdog_device *wdd) +{ +twd_wdt_set_armed (watchdog_get_drvdata (wdd), true); + +return 0 ; +} + +static int twd_wdt_stop (struct watchdog_device *wdd) +{ +twd_wdt_set_armed (watchdog_get_drvdata (wdd), false); + +return 0 ; +} + +static int twd_wdt_ping (struct watchdog_device *wdd) +{ +on_each_cpu (twd_wdt_cpu_ping,watchdog_get_drvdata (wdd),1 ); + +return 0 ; +} + +static int twd_wdt_set_timeout (struct watchdog_device *wdd,unsigned int t) +{ + wdd->timeout = t; +if (watchdog_active (wdd) ||watchdog_hw_running (wdd)) +twd_wdt_ping (wdd); + +return 0 ; +} + +static unsigned int twd_wdt_get_timeleft (struct watchdog_device *wdd)
drivers/watchdog/arm_twd_wdt.c line 212
Quoted 10 lines
drivers/watchdog/arm_twd_wdt.c new file +10
-0+{ +struct twd_wdt *wdt =watchdog_get_drvdata (wdd); +u64 ticks; + + wdt->counter_min =U32_MAX ; +on_each_cpu (twd_wdt_cpu_counter, wdt,1 ); + ticks = (u64 )wdt->counter_min * (TWD_WDT_PRESCALE +1 ); + +return div_u64 (ticks,READ_ONCE (wdt->rate)); +}
[Severity: Medium]
Can twd_wdt_set_armed() race with CPU hotplug without cpus_read_lock() and leave a watchdog armed on an offline CPU?
twd_wdt_cpu_online() and twd_wdt_cpu_offline() run at CPUHP_AP_ONLINE_DYN in the per-CPU cpuhp/%u thread while the CPU is already or still in cpu_online_mask with local interrupts enabled:
CPU0 CPU1 (cpuhp/1)
_cpu_down()
twd_wdt_cpu_offline()
twd_wdt_cpu_stop(wdt)
twd_wdt_start()
twd_wdt_set_armed(wdt, true)
WRITE_ONCE(wdt->armed, true)
on_each_cpu(twd_wdt_cpu_start, ...)
<IPI>
twd_wdt_cpu_start(wdt)
take_cpu_down()
__cpu_disable() <-- offline & armedCPU1 finishes going offline with its watchdog running; because it is no longer in cpu_online_mask, subsequent pings or stops never reach it and the system resets when the counter expires. During bringup, an on_each_cpu() IPI from twd_wdt_set_armed() can likewise arrive on the target CPU between READ_ONCE(wdt->armed) and twd_wdt_cpu_start()/twd_wdt_cpu_stop() in twd_wdt_cpu_online(), and twd_wdt_get_timeleft() can read TWD_WDT_COUNTER as 0 from an online CPU before twd_wdt_cpu_online() or after twd_wdt_cpu_offline().
Unlike twd_wdt_clk_notify(), twd_wdt_set_armed() and twd_wdt_get_timeleft() are only called from watchdog ops and PM callbacks in task context, so they can guard their operations with cpus_read_lock().
Quoted 34 lines
drivers/watchdog/arm_twd_wdt.c new file +34
-0+ +/* +* The TWD runs from the peripheral clock, which follows the CPU clock. While +* the rate goes up, count with the new rate already: the watchdog then just +* fires later than asked until the change is done. +*/ +static int twd_wdt_clk_notify (struct notifier_block *nb,unsigned long event, +void *data) +{ + struct twd_wdt *wdt = container_of(nb, struct twd_wdt, clk_nb); +struct clk_notifier_data *cnd = data; +unsigned long rate; + +switch (event) { +case PRE_RATE_CHANGE : +if (cnd->new_rate <= cnd->old_rate) +return NOTIFY_OK ; + rate = cnd->new_rate; +break ; +case POST_RATE_CHANGE : + rate = cnd->new_rate; +break ; +case ABORT_RATE_CHANGE : + rate = cnd->old_rate; +break ; +default : +return NOTIFY_DONE ; + } + +if (!rate) +return NOTIFY_OK ; + +WRITE_ONCE (wdt->rate, rate); +/*
drivers/watchdog/arm_twd_wdt.c line 256
Quoted 10 lines
drivers/watchdog/arm_twd_wdt.c new file +10
-0+* Pairs with the barrier in twd_wdt_set_armed(): either the watchdog +* is started with the new rate or it is seen armed here and pinged. +*/ +smp_mb (); + +if (READ_ONCE (wdt->armed)) +on_each_cpu (twd_wdt_cpu_ping, wdt,1 ); + +return NOTIFY_OK ; +}
[Severity: Medium]
Does calling twd_wdt_cpu_ping() on every clock rate change reset the watchdog countdown to the full wdd.timeout instead of scaling the remaining time in TWD_WDT_COUNTER? On systems where cpufreq scales the CPU and TWD clocks during normal activity, frequent rate changes will continually reload TWD_WDT_LOAD and prevent the watchdog from expiring when userspace stops pinging it. Also, when cnd->new_rate > cnd->old_rate, PRE_RATE_CHANGE already updates wdt->rate to cnd->new_rate and pings all CPUs, and POST_RATE_CHANGE then repeats the same update and IPIs.
Quoted 10 lines
drivers/watchdog/arm_twd_wdt.c new file +10
-0+ +/* +* A CPU whose power domain was turned off in idle comes back with its +* watchdog stopped. Only then set it up again: reloading a watchdog that +* kept running would ping it on every idle exit. +*/ +static int twd_wdt_cpu_pm_notify (struct notifier_block *nb, +unsigned long action,void *data) +{ + struct twd_wdt *wdt = container_of(nb, struct twd_wdt, pm_nb);
drivers/watchdog/arm_twd_wdt.c line 276
Quoted 10 lines
drivers/watchdog/arm_twd_wdt.c new file +10
-0+ +if (action !=CPU_PM_EXIT && action !=CPU_PM_ENTER_FAILED ) +return NOTIFY_DONE ; + +if (READ_ONCE (wdt->armed) && + !(readl (wdt->base +TWD_WDT_CONTROL ) &TWD_WDT_CTRL_WD_MODE )) +twd_wdt_cpu_start (wdt); + +return NOTIFY_OK ; +}
[Severity: Low]
When a CPU wakes from a power-off idle state that reset its TWD block, does calling twd_wdt_cpu_start() reload the full wdd.timeout instead of restoring the remaining counter value from CPU_PM_ENTER? If CPUs repeatedly enter and exit deep idle on timer or device interrupts before wdd.timeout elapses, each wakeup resets the countdown and keeps the watchdog from firing even if userspace is hung.
[ ... ]
Quoted 15 lines
drivers/watchdog/arm_twd_wdt.c new file +15
-0+static int twd_wdt_cpu_online (unsigned int cpu,struct hlist_node *node) +{ + struct twd_wdt *wdt = hlist_entry(node, struct twd_wdt, node); + +/* +* Also called for every online CPU at probe time. A watchdog that is +* running while the device is not active would not be pinged. +*/ +if (READ_ONCE (wdt->armed)) +twd_wdt_cpu_start (wdt); +else +twd_wdt_cpu_stop (wdt); + +return 0 ; +}
drivers/watchdog/arm_twd_wdt.c line 332
Quoted 10 lines
drivers/watchdog/arm_twd_wdt.c new file +10
-0+ +static int twd_wdt_cpu_offline (unsigned int cpu,struct hlist_node *node) +{ + struct twd_wdt *wdt = hlist_entry(node, struct twd_wdt, node); + +/* Nobody pings the watchdog of an offline CPU */ +twd_wdt_cpu_stop (wdt); + +return 0 ; +}
[Severity: Medium]
Can an IPI from twd_wdt_clk_notify() or twd_wdt_ping() interrupt twd_wdt_cpu_stop() or twd_wdt_cpu_start() when called from twd_wdt_cpu_online() and twd_wdt_cpu_offline()?
Unlike on_each_cpu(), CPUHP_AP_ONLINE_DYN callbacks run in task context with local interrupts enabled while the CPU is in cpu_online_mask:
twd_wdt_cpu_offline()
twd_wdt_cpu_stop()
writel(TWD_WDT_DISABLE_KEY1, wdt->base + TWD_WDT_DISABLE)
<IPI: twd_wdt_cpu_ping()>
writel(..., wdt->base + TWD_WDT_LOAD)
writel(TWD_WDT_DISABLE_KEY2, wdt->base + TWD_WDT_DISABLE)
writel(0, wdt->base + TWD_WDT_CONTROL) <-- stays in watchdog modeWriting TWD_WDT_LOAD between TWD_WDT_DISABLE_KEY1 and TWD_WDT_DISABLE_KEY2 breaks the hardware unlock sequence, leaving the watchdog armed when the CPU goes offline or when twd_wdt_cpu_start() tries to change the prescaler. In twd_wdt_cpu_start(), an IPI from twd_wdt_clk_notify() arriving after twd_wdt_ticks() reads the old wdt->rate is also overwritten when twd_wdt_cpu_start() resumes and writes the stale tick count to TWD_WDT_LOAD. Disabling local IRQs around the register accesses in twd_wdt_cpu_online() and twd_wdt_cpu_offline() avoids both races.
Quoted 7 lines
drivers/watchdog/arm_twd_wdt.c new file +7
-0+ +static void twd_wdt_remove_instance (void *data) +{ +struct twd_wdt *wdt = data; + +cpuhp_state_remove_instance_nocalls (twd_wdt_hp_state, &wdt->node); +}
[ ... ]
Quoted 7 lines
drivers/watchdog/arm_twd_wdt.c new file +7
-0+on_each_cpu (twd_wdt_cpu_probe, wdt,1 ); +if (!cpumask_empty (&wdt->running)) { +/* +* Left running by the bootloader: the online callback takes it +* over with our settings on every CPU without stopping it. +*/ + wdt->armed = true;
drivers/watchdog/arm_twd_wdt.c line 407
Quoted 10 lines
drivers/watchdog/arm_twd_wdt.c new file +10
-0+set_bit (WDOG_HW_RUNNING , &wdt->wdd.status); + } + + ret =cpuhp_state_add_instance (twd_wdt_hp_state, &wdt->node); +if (ret) +return ret; + + ret =devm_add_action_or_reset (dev, twd_wdt_remove_instance, wdt); +if (ret) +return ret;
[Severity: Medium]
Does using cpuhp_state_remove_instance_nocalls() in twd_wdt_remove_instance() leave the hardware watchdogs armed if probe fails after cpuhp_state_add_instance() or if the device is unbound before /dev/watchdog is opened?
When a bootloader leaves a watchdog running, cpuhp_state_add_instance() arms all online CPUs with wdt->wdd.timeout and sets WDOG_HW_RUNNING. If a later step in twd_wdt_probe() fails, or if the device is unbound while WDOG_ACTIVE is still clear (where watchdog_cdev_unregister() stops the keepalive worker without calling watchdog_stop()), cpuhp_state_remove_instance_nocalls() skips twd_wdt_cpu_offline() and leaves all CPUs counting down to a system reset. Using cpuhp_state_remove_instance() runs twd_wdt_cpu_offline() on each online CPU during teardown.
[ ... ]
Quoted 4 lines
drivers/watchdog/arm_twd_wdt.c new file +4
-0+/* +* The watchdogs lose their state in suspend. The secondary CPUs get theirs +* back through the hotplug state, the boot CPU through resume. +*/
drivers/watchdog/arm_twd_wdt.c line 459
Quoted 10 lines
drivers/watchdog/arm_twd_wdt.c new file +10
-0+static int twd_wdt_suspend (struct device *dev) +{ +struct twd_wdt *wdt =dev_get_drvdata (dev); + + wdt->resume_armed =READ_ONCE (wdt->armed); +if (wdt->resume_armed) +twd_wdt_stop (&wdt->wdd); + +return 0 ; +}
[Severity: Low]
Is the comment above twd_wdt_suspend() accurate about how secondary CPUs have their watchdogs restored? twd_wdt_suspend() runs before pm_sleep_disable_secondary_cpus() and clears wdt->armed via twd_wdt_stop(), so when pm_sleep_enable_secondary_cpus() brings secondary CPUs back online before twd_wdt_resume(), twd_wdt_cpu_online() sees wdt->armed as false and twd_wdt_resume() -> twd_wdt_start() is what restarts the watchdog on all online CPUs.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Guenter Roeck
maintainerQuoted 8 lines · On 11/14/26 06:11, Fil Dunsky via B4 Relay wrote:
From: Fil Dunsky <[email protected]>
ARM11 MPCore, Cortex-A5 and Cortex-A9 MPCore systems have a watchdog next to the local timer of every CPU, banked at the same address. The binding "arm,cortex-a9-twd-wdt" exists, but there has been no driver since
mpcore_wdtwas removed in v3.11, among other reasons because it only ever programmed the CPU that ran the ioctl.
Quoted 6 lines
Program, ping and stop the watchdogs of all online CPUs together with
on_each_cpu(), and use a CPU hotplug state to arm the watchdog of a CPU coming online while the device is active and to stop it on a CPU going offline, which could not ping it any more. The watchdog is used in reset mode only, its interrupt is not needed.
Watchdog drivers are supposed to watch the system as a whole, not on a per-CPU level. This patch goes way beyond the scope of a system watchdog driver. Per-CPU watchdogs are handled in kernel/watchdog.c. I do not think it is a good idea to overlay that with a second per-CPU watchdog mechanism.
Guenter
Hi Guenter,
Quoted 4 lines · Guenter Roeck
Watchdog drivers are supposed to watch the system as a whole, not on a per-CPU level. This patch goes way beyond the scope of a system watchdog driver. Per-CPU watchdogs are handled in
kernel/watchdog.c. I do not think it is a good idea to overlay that with a second per-CPU watchdog mechanism.
Thanks, understood. Watching individual CPUs was not the intent: all the watchdogs get the same timeout and are pinged together from the ioctl, so the driver acts as one system watchdog. Going through every CPU only follows from the registers being banked, and it is what made the driver grow (hotplug state, CPU PM, the races Sashiko found).
The board needs one system watchdog and nothing per CPU: its boot loader starts the watchdog of CPU0 only, and the SoC has no other watchdog. Would a driver along these lines be acceptable?
- use the watchdog of CPU0 only: start, stop, ping and get_timeleft run there through smp_call_function_single();
- no CPU hotplug state: on 32-bit ARM CPU0 cannot be taken offline unless the platform allows it with cpu_can_disable(), and the driver would not probe if CPU0 is hotpluggable;
- the watchdogs of the other CPUs are not used, one found running at probe time is stopped;
- keep following clock rate changes and set the watchdog up again on resume;
- keep the restart handler.
Fil
Guenter Roeck
maintainerQuoted 11 lines · Fil Dunsky
Hi Guenter,
Quoted 4 lines · Guenter Roeck
Watchdog drivers are supposed to watch the system as a whole, not on a per-CPU level. This patch goes way beyond the scope of a system watchdog driver. Per-CPU watchdogs are handled in
kernel/watchdog.c. I do not think it is a good idea to overlay that with a second per-CPU watchdog mechanism.Thanks, understood. Watching individual CPUs was not the intent: all the watchdogs get the same timeout and are pinged together from the ioctl, so the driver acts as one system watchdog. Going through every CPU only
... but a single stalled CPU would trigger it. That overlaps with the per-CPU watchdog timer. Maybe such stall detection is warranted; however, as I mentioned above, it should be implemented as extension of kernel/watchdog.c.
Quoted 7 lines
follows from the registers being banked, and it is what made the driver grow (hotplug state, CPU PM, the races Sashiko found).
The board needs one system watchdog and nothing per CPU: its boot loader starts the watchdog of CPU0 only, and the SoC has no other watchdog. Would a driver along these lines be acceptable?
Quoted 7 lines
- use the watchdog of CPU0 only: start, stop, ping and
get_timeleftrun there throughsmp_call_function_single();
- no CPU hotplug state: on 32-bit ARM CPU0 cannot be taken offline unless the platform allows it withcpu_can_disable(), and the driver would not probe if CPU0 is hotpluggable;
- the watchdogs of the other CPUs are not used, one found running at probe time is stopped;
I'd suggest to simply not check for it in the first place to keep the code simple. It isn't supposed to happen, it does not currently happen as you point out above, and anyone starting it anyway will immediately stop doing so.
Quoted 4 lines
- keep following clock rate changes and set the watchdog up again on resume;
- keep the restart handler.
Yes.
Thanks,
Guenter