-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
watchdog: Add hrtimer-based pretimeout feature
This adds the option to use a hrtimer to generate a watchdog pretimeout event for hardware watchdogs that do not natively support watchdog pretimeouts. With this enabled, all watchdogs will appear to have pretimeout support in userspace. If no pretimeout value is set, there will be no change in the watchdog's behavior. If a pretimeout value is set for a specific watchdog that does not have built-in pretimeout support, a timer will be started that should fire at the specified time before the watchdog timeout would occur. When the watchdog is successfully pinged, the timer will be restarted. If the timer is allowed to fire it will generate a pretimeout event. However because a software timer is used, it may not be able to fire in every circumstance. If the watchdog does support a pretimeout natively, that functionality will be used instead of the hrtimer. The general design of this feaure was inspired by the software watchdog, specifically its own pretimeout implementation. However the software watchdog and this feature are completely independent. They can be used together; with or without CONFIG_SOFT_WATCHDOG_PRETIMEOUT enabled. The main advantage of using the hrtimer pretimeout with a hardware watchdog, compared to running the software watchdog with a hardware watchdog, is that if the hardware watchdog driver is unable to ping the watchdog (e.g. due to a bus or communication error), then the hrtimer pretimeout would still fire whereas the software watchdog would not. Signed-off-by: Curtis Klein <curtis.klein@hpe.com> Reviewed-by: Guenter Roeck <linux@roeck-us.net> Link: https://lore.kernel.org/r/1612383090-27110-1-git-send-email-curtis.klein@hpe.com Signed-off-by: Guenter Roeck <linux@roeck-us.net> Signed-off-by: Wim Van Sebroeck <wim@linux-watchdog.org>
- Loading branch information
1 parent
e1138ce
commit 7b7d2fd
Showing
6 changed files
with
121 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// SPDX-License-Identifier: GPL-2.0 | ||
/* | ||
* (c) Copyright 2021 Hewlett Packard Enterprise Development LP. | ||
*/ | ||
|
||
#include <linux/hrtimer.h> | ||
#include <linux/watchdog.h> | ||
|
||
#include "watchdog_core.h" | ||
#include "watchdog_pretimeout.h" | ||
|
||
static enum hrtimer_restart watchdog_hrtimer_pretimeout(struct hrtimer *timer) | ||
{ | ||
struct watchdog_core_data *wd_data; | ||
|
||
wd_data = container_of(timer, struct watchdog_core_data, pretimeout_timer); | ||
|
||
watchdog_notify_pretimeout(wd_data->wdd); | ||
return HRTIMER_NORESTART; | ||
} | ||
|
||
void watchdog_hrtimer_pretimeout_init(struct watchdog_device *wdd) | ||
{ | ||
struct watchdog_core_data *wd_data = wdd->wd_data; | ||
|
||
hrtimer_init(&wd_data->pretimeout_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); | ||
wd_data->pretimeout_timer.function = watchdog_hrtimer_pretimeout; | ||
} | ||
|
||
void watchdog_hrtimer_pretimeout_start(struct watchdog_device *wdd) | ||
{ | ||
if (!(wdd->info->options & WDIOF_PRETIMEOUT) && | ||
!watchdog_pretimeout_invalid(wdd, wdd->pretimeout)) | ||
hrtimer_start(&wdd->wd_data->pretimeout_timer, | ||
ktime_set(wdd->timeout - wdd->pretimeout, 0), | ||
HRTIMER_MODE_REL); | ||
else | ||
hrtimer_cancel(&wdd->wd_data->pretimeout_timer); | ||
} | ||
|
||
void watchdog_hrtimer_pretimeout_stop(struct watchdog_device *wdd) | ||
{ | ||
hrtimer_cancel(&wdd->wd_data->pretimeout_timer); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters