mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Yu Zhe <yuzhe@nfschina.com>
To: Peter Zijlstra <peterz@infradead.org>
Cc: tglx@linutronix.de, mingo@redhat.com, bp@alien8.de,
	dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com,
	linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org,
	liqiong@nfschina.com
Subject: Re: [PATCH] x86/aperfmperf: use time_is_before_jiffies(a + b) to replace "jiffies - a > b"
Date: Thu, 28 Jul 2022 10:55:51 +0800	[thread overview]
Message-ID: <ecd4dcc3-321c-e228-96a3-bac08c56794a@nfschina.com> (raw)
In-Reply-To: <YuFhIgsUgNJ+o9xG@worktop.programming.kicks-ass.net>

在 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
>>
>

  reply	other threads:[~2022-07-28  2:56 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-27  3:14 Yu Zhe
2022-07-27 16:00 ` Peter Zijlstra
2022-07-28  2:55   ` Yu Zhe [this message]
2022-07-28 10:30     ` Peter Zijlstra

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ecd4dcc3-321c-e228-96a3-bac08c56794a@nfschina.com \
    --to=yuzhe@nfschina.com \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=hpa@zytor.com \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=liqiong@nfschina.com \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®