Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1461330

Re: [RESEND PATCH v4] x86/hpet: Reduce HPET counter read contention

From Dave Hansen <dave.hansen@intel.com>
Newsgroups linux.kernel
Subject Re: [RESEND PATCH v4] x86/hpet: Reduce HPET counter read contention
Date 2016-08-12 19:20 +0200
Message-ID <s5ohH-4zo-7@gated-at.bofh.it> (permalink)
References <s4GA2-f8-39@gated-at.bofh.it> <s53ZD-89S-1@gated-at.bofh.it> <s58FX-2QI-11@gated-at.bofh.it> <s58FX-2QI-9@gated-at.bofh.it> <s5ohH-4zo-9@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


On 08/12/2016 10:01 AM, Waiman Long wrote:
> The reason for using a special lock is that I want both sequence number
> update and locking to be done together atomically. They can be made
> separate as is in the seqlock. However, that will make the code more
> complex to make sure that all the threads see a consistent set of lock
> state and sequence number.

Why do we need a sequence number?  The "cached" HPET itself could be used.

I'm thinking something like below could use a spinlock instead of the
doing a custom cmpxchg sequence.  The spin_is_locked() should allow the
contended "readers" to avoid using atomics.

spinlock_t hpet_lock;
u32 hpet_value;
...
{
	u32 old_hpet = READ_ONCE(hpet_value);
	u32 new_hpet;

	// need to ensure that the spin_is_locked() is ordered after
	// the READ_ONCE().
	smp_rmb();
	// spin_is_locked() doesn't do atomics
	if (!spin_is_locked(&hpet_lock) && spin_trylock(&hpet_lock)) {
		WRITE_ONCE(hpet_value, real_read_hpet());
		spin_unlock(&hpet_lock);
		return hpet_value;
	}
	// Contended case.  We spin here waiting for the guy who holds
	// the lock to write a new value to 'hpet_value'.
	//
	// We know that our old_hpet is older than our check for the
	// spinlock being locked. So, someone must either have already
	// updated it or be updating it.
	do {
		cpu_relax();
		// We do not do a rmb() here.  We don't need a guarantee
		// that this read is up-to-date, just that it will
		// _eventually_ see an up-to-date value.
		new_hpet = READ_ONCE(hpet_value);
	} while (old_hpet == new_hpet);
	return new_hpet;
}

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Re: [RESEND PATCH v4] x86/hpet: Reduce HPET counter read contention Dave Hansen <dave.hansen@intel.com> - 2016-08-11 21:40 +0200
  Re: [RESEND PATCH v4] x86/hpet: Reduce HPET counter read contention Dave Hansen <dave.hansen@intel.com> - 2016-08-12 02:40 +0200
    Re: [RESEND PATCH v4] x86/hpet: Reduce HPET counter read contention Dave Hansen <dave.hansen@intel.com> - 2016-08-12 19:20 +0200
      Re: [RESEND PATCH v4] x86/hpet: Reduce HPET counter read contention Andy Lutomirski <luto@amacapital.net> - 2016-08-12 22:20 +0200
        Re: [RESEND PATCH v4] x86/hpet: Reduce HPET counter read contention Dave Hansen <dave.hansen@intel.com> - 2016-08-12 23:20 +0200
        Re: [RESEND PATCH v4] x86/hpet: Reduce HPET counter read contention Dave Hansen <dave.hansen@intel.com> - 2016-08-12 23:30 +0200

csiph-web