From patchwork Thu Dec 1 14:06:46 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: 9456221 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 B7B9E60235 for ; Thu, 1 Dec 2016 14:07:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A982F284D9 for ; Thu, 1 Dec 2016 14:07:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9CBBC284DE; Thu, 1 Dec 2016 14:07:24 +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 A5C9E284D9 for ; Thu, 1 Dec 2016 14:07:23 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 1108D6E7F3; Thu, 1 Dec 2016 14:07:10 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wm0-x243.google.com (mail-wm0-x243.google.com [IPv6:2a00:1450:400c:c09::243]) by gabe.freedesktop.org (Postfix) with ESMTPS id 51DEE6E1B5 for ; Thu, 1 Dec 2016 14:07:05 +0000 (UTC) Received: by mail-wm0-x243.google.com with SMTP id g23so34457265wme.1 for ; Thu, 01 Dec 2016 06:07:05 -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=UnWP1NN1eL9J8ZUWlk71nMJ1yE7cjUzNDgCJ7sqH0zelD4YgPb6agMeqIbqqED0RkJ S6orNCE/yFiWeiZD1iEfaRlKLMF95DSj0PKvHRvbIjm0ojBr0TnGqFB+GQbxdppGVNfN PvLCU36YrFHMIPXDw4U5PigtQS/kGq3hVJBT38n8xlEVZgu4ocR/+VPO9LjcH0TTGkNx 1CNRFYCp72RSNVYmee5DuHVyx3gG/24tBKTGcasvVXy1E5i7r2KdzkYdVdKOzH1uiQjJ xBxwfUFM0CKzdJ2KswFOs52+YWwDDKaLFQt1f8bxlpFbl9SMU04iBEqWR8YAuQw/e5Cs 5Ewg== 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=CgTcZ8rQIEN24xUFt+2TRRdFS56ePUB6VhkF6rXsvNA8NogXZrZUmsv/Va2e6yveBa fJHmY0ZqxiRTb2aiesCz9Sj391kmsaQ80zuPH4+NtmXd6/Ur9iQJZS2qzkJr0fxTOKlt W9VJCppXD7YQxbSz9Gr7vFAVoEM6TRI4Q10soiYv/yFvG5inuOc+1AYhz6yjhQDeBvCH y047czln2wI6UMxGY9h5TFM1hO7EhinEiddczNRlrfL0vKZUxbs3ED2BoHXCADp0wLbW zr86JTpy3k+YU1ZG4X+kt739G/5A2MSeACZi+RYzBzXRPX0+/cLy8B2llHUvu/mstSHj o04Q== X-Gm-Message-State: AKaTC03B+7iCNkhXJ4xNTL/3TlPFDVrjhIVw/EcxhqpxeWRXRRGLGVERaJnU0HLAMV0YoA== X-Received: by 10.28.136.80 with SMTP id k77mr32444240wmd.57.1480601223780; Thu, 01 Dec 2016 06:07:03 -0800 (PST) Received: from cassiopeia.fritz.box ([2001:a61:116e:7d01:dc12:8e88:ab9d:8694]) by smtp.gmail.com with ESMTPSA id vr9sm411514wjc.35.2016.12.01.06.07.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 01 Dec 2016 06:07:03 -0800 (PST) From: =?UTF-8?q?Nicolai=20H=C3=A4hnle?= To: linux-kernel@vger.kernel.org Subject: [PATCH v2 03/11] locking/ww_mutex: Extract stamp comparison to __ww_mutex_stamp_after Date: Thu, 1 Dec 2016 15:06:46 +0100 Message-Id: <1480601214-26583-4-git-send-email-nhaehnle@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1480601214-26583-1-git-send-email-nhaehnle@gmail.com> References: <1480601214-26583-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 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 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;