Message ID | 20230518203416.3323-1-zeming@nfschina.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp871094vqo; Tue, 16 May 2023 21:31:29 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4POiYu+xI0iPvGydWVetR+ch+KpxRcpFFzWe+T5JRM5LpBVLljFjHlpUZcDoWZgtJjvcpI X-Received: by 2002:a05:6a20:c701:b0:f3:1c69:7eeb with SMTP id hi1-20020a056a20c70100b000f31c697eebmr38790866pzb.17.1684297889516; Tue, 16 May 2023 21:31:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684297889; cv=none; d=google.com; s=arc-20160816; b=PSAYh9+KOObbyewqoP4+QhqSZo5q5oOB5lMaBCsBjl4KJNYiDuHuEJIr+M7IGBJddC 3BsmjpcrtQGUnbEoD+Nhj1sgzsdXHcpeIx49UZSumdZttYZ9RCLd04ZFlu7LnSwzSADp HppHGUxZEGOSMUrq6Ch6kI7/I6esakEvDQ18augv5kjCcxRynEFVJ1h6wZQ9aeI5Wyjl yysDU0XlaUoUZ3aKcKtN1Ap3F3peIlocPUFrGYrLVDiHyYHITC5vG9/BkHX+7D0EXUlo ySsjDQOupHr98YZFmghA/TF5tmVAoWpzq1+RTMFXFVxv3hiTp3jhkM9Zm/Yx+H4xUyMh Mw8Q== 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; bh=oiUn5dEHBhf+38HghSn0bjXjsqzW3OiA7bRXz6qMVI0=; b=KiVuOF0zC4JOzdaevJhZBJhzEXR3U+SmH8aR/wSv+uE9/BT6NaFlz24UndN/Kh2Xfg anaeKBkfgXMjt915wohi2LWGezkEgHzXrPdFIrWRSrFGrLuCnd8ZWo2vD6O2NUOrnQsW FmRA9TREosWvWLhB4NdejDjjgcKiFDcndE+IWlrZFnc5CeLLwHPhizqs0jurZYlmXe6z GcietD3z1yTe5bgLVJiwrg4+acrKQMRb0+TWJMHj+iSIzW2eVcGSeG/ymBk4JOrsjVu5 LWq8ZaAAhQXda4NU3IdGwvdEOp1LoRubNaY9QtZYtM+xISa7x6IL27fiU7LQIamKWBSj XBKw== ARC-Authentication-Results: i=1; mx.google.com; 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bs3-20020a632803000000b0052ca7192675si19684774pgb.729.2023.05.16.21.31.16; Tue, 16 May 2023 21:31:29 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229437AbjEQEDP (ORCPT <rfc822;pacteraone@gmail.com> + 99 others); Wed, 17 May 2023 00:03:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41706 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229517AbjEQEDM (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Wed, 17 May 2023 00:03:12 -0400 Received: from mail.nfschina.com (unknown [42.101.60.195]) by lindbergh.monkeyblade.net (Postfix) with SMTP id 84B6A3A9C for <linux-kernel@vger.kernel.org>; Tue, 16 May 2023 21:03:10 -0700 (PDT) Received: from localhost.localdomain (unknown [219.141.250.2]) by mail.nfschina.com (Maildata Gateway V2.8.8) with ESMTPA id B2F4D180120CD7; Wed, 17 May 2023 12:03:00 +0800 (CST) X-MD-Sfrom: zeming@nfschina.com X-MD-SrcIP: 219.141.250.2 From: Li zeming <zeming@nfschina.com> To: mingo@redhat.com, peterz@infradead.org, juri.lelli@redhat.com, vincent.guittot@linaro.org, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de, bristot@redhat.com, vschneid@redhat.com Cc: linux-kernel@vger.kernel.org, Li zeming <zeming@nfschina.com> Subject: [PATCH] sched: core: Simplify cpuset_cpumask_can_shrink() Date: Fri, 19 May 2023 04:34:16 +0800 Message-Id: <20230518203416.3323-1-zeming@nfschina.com> X-Mailer: git-send-email 2.18.2 X-Spam-Status: No, score=0.9 required=5.0 tests=BAYES_00,DATE_IN_FUTURE_24_48, RDNS_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no 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?1766114343739695274?= X-GMAIL-MSGID: =?utf-8?q?1766114343739695274?= |
Series |
sched: core: Simplify cpuset_cpumask_can_shrink()
|
|
Commit Message
Li zeming
May 18, 2023, 8:34 p.m. UTC
Remove useless intermediate variable "ret" and its initialization.
Directly return dl_cpuset_cpumask_can_shrink() result.
Signed-off-by: Li zeming <zeming@nfschina.com>
---
kernel/sched/core.c | 8 ++------
1 file changed, 2 insertions(+), 6 deletions(-)
Comments
On 5/19/2023 2:04 AM, Li zeming wrote: > Remove useless intermediate variable "ret" and its initialization. > Directly return dl_cpuset_cpumask_can_shrink() result. > > Signed-off-by: Li zeming <zeming@nfschina.com> Acked-by : Mukesh Ojha <quic_mojha@quicinc.com> -Mukesh > --- > kernel/sched/core.c | 8 ++------ > 1 file changed, 2 insertions(+), 6 deletions(-) > > diff --git a/kernel/sched/core.c b/kernel/sched/core.c > index a66960da3f5c..f3f2ece26291 100644 > --- a/kernel/sched/core.c > +++ b/kernel/sched/core.c > @@ -9273,14 +9273,10 @@ void __init init_idle(struct task_struct *idle, int cpu) > int cpuset_cpumask_can_shrink(const struct cpumask *cur, > const struct cpumask *trial) > { > - int ret = 1; > - > if (cpumask_empty(cur)) > - return ret; > - > - ret = dl_cpuset_cpumask_can_shrink(cur, trial); > + return 1; > > - return ret; > + return dl_cpuset_cpumask_can_shrink(cur, trial); > } > > int task_can_attach(struct task_struct *p,
On 19/05/23 04:34, Li zeming wrote: > Remove useless intermediate variable "ret" and its initialization. > Directly return dl_cpuset_cpumask_can_shrink() result. > FWIW, this sort of intermediate variable can and will be optimized away by the compiler. It's pretty obvious to see in the objdump (GCC 13.1): before/core.o: mainline core.o after/core.o: patched core.o $ gdb -batch -ex 'disassemble cpuset_cpumask_can_shrink' before/core.o Dump of assembler code for function cpuset_cpumask_can_shrink: 0x000000000000b260 <+0>: endbr64 0x000000000000b264 <+4>: cmpq $0x0,(%rdi) 0x000000000000b268 <+8>: jne 0xb274 <cpuset_cpumask_can_shrink+20> 0x000000000000b26a <+10>: mov $0x1,%eax 0x000000000000b26f <+15>: jmpq 0xb274 <cpuset_cpumask_can_shrink+20> 0x000000000000b274 <+20>: jmpq 0xb279 $ diff <(gdb -batch -ex 'disassemble cpuset_cpumask_can_shrink' before/core.o) \ <(gdb -batch -ex 'disassemble cpuset_cpumask_can_shrink' after/core.o) <nothing> Generally I think it's good to not be afraid to use intermediate variables if they improve readability, even if they have only one use (e.g. as parameter to a function with many arguments / long expressions used as parameters). In this case though, the intermediate variable really doesn't do much for readability :-) Reviewed-by: Valentin Schneider <vschneid@redhat.com> > Signed-off-by: Li zeming <zeming@nfschina.com> > --- > kernel/sched/core.c | 8 ++------ > 1 file changed, 2 insertions(+), 6 deletions(-) > > diff --git a/kernel/sched/core.c b/kernel/sched/core.c > index a66960da3f5c..f3f2ece26291 100644 > --- a/kernel/sched/core.c > +++ b/kernel/sched/core.c > @@ -9273,14 +9273,10 @@ void __init init_idle(struct task_struct *idle, int cpu) > int cpuset_cpumask_can_shrink(const struct cpumask *cur, > const struct cpumask *trial) > { > - int ret = 1; > - > if (cpumask_empty(cur)) > - return ret; > - > - ret = dl_cpuset_cpumask_can_shrink(cur, trial); > + return 1; > > - return ret; > + return dl_cpuset_cpumask_can_shrink(cur, trial); > } > > int task_can_attach(struct task_struct *p, > -- > 2.18.2
diff --git a/kernel/sched/core.c b/kernel/sched/core.c index a66960da3f5c..f3f2ece26291 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -9273,14 +9273,10 @@ void __init init_idle(struct task_struct *idle, int cpu) int cpuset_cpumask_can_shrink(const struct cpumask *cur, const struct cpumask *trial) { - int ret = 1; - if (cpumask_empty(cur)) - return ret; - - ret = dl_cpuset_cpumask_can_shrink(cur, trial); + return 1; - return ret; + return dl_cpuset_cpumask_can_shrink(cur, trial); } int task_can_attach(struct task_struct *p,