From patchwork Tue Sep 12 19:55:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?TWljaGHFgiBNaXJvc8WCYXc=?= X-Patchwork-Id: 138521 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9ecd:0:b0:3f2:4152:657d with SMTP id t13csp784918vqx; Tue, 12 Sep 2023 18:18:53 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGijn4GLu4gJAMWNHkNF3ZAPAgauU1uupFYNpyHeCsmoY/dCs1XgWM5Z8FYJ+sGwyotwTZF X-Received: by 2002:a05:6a20:840c:b0:153:78c1:c40f with SMTP id c12-20020a056a20840c00b0015378c1c40fmr1349180pzd.15.1694567933654; Tue, 12 Sep 2023 18:18:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694567933; cv=none; d=google.com; s=arc-20160816; b=po0UAaEnS/rEz8wAWvjTFy3KCfFwI30gBrYX5tl5kEcpdRM70QCIfcf6yGVTClheOx vGpky1AjZTIfxvGhmVjbguthOF0SjOmr/dZ7OiwKx2Ddv61FbL+3314qngnsX4Q3mXfA BucvhaIiyaMhWHDbaLvohbaE9voJl53AnpomKejfwVR/oRJwXGivu21EJfYx5KMMMego 89+k9ByAoAoVfE1C2jmdU+YCb3DoePBaLR3zBqbsWKMvFg07olq1S0l6bNQA6XLi/Z/r 8qx5KN3e6dbsr+ZPZqrxbSMjyayiCSKWIsriGWUCChAgwe3ZA+ilY97xHurc6MjsmxTI StNQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:content-transfer-encoding :mime-version:subject:message-id:date:dkim-signature; bh=bIG981QgLgyPMGjO/7RGs0y9MAXh1lBMMQqNwmbfalA=; fh=tyZufdtKU8i3QJ3YqjhtI8A6hXNmCazTE4jjM25vgfY=; b=hq7KRG+CammV3SlFDEutsW7YeOVMl7zxvtM/YaXDWL5O7jS6vqYqXSgKMTOVhz5RXF vb6Wj3Hua6vhIwYuzhLCCBhGm+YEGEFZwxAZ1DWNlFsgrnzzCBIZEkoiWw7o22FXb0CT ewDN943s6inj5XYMNDZ5jd17kI3XanG5w3arEkTJQdhEUg4OqKmO8NSiF5R5h+mpA+pT Dw7rV4gkXss3tGXM/xtdr5gt0GnN+Nj3ZF5lp04jMDk/sehYVNyQLrZsU4O4j+vt58R+ An5G5jx062SyT41LJWZPnIw36+Frm4tM2F43j2GP7Jb5kRsP81FB+s6zhtn5YYdTYjUo RmBA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rere.qmqm.pl header.s=1 header.b=lmOpXkrU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=rere.qmqm.pl Received: from howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id pi10-20020a17090b1e4a00b00261326aa56esi528967pjb.5.2023.09.12.18.18.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Sep 2023 18:18:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@rere.qmqm.pl header.s=1 header.b=lmOpXkrU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=rere.qmqm.pl Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 62AE983B008E; Tue, 12 Sep 2023 12:55:22 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232575AbjILTzW (ORCPT + 36 others); Tue, 12 Sep 2023 15:55:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53546 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229500AbjILTzU (ORCPT ); Tue, 12 Sep 2023 15:55:20 -0400 Received: from rere.qmqm.pl (rere.qmqm.pl [91.227.64.183]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 346451AE for ; Tue, 12 Sep 2023 12:55:16 -0700 (PDT) Received: from remote.user (localhost [127.0.0.1]) by rere.qmqm.pl (Postfix) with ESMTPSA id 4RlZ7P3vzrzB1; Tue, 12 Sep 2023 21:55:13 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=rere.qmqm.pl; s=1; t=1694548513; bh=hQNQ4QCGqogXkkq7quiXHYiRdH8sQiU3p2y0WgbusoQ=; h=Date:Subject:From:To:Cc:From; b=lmOpXkrUV529cwb3qYNI2wBT30mIicDUa0eryPCudafDE5DcDSGg7Pl7LZJKkkg3P bxtKM3jx+1RHManGMndEC38D4U2YC0ggtwHzyWNh7i0b0TfvixbA4A0dW/L3GF9jmb +UFIayaa1D1wuv4rAOzZ47jS7UUulgyTRNeOP1twtPedLUKdVhVo4QHwsAhsh3dzrH nI6kXLsy8Z9yZuGYGd4ITYm/i6F1JqGARRGax11k7x8nEDDgN1MwAT5W5GkSLYXpM3 ay78rKGbF5SPd9OPVF7T3rARuB6GeJXgF+RTtCpNaYhIwvniqBNNYIvmdSv5tT5u2x 5HxKrlP6gGoOQ== X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.8 at mail Date: Tue, 12 Sep 2023 21:55:13 +0200 Message-Id: <13334f7016362b2031eb65b03cb1a49b6500957f.1694548262.git.mirq-linux@rere.qmqm.pl> Subject: [PATCH v3] locking/mutex: remove redundant argument from __mutex_lock_common() MIME-Version: 1.0 From: =?utf-8?b?TWljaGHFgiBNaXJvc8WCYXc=?= To: Peter Zijlstra , Ingo Molnar , Will Deacon Cc: Waiman Long , Boqun Feng , linux-kernel@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Tue, 12 Sep 2023 12:55:22 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776883265451721116 X-GMAIL-MSGID: 1776883265451721116 use_ww_ctx is equivalent to ww_ctx != NULL. The one case where use_ww_ctx was true but ww_ctx == NULL leads to the same __mutex_add_waiter() call via __ww_mutex_add_waiter(). Since now __ww_mutex_add_waiter() is called only with ww_mutex != NULL (from both regular and PREEMPT_RT implementations), remove the branch there. Resulting object size diffs (by gcc-12) are minor: text data bss dec hex filename (x86-64) 22603 4696 16 27315 6ab3 /tmp/before.o 22593 4696 16 27305 6aa9 /tmp/after.o text data bss dec hex filename (arm) 13488 56 8 13552 34f0 /tmp/before.o 13492 56 8 13556 34f4 /tmp/after.o Signed-off-by: Michał Mirosław --- v3: extended commit message with `size` diffs + added back `if (ww_ctx)`-guarded store: compiler hoists it into the following branch anyway and so it avoids the unnecessary store in the `ww_ctx == NULL` case. v2: extended commit message to note that PREEMPT_RT does not call __ww_mutex_add_waiter() with ww_ctx == NULL --- kernel/locking/mutex.c | 15 ++++++--------- kernel/locking/ww_mutex.h | 5 ----- 2 files changed, 6 insertions(+), 14 deletions(-) diff --git a/kernel/locking/mutex.c b/kernel/locking/mutex.c index 4a3c006c41fb..045f7da4e473 100644 --- a/kernel/locking/mutex.c +++ b/kernel/locking/mutex.c @@ -578,15 +578,12 @@ EXPORT_SYMBOL(ww_mutex_unlock); static __always_inline int __sched __mutex_lock_common(struct mutex *lock, unsigned int state, unsigned int subclass, struct lockdep_map *nest_lock, unsigned long ip, - struct ww_acquire_ctx *ww_ctx, const bool use_ww_ctx) + struct ww_acquire_ctx *ww_ctx) { struct mutex_waiter waiter; struct ww_mutex *ww; int ret; - if (!use_ww_ctx) - ww_ctx = NULL; - might_sleep(); MUTEX_WARN_ON(lock->magic != lock); @@ -637,12 +634,12 @@ __mutex_lock_common(struct mutex *lock, unsigned int state, unsigned int subclas debug_mutex_lock_common(lock, &waiter); waiter.task = current; - if (use_ww_ctx) + if (ww_ctx) waiter.ww_ctx = ww_ctx; lock_contended(&lock->dep_map, ip); - if (!use_ww_ctx) { + if (!ww_ctx) { /* add waiting tasks to the end of the waitqueue (FIFO): */ __mutex_add_waiter(lock, &waiter, &lock->wait_list); } else { @@ -754,14 +751,14 @@ static int __sched __mutex_lock(struct mutex *lock, unsigned int state, unsigned int subclass, struct lockdep_map *nest_lock, unsigned long ip) { - return __mutex_lock_common(lock, state, subclass, nest_lock, ip, NULL, false); + return __mutex_lock_common(lock, state, subclass, nest_lock, ip, NULL); } static int __sched __ww_mutex_lock(struct mutex *lock, unsigned int state, unsigned int subclass, unsigned long ip, struct ww_acquire_ctx *ww_ctx) { - return __mutex_lock_common(lock, state, subclass, NULL, ip, ww_ctx, true); + return __mutex_lock_common(lock, state, subclass, NULL, ip, ww_ctx); } /** @@ -841,7 +838,7 @@ mutex_lock_io_nested(struct mutex *lock, unsigned int subclass) token = io_schedule_prepare(); __mutex_lock_common(lock, TASK_UNINTERRUPTIBLE, - subclass, NULL, _RET_IP_, NULL, 0); + subclass, NULL, _RET_IP_, NULL); io_schedule_finish(token); } EXPORT_SYMBOL_GPL(mutex_lock_io_nested); diff --git a/kernel/locking/ww_mutex.h b/kernel/locking/ww_mutex.h index 3ad2cc4823e5..11acb2efe976 100644 --- a/kernel/locking/ww_mutex.h +++ b/kernel/locking/ww_mutex.h @@ -493,11 +493,6 @@ __ww_mutex_add_waiter(struct MUTEX_WAITER *waiter, struct MUTEX_WAITER *cur, *pos = NULL; bool is_wait_die; - if (!ww_ctx) { - __ww_waiter_add(lock, waiter, NULL); - return 0; - } - is_wait_die = ww_ctx->is_wait_die; /*