Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp390989ybz; Wed, 15 Apr 2020 10:40:26 -0700 (PDT) X-Google-Smtp-Source: APiQypJz6ngMh8eZhfDkK95us6xX2XOpbBUXobLKRzT0DWF6V/qzfTL/yiOzVIeHgxgCjIMPpT7X X-Received: by 2002:a17:906:459:: with SMTP id e25mr6188580eja.379.1586972426515; Wed, 15 Apr 2020 10:40:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586972426; cv=none; d=google.com; s=arc-20160816; b=AD4P0za7/ASB/nwRp3FfKsBgWpHfAwHKVbnzUu4wM3cIP6wU3Hp69ZAMyNI0JUDpoP 2P0CfLvcTPq0bvzX6Luvs2PMDOreiKS+Ypz0TUSd6IyzwnLEISj488/ztyWMN5rwfhov yZJ66HvLp164VvGPBXOPAaRLntysGI3RSMrDeIgcfLk5NDKJ+UJRBjuNIf6paOBtSrBh b/6RqbH4Lz/qqO4YGG8y0AxeQdUYNil1UCY035UdpS3WpDXKSmIPodGuycctwE4FlWlT vwft8GcjBkWcCWGi0C+2CQU4zlpNIvQjncwgPuD51Dp+zZzTMXASc0GQ02vx0HUknEMD BNDg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=i0XaLfPZCpgh3n4hsGdRHbwiuIq+3kj3Y8IuZgE+IYk=; b=RYbrtvwA3iyLh+DKsQMA1AWlnMF8MFqh2mjJVskNzOE6ePWX2RPJ53r+YWZsuy3N1/ fisSiAQXQdv3DSpdsn+Piike7wLEUQxDfok8kOnTn54tAe0a7utyM93aoCBsSPhQoVfR 6gae5U0r0ED1b2Vt+D0RZulsO2APmBz7xCt2mY3tEYSJjVAYuRVUQXvxiJiz4D0CGGeD 2ONmMtUg3v96WRDCGPzNHPGRUgpHnWi9ZuH0qKme7JrMWXKht6+CnIMURH1UNUBMMO/p +NsaqqsQTfQBMtzB6nFFk9n0oEa9DMfc3zbCB4/6Qhm7B7N4EeaTCNH8z7eiRWmbD7bu rzYA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dm19si10573222edb.223.2020.04.15.10.39.59; Wed, 15 Apr 2020 10:40:26 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2437036AbgDNIub (ORCPT + 99 others); Tue, 14 Apr 2020 04:50:31 -0400 Received: from out30-130.freemail.mail.aliyun.com ([115.124.30.130]:51972 "EHLO out30-130.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729365AbgDNIua (ORCPT ); Tue, 14 Apr 2020 04:50:30 -0400 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R141e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e01355;MF=rocking@linux.alibaba.com;NM=1;PH=DS;RN=9;SR=0;TI=SMTPD_---0TvW-l9J_1586854193; Received: from localhost(mailfrom:rocking@linux.alibaba.com fp:SMTPD_---0TvW-l9J_1586854193) by smtp.aliyun-inc.com(127.0.0.1); Tue, 14 Apr 2020 16:50:23 +0800 From: Peng Wang 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 Cc: linux-kernel@vger.kernel.org Subject: [PATCH v2] sched/fair: Simplify the code of should_we_balance() Date: Tue, 14 Apr 2020 16:48:19 +0800 Message-Id: X-Mailer: git-send-email 2.9.5 In-Reply-To: <245c792f0e580b3ca342ad61257f4c066ee0f84f.1586594833.git.rocking@linux.alibaba.com> References: <245c792f0e580b3ca342ad61257f4c066ee0f84f.1586594833.git.rocking@linux.alibaba.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org We only consider group_balance_cpu() after there is no idle cpu. So, just do comparison before return at these two cases. Reviewed-by: Valentin Schneider Reviewed-by: Vincent Guittot Signed-off-by: Peng Wang --- kernel/sched/fair.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 02f323b..c3f57f4 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -9409,7 +9409,7 @@ static int active_load_balance_cpu_stop(void *data); static int should_we_balance(struct lb_env *env) { struct sched_group *sg = env->sd->groups; - int cpu, balance_cpu = -1; + int cpu; /* * Ensure the balancing environment is consistent; can happen @@ -9430,18 +9430,12 @@ static int should_we_balance(struct lb_env *env) if (!idle_cpu(cpu)) continue; - balance_cpu = cpu; - break; + /* Are we the first idle CPU? */ + return cpu == env->dst_cpu; } - if (balance_cpu == -1) - balance_cpu = group_balance_cpu(sg); - - /* - * First idle CPU or the first CPU(busiest) in this sched group - * is eligible for doing load balancing at this and above domains. - */ - return balance_cpu == env->dst_cpu; + /* Are we the first CPU in the balance mask of this group? */ + return group_balance_cpu(sg) == env->dst_cpu; } /* -- 2.9.5