From patchwork Mon Nov 28 12:20:04 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Nicolai_H=C3=A4hnle?= X-Patchwork-Id: 9449473 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 70125600CB for ; Mon, 28 Nov 2016 12:20:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 60B6E20453 for ; Mon, 28 Nov 2016 12:20:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5597C27BFF; Mon, 28 Nov 2016 12:20:52 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id E75D020453 for ; Mon, 28 Nov 2016 12:20:51 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 92D056E2D0; Mon, 28 Nov 2016 12:20:36 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wm0-x244.google.com (mail-wm0-x244.google.com [IPv6:2a00:1450:400c:c09::244]) by gabe.freedesktop.org (Postfix) with ESMTPS id E5F736E2BD for ; Mon, 28 Nov 2016 12:20:25 +0000 (UTC) Received: by mail-wm0-x244.google.com with SMTP id g23so18701591wme.1 for ; Mon, 28 Nov 2016 04:20:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=EiAL+0zqfY8XXrIqFdg6UIT/lYRHtd1vHgEj1ErtdwI=; b=ch0ZW7E18IDNr7UaqTxHxap9UdPPrq2Tkv5nQu2QPCeOKSTCNTNSbqm9dyjrooVBfG DKoFrUTe5AuRf0xXV7EUhmjI8RjaSHivb88QNSTSWaLH6KkDAuJFrCtgF6tDjCkV9suN iuVKF6fEwFk076hzUWYc0AMEMnJJU2SF7oRAZZfQveumkhNw1+lcXCY/ng4ZWizRZkVE oSmXGJz3LGUcsh8yvQRFUt2+SUjZmkqzukbKWY03lrQfrBZiyITXC2iFqGRMxqyC3mPG s13NarMWiTEAx+3n70WsQGlV8etnqttlKO8DF8IAuf3i8oCMmgHhxFwGeYTetKL7o9om HP4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=EiAL+0zqfY8XXrIqFdg6UIT/lYRHtd1vHgEj1ErtdwI=; b=lnjDI4iOELkqgoNH58UCDxs+/mgLcYFXsg/Dj7NJk+feiKGCuRqBbqjF+pk+QkYirh L2PL/LqcaS+PvX9JfkFvj5xRRb2ZeRV8BYSRWzXIDjvTQkNp0stq0uqUI9NecrQApf3u gO6WkMmBF7Q92O7ASnVqKy2Ypd9ImGfFA+2+98Nc4A53E13qt0FSofRT6VwE2gWolhqN cmECnXwrf9XHmPC6yg+iWIanDFlR5zwqhslc2IAvlXB2O2bIMljIfBZYWh8W5zLRV5z3 7gxuNeQdXUQE8MBBibNcq2Lxfc6N6UQNiQ5p1ta+TJTPcdVjD7znINITf41G6VdttDg3 ciDQ== X-Gm-Message-State: AKaTC019oOlh0w8o7tmHUOIVlsYv2U+8G18NwpuSLi22jfo8EFrZCSvAUQ2zzqX8HEaKaQ== X-Received: by 10.28.39.5 with SMTP id n5mr18477399wmn.54.1480335624323; Mon, 28 Nov 2016 04:20:24 -0800 (PST) Received: from cassiopeia.fritz.box ([2001:a61:1119:dc01:d88b:9432:f601:27ed]) by smtp.gmail.com with ESMTPSA id a13sm28830511wma.18.2016.11.28.04.20.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 28 Nov 2016 04:20:23 -0800 (PST) From: =?UTF-8?q?Nicolai=20H=C3=A4hnle?= To: linux-kernel@vger.kernel.org Subject: [PATCH 03/11] locking/ww_mutex: Extract stamp comparison to __ww_mutex_stamp_after Date: Mon, 28 Nov 2016 13:20:04 +0100 Message-Id: <1480335612-12069-4-git-send-email-nhaehnle@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1480335612-12069-1-git-send-email-nhaehnle@gmail.com> References: <1480335612-12069-1-git-send-email-nhaehnle@gmail.com> MIME-Version: 1.0 Cc: Maarten Lankhorst , =?UTF-8?q?Nicolai=20H=C3=A4hnle?= , Peter Zijlstra , dri-devel@lists.freedesktop.org, Ingo Molnar X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Nicolai Hähnle The function will be re-used in subsequent patches. Cc: Peter Zijlstra Cc: Ingo Molnar Cc: Maarten Lankhorst Cc: Daniel Vetter Cc: Chris Wilson Cc: dri-devel@lists.freedesktop.org Signed-off-by: Nicolai Hähnle --- kernel/locking/mutex.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/kernel/locking/mutex.c b/kernel/locking/mutex.c index 0afa998..200629a 100644 --- a/kernel/locking/mutex.c +++ b/kernel/locking/mutex.c @@ -277,6 +277,13 @@ static __always_inline void ww_mutex_lock_acquired(struct ww_mutex *ww, ww_ctx->acquired++; } +static inline bool __sched +__ww_mutex_stamp_after(struct ww_acquire_ctx *a, struct ww_acquire_ctx *b) +{ + return a->stamp - b->stamp <= LONG_MAX && + (a->stamp != b->stamp || a > b); +} + /* * After acquiring lock with fastpath or when we lost out in contested * slowpath, set ctx and wake up any waiters so they can recheck. @@ -610,8 +617,7 @@ __ww_mutex_lock_check_stamp(struct mutex *lock, struct ww_acquire_ctx *ctx) if (!hold_ctx) return 0; - if (ctx->stamp - hold_ctx->stamp <= LONG_MAX && - (ctx->stamp != hold_ctx->stamp || ctx > hold_ctx)) { + if (__ww_mutex_stamp_after(ctx, hold_ctx)) { #ifdef CONFIG_DEBUG_MUTEXES DEBUG_LOCKS_WARN_ON(ctx->contending_lock); ctx->contending_lock = ww;