Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1224588 > unrolled thread
| Started by | Zhu Jefferry <Jefferry.Zhu@freescale.com> |
|---|---|
| First post | 2015-09-15 04:10 +0200 |
| Last post | 2015-09-17 09:20 +0200 |
| Articles | 10 — 2 participants |
Back to article view | Back to linux.kernel
RE: [PATCH v2] futex: lower the lock contention on the HB lock during wake up Zhu Jefferry <Jefferry.Zhu@freescale.com> - 2015-09-15 04:10 +0200
RE: [PATCH v2] futex: lower the lock contention on the HB lock during wake up Thomas Gleixner <tglx@linutronix.de> - 2015-09-16 02:10 +0200
RE: [PATCH v2] futex: lower the lock contention on the HB lock during wake up Zhu Jefferry <Jefferry.Zhu@freescale.com> - 2015-09-16 02:20 +0200
RE: [PATCH v2] futex: lower the lock contention on the HB lock during wake up Thomas Gleixner <tglx@linutronix.de> - 2015-09-16 10:10 +0200
RE: [PATCH v2] futex: lower the lock contention on the HB lock during wake up Zhu Jefferry <Jefferry.Zhu@freescale.com> - 2015-09-16 12:10 +0200
RE: [PATCH v2] futex: lower the lock contention on the HB lock during wake up Thomas Gleixner <tglx@linutronix.de> - 2015-09-16 12:30 +0200
RE: [PATCH v2] futex: lower the lock contention on the HB lock during wake up Zhu Jefferry <Jefferry.Zhu@freescale.com> - 2015-09-16 13:20 +0200
RE: [PATCH v2] futex: lower the lock contention on the HB lock during wake up Thomas Gleixner <tglx@linutronix.de> - 2015-09-16 15:40 +0200
RE: [PATCH v2] futex: lower the lock contention on the HB lock during wake up Zhu Jefferry <Jefferry.Zhu@freescale.com> - 2015-09-17 02:00 +0200
RE: [PATCH v2] futex: lower the lock contention on the HB lock during wake up Thomas Gleixner <tglx@linutronix.de> - 2015-09-17 09:20 +0200
| From | Zhu Jefferry <Jefferry.Zhu@freescale.com> |
|---|---|
| Date | 2015-09-15 04:10 +0200 |
| Subject | RE: [PATCH v2] futex: lower the lock contention on the HB lock during wake up |
| Message-ID | <q8NQZ-7HD-5@gated-at.bofh.it> |
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
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [next] | [standalone]
| From | Thomas Gleixner <tglx@linutronix.de> |
|---|---|
| Date | 2015-09-16 02:10 +0200 |
| Message-ID | <q98sq-4Cv-7@gated-at.bofh.it> |
| In reply to | #1224588 |
On Tue, 15 Sep 2015, Zhu Jefferry wrote:
Please configure your e-mail client proper and follow the basic rules:
- Choose a meaningful subject for your questions
You just copied a random subject line from some other mail thread,
which makes your mail look like a patch. But it's not a patch. You
have a question about futexes and patches related to them.
- Make sure your lines are no longer than 72 to 76 characters in length.
You can't assume that all e-mail and news clients behave like yours, and while yours might wrap lines automatically when the text reaches the right of the window containing it, not all do.
For the sentence above I need a 190 character wide display ....
- Do not use colors or other gimmicks. They just make the mail
unreadable in simple text based readers.
> 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)
I have no idea what that metager thing tells you and I really don't
want to know. Plain git tells me:
# git show 23b7776290b10297fe2cae0fb5f166a4f2c68121
Merge: 6bc4c3ad3619 6fab54101923
Author: Linus Torvalds <torvalds@linux-foundation.org
Date: Mon Jun 22 15:52:04 2015 -0700
Merge branch 'sched-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
So that's a merge commit where Linus pulled a pile of changes into the
mainline kernel. And that merge does not contain the patch above, but
it contains a different change to the futex code.
> 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.
Use the proper tools and not some random web interface. The commit you
are looking for is a completely different one.
# git log kernel/futex.c
....
commit 802ab58da74bb49ab348d2872190ef26ddc1a3e0
Author: Sebastian Andrzej Siewior <bigeasy@linutronix.de
Date: Wed Jun 17 10:33:50 2015 +0200
futex: Lower the lock contention on the HB lock during wake up
....
And that's the same as the one in the LKML thread plus a fixup.
> 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.
The patches above are merily an optimization and completely unrelated
to your problem.
You fail to provide the real interesting information here:
- Which architecture/SoC
- Which kernel version and which extra patches
- Which glibc version and which extra patches
> 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.
The futex code is more or less a conglomorate of corner cases.
But again you fail to provide the real interesting information:
- What is the actual failure ?
The information that you discussed that with your customer is
completely irrelevant and your suspicion does not clarify the issue
either.
> 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).
There might be some timing problem, if the code would look like the
scheme you painted below, but it does not.
> 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
If the futex is uncontended then you don't enter the kernel for
acquiring the futex.
> after acquire the lock mutex_lock
> val = *futex;
> sys_futex(LOCK_PI, futex, val);
The futex FUTEX_LOCK_PI operation does not take the user space value. That's
what FUTEX_WAIT does.
> lock(hash_bucket(futex));
> set FUTEX_WAITERS flag
> unlock(hash_bucket(futex)) and retry due to page fault
So here you are completely off the track. If the 'set FUTEX_WAITERS
bit' operation fails due to a page fault, then the FUTEX_WAITERS bit
is not set. So it cannot be observed on the other core.
The flow is:
sys_futex(LOCK_PI, futex, ...)
retry:
lock(hb(futex));
ret = set_waiter_bit(futex);
if (ret == -EFAULT) {
unlock(hb(futex));
handle_fault();
goto retry;
}
list_add();
unlock(hb(futex));
schedule();
So when set_waiter_bit() succeeds, then the hash bucket lock is held
and blocks the waker. So it's guaranteed that the waker will see the
waiter on the list.
If set_waiter_bit() faults, then the waiter bit is not set and
therefor there is nothing to wake. So the waker will not enter the
kernel because the futex is uncontended.
So now, lets assume that the waiter failed to set the waiter bit and
the waker unlocked the futex. When the waiter retries then it actually
checks whether the futex still has an owner. So it observes the owner
has been cleared, it acquires the futex and returns.
It's a bit more complex than that due to handling of the gazillion of
corner cases, but that's the basic synchronization mechanism and there
is no hidden timing issue on SMP.
Random speculation is not helping here.
Thanks,
tglx
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Zhu Jefferry <Jefferry.Zhu@freescale.com> |
|---|---|
| Date | 2015-09-16 02:20 +0200 |
| Message-ID | <q98C6-4ND-5@gated-at.bofh.it> |
| In reply to | #1225605 |
Thanks for your detail guideline and explanations. Please see my questions in-line.
> -----Original Message-----
> From: Thomas Gleixner [mailto:tglx@linutronix.de]
> Sent: Wednesday, September 16, 2015 8:01 AM
> To: Zhu Shuangjun-R65879
> Cc: linux-kernel@vger.kernel.org; bigeasy@linutronix.de
> Subject: RE: [PATCH v2] futex: lower the lock contention on the HB lock
> during wake up
>
> On Tue, 15 Sep 2015, Zhu Jefferry wrote:
>
> Please configure your e-mail client proper and follow the basic rules:
>
> - Choose a meaningful subject for your questions
>
> You just copied a random subject line from some other mail thread,
> which makes your mail look like a patch. But it's not a patch. You
> have a question about futexes and patches related to them.
>
> - Make sure your lines are no longer than 72 to 76 characters in length.
>
> You can't assume that all e-mail and news clients behave like yours,
> and while yours might wrap lines automatically when the text reaches the
> right of the window containing it, not all do.
>
> For the sentence above I need a 190 character wide display ....
>
> - Do not use colors or other gimmicks. They just make the mail
> unreadable in simple text based readers.
>
> > 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=23b7776290b10297fe2cae0fb5f166a4f2
> > c68121)
>
> I have no idea what that metager thing tells you and I really don't want
> to know. Plain git tells me:
>
> # git show 23b7776290b10297fe2cae0fb5f166a4f2c68121
> Merge: 6bc4c3ad3619 6fab54101923
> Author: Linus Torvalds <torvalds@linux-foundation.org
> Date: Mon Jun 22 15:52:04 2015 -0700
>
> Merge branch 'sched-core-for-linus' of
> git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
>
> So that's a merge commit where Linus pulled a pile of changes into the
> mainline kernel. And that merge does not contain the patch above, but it
> contains a different change to the futex code.
>
> > 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.
>
> Use the proper tools and not some random web interface. The commit you
> are looking for is a completely different one.
>
> # git log kernel/futex.c
> ....
> commit 802ab58da74bb49ab348d2872190ef26ddc1a3e0
> Author: Sebastian Andrzej Siewior <bigeasy@linutronix.de
> Date: Wed Jun 17 10:33:50 2015 +0200
>
> futex: Lower the lock contention on the HB lock during wake up ....
>
> And that's the same as the one in the LKML thread plus a fixup.
>
> > 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.
>
> The patches above are merily an optimization and completely unrelated to
> your problem.
>
> You fail to provide the real interesting information here:
>
> - Which architecture/SoC
> - Which kernel version and which extra patches
> - Which glibc version and which extra patches
>
> > 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.
>
> The futex code is more or less a conglomorate of corner cases.
>
> But again you fail to provide the real interesting information:
>
> - What is the actual failure ?
>
> The information that you discussed that with your customer is completely
> irrelevant and your suspicion does not clarify the issue either.
>
> > 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).
>
> There might be some timing problem, if the code would look like the
> scheme you painted below, but it does not.
>
> > 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
>
> If the futex is uncontended then you don't enter the kernel for acquiring
> the futex.
>
> > after acquire the lock mutex_lock
> > val = *futex;
> > sys_futex(LOCK_PI,
> > futex, val);
>
> The futex FUTEX_LOCK_PI operation does not take the user space value.
> That's what FUTEX_WAIT does.
>
> >
> lock(hash_bucket(futex));
> > set FUTEX_WAITERS
> flag
> >
> > unlock(hash_bucket(futex)) and retry due to page fault
>
> So here you are completely off the track. If the 'set FUTEX_WAITERS bit'
> operation fails due to a page fault, then the FUTEX_WAITERS bit is not
> set. So it cannot be observed on the other core.
>
> The flow is:
>
> sys_futex(LOCK_PI, futex, ...)
>
> retry:
> lock(hb(futex));
> ret = set_waiter_bit(futex);
> if (ret == -EFAULT) {
> unlock(hb(futex));
> handle_fault();
> goto retry;
> }
>
> list_add();
> unlock(hb(futex));
> schedule();
>
> So when set_waiter_bit() succeeds, then the hash bucket lock is held and
> blocks the waker. So it's guaranteed that the waker will see the waiter
> on the list.
>
> If set_waiter_bit() faults, then the waiter bit is not set and therefor
> there is nothing to wake. So the waker will not enter the kernel because
> the futex is uncontended.
>
I assume your pseudo code set_waiter_bit is mapped to the real code "futex_lock_pi_atomic",
It's possible for futex_lock_pi_atomic to successfully set FUTEX_WAITERS bit, but return with
Page fault, for example, like fail in lookup_pi_state().
> So now, lets assume that the waiter failed to set the waiter bit and the
> waker unlocked the futex. When the waiter retries then it actually checks
> whether the futex still has an owner. So it observes the owner has been
> cleared, it acquires the futex and returns.
>
> It's a bit more complex than that due to handling of the gazillion of
> corner cases, but that's the basic synchronization mechanism and there is
> no hidden timing issue on SMP.
>
> Random speculation is not helping here.
>
> Thanks,
>
> tglx
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Thomas Gleixner <tglx@linutronix.de> |
|---|---|
| Date | 2015-09-16 10:10 +0200 |
| Message-ID | <q9fWW-72h-13@gated-at.bofh.it> |
| In reply to | #1225608 |
On Wed, 16 Sep 2015, Zhu Jefferry wrote:
> Thanks for your detail guideline and explanations. Please see my questions in-line.
Please trim the reply to the relevant sections. It's annoying if I
have to search your replies inside of useless quoted text.
> > -----Original Message-----
> > From: Thomas Gleixner [mailto:tglx@linutronix.de]
> > The flow is:
> >
> > sys_futex(LOCK_PI, futex, ...)
> >
> > retry:
> > lock(hb(futex));
> > ret = set_waiter_bit(futex);
> > if (ret == -EFAULT) {
> > unlock(hb(futex));
> > handle_fault();
> > goto retry;
> > }
> >
> > list_add();
> > unlock(hb(futex));
> > schedule();
> >
> > So when set_waiter_bit() succeeds, then the hash bucket lock is held and
> > blocks the waker. So it's guaranteed that the waker will see the waiter
> > on the list.
> >
> > If set_waiter_bit() faults, then the waiter bit is not set and therefor
> > there is nothing to wake. So the waker will not enter the kernel because
> > the futex is uncontended.
> >
> I assume your pseudo code set_waiter_bit is mapped to the real code
> "futex_lock_pi_atomic", It's possible for futex_lock_pi_atomic to
> successfully set FUTEX_WAITERS bit, but return with Page fault, for
> example, like fail in lookup_pi_state().
No. It's not. lookup_pi_state() cannot return EFAULT. The only
function which can fault inside of lock_pi_update_atomic() is the
actual cmpxchg. Though lock_pi_update_atomic() can successfully set
the waiter bit and then return with some other failure code (ESRCH,
EAGAIN, ...). But that does not matter at all.
Any failure return will end up in a retry. And if the waker managed to
release the futex before the retry takes place then the waiter will
see that and take the futex.
As I said before:
> > Random speculation is not helping here.
You still fail to provide the relevant information I asked for. If you
cannot provide that information, we can't help.
Thanks,
tglx
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Zhu Jefferry <Jefferry.Zhu@freescale.com> |
|---|---|
| Date | 2015-09-16 12:10 +0200 |
| Message-ID | <q9hP5-1id-39@gated-at.bofh.it> |
| In reply to | #1225813 |
> > I assume your pseudo code set_waiter_bit is mapped to the real code > > "futex_lock_pi_atomic", It's possible for futex_lock_pi_atomic to > > successfully set FUTEX_WAITERS bit, but return with Page fault, for > > example, like fail in lookup_pi_state(). > > No. It's not. lookup_pi_state() cannot return EFAULT. The only function > which can fault inside of lock_pi_update_atomic() is the actual cmpxchg. > Though lock_pi_update_atomic() can successfully set the waiter bit and > then return with some other failure code (ESRCH, EAGAIN, ...). But that > does not matter at all. > > Any failure return will end up in a retry. And if the waker managed to > release the futex before the retry takes place then the waiter will see > that and take the futex. > Let me try to descript the application failure here. The application is a multi-thread program, to use the pairs of mutex_lock and mutex_unlock to protect the shared data structure. The type of this mutex is PTHREAD_MUTEX_PI_RECURSIVE_NP. After running long time, to say several days, the mutex_lock data structure in user space looks like corrupt. thread 0 can do mutex_lock/unlock __lock = this thread | FUTEX_WAITERS __owner = 0, should be this thread __counter keep increasing, although there is no recursive mutex_lock call. thread 1 will be stuck The primary debugging shows the content of __lock is wrong in first. After a call of Mutex_unlock, the value of __lock should not be this thread self. But we observed The value of __lock is still self after unlock. So, other threads will be stuck, This thread could lock due to recursive type and __counter keep increasing, although mutex_unlock return fails, due to the wrong value of __owner, but the application did not check the return value. So the thread 0 looks like fine. But thread 1 will be stuck forever. -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Thomas Gleixner <tglx@linutronix.de> |
|---|---|
| Date | 2015-09-16 12:30 +0200 |
| Message-ID | <q9i8s-1Fl-41@gated-at.bofh.it> |
| In reply to | #1225915 |
On Wed, 16 Sep 2015, Zhu Jefferry wrote: > The application is a multi-thread program, to use the pairs of mutex_lock and > mutex_unlock to protect the shared data structure. The type of this mutex > is PTHREAD_MUTEX_PI_RECURSIVE_NP. After running long time, to say several days, > the mutex_lock data structure in user space looks like corrupt. > > thread 0 can do mutex_lock/unlock > __lock = this thread | FUTEX_WAITERS > __owner = 0, should be this thread The kernel does not know about __owner. > __counter keep increasing, although there is no recursive mutex_lock call. > > thread 1 will be stuck > > The primary debugging shows the content of __lock is wrong in first. After a call of > Mutex_unlock, the value of __lock should not be this thread self. But we observed > The value of __lock is still self after unlock. So, other threads will be stuck, How did you observe that? > This thread could lock due to recursive type and __counter keep increasing, > although mutex_unlock return fails, due to the wrong value of __owner, > but the application did not check the return value. So the thread 0 looks > like fine. But thread 1 will be stuck forever. Oh well. So thread 0 looks all fine, despite not checking return values. Thanks, tglx -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Zhu Jefferry <Jefferry.Zhu@freescale.com> |
|---|---|
| Date | 2015-09-16 13:20 +0200 |
| Message-ID | <q9iUO-2PF-27@gated-at.bofh.it> |
| In reply to | #1225977 |
> On Wed, 16 Sep 2015, Zhu Jefferry wrote:
> > The application is a multi-thread program, to use the pairs of
> > mutex_lock and mutex_unlock to protect the shared data structure. The
> > type of this mutex is PTHREAD_MUTEX_PI_RECURSIVE_NP. After running
> > long time, to say several days, the mutex_lock data structure in user
> space looks like corrupt.
> >
> > thread 0 can do mutex_lock/unlock
> > __lock = this thread | FUTEX_WAITERS
> > __owner = 0, should be this thread
>
> The kernel does not know about __owner.
Correct, it shows the last failure is in mutex_unlock,
which clear the __owner in user space.
>
> > __counter keep increasing, although there is no recursive mutex_lock
> call.
> >
> > thread 1 will be stuck
> >
> > The primary debugging shows the content of __lock is wrong in first.
> > After a call of Mutex_unlock, the value of __lock should not be this
> > thread self. But we observed The value of __lock is still self after
> > unlock. So, other threads will be stuck,
>
> How did you observe that?
Add one assert in mutex_unlock, after it finish the __lock modify either in
User space or kernel space, before return.
>
> > This thread could lock due to recursive type and __counter keep
> > increasing, although mutex_unlock return fails, due to the wrong value
> > of __owner, but the application did not check the return value. So the
> > thread 0 looks like fine. But thread 1 will be stuck forever.
>
> Oh well. So thread 0 looks all fine, despite not checking return values.
>
Correct.
Actually, I'm not clear how about the state changing of futex in kernel.
I search the Internet, see a similar failure from other users. He is using
Kernel 2.6.38. Our customer is using kernel 2.6.34 (WindRiver Linux 4.1)
====
http://www.programdoc.com/1272_157986_1.htm
Maybe, there is a bug about pi-futex, it would let the program in
user-space going to hang.
We have a board: CPU is powerpc 8572, two core. after ran one month,
the state of pi-futex in user-space got bad:
mutex->__data.__lock is 0x8000023e,
mutex->__data.__count is 0,
mutex->__data.__owner is 0.
But I can not understand the sample failure case which he mentioned. But I think
It might be helpful for you to analyze the corner case.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Thomas Gleixner <tglx@linutronix.de> |
|---|---|
| Date | 2015-09-16 15:40 +0200 |
| Message-ID | <q9l6j-5SL-47@gated-at.bofh.it> |
| In reply to | #1226008 |
On Wed, 16 Sep 2015, Zhu Jefferry wrote: > > > The primary debugging shows the content of __lock is wrong in first. > > > After a call of Mutex_unlock, the value of __lock should not be this > > > thread self. But we observed The value of __lock is still self after > > > unlock. So, other threads will be stuck, > > > > How did you observe that? > > Add one assert in mutex_unlock, after it finish the __lock modify either in > User space or kernel space, before return. And that assert tells you that the kernel screwed up the futex value? No, it does not. It merily tells you that the value is not what you expect, but it does not tell you what caused that. Hint: There are proper instrumentation tools, e.g. tracing, which tell you the exact flow of events and not just the observation after the fact. > > > This thread could lock due to recursive type and __counter keep > > > increasing, although mutex_unlock return fails, due to the wrong value > > > of __owner, but the application did not check the return value. So the > > > thread 0 looks like fine. But thread 1 will be stuck forever. > > > > Oh well. So thread 0 looks all fine, despite not checking return values. > > > > Correct. No. That's absolutely NOT correct. Not checking return values can cause all kind of corruptions. Return values are there for a reason. > Actually, I'm not clear how about the state changing of futex in kernel. > I search the Internet, see a similar failure from other users. He is using > Kernel 2.6.38. Our customer is using kernel 2.6.34 (WindRiver Linux 4.1) So your customer should talk to WindRiver about this. I have no idea what kind of patches WindRiver has in their kernel and I really don't want to know it. If you can reproduce that issue against a recent mainline kernel, then I'm happy to analyze that. > ==== > http://www.programdoc.com/1272_157986_1.htm Your supply of weird web pages seems to be infinite. > But I can not understand the sample failure case which he mentioned. But I think > It might be helpful for you to analyze the corner case. No, it's absolutely NOT helpful because it's just random guesswork as the flow he is describing is just not possible. That guy never showed his test case, so I have no idea how he can 'proof' his theory. Thanks, tglx -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Zhu Jefferry <Jefferry.Zhu@freescale.com> |
|---|---|
| Date | 2015-09-17 02:00 +0200 |
| Message-ID | <q9uMh-2R6-1@gated-at.bofh.it> |
| In reply to | #1226088 |
> On Wed, 16 Sep 2015, Zhu Jefferry wrote: > > > > The primary debugging shows the content of __lock is wrong in first. > > > > After a call of Mutex_unlock, the value of __lock should not be > > > > this thread self. But we observed The value of __lock is still > > > > self after unlock. So, other threads will be stuck, > > > > > > How did you observe that? > > > > Add one assert in mutex_unlock, after it finish the __lock modify > > either in User space or kernel space, before return. > > And that assert tells you that the kernel screwed up the futex value? > No, it does not. It merily tells you that the value is not what you > expect, but it does not tell you what caused that. > > Hint: There are proper instrumentation tools, e.g. tracing, which tell > you the exact flow of events and not just the observation after the fact. I'm trying to get more details about the failure flow. But I'm told a little Bit timing changing in the code might impact the failure appear in a longer time, or even disappear. > > > > > This thread could lock due to recursive type and __counter keep > > > > increasing, although mutex_unlock return fails, due to the wrong > > > > value of __owner, but the application did not check the return > > > > value. So the thread 0 looks like fine. But thread 1 will be stuck > forever. > > > > > > Oh well. So thread 0 looks all fine, despite not checking return > values. > > > > > > > Correct. > > No. That's absolutely NOT correct. Not checking return values can cause > all kind of corruptions. Return values are there for a reason. > Besides the application did not check the return value, the mutex_unlock in Libc did not check the return value from kernel neither. -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Thomas Gleixner <tglx@linutronix.de> |
|---|---|
| Date | 2015-09-17 09:20 +0200 |
| Message-ID | <q9BE6-4IO-21@gated-at.bofh.it> |
| In reply to | #1226584 |
On Wed, 16 Sep 2015, Zhu Jefferry wrote: > Besides the application did not check the return value, the mutex_unlock in > Libc did not check the return value from kernel neither. That's even worse. Thanks, tglx -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web