i915_timer_util.c 799 B

123456789101112131415161718192021222324252627282930313233343536
  1. // SPDX-License-Identifier: MIT
  2. /* Copyright © 2025 Intel Corporation */
  3. #include <linux/jiffies.h>
  4. #include "i915_timer_util.h"
  5. void cancel_timer(struct timer_list *t)
  6. {
  7. if (!timer_active(t))
  8. return;
  9. timer_delete(t);
  10. WRITE_ONCE(t->expires, 0);
  11. }
  12. void set_timer_ms(struct timer_list *t, unsigned long timeout)
  13. {
  14. if (!timeout) {
  15. cancel_timer(t);
  16. return;
  17. }
  18. timeout = msecs_to_jiffies(timeout);
  19. /*
  20. * Paranoia to make sure the compiler computes the timeout before
  21. * loading 'jiffies' as jiffies is volatile and may be updated in
  22. * the background by a timer tick. All to reduce the complexity
  23. * of the addition and reduce the risk of losing a jiffy.
  24. */
  25. barrier();
  26. /* Keep t->expires = 0 reserved to indicate a canceled timer. */
  27. mod_timer(t, jiffies + timeout ?: 1);
  28. }