lib/spinlock_debug: avoid one thread can not obtain the spinlock for a long time.
PATCH 1/1 lib/spinlock_debug: avoid one thread can not obtain the spinlock for a long time.
loops_per_jiffy is larger than expectation that possible causes one thread can not obtain the spin lock for a long time. So use cpu_clock() to reach timeout in one second which can avoid HARD LOCKUP.
--- kernel/locking/spinlock_debug.c | 8 +++++++- 1 files changed, 7 insertions(+), 1 deletions(-)
kernel/locking/spinlock_debug.c +7 -1
@@ -105,13 +105,19 @@ static inline void debug_spin_unlock(raw_spinlock_t *lock)static void __spin_lock_debug (raw_spinlock_t *lock) { -u64 i; +u64 i, t;u64 loops = loops_per_jiffy *HZ ; +u64 one_second =1000000000 ; +u32 this_cpu =raw_smp_processor_id (); + + t =cpu_clock (this_cpu);for (i =0 ; i < loops; i++) {if (arch_spin_trylock (&lock->raw_lock))return ;__delay (1 ); +if (cpu_clock (this_cpu) - t > one_second) +break ; }/* lockup suspected: */ spin_dump (lock,"lockup suspected" );
Signature · 1 line
1.7.1
Peter Zijlstra
maintainerQuoted 4 lines · Xiaoming
loops_per_jiffyis larger than expectation that possible causes one thread can not obtain the spin lock for a long time. So usecpu_clock()to reach timeout in one second which can avoid HARD LOCKUP.
This is just not making sense.. one thing is broken so then you tape on another? Fix the first already.
Also, why do you care?
Dear Peter
If we wait the end of loop as loops_per_jiffy.
It may last more than 130s and local IRQ disabled at interval which may cause Hard LOCKUP. We break out in 1 second and dump the stack for debug.
Quoted 19 lines
-----Original Message-----
From: Peter Zijlstra [mailto:[email protected]]
Sent: Wednesday, April 30, 2014 2:06 PM
To: Wang, Xiaoming
Cc: [email protected]; [email protected]; Liu, Chuansheng
Subject: Re: [PATCH]lib/spinlock_debug: avoid one thread can not obtain the spinlock for a long time.Quoted 3 lines · Xiaoming
loops_per_jiffyis larger than expectation that possible causes one thread can not obtain the spin lock for a long time.
So usecpu_clock()to reach timeout in one second which can avoidHARD
Quoted 1 line
LOCKUP.
This is just not making sense.. one thing is broken so then you tape on another? Fix the first already.
Also, why do you care?
Peter Zijlstra
maintainerQuoted 5 lines · Xiaoming
Dear Peter
If we wait the end of loop asloops_per_jiffy.
It may last more than 130s and local IRQ disabled at interval which may cause Hard LOCKUP. We break out in 1 second and dump the stack for debug.
Yeah, so? That makes shoddy engineering alright then?
So either fix the loops_per_jiffy thing, it is supposed to wait for 1 second after all, or explain why its broken and entirely replace it.
What you do not do is make a loop with 2 differently broken timeouts and hope one works.