Message ID | 20230320092652.16649-1-zbestahu@gmail.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:604a:0:0:0:0:0 with SMTP id j10csp1113288wrt; Mon, 20 Mar 2023 02:36:37 -0700 (PDT) X-Google-Smtp-Source: AK7set8rMmhiX50u2GftuQm27kfnLpegOOC09AK5TxQDM/WrtdtX/6fbkgPb8olM3Ao/lOLosn00 X-Received: by 2002:a17:903:1d2:b0:1a1:aa68:7e61 with SMTP id e18-20020a17090301d200b001a1aa687e61mr12603006plh.33.1679304996730; Mon, 20 Mar 2023 02:36:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679304996; cv=none; d=google.com; s=arc-20160816; b=pMOOVowByfO034EEUKW845ywdpVczGrulPmQJAkLuyBmc2YOkz+dBrDuZ9Dl6B8qyY 6bbPNondQTFk1RGuunywyPvP2ddTN4my0krbvZoJo3AWxdDKNxI8aiJ/D3CDtL4iauu6 5PS2jKDcWSOWzPlMl6q04rcYIEuX8Gj0Mhft2AC5xvLMFI213BxynSqPWokTwtIdxGVu wwPjY+Aajny7vwHEcjz/x0n5yMmso4wbeqsKweyKGPJoiy9+cObooOKvFUU1DXp92uS6 ZddFQdGyUksp7RD2ATU60FqJZq0d7mr16WtqjgssuJ5Pl8buABxUQminGNnKTfvZFf8d SZZQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from :dkim-signature; bh=mlRkPjgE6TNTCRfOd4LJQHCW3cMFbfvmsoyX6CTOd28=; b=OA+0Dd3G2PvsDFYMKsbeEmKikgIZfiKnV82sy5991cycp60WLSNblYga41mB9VbJqg v+3gk5b8GDo1u8Ft1tqbPc+on+gqpuP1XH/G9PxrQjd2Wcps3cXcE987QkJdT5pOXzvH In+iPfkHem11VP/QAkzV8Vgn8qKDvQxU7Xj9wUdzaXHR8jHKDJ4QNUj5vps58h1cxXjH CZ6h+zJZnm6pvFk/t8HUeEJLmUUr8aJW078/I/IOioNGGJyNw0aQbyZ0enjCzNZXI66T bGRELo6kHSyB3fLI7AAV/y8K9de2BwYTiUJv7QYQOawANSjZ/cj5qVHuosuYTK9X2OA4 G8og== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=nck84eVI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g12-20020a170902e38c00b0019d038765f6si9398187ple.449.2023.03.20.02.36.21; Mon, 20 Mar 2023 02:36:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=nck84eVI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230347AbjCTJ2T (ORCPT <rfc822;ezelljr.billy@gmail.com> + 99 others); Mon, 20 Mar 2023 05:28:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39142 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231319AbjCTJ1w (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 20 Mar 2023 05:27:52 -0400 Received: from mail-pl1-x635.google.com (mail-pl1-x635.google.com [IPv6:2607:f8b0:4864:20::635]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C4CF424480 for <linux-kernel@vger.kernel.org>; Mon, 20 Mar 2023 02:27:18 -0700 (PDT) Received: by mail-pl1-x635.google.com with SMTP id o11so11777568ple.1 for <linux-kernel@vger.kernel.org>; Mon, 20 Mar 2023 02:27:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1679304438; h=message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=mlRkPjgE6TNTCRfOd4LJQHCW3cMFbfvmsoyX6CTOd28=; b=nck84eVIWYKc6j5O2HotAFWxm9ge477KpfBKUiLzgG61Kg4Lzx4EspGOyF4YyJgvcO /SMx7ZcNtb/bEGJmUHO5nl5MMISdbajbdDrLWvhyWX5p7IF6k5zJoVsqM3rB8E8/h+fX cmQEQXjkfug+dJX4bwF7dPbtblsZST3EB2gyW2zhq21GcezdsAqdnIePIjmb0/4ddN6b BWNwASyPbkAAU2PjjDBeIqvRan8tE6r/YCm0TlvuR+F/EMZm9nrQ0x/vqVQVDn5xZV4h BXFR9NxTrXj6NADW5VbrF/N7TdgJXPxlUUeXEnaEfynAvkRpFkAENXKqN5fgV1l+YAfW JOMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679304438; h=message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=mlRkPjgE6TNTCRfOd4LJQHCW3cMFbfvmsoyX6CTOd28=; b=Bcobo56EhaufYzSEf4LMXJsqhXi7ToDvOaulDLr19tNM0zEZR8XuyZdC7ZbY60vlTQ mEFykp40F6vOD86HYIvyuwjDuPhOkguFC5wWRi/bnAVZdqMK32OzWRyV0ActVCBotCQU h1kNvqbRORoOJxhmY+JJLQTL0aFg0fSA9n2/asVkgPTm95XX8dh8UDdYrjYZKT58F8nE P9zXmgenCa9zdK94edHWyxM7GV1SfJnGhyVtlXwrGT9lqdpakWa6lHmFrXvZPken67Pf Mp1FOFSFnUaDxNUrX48A46ORUxt59ipMtvnxtcuae98b1be9mlmz8e+aN1eP0jQrte3g cQqw== X-Gm-Message-State: AO0yUKVyYz4rozBVWK8kMwOOdtGCoNOttLJo+Rr8Wl/va3Zu5FXsS0hW 16OBAy/K18Ll3KjwVqoL0z4= X-Received: by 2002:a17:902:f687:b0:1a1:c551:bd00 with SMTP id l7-20020a170902f68700b001a1c551bd00mr5674478plg.35.1679304438180; Mon, 20 Mar 2023 02:27:18 -0700 (PDT) Received: from localhost.localdomain ([156.236.96.165]) by smtp.gmail.com with ESMTPSA id t8-20020a63dd08000000b00502ecb91940sm5880011pgg.55.2023.03.20.02.27.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Mar 2023 02:27:17 -0700 (PDT) From: Yue Hu <zbestahu@gmail.com> To: tj@kernel.org, jiangshanlai@gmail.com Cc: linux-kernel@vger.kernel.org, huyue2@coolpad.com, zhangwen@coolpad.com Subject: [PATCH] workqueue: Drop the NOT_RUNNING check to flags in worker_{set,clr}_flags Date: Mon, 20 Mar 2023 17:26:52 +0800 Message-Id: <20230320092652.16649-1-zbestahu@gmail.com> X-Mailer: git-send-email 2.17.1 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1760878916215595196?= X-GMAIL-MSGID: =?utf-8?q?1760878916215595196?= |
Series |
workqueue: Drop the NOT_RUNNING check to flags in worker_{set,clr}_flags
|
|
Commit Message
Yue Hu
March 20, 2023, 9:26 a.m. UTC
From: Yue Hu <huyue2@coolpad.com> We know whether the worker flags are belong to WORKER_NOT_RUNNING or not when we are setting and clearing them. So check the flags not running related is unnecessary for both the cases. Currently, worker_{set,clr}_flags() are all used for WORKER_NOT_RUNNING except for clearing WORKER_IDLE. Let's change to directly clear it instead. Also, update the comment a little in worker_clr_flags(). Signed-off-by: Yue Hu <huyue2@coolpad.com> --- kernel/workqueue.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-)
Comments
On Fri, Mar 24, 2023 at 9:58 AM Tejun Heo <tj@kernel.org> wrote: > > On Mon, Mar 20, 2023 at 05:26:52PM +0800, Yue Hu wrote: > > From: Yue Hu <huyue2@coolpad.com> > > > > We know whether the worker flags are belong to WORKER_NOT_RUNNING or not > > when we are setting and clearing them. So check the flags not running > > related is unnecessary for both the cases. > > > > Currently, worker_{set,clr}_flags() are all used for WORKER_NOT_RUNNING > > except for clearing WORKER_IDLE. Let's change to directly clear it > > instead. Also, update the comment a little in worker_clr_flags(). > > I'm not sure this is better. Semantically, the existing code seems clearer > and less error-prone to me and this isn't gonna make any meaningful perf > difference. Lai, what do you think? objdump -DSr kernel/workqueue.o | less 3275: 00 00 3273: R_X86_64_32S current_task WARN_ON_ONCE(worker->task != current); 3277: 48 39 43 40 cmp %rax,0x40(%rbx) 327b: 0f 85 91 00 00 00 jne 3312 <process_one_work+0x3a2> !(worker->flags & WORKER_NOT_RUNNING)) { 3281: 8b 43 68 mov 0x68(%rbx),%eax if ((flags & WORKER_NOT_RUNNING) && 3284: a9 c8 01 00 00 test $0x1c8,%eax 3289: 75 0b jne 3296 <process_one_work+0x326> struct worker_pool *pool = worker->pool; 328b: 48 8b 43 48 mov 0x48(%rbx),%rax pool->nr_running--; 328f: 83 68 20 01 subl $0x1,0x20(%rax) 3293: 8b 43 68 mov 0x68(%rbx),%eax worker->flags |= flags; 3296: 83 c8 40 or $0x40,%eax 3299: 89 43 68 mov %eax,0x68(%rbx) It seems the compiler will do the trick. The clearer existing code seems better. Thanks Lai > > Thanks. > > -- > tejun
Hi Tejun, Lai, On Sat, 25 Mar 2023 17:20:14 +0800 Lai Jiangshan <jiangshanlai@gmail.com> wrote: > On Fri, Mar 24, 2023 at 9:58 AM Tejun Heo <tj@kernel.org> wrote: > > > > On Mon, Mar 20, 2023 at 05:26:52PM +0800, Yue Hu wrote: > > > From: Yue Hu <huyue2@coolpad.com> > > > > > > We know whether the worker flags are belong to WORKER_NOT_RUNNING or not > > > when we are setting and clearing them. So check the flags not running > > > related is unnecessary for both the cases. > > > > > > Currently, worker_{set,clr}_flags() are all used for WORKER_NOT_RUNNING > > > except for clearing WORKER_IDLE. Let's change to directly clear it > > > instead. Also, update the comment a little in worker_clr_flags(). > > > > I'm not sure this is better. Semantically, the existing code seems clearer > > and less error-prone to me and this isn't gonna make any meaningful perf > > difference. Lai, what do you think? > > objdump -DSr kernel/workqueue.o | less > > 3275: 00 00 > 3273: R_X86_64_32S current_task > WARN_ON_ONCE(worker->task != current); > 3277: 48 39 43 40 cmp %rax,0x40(%rbx) > 327b: 0f 85 91 00 00 00 jne 3312 <process_one_work+0x3a2> > !(worker->flags & WORKER_NOT_RUNNING)) { > 3281: 8b 43 68 mov 0x68(%rbx),%eax > if ((flags & WORKER_NOT_RUNNING) && > 3284: a9 c8 01 00 00 test $0x1c8,%eax > 3289: 75 0b jne 3296 <process_one_work+0x326> > struct worker_pool *pool = worker->pool; > 328b: 48 8b 43 48 mov 0x48(%rbx),%rax > pool->nr_running--; > 328f: 83 68 20 01 subl $0x1,0x20(%rax) > 3293: 8b 43 68 mov 0x68(%rbx),%eax > worker->flags |= flags; > 3296: 83 c8 40 or $0x40,%eax > 3299: 89 43 68 mov %eax,0x68(%rbx) > > It seems the compiler will do the trick. The clearer existing code > seems better. Thank you for taking time to review the patch. The `worker_set_flags` has two behaviors. One is set worker flags unconditionally. Another is to conditionally adjust `nr_running`. I understand the adjustment should be only for the flags that we set to NOT_RUNNING. And currently the `worker_set_flags()` is not universally used when setting them, such as in the case of setting WOKER_IDLE. So, I think this helper is not fulfilling its responsibility, it is actually just only processing `not_running` state. If the change is meaningful, maybe it's better to name it as worker_set_not_running_flags()? Anyway, it is just a minor change. Thanks. > > Thanks > Lai > > > > > Thanks. > > > > -- > > tejun
diff --git a/kernel/workqueue.c b/kernel/workqueue.c index de4282736999..c56112cb17c3 100644 --- a/kernel/workqueue.c +++ b/kernel/workqueue.c @@ -978,10 +978,8 @@ static inline void worker_set_flags(struct worker *worker, unsigned int flags) WARN_ON_ONCE(worker->task != current); /* If transitioning into NOT_RUNNING, adjust nr_running. */ - if ((flags & WORKER_NOT_RUNNING) && - !(worker->flags & WORKER_NOT_RUNNING)) { + if (!(worker->flags & WORKER_NOT_RUNNING)) pool->nr_running--; - } worker->flags |= flags; } @@ -1007,12 +1005,11 @@ static inline void worker_clr_flags(struct worker *worker, unsigned int flags) /* * If transitioning out of NOT_RUNNING, increment nr_running. Note - * that the nested NOT_RUNNING is not a noop. NOT_RUNNING is mask - * of multiple flags, not a single flag. + * that NOT_RUNNING is mask of multiple flags, not a single flag. */ - if ((flags & WORKER_NOT_RUNNING) && (oflags & WORKER_NOT_RUNNING)) - if (!(worker->flags & WORKER_NOT_RUNNING)) - pool->nr_running++; + if ((oflags & WORKER_NOT_RUNNING) && + (!(worker->flags & WORKER_NOT_RUNNING))) + pool->nr_running++; } /** @@ -1835,7 +1832,9 @@ static void worker_leave_idle(struct worker *worker) if (WARN_ON_ONCE(!(worker->flags & WORKER_IDLE))) return; - worker_clr_flags(worker, WORKER_IDLE); + WARN_ON_ONCE(worker->task != current); + + worker->flags &= ~WORKER_IDLE; pool->nr_idle--; list_del_init(&worker->entry); }