Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754231AbdIFA2u (ORCPT ); Tue, 5 Sep 2017 20:28:50 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:5972 "EHLO szxga04-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753133AbdIFA2t (ORCPT ); Tue, 5 Sep 2017 20:28:49 -0400 Subject: Re: a competition when some threads acquire futex To: Thomas Gleixner CC: , , , , References: <3e497508-876f-6474-3f3d-acab06a63b55@huawei.com> From: "chengjian (D)" Message-ID: <555186f2-8240-f7d0-e1b0-9ad1a67ff34c@huawei.com> Date: Wed, 6 Sep 2017 08:27:31 +0800 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 7bit X-Originating-IP: [10.177.219.85] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A090201.59AF411B.0031,ss=1,re=0.000,recu=0.000,reip=0.000,cl=1,cld=1,fgs=0, ip=0.0.0.0, so=2014-11-16 11:51:01, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: 62014360db6aa97040ed5abcc650f4da Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1862 Lines: 84 >> 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( ); > Hi Thomas, I wrote _cond_resched( ) in futex_wake( ) which will be called to wake up waiters when the process release the futex. But the patch producted by git format-patch displayed in wake_futex_pi( ). ```c /* * Wake up waiters matching bitset queued on this futex (uaddr). */ static int futex_wake(u32 __user *uaddr, unsigned int flags, int nr_wake, u32 bitset) { struct futex_hash_bucket *hb; struct futex_q *this, *next; union futex_key key = FUTEX_KEY_INIT; int ret; DEFINE_WAKE_Q(wake_q); if (!bitset) return -EINVAL; ret = get_futex_key(uaddr, flags & FLAGS_SHARED, &key, VERIFY_READ); if (unlikely(ret != 0)) goto out; hb = hash_futex(&key); /* Make sure we really have tasks to wakeup */ if (!hb_waiters_pending(hb)) goto out_put_key; spin_lock(&hb->lock); plist_for_each_entry_safe(this, next, &hb->chain, list) { if (match_futex (&this->key, &key)) { if (this->pi_state || this->rt_waiter) { ret = -EINVAL; break; } /* Check if one of the bits is set in both bitsets */ if (!(this->bitset & bitset)) continue; mark_wake_futex(&wake_q, this); if (++ret >= nr_wake) break; } } spin_unlock(&hb->lock); wake_up_q(&wake_q); + _cond_resched( ); out_put_key: put_futex_key(&key); out: return ret; } ``` Thanks. Cheng Jian