mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Waiman Long <waiman.long@hpe.com>
To: Dave Hansen <dave.hansen@intel.com>
Cc: Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@redhat.com>, "H. Peter Anvin" <hpa@zytor.com>,
	<linux-kernel@vger.kernel.org>, <x86@kernel.org>,
	Jiang Liu <jiang.liu@linux.intel.com>,
	Borislav Petkov <bp@suse.de>, Andy Lutomirski <luto@kernel.org>,
	Prarit Bhargava <prarit@redhat.com>,
	Scott J Norton <scott.norton@hpe.com>,
	Douglas Hatch <doug.hatch@hpe.com>,
	Randy Wright <rwright@hpe.com>,
	John Stultz <john.stultz@linaro.org>
Subject: Re: [RESEND PATCH v4] x86/hpet: Reduce HPET counter read contention
Date: Thu, 11 Aug 2016 19:22:00 -0400	[thread overview]
Message-ID: <57AD0898.7030506@hpe.com> (raw)
In-Reply-To: <57ACD2DE.6080306@intel.com>

On 08/11/2016 03:32 PM, Dave Hansen wrote:
> On 08/10/2016 11:29 AM, Waiman Long wrote:
>> +static cycle_t read_hpet(struct clocksource *cs)
>> +{
>> +	int seq;
>> +
>> +	seq = READ_ONCE(hpet_save.seq);
>> +	if (!HPET_SEQ_LOCKED(seq)) {
> ...
>> +	}
>> +
>> +	/*
>> +	 * Wait until the locked sequence number changes which indicates
>> +	 * that the saved HPET value is up-to-date.
>> +	 */
>> +	while (READ_ONCE(hpet_save.seq) == seq) {
>> +		/*
>> +		 * Since reading the HPET is much slower than a single
>> +		 * cpu_relax() instruction, we use two here in an attempt
>> +		 * to reduce the amount of cacheline contention in the
>> +		 * hpet_save.seq cacheline.
>> +		 */
>> +		cpu_relax();
>> +		cpu_relax();
>> +	}
>> +
>> +	return (cycle_t)READ_ONCE(hpet_save.hpet);
>> +}
> It's a real bummer that this all has to be open-coded.  I have to wonder
> if there were any alternatives that you tried that were simpler.

What do you mean by "open-coded"? Do you mean the function can be inlined?


> Is READ_ONCE()/smp_store_release() really strong enough here?  It
> guarantees ordering, but you need ordering *and* a guarantee that your
> write is visible to the reader.  Don't you need actual barriers for
> that?  Otherwise, you might be seeing a stale HPET value, and the spin
> loop that you did waiting for it to be up-to-date was worthless.  The
> seqlock code, uses barriers, btw.

The cmpxchg() and smp_store_release() act as the lock/unlock sequence 
with the proper barriers. Another important point is that the hpet value 
is visible to the other readers  before the sequence number. This is 
what the smp_store_release() is providing. cmpxchg is an actual barrier, 
even though smp_store_release() is not. However, the x86 architecture 
will guarantee the writes are in order, I think.

> Also, since you're fundamentally reading a second-hand HPET value, does
> that have any impact on the precision of the HPET as a timesource?  Or,
> is it so coarse already that this isn't an issue?

There can always be unexpected latency in the returned time value, such 
as an interrupt or NMI. I think as long as the time won't go backward, 
it should be fine.

Cheers,
Longman

  reply	other threads:[~2016-08-11 23:22 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-10 18:29 Waiman Long
2016-08-10 18:37 ` Long, Wai Man
2016-08-10 19:01   ` Prarit Bhargava
2016-08-11 19:32 ` Dave Hansen
2016-08-11 23:22   ` Waiman Long [this message]
2016-08-12  0:31     ` Dave Hansen
2016-08-12 17:01       ` Waiman Long
2016-08-12 17:16         ` Dave Hansen
2016-08-12 18:31           ` Waiman Long
2016-08-12 20:18             ` Andy Lutomirski
2016-08-12 21:10               ` Waiman Long
2016-08-12 21:20                 ` Dave Hansen
2016-08-12 21:32                   ` Waiman Long
2016-08-12 21:16               ` Dave Hansen
2016-08-12 21:32                 ` Waiman Long
  -- strict thread matches above, loose matches on Subject: below --
2016-06-17 20:20 Waiman Long
2016-07-13 15:02 ` Waiman Long

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=57AD0898.7030506@hpe.com \
    --to=waiman.long@hpe.com \
    --cc=bp@suse.de \
    --cc=dave.hansen@intel.com \
    --cc=doug.hatch@hpe.com \
    --cc=hpa@zytor.com \
    --cc=jiang.liu@linux.intel.com \
    --cc=john.stultz@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luto@kernel.org \
    --cc=mingo@redhat.com \
    --cc=prarit@redhat.com \
    --cc=rwright@hpe.com \
    --cc=scott.norton@hpe.com \
    --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

Powered by JetHome