watchdog_hrtimer_pretimeout.c 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * (c) Copyright 2021 Hewlett Packard Enterprise Development LP.
  4. */
  5. #include <linux/hrtimer.h>
  6. #include <linux/watchdog.h>
  7. #include "watchdog_core.h"
  8. #include "watchdog_pretimeout.h"
  9. static enum hrtimer_restart watchdog_hrtimer_pretimeout(struct hrtimer *timer)
  10. {
  11. struct watchdog_core_data *wd_data;
  12. wd_data = container_of(timer, struct watchdog_core_data, pretimeout_timer);
  13. watchdog_notify_pretimeout(wd_data->wdd);
  14. return HRTIMER_NORESTART;
  15. }
  16. void watchdog_hrtimer_pretimeout_init(struct watchdog_device *wdd)
  17. {
  18. struct watchdog_core_data *wd_data = wdd->wd_data;
  19. hrtimer_init(&wd_data->pretimeout_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
  20. wd_data->pretimeout_timer.function = watchdog_hrtimer_pretimeout;
  21. }
  22. void watchdog_hrtimer_pretimeout_start(struct watchdog_device *wdd)
  23. {
  24. if (!(wdd->info->options & WDIOF_PRETIMEOUT) &&
  25. !watchdog_pretimeout_invalid(wdd, wdd->pretimeout))
  26. hrtimer_start(&wdd->wd_data->pretimeout_timer,
  27. ktime_set(wdd->timeout - wdd->pretimeout, 0),
  28. HRTIMER_MODE_REL);
  29. else
  30. hrtimer_cancel(&wdd->wd_data->pretimeout_timer);
  31. }
  32. void watchdog_hrtimer_pretimeout_stop(struct watchdog_device *wdd)
  33. {
  34. hrtimer_cancel(&wdd->wd_data->pretimeout_timer);
  35. }