Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752978AbdIEThQ (ORCPT ); Tue, 5 Sep 2017 15:37:16 -0400 Received: from Galois.linutronix.de ([146.0.238.70]:46726 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752894AbdIEThO (ORCPT ); Tue, 5 Sep 2017 15:37:14 -0400 Date: Tue, 5 Sep 2017 21:37:03 +0200 (CEST) From: Thomas Gleixner To: "chengjian (D)" cc: huawei.libin@huawei.com, mingo@redhat.com, peterz@infradead.org, dvhart@infradead.org, linux-kernel@vger.kernel.org Subject: Re: a competition when some threads acquire futex In-Reply-To: <3e497508-876f-6474-3f3d-acab06a63b55@huawei.com> Message-ID: References: <3e497508-876f-6474-3f3d-acab06a63b55@huawei.com> User-Agent: Alpine 2.20 (DEB 67 2015-01-07) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Linutronix-Spam-Score: -1.0 X-Linutronix-Spam-Level: - X-Linutronix-Spam-Status: No , -1.0 points, 5.0 required, ALL_TRUSTED=-1,SHORTCIRCUIT=-0.0001 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1118 Lines: 40 On Tue, 5 Sep 2017, chengjian (D) wrote: > int main(int argc, char** argv) > { > pthread_t id1; > pthread_t id2; > > printf("main pid = %d\n", getpid( )); > > pthread_mutex_init(&mutex, NULL); So this is a plain mutex, which maps to a plain futex. > use perf ftrace to shows the graph of the function calls. We found that the > process 17327 auquire the lock quickly after call futex_wake( ), so the > process 17328 futex_wait( ) all the time. The observed functions look correct for that futex type. > diff --git a/kernel/futex.c b/kernel/futex.c > index 3d38eaf..0b2d17a 100644 > --- a/kernel/futex.c > +++ b/kernel/futex.c > @@ -1545,6 +1545,7 @@ static int wake_futex_pi(u32 __user *uaddr, u32 uval, > struct futex_pi_state *pi_ > spin_unlock(&hb->lock); > wake_up_q(&wake_q); > + _cond_resched( ); What's less correct is the placement of the cond_resched() which you patch into the function: wake_futex_pi() wake_futex_pi() is not even remotely involved in this problem, so I have a hard time to understand how this patch 'solves' it. Thanks, tglx