Re: a competition when some threads acquire futex

2017-09-06 Thread chengjian (D)
On 2017/9/6 16:36, Thomas Gleixner write: Ok. Still that patch has issues. 1) It's white space damaged. Please use TAB not spaces for indentation. checkpatch.pl would have told you. 2) Why are you using _cond_resched() instead of plain cond_resched(). cond_resched() is what you want to

Re: a competition when some threads acquire futex

2017-09-06 Thread Peter Zijlstra
On Wed, Sep 06, 2017 at 10:56:08AM +0200, Peter Zijlstra wrote: > Right, but even if it was a coherent patch, I'm not sure it makes sense. > > futex_wait() / futex_wake() don't make ordering guarantees and in > general you don't get to have wakeup preemption if you don't run a > PREEMPT kernel. >

Re: a competition when some threads acquire futex

2017-09-06 Thread Peter Zijlstra
On Wed, Sep 06, 2017 at 10:36:29AM +0200, Thomas Gleixner wrote: > On Wed, 6 Sep 2017, chengjian (D) wrote: > > > > > 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 in

Re: a competition when some threads acquire futex

2017-09-06 Thread Thomas Gleixner
On Wed, 6 Sep 2017, chengjian (D) wrote: > > > 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

Re: a competition when some threads acquire futex

2017-09-05 Thread chengjian (D)
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_res

Re: a competition when some threads acquire futex

2017-09-05 Thread Thomas Gleixner
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 ftr

a competition when some threads acquire futex

2017-09-04 Thread chengjian (D)
A competition happend when some thread use pthread_mutex(futex in kernel). I make a demo about this : two thread get a lock and then sleep for a few time, finally unlock when waked up. ```cpp pthread_mutex_lock(&mutex); //printf("tid = %lu, count = %d\n", pthread_self( ), i);