linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH -tip 0/4] rtmutex: Spin on owner
@ 2015-05-19 17:24 Davidlohr Bueso
  2015-05-19 17:24 ` [PATCH 1/4] locking/rtmutex: Implement lockless top-waiter wakeup Davidlohr Bueso
                   ` (4 more replies)
  0 siblings, 5 replies; 48+ messages in thread
From: Davidlohr Bueso @ 2015-05-19 17:24 UTC (permalink / raw)
  To: Thomas Gleixner, Peter Zijlstra, Ingo Molnar
  Cc: Steven Rostedt, Mike Galbraith, Paul E. McKenney,
	Sebastian Andrzej Siewior, Davidlohr Bueso, linux-kernel

Hello,

First three patches are straightforward and found while
going through the code. Patch 4 is the actual meat of the
set, but similar to what we have already in regular mutexes.
While having optimistic spinning in rtmutexes is a desired
feature, I've marked it RFC as I could very well have missed
something inherint in the rt flavor.

Details in the individual patches. Passes pi tests from
Darren's futextest suite as well as all weekend running
pi_stress from rt-tests on a 60 core box.

Thanks!

Davidlohr Bueso (4):
  locking/rtmutex: Implement lockless top-waiter wakeup
  locking/rtmutex: Use cmp-cmpxchg
  locking/rtmutex: Update stale plist comments
  locking/rtmutex: Support spin on owner (osq)

 include/linux/rtmutex.h  |   4 ++
 kernel/Kconfig.locks     |   4 ++
 kernel/locking/rtmutex.c | 175 +++++++++++++++++++++++++++++++++++++++++------
 3 files changed, 162 insertions(+), 21 deletions(-)

-- 
2.1.4


