* [PATCH] lib/spinlock_debug: Tweak the loop time to fit different _delay() @ 2014-04-30 22:40 Wang, Xiaoming 2014-04-30 8:50 ` Peter Zijlstra 2014-04-30 8:55 ` Peter Zijlstra 0 siblings, 2 replies; 5+ messages in thread From: Wang, Xiaoming @ 2014-04-30 22:40 UTC (permalink / raw) To: peterz, mingo, linux-kernel; +Cc: chuansheng.liu, xiaoming.wang loops_per_jiffy*Hz is not always 1 second exactly it depends on the realization of _delay() . delay_tsc is used as _delay() in arch/x86/lib/delay.c It makes loop loops_per_jiffy larger than exception and causes one thread can not obtain the spin lock for a long time which may trigger HARD LOCKUP in this case. So we use cpu_clock() which is more accurate. Signed-off-by: Chuansheng Liu <chuansheng.liu@intel.com> Signed-off-by: xiaoming wang <xiaoming.wang@intel.com> --- kernel/locking/spinlock_debug.c | 9 ++++++--- 1 files changed, 6 insertions(+), 3 deletions(-) diff --git a/kernel/locking/spinlock_debug.c b/kernel/locking/spinlock_debug.c index 0374a59..471d26c 100644 --- a/kernel/locking/spinlock_debug.c +++ b/kernel/locking/spinlock_debug.c @@ -105,10 +105,13 @@ static inline void debug_spin_unlock(raw_spinlock_t *lock) static void __spin_lock_debug(raw_spinlock_t *lock) { - u64 i; - u64 loops = loops_per_jiffy * HZ; + u64 t; + u64 one_second = 1000000000; + u32 this_cpu = raw_smp_processor_id(); + + t = cpu_clock(this_cpu); - for (i = 0; i < loops; i++) { + while (cpu_clock(this_cpu) - t < one_second) { if (arch_spin_trylock(&lock->raw_lock)) return; __delay(1); -- 1.7.1 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] lib/spinlock_debug: Tweak the loop time to fit different _delay() 2014-04-30 22:40 [PATCH] lib/spinlock_debug: Tweak the loop time to fit different _delay() Wang, Xiaoming @ 2014-04-30 8:50 ` Peter Zijlstra 2014-04-30 8:55 ` Peter Zijlstra 1 sibling, 0 replies; 5+ messages in thread From: Peter Zijlstra @ 2014-04-30 8:50 UTC (permalink / raw) To: Wang, Xiaoming; +Cc: mingo, linux-kernel, chuansheng.liu On Wed, Apr 30, 2014 at 06:40:38PM -0400, Wang, Xiaoming wrote: > loops_per_jiffy*Hz is not always 1 second exactly > it depends on the realization of _delay() . > delay_tsc is used as _delay() in arch/x86/lib/delay.c > It makes loop loops_per_jiffy larger than exception > and causes one thread can not obtain the spin lock for > a long time which may trigger HARD LOCKUP in this case. > So we use cpu_clock() which is more accurate. > > Signed-off-by: Chuansheng Liu <chuansheng.liu@intel.com> > Signed-off-by: xiaoming wang <xiaoming.wang@intel.com> > --- > kernel/locking/spinlock_debug.c | 9 ++++++--- > 1 files changed, 6 insertions(+), 3 deletions(-) > > diff --git a/kernel/locking/spinlock_debug.c b/kernel/locking/spinlock_debug.c > index 0374a59..471d26c 100644 > --- a/kernel/locking/spinlock_debug.c > +++ b/kernel/locking/spinlock_debug.c > @@ -105,10 +105,13 @@ static inline void debug_spin_unlock(raw_spinlock_t *lock) > > static void __spin_lock_debug(raw_spinlock_t *lock) > { > - u64 i; > - u64 loops = loops_per_jiffy * HZ; > + u64 t; > + u64 one_second = 1000000000; > + u32 this_cpu = raw_smp_processor_id(); > + > + t = cpu_clock(this_cpu); > > - for (i = 0; i < loops; i++) { > + while (cpu_clock(this_cpu) - t < one_second) { > if (arch_spin_trylock(&lock->raw_lock)) > return; > __delay(1); Yep, and now you've broken support for archs that fall back to jiffies for cpu_clock :-), jiffies need not progress if you've got IRQs disabled. ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] lib/spinlock_debug: Tweak the loop time to fit different _delay() 2014-04-30 22:40 [PATCH] lib/spinlock_debug: Tweak the loop time to fit different _delay() Wang, Xiaoming 2014-04-30 8:50 ` Peter Zijlstra @ 2014-04-30 8:55 ` Peter Zijlstra 2014-04-30 9:30 ` Liu, Chuansheng 1 sibling, 1 reply; 5+ messages in thread From: Peter Zijlstra @ 2014-04-30 8:55 UTC (permalink / raw) To: Wang, Xiaoming; +Cc: mingo, linux-kernel, chuansheng.liu On Wed, Apr 30, 2014 at 06:40:38PM -0400, Wang, Xiaoming wrote: > loops_per_jiffy*Hz is not always 1 second exactly > it depends on the realization of _delay() . > delay_tsc is used as _delay() in arch/x86/lib/delay.c This just states delay() is broken. The primary response should be to try and fix that, no? ^ permalink raw reply [flat|nested] 5+ messages in thread
* RE: [PATCH] lib/spinlock_debug: Tweak the loop time to fit different _delay() 2014-04-30 8:55 ` Peter Zijlstra @ 2014-04-30 9:30 ` Liu, Chuansheng 2014-04-30 9:52 ` Peter Zijlstra 0 siblings, 1 reply; 5+ messages in thread From: Liu, Chuansheng @ 2014-04-30 9:30 UTC (permalink / raw) To: Peter Zijlstra, Wang, Xiaoming Cc: mingo@redhat.com, linux-kernel@vger.kernel.org Hello Peter, > -----Original Message----- > From: Peter Zijlstra [mailto:peterz@infradead.org] > Sent: Wednesday, April 30, 2014 4:55 PM > To: Wang, Xiaoming > Cc: mingo@redhat.com; linux-kernel@vger.kernel.org; Liu, Chuansheng > Subject: Re: [PATCH] lib/spinlock_debug: Tweak the loop time to fit different > _delay() > > On Wed, Apr 30, 2014 at 06:40:38PM -0400, Wang, Xiaoming wrote: > > loops_per_jiffy*Hz is not always 1 second exactly > > it depends on the realization of _delay() . > > delay_tsc is used as _delay() in arch/x86/lib/delay.c > > This just states delay() is broken. The primary response should be to > try and fix that, no? delay(1s_count) is accurate, but delay(1) is not accurate indeed, since executing some instruction, then the 1 cycle delay maybe be used already. ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] lib/spinlock_debug: Tweak the loop time to fit different _delay() 2014-04-30 9:30 ` Liu, Chuansheng @ 2014-04-30 9:52 ` Peter Zijlstra 0 siblings, 0 replies; 5+ messages in thread From: Peter Zijlstra @ 2014-04-30 9:52 UTC (permalink / raw) To: Liu, Chuansheng Cc: Wang, Xiaoming, mingo@redhat.com, linux-kernel@vger.kernel.org On Wed, Apr 30, 2014 at 09:30:55AM +0000, Liu, Chuansheng wrote: > > From: Peter Zijlstra [mailto:peterz@infradead.org] > > Sent: Wednesday, April 30, 2014 4:55 PM > > To: Wang, Xiaoming > > Cc: mingo@redhat.com; linux-kernel@vger.kernel.org; Liu, Chuansheng > > Subject: Re: [PATCH] lib/spinlock_debug: Tweak the loop time to fit different > > _delay() > > > > On Wed, Apr 30, 2014 at 06:40:38PM -0400, Wang, Xiaoming wrote: > > > loops_per_jiffy*Hz is not always 1 second exactly > > > it depends on the realization of _delay() . > > > delay_tsc is used as _delay() in arch/x86/lib/delay.c > > > > This just states delay() is broken. The primary response should be to > > try and fix that, no? > > > delay(1s_count) is accurate, but delay(1) is not accurate indeed, since executing > some instruction, then the 1 cycle delay maybe be used already. OK, so there's (finally) a problem statement, so is there anything sane we can do about that? But yes, a trylock is a cmpxchg, and a cmpxchg on a contended cacheline can be _much_ longer than one loop. Now the real problem is coming up with something that'll work for all architectures. ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2014-04-30 9:52 UTC | newest] Thread overview: 5+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2014-04-30 22:40 [PATCH] lib/spinlock_debug: Tweak the loop time to fit different _delay() Wang, Xiaoming 2014-04-30 8:50 ` Peter Zijlstra 2014-04-30 8:55 ` Peter Zijlstra 2014-04-30 9:30 ` Liu, Chuansheng 2014-04-30 9:52 ` 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.