[PATCH v1] X86 architecture (32-bit and 64-bit): Convert to use jiffies macro

From: Chen Yufan
Date: Wed Aug 21 2024 - 23:48:06 EST


Use time_after macro instead of using
jiffies directly to handle wraparound.

Signed-off-by: Chen Yufan <chenyufan@xxxxxxxx>
---
arch/x86/kernel/cpu/aperfmperf.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/arch/x86/kernel/cpu/aperfmperf.c b/arch/x86/kernel/cpu/aperfmperf.c
index 0b69bfbf3..5fe0a7576 100644
--- a/arch/x86/kernel/cpu/aperfmperf.c
+++ b/arch/x86/kernel/cpu/aperfmperf.c
@@ -16,6 +16,7 @@
#include <linux/sched/topology.h>
#include <linux/smp.h>
#include <linux/syscore_ops.h>
++#include <linux/jiffies.h>

#include <asm/cpu.h>
#include <asm/cpu_device_id.h>
@@ -434,7 +435,7 @@ unsigned int arch_freq_get_on_cpu(int cpu)
* Bail on invalid count and when the last update was too long ago,
* which covers idle and NOHZ full CPUs.
*/
- if (!mcnt || (jiffies - last) > MAX_SAMPLE_AGE)
+ if (!mcnt || time_after(jiffies, last + MAX_SAMPLE_AGE))
goto fallback;

return div64_u64((cpu_khz * acnt), mcnt);
--
2.39.0