Skip to content

Commit 3822da3

Browse files
nhaehnleingomolnar
authored andcommitted
locking/ww_mutex: Extract stamp comparison to __ww_mutex_stamp_after()
The function will be re-used in subsequent patches. Signed-off-by: Nicolai Hähnle <Nicolai.Haehnle@amd.com> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: Daniel Vetter <daniel@ffwll.ch> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Maarten Lankhorst <dev@mblankhorst.nl> Cc: Paul E. McKenney <paulmck@linux.vnet.ibm.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: dri-devel@lists.freedesktop.org Link: http://lkml.kernel.org/r/1482346000-9927-4-git-send-email-nhaehnle@gmail.com Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent e274795 commit 3822da3

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

‎kernel/locking/mutex.c‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,13 @@ static __always_inline void ww_mutex_lock_acquired(struct ww_mutex *ww,
281281
ww_ctx->acquired++;
282282
}
283283

284+
static inline bool __sched
285+
__ww_ctx_stamp_after(struct ww_acquire_ctx *a, struct ww_acquire_ctx *b)
286+
{
287+
return a->stamp - b->stamp <= LONG_MAX &&
288+
(a->stamp != b->stamp || a > b);
289+
}
290+
284291
/*
285292
* After acquiring lock with fastpath or when we lost out in contested
286293
* slowpath, set ctx and wake up any waiters so they can recheck.
@@ -597,8 +604,7 @@ __ww_mutex_lock_check_stamp(struct mutex *lock, struct ww_acquire_ctx *ctx)
597604
if (!hold_ctx)
598605
return 0;
599606

600-
if (ctx->stamp - hold_ctx->stamp <= LONG_MAX &&
601-
(ctx->stamp != hold_ctx->stamp || ctx > hold_ctx)) {
607+
if (__ww_ctx_stamp_after(ctx, hold_ctx)) {
602608
#ifdef CONFIG_DEBUG_MUTEXES
603609
DEBUG_LOCKS_WARN_ON(ctx->contending_lock);
604610
ctx->contending_lock = ww;

0 commit comments

Comments
 (0)