^ permalink raw reply	[flat|nested] 48+ messages in thread
* RE: [PATCH v2] futex: lower the lock contention on the HB lock during wake up
@ 2015-09-15  1:26 Zhu Jefferry
  2015-09-16  0:01 ` Thomas Gleixner
  0 siblings, 1 reply; 48+ messages in thread
From: Zhu Jefferry @ 2015-09-15  1:26 UTC (permalink / raw)
  To: linux-kernel; +Cc: tglx, bigeasy

Hi 

Just in the list, I see the patch "[PATCH v2] futex: lower the lock contention on the HB lock during wake up" at http://www.gossamer-threads.com/lists/linux/kernel/2199938?search_string=futex;#2199938.

But I see another patch with same name, different content here,
    23b7776290b10297fe2cae0fb5f166a4f2c68121(http://code.metager.de/source/xref/linux/stable/kernel/futex.c?r=23b7776290b10297fe2cae0fb5f166a4f2c68121) 23-Jun-2015 Linus Torvalds 
    futex: Lower the lock contention on the HB lock during wake up wake_futex_pi() wakes the task before releasing the hash bucket lock (HB). 
    The first thing the woken up task usually does is to acquire the lock which requires the HB lock. On SMP Systems this leads to blocking 
     on the HB lock which is released by the owner shortly after. This patch rearranges the unlock path by first releasing the HB lock and
     then waking up the task.

Could you please help to give a little bit more explanation on this, why they have same name with different modify in the futex.c? I'm a newbie in the community.

Actually, I encounter a customer issue which is related to the glibc code "pthread_mutex_lock", which is using the futex service in kernel, without the patches above.

After lots of customer discussing, ( I could not reproduce the failure in my office), I seriously suspect there might be some particular corner cases in the futex code.

In the unlock flow, the user space code (pthread_mutex_unlock) will check FUTEX_WAITERS flag first, then wakeup the waiters in the kernel list. But in the lock flow, the kernel code (futex) will set FUTEX_WAITERS in first too, then try to get the waiter from the list. They are following same sequence, flag first, entry in list secondly. But there might be some timing problem in SMP system, if the query (unlock flow) is executing just before the list adding action (lock flow).

It might cause the mutex is never really released, and other threads will infinite waiting. Could you please help to take a look at it?

===========================================================================================================================
CPU 0 (trhead 0)                                CPU 1 (thread 1)

 mutex_lock                                               
 val = *futex;                                  
 sys_futex(LOCK_PI, futex, val);                
                                                
 return to user space                           
 after acquire the lock                           mutex_lock
                                                  val = *futex;
                                                  sys_futex(LOCK_PI, futex, val);
                                                    lock(hash_bucket(futex));
                                                    set FUTEX_WAITERS flag
                                                    unlock(hash_bucket(futex)) and retry due to page fault
                                                
 mutex_unlock in user space                     
 check FUTEX_WAITERS flag                                               
 sys_futex(UNLOCK_PI, futex, val);              
   lock(hash_bucket(futex));        <--.            
                                       .---------   waiting for the lock of (hash_bucket(futex)) to do list adding
                                                
   try to get the waiter in waitling <--.           
   list, but it's empty                 |       
                                        |       
   set new_owner to itself              |       
   instead of expecting waiter          |       
                                        |       
                                        |       
   unlock(hash_bucket(futex));          |       
                                        |           lock(hash_bucket(futex));
                                        .--------   add itself to the waiting list
                                                    unlock(hash_bucket(futex));
                                                    waiting forever since there is nobody will release the PI
   the futex is owned by itself                 
   forever in userspace. Because                
   the __owner in user space has                
   been cleared and mutex_unlock                
   will fail forever before it 
   call kernel.                           


Thanks,
Jeff


^ permalink raw reply	[flat|nested] 48+ messages in thread

end of thread, other threads:[~2015-09-17  7:09 UTC | newest]

Thread overview: 48+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-05-19 17:24 [PATCH -tip 0/4] rtmutex: Spin on owner Davidlohr Bueso
2015-05-19 17:24 ` [PATCH 1/4] locking/rtmutex: Implement lockless top-waiter wakeup Davidlohr Bueso
2015-06-05 12:35   ` Thomas Gleixner
2015-06-16 19:29   ` [PATCH] futex: lower the lock contention on the HB lock during wake up Sebastian Andrzej Siewior
2015-06-16 19:50     ` Davidlohr Bueso
2015-06-17  8:33       ` [PATCH v2] " Sebastian Andrzej Siewior
2015-06-17 14:17         ` Mike Galbraith
2015-06-17 14:28           ` Sebastian Andrzej Siewior
2015-06-17 14:31             ` Mike Galbraith
2015-06-21  4:35             ` Mike Galbraith
2015-06-18 20:30         ` [tip:sched/core] futex: Lower " tip-bot for Sebastian Andrzej Siewior
2015-06-19 17:51         ` [PATCH v2] futex: lower " Kevin Hilman
2015-06-19 18:54           ` Thomas Gleixner
2015-06-19 19:32             ` Kevin Hilman
2015-06-19 19:33         ` [tip:sched/locking] futex: Lower " tip-bot for Sebastian Andrzej Siewior
2015-06-18 20:30   ` [tip:sched/core] locking/rtmutex: Implement lockless top-waiter wakeup tip-bot for Davidlohr Bueso
2015-05-19 17:24 ` [PATCH 2/4] locking/rtmutex: Use cmp-cmpxchg Davidlohr Bueso
2015-06-05 12:38   ` Thomas Gleixner
2015-06-06 15:27     ` Davidlohr Bueso
2015-06-15 18:34       ` Jason Low
2015-06-15 19:37         ` Davidlohr Bueso
2015-06-16  1:00           ` Jason Low
2015-05-19 17:24 ` [PATCH 3/4] locking/rtmutex: Update stale plist comments Davidlohr Bueso
2015-06-05 12:39   ` Thomas Gleixner
2015-06-18 20:57   ` [tip:sched/core] " tip-bot for Davidlohr Bueso
2015-06-19 19:33   ` [tip:sched/locking] " tip-bot for Davidlohr Bueso
2015-05-19 17:24 ` [PATCH -rfc 4/4] locking/rtmutex: Support spin on owner (osq) Davidlohr Bueso
2015-05-20  7:11   ` Paul Bolle
2015-05-25 20:35     ` Davidlohr Bueso
2015-05-29 15:19   ` Davidlohr Bueso
2015-05-29 18:01     ` Davidlohr Bueso
2015-06-05 13:59   ` Thomas Gleixner
2015-06-09  4:41     ` Davidlohr Bueso
2015-06-09  9:29       ` Thomas Gleixner
2015-06-09 11:21         ` Peter Zijlstra
2015-06-09 12:53           ` Thomas Gleixner
2015-05-25 20:35 ` [PATCH -tip 0/4] rtmutex: Spin on owner Davidlohr Bueso
2015-05-26 19:05   ` Thomas Gleixner
2015-09-15  1:26 [PATCH v2] futex: lower the lock contention on the HB lock during wake up Zhu Jefferry
2015-09-16  0:01 ` Thomas Gleixner
2015-09-16  0:17   ` Zhu Jefferry
2015-09-16  8:06     ` Thomas Gleixner
2015-09-16  9:52       ` Zhu Jefferry
2015-09-16 10:22         ` Thomas Gleixner
2015-09-16 11:13           ` Zhu Jefferry
2015-09-16 13:39             ` Thomas Gleixner
2015-09-16 23:57               ` Zhu Jefferry
2015-09-17  7:08                 ` Thomas Gleixner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).