mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "chengjian (D)" <cj.chengjian@huawei.com>
To: Thomas Gleixner <tglx@linutronix.de>
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
Date: Wed, 6 Sep 2017 08:27:31 +0800	[thread overview]
Message-ID: <555186f2-8240-f7d0-e1b0-9ad1a67ff34c@huawei.com> (raw)
In-Reply-To: <alpine.DEB.2.20.1709052131130.2393@nanos>

>> 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

  reply	other threads:[~2017-09-06  0:28 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-09-05  1:50 chengjian (D)
2017-09-05 19:37 ` Thomas Gleixner
2017-09-06  0:27   ` chengjian (D) [this message]
2017-09-06  8:36     ` Thomas Gleixner
2017-09-06  8:56       ` Peter Zijlstra
2017-09-06  9:06         ` Peter Zijlstra
2017-09-06  9:09       ` chengjian (D)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=555186f2-8240-f7d0-e1b0-9ad1a67ff34c@huawei.com \
    --to=cj.chengjian@huawei.com \
    --cc=dvhart@infradead.org \
    --cc=huawei.libin@huawei.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=tglx@linutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®