[PATCH 2/5] PM: runtime: Convert last_busy to atomic64_t
From: Brian Norris
Date: Fri Oct 02 2026 - 19:08:15 EST
I want to use the atomic64 compare/exchange helpers. There are no
similar 32-bit-portable helpers for non-atomic64_t.
Signed-off-by: Brian Norris <briannorris@xxxxxxxxxxxx>
---
This conflicts with some pending work I have here:
[PATCH 2/5] PM: runtime: Avoid racy clock checks for autosuspend-retry
https://lore.kernel.org/all/20260929114714.2.Id0a3276d23d30e0b5fd4d6dca730be0f9d8fe018@changeid/
It shouldn't be much trouble for me to rework one of the two, pending
feedback on whether my approaches are acceptable.
drivers/base/power/runtime.c | 4 +++-
include/linux/pm.h | 3 ++-
include/linux/pm_runtime.h | 2 +-
3 files changed, 6 insertions(+), 3 deletions(-)
diff --git a/drivers/base/power/runtime.c b/drivers/base/power/runtime.c
index e70726b499e7..9eed1f79429d 100644
--- a/drivers/base/power/runtime.c
+++ b/drivers/base/power/runtime.c
@@ -5,6 +5,8 @@
* Copyright (c) 2009 Rafael J. Wysocki <rjw@xxxxxxx>, Novell Inc.
* Copyright (C) 2010 Alan Stern <stern@xxxxxxxxxxxxxxxxxxx>
*/
+
+#include <linux/atomic.h>
#include <linux/sched/mm.h>
#include <linux/ktime.h>
#include <linux/hrtimer.h>
@@ -186,7 +188,7 @@ u64 pm_runtime_autosuspend_expiration(struct device *dev)
if (autosuspend_delay < 0)
return 0;
- expires = READ_ONCE(dev->power.last_busy);
+ expires = atomic64_read(&dev->power.last_busy);
expires += (u64)autosuspend_delay * NSEC_PER_MSEC;
if (expires > ktime_get_mono_fast_ns())
return expires; /* Expires in the future */
diff --git a/include/linux/pm.h b/include/linux/pm.h
index ef3f1310e749..531e46ff878e 100644
--- a/include/linux/pm.h
+++ b/include/linux/pm.h
@@ -8,6 +8,7 @@
#ifndef _LINUX_PM_H
#define _LINUX_PM_H
+#include <linux/atomic.h>
#include <linux/completion.h>
#include <linux/export.h>
#include <linux/hrtimer_types.h>
@@ -812,7 +813,7 @@ struct dev_pm_info {
enum rpm_status last_status;
int runtime_error;
int autosuspend_delay;
- u64 last_busy;
+ atomic64_t last_busy;
u64 active_time;
u64 suspended_time;
u64 accounting_timestamp;
diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
index 322e3b17f987..289fa72c0af7 100644
--- a/include/linux/pm_runtime.h
+++ b/include/linux/pm_runtime.h
@@ -242,7 +242,7 @@ static inline bool pm_runtime_has_no_callbacks(struct device *dev)
*/
static inline void pm_runtime_mark_last_busy(struct device *dev)
{
- WRITE_ONCE(dev->power.last_busy, ktime_get_mono_fast_ns());
+ atomic64_set(&dev->power.last_busy, ktime_get_mono_fast_ns());
}
/**
--
2.56.0.rc1.315.gc6ed9934b7-goog