[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <62d8f603dc654d74b98cf2a5d4cf8c61@AcuMS.aculab.com>
Date: Fri, 3 May 2019 14:37:21 +0000
From: David Laight <David.Laight@...LAB.COM>
To: 'Peter Zijlstra' <peterz@...radead.org>,
Waiman Long <longman@...hat.com>
CC: Ingo Molnar <mingo@...hat.com>, Will Deacon <will.deacon@....com>,
"Thomas Gleixner" <tglx@...utronix.de>,
Borislav Petkov <bp@...en8.de>,
"H. Peter Anvin" <hpa@...or.com>,
"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
"x86@...nel.org" <x86@...nel.org>,
"Davidlohr Bueso" <dave@...olabs.net>,
Linus Torvalds <torvalds@...ux-foundation.org>,
Tim Chen <tim.c.chen@...ux.intel.com>,
huang ying <huang.ying.caritas@...il.com>
Subject: RE: [PATCH-tip v7 08/20] locking/rwsem: Implement lock handoff to
prevent lock starvation
From: Peter Zijlstra
> Sent: 03 May 2019 14:11
> To: Waiman Long
...
> I've changed that like so.
>
> --- a/kernel/locking/rwsem.c
> +++ b/kernel/locking/rwsem.c
> @@ -406,19 +406,23 @@ static inline bool rwsem_try_write_lock(
> long new;
>
> lockdep_assert_held(&sem->wait_lock);
> +
> do {
> bool has_handoff = !!(count & RWSEM_FLAG_HANDOFF);
>
> if (has_handoff && wstate == WRITER_NOT_FIRST)
> return false;
>
> + new = count;
> +
> if (count & RWSEM_LOCK_MASK) {
> if (has_handoff || (wstate != WRITER_HANDOFF))
> return false;
> - new = count | RWSEM_FLAG_HANDOFF;
> +
> + new |= RWSEM_FLAG_HANDOFF;
> } else {
> - new = (count | RWSEM_WRITER_LOCKED) &
> - ~RWSEM_FLAG_HANDOFF;
> + new |= RWSEM_WRITER_LOCKED;
> + new &= ~RWSEM_FLAG_HANDOFF;
>
> if (list_is_singular(&sem->wait_list))
> new &= ~RWSEM_FLAG_WAITERS;
The compiler will probably convert it back :-)
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
Powered by blists - more mailing lists