* [PATCH] x86/aperfmperf: use time_is_before_jiffies(a + b) to replace "jiffies - a > b"
@ 2022-07-27 3:14 Yu Zhe
2022-07-27 16:00 ` Peter Zijlstra
0 siblings, 1 reply; 4+ messages in thread
From: Yu Zhe @ 2022-07-27 3:14 UTC (permalink / raw)
To: tglx, mingo, bp, dave.hansen, x86, hpa
Cc: linux-kernel, kernel-janitors, liqiong, Yu Zhe
time_is_before_jiffies deals with timer wrapping correctly.
Signed-off-by: Yu Zhe <yuzhe@nfschina.com>
---
arch/x86/kernel/cpu/aperfmperf.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/x86/kernel/cpu/aperfmperf.c b/arch/x86/kernel/cpu/aperfmperf.c
index 1f60a2b27936..22e0bac3fffe 100644
--- a/arch/x86/kernel/cpu/aperfmperf.c
+++ b/arch/x86/kernel/cpu/aperfmperf.c
@@ -423,7 +423,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_is_before_jiffies(last + MAX_SAMPLE_AGE))
goto fallback;
return div64_u64((cpu_khz * acnt), mcnt);
--
2.11.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] x86/aperfmperf: use time_is_before_jiffies(a + b) to replace "jiffies - a > b"
2022-07-27 3:14 [PATCH] x86/aperfmperf: use time_is_before_jiffies(a + b) to replace "jiffies - a > b" Yu Zhe
@ 2022-07-27 16:00 ` Peter Zijlstra
2022-07-28 2:55 ` Yu Zhe
0 siblings, 1 reply; 4+ messages in thread
From: Peter Zijlstra @ 2022-07-27 16:00 UTC (permalink / raw)
To: Yu Zhe
Cc: tglx, mingo, bp, dave.hansen, x86, hpa, linux-kernel,
kernel-janitors, liqiong
On Wed, Jul 27, 2022 at 11:14:05AM +0800, Yu Zhe wrote:
> time_is_before_jiffies deals with timer wrapping correctly.
Please explain how the current code does not.
>
> Signed-off-by: Yu Zhe <yuzhe@nfschina.com>
> ---
> arch/x86/kernel/cpu/aperfmperf.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/arch/x86/kernel/cpu/aperfmperf.c b/arch/x86/kernel/cpu/aperfmperf.c
> index 1f60a2b27936..22e0bac3fffe 100644
> --- a/arch/x86/kernel/cpu/aperfmperf.c
> +++ b/arch/x86/kernel/cpu/aperfmperf.c
> @@ -423,7 +423,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_is_before_jiffies(last + MAX_SAMPLE_AGE))
> goto fallback;
>
> return div64_u64((cpu_khz * acnt), mcnt);
> --
> 2.11.0
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] x86/aperfmperf: use time_is_before_jiffies(a + b) to replace "jiffies - a > b"
2022-07-27 16:00 ` Peter Zijlstra
@ 2022-07-28 2:55 ` Yu Zhe
2022-07-28 10:30 ` Peter Zijlstra
0 siblings, 1 reply; 4+ messages in thread
From: Yu Zhe @ 2022-07-28 2:55 UTC (permalink / raw)
To: Peter Zijlstra
Cc: tglx, mingo, bp, dave.hansen, x86, hpa, linux-kernel,
kernel-janitors, liqiong
在 2022年07月28日 00:00, Peter Zijlstra 写道:
> On Wed, Jul 27, 2022 at 11:14:05AM +0800, Yu Zhe wrote:
>> time_is_before_jiffies deals with timer wrapping correctly.
> Please explain how the current code does not.
1. If the timer wrap changes in the future you won't have to alter your code.
2. unsigned long ut;
ut = ULONG_MAX + 4;
printf("time_after(ut, ULONG_MAX), ut:%d, %d --> %d\n", ut,
time_after(ut, ULONG_MAX), (ULONG_MAX - ut) < 0);
In this case, time_after returns true, it's correct.
>> Signed-off-by: Yu Zhe <yuzhe@nfschina.com>
>> ---
>> arch/x86/kernel/cpu/aperfmperf.c | 2 +-
>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/arch/x86/kernel/cpu/aperfmperf.c b/arch/x86/kernel/cpu/aperfmperf.c
>> index 1f60a2b27936..22e0bac3fffe 100644
>> --- a/arch/x86/kernel/cpu/aperfmperf.c
>> +++ b/arch/x86/kernel/cpu/aperfmperf.c
>> @@ -423,7 +423,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_is_before_jiffies(last + MAX_SAMPLE_AGE))
>> goto fallback;
>>
>> return div64_u64((cpu_khz * acnt), mcnt);
>> --
>> 2.11.0
>>
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] x86/aperfmperf: use time_is_before_jiffies(a + b) to replace "jiffies - a > b"
2022-07-28 2:55 ` Yu Zhe
@ 2022-07-28 10:30 ` Peter Zijlstra
0 siblings, 0 replies; 4+ messages in thread
From: Peter Zijlstra @ 2022-07-28 10:30 UTC (permalink / raw)
To: Yu Zhe
Cc: tglx, mingo, bp, dave.hansen, x86, hpa, linux-kernel,
kernel-janitors, liqiong
On Thu, Jul 28, 2022 at 10:55:51AM +0800, Yu Zhe wrote:
> 在 2022年07月28日 00:00, Peter Zijlstra 写道:
>
> > On Wed, Jul 27, 2022 at 11:14:05AM +0800, Yu Zhe wrote:
> > > time_is_before_jiffies deals with timer wrapping correctly.
> > Please explain how the current code does not.
>
> 1. If the timer wrap changes in the future you won't have to alter your code.
>
> 2. unsigned long ut;
>
> ut = ULONG_MAX + 4;
>
> printf("time_after(ut, ULONG_MAX), ut:%d, %d --> %d\n", ut,
> time_after(ut, ULONG_MAX), (ULONG_MAX - ut) < 0);
>
>
> In this case, time_after returns true, it's correct.
Now try the same with the existing code...
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2022-07-28 10:31 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-27 3:14 [PATCH] x86/aperfmperf: use time_is_before_jiffies(a + b) to replace "jiffies - a > b" Yu Zhe
2022-07-27 16:00 ` Peter Zijlstra
2022-07-28 2:55 ` Yu Zhe
2022-07-28 10:30 ` Peter Zijlstra
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.