Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1466627

Re: [PATCH v4] locking/mutex: Prevent lock starvation when spinning is disabled

From Peter Zijlstra <peterz@infradead.org>
Newsgroups linux.kernel
Subject Re: [PATCH v4] locking/mutex: Prevent lock starvation when spinning is disabled
Date 2016-08-19 21:40 +0200
Message-ID <s7XO1-1lr-3@gated-at.bofh.it> (permalink)
References <s7HpU-7RC-31@gated-at.bofh.it> <s7XO1-1lr-5@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


Please trim your emails..

On Fri, Aug 19, 2016 at 12:57:06PM -0400, Waiman Long wrote:

> >+static inline bool __mutex_trylock_pending(struct mutex *lock)
> >+{
> >+	return atomic_read(&lock->count)>= 0&&
> >+	       atomic_xchg_acquire(&lock->count, -1) == 1;
> >+}
> >+
> 
> Maybe you can make a more general __mutex_trylock function that is used in
> all three trylock attempts in the slowpath. For example,
> 
> static inline bool __mutex_trylock(struct mutex *lock, bool waiter)
> {
>     if (waiter) {
>         return atomic_read(&lock->count) >= 0 &&
>                atomic_xchg_acquire(&lock->count, -1) == 1;
>     } else {
>         return !need_yield_to_waiter(lock) &&
>                !mutex_is_locked(lock) &&
>                ((atomic_xchg_acquire(&lock->count, 0) == 1);
>     }
> }

That seems more messy to me..

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH v4] locking/mutex: Prevent lock starvation when spinning is  disabled Jason Low <jason.low2@hpe.com> - 2016-08-19 04:10 +0200
  Re: [PATCH v4] locking/mutex: Prevent lock starvation when spinning  is disabled Jason Low <jason.low2@hpe.com> - 2016-08-19 06:30 +0200
    Re: [PATCH v4] locking/mutex: Prevent lock starvation when spinning  is disabled Peter Zijlstra <peterz@infradead.org> - 2016-08-19 14:20 +0200
  Re: [PATCH v4] locking/mutex: Prevent lock starvation when spinning  is disabled Peter Zijlstra <peterz@infradead.org> - 2016-08-19 21:40 +0200
    Re: [PATCH v4] locking/mutex: Prevent lock starvation when spinning  is disabled Linus Torvalds <torvalds@linux-foundation.org> - 2016-08-19 21:50 +0200
      Re: [PATCH v4] locking/mutex: Prevent lock starvation when spinning  is disabled Peter Zijlstra <peterz@infradead.org> - 2016-08-23 14:50 +0200

csiph-web