From patchwork Wed Nov 23 11:25:23 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: 9443011 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 159D2600BA for ; Wed, 23 Nov 2016 11:26:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E12551FE95 for ; Wed, 23 Nov 2016 11:26:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D61E52236A; Wed, 23 Nov 2016 11:26:02 +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 7655F1FE95 for ; Wed, 23 Nov 2016 11:26:02 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 3A0476E81F; Wed, 23 Nov 2016 11:25:59 +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 ECE566E81D for ; Wed, 23 Nov 2016 11:25:51 +0000 (UTC) Received: by mail-wm0-x244.google.com with SMTP id u144so1683369wmu.0 for ; Wed, 23 Nov 2016 03:25:51 -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=PQoId+erDFAw14F/2bRPb4uf8Sh6Japbu9qFij1a69g=; b=aYAdiX6BAQuBOVUEQ8GQgNziSWnu4VXHjQX0NKcucW4Vk3xZVQAX+uu9Gr2eTeeHiB 06Xeucn/oxeggPBg35uLgmRo+qJTMkmlqWnbzPDYYzSbbhej5p/h2/tva9kBk5bdIfso 0NtWPywkU0KvbpebUTqpExnRd/oa2AP2pIrctVCcNDLtCJ9e/qVZR0GJERm7rehc73+N gzw4uj5gXtj/TN4iNLLquQ7BDvYoukSxXNLcAN28oaE/KSEb86h7ojGUK3jqtUPFEXsB m6UeavbYHxZqi1OtYiubUXQTVPlNPkYN3/8+3eQe4gNPBUvQxEL5tiAjf9/eMOJ1gLQj ePKQ== 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=PQoId+erDFAw14F/2bRPb4uf8Sh6Japbu9qFij1a69g=; b=Wg4ESQj+qTiC4WGawAorXoC1xIdmglzRImhqi9ND/inlAnsV4VCndbAYVKeoU8U1HZ zNwTH9hU1aR81oqJSN5ouG3lxN/tHDRiVFNnEdRUqlk3Ua4Ibk3bAs50EXdAcvMjRntE JBwFWFk5yEf2zwVN73q2PbxoWwrzJz0Bh05EbSDriLteuVlMc/ujmG+UCQBFgkekW/C/ NI6grow0nz5zcskwQa1M9yB521IXdlXtwDPgI3CrmCWXp8d7WSf9IFvAQb6duEqQEDjh rr/lT6/uGNcU0xIF67hhznCeAcmkLiVRVfXOnMvCjBnvlGe5oNUbNxtU68QhsFTo5Ryq 1+6Q== X-Gm-Message-State: AKaTC01xlX5BQu5MU5K2qVqBq/CreQmCjyY6tnb98Z4aFU5o235c3lo1qFkrPXmfxTs8jw== X-Received: by 10.28.27.133 with SMTP id b127mr7172442wmb.59.1479900350361; Wed, 23 Nov 2016 03:25:50 -0800 (PST) Received: from cassiopeia.fritz.box ([2001:a61:1157:fa01:f4ca:31b1:e109:5ff4]) by smtp.gmail.com with ESMTPSA id c133sm2264367wme.12.2016.11.23.03.25.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 23 Nov 2016 03:25:49 -0800 (PST) From: =?UTF-8?q?Nicolai=20H=C3=A4hnle?= To: linux-kernel@vger.kernel.org Subject: [PATCH 2/4] locking/ww_mutex: Remove redundant wakeups in ww_mutex_set_context_slowpath Date: Wed, 23 Nov 2016 12:25:23 +0100 Message-Id: <1479900325-28358-2-git-send-email-nhaehnle@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1479900325-28358-1-git-send-email-nhaehnle@gmail.com> References: <1479900325-28358-1-git-send-email-nhaehnle@gmail.com> MIME-Version: 1.0 Cc: =?UTF-8?q?Nicolai=20H=C3=A4hnle?= , Peter Zijlstra , dri-devel@lists.freedesktop.org, Ingo Molnar , Maarten Lankhorst 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 When ww_mutex_set_context_slowpath runs, we are in one of two situations: 1. The current task was woken up by ww_mutex_unlock. 2. The current task is racing with ww_mutex_unlock: We entered the slow path while lock->base.count <= 0, but skipped the wait in __mutex_lock_common. In both cases, all tasks that are currently contending for the lock are either racing as in point 2 and blocked on lock->wait_lock, or they have been or will be woken up by ww_mutex_unlock. Either way, they will check their stamp against ours without having to be woken up again. This improvement is possible only after the changed behavior of ww_mutex_unlock from the previous patch ("locking/ww_mutex: Fix a deadlock affecting ww_mutexes"). Cc: Peter Zijlstra Cc: Ingo Molnar Cc: Chris Wilson Cc: Maarten Lankhorst Cc: dri-devel@lists.freedesktop.org Signed-off-by: Nicolai Hähnle --- kernel/locking/mutex.c | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/kernel/locking/mutex.c b/kernel/locking/mutex.c index 7fbf9b4..7c09376 100644 --- a/kernel/locking/mutex.c +++ b/kernel/locking/mutex.c @@ -192,8 +192,10 @@ ww_mutex_set_context_fastpath(struct ww_mutex *lock, } /* - * After acquiring lock in the slowpath set ctx and wake up any - * waiters so they can recheck. + * After acquiring lock in the slowpath set ctx. + * + * Unlike the fast path, other waiters are already woken up by ww_mutex_unlock, + * so we don't have to do it again here. * * Callers must hold the mutex wait_lock. */ @@ -201,19 +203,8 @@ static __always_inline void ww_mutex_set_context_slowpath(struct ww_mutex *lock, struct ww_acquire_ctx *ctx) { - struct mutex_waiter *cur; - ww_mutex_lock_acquired(lock, ctx); lock->ctx = ctx; - - /* - * Give any possible sleeping processes the chance to wake up, - * so they can recheck if they have to back off. - */ - list_for_each_entry(cur, &lock->base.wait_list, list) { - debug_mutex_wake_waiter(&lock->base, cur); - wake_up_process(cur->task); - } } #ifdef CONFIG_MUTEX_SPIN_ON_OWNER