From patchwork Wed Dec 21 18:46:31 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: 9483635 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 81406601D3 for ; Wed, 21 Dec 2016 18:47:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 75F0728424 for ; Wed, 21 Dec 2016 18:47:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6AC7D28419; Wed, 21 Dec 2016 18:47:15 +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 2B34D28419 for ; Wed, 21 Dec 2016 18:47:15 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 2D2936F0D1; Wed, 21 Dec 2016 18:47:03 +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 9E3496E0F0 for ; Wed, 21 Dec 2016 18:46:52 +0000 (UTC) Received: by mail-wm0-x244.google.com with SMTP id m203so32030076wma.3 for ; Wed, 21 Dec 2016 10:46:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=rVZWf5n9+tjjxmWt+a/vXil0XT54eNULnxI624NIsA8=; b=uS6svfpuESI6d/I7HxS20fL4a7WIHl8gWyKHxQeG3AS2AgJ51sDBaRjovrLaZC5gZo 7cPKxYt9ufu3Z8OeevUYSud6aJrZxtxxcIyV2yl2stcpZxeLQ1tj56Wxae8qEFjP7U0n 6P1Hq0KTgEGu3gKdKllIWw5YhUy+WZImcV//GuK58qiDPf/Q6AuAdNNVlwtpN6LqDVk6 bGGm8fdh7LtQNwQCo8wRk2mBnJMmoFze8reE22l9VejUd2goLPyLO2405f1uKAh4sOig 5XpccoFxd8P3JVHWS08yi5mhbNGH9U99CbXvZOoBtqONyIBMqSHKzWEqhL76khCKsChA iUHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=rVZWf5n9+tjjxmWt+a/vXil0XT54eNULnxI624NIsA8=; b=UdRoC4lKYBwO2yPhNhQCLSM60RQN4vyophyqGgF/rBZ56Znt7j5ZD57ZBV+ddgUjvV 717BoNASz7dIUFSLRQCvZBI9xqX6Yz3ksqje6nKDKSHDZ051Ac/3OdwTDCEeXbBs8Wi6 WJsz/O7YmhgWQjsgALOBlZdejnRrmI5wYGxgh5V3rW4X0DIPxrm9ssGy/ZVahmAYgAN9 jcI4zKyDh+9WwoTS0YOJovhX7SkRPkon7v0AIS81psPMFLX3TPknpJfTbzs7PDIiHber pHqBFH2AV702QUMRGCQjWjrJzAI0qv+0PmVWXbryb/eSg3ZC9FaIHth9ALbgrPy53v0I wWqg== X-Gm-Message-State: AIkVDXKnJOwiE4HDRXeIR5qyXt/gxCzJhXwvlxb4Odc2XpX30I/6HFoJ0wEAYDlObdiTlQ== X-Received: by 10.28.216.9 with SMTP id p9mr6014289wmg.11.1482346010795; Wed, 21 Dec 2016 10:46:50 -0800 (PST) Received: from cassiopeia.fritz.box ([2001:a61:110a:1701:2511:6687:1ba5:b45b]) by smtp.gmail.com with ESMTPSA id ke6sm31840526wjb.21.2016.12.21.10.46.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 21 Dec 2016 10:46:50 -0800 (PST) From: =?UTF-8?q?Nicolai=20H=C3=A4hnle?= To: linux-kernel@vger.kernel.org Subject: [PATCH v3 03/12] locking/ww_mutex: Extract stamp comparison to __ww_mutex_stamp_after Date: Wed, 21 Dec 2016 19:46:31 +0100 Message-Id: <1482346000-9927-4-git-send-email-nhaehnle@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1482346000-9927-1-git-send-email-nhaehnle@gmail.com> References: <1482346000-9927-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. v3: rename to __ww_ctx_stamp_after (Chris Wilson) 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 Reviewed-by: Chris Wilson --- 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 c02c566..66718d6 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_ctx_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. @@ -602,8 +609,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_ctx_stamp_after(ctx, hold_ctx)) { #ifdef CONFIG_DEBUG_MUTEXES DEBUG_LOCKS_WARN_ON(ctx->contending_lock); ctx->contending_lock = ww;