lkml.org 
[lkml]   [2017]   [Sep]   [5]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
SubjectRe: a competition when some threads acquire futex
From
Date
>> 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


\
 
 \ /
  Last update: 2017-09-06 02:29    [W:0.053 / U:9.324 seconds]
©2003-2017 Jasper Spaans. hosted at Digital OceanAdvertise on this site