Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp733754ybl; Fri, 13 Dec 2019 03:50:24 -0800 (PST) X-Google-Smtp-Source: APXvYqzrqKWsTFuxeIpItF5M9TjBQLBPts+yJara98wntxZXfHYVZezyfySVC9qK8bRN8powhxkb X-Received: by 2002:a9d:6c01:: with SMTP id f1mr13628841otq.133.1576237824534; Fri, 13 Dec 2019 03:50:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576237824; cv=none; d=google.com; s=arc-20160816; b=go17MeA2ffHsIhxCTwj395Id58RcLYsMERqR3JzPekMSBYCJjJxgSlLOjSjHojx6eW ljE5J2NPzaKmlpBiPg9hzENy4aQll2yGGzAnINoYcY6w154MhjxWz95NIgp5c9C2hCav iQc0RKwhAUxlOUJUO5OrzXmU2yva/L3vyKba/WWZKjWazpKgwT3qQB5wbrKvutxuaPY9 fqBYpTytCSkfkZ7CIKDUdYF6hn57UwnMBwG+DV98UGZwA4A70ePkv+lKYz7s4sBDyN7e 2eunkZurMAJUYH3maHitBWKG9VZ/4FZKtWoaOp4NjC2V8SRKrmRnOjCegh+aXOkCN8H/ ZxEw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=QXvXjDM9NorDuRJY+14DaZxeQseUvrPEkTe+Lb7+P+Q=; b=Yp5c/AKOsZBineYvqAREQx7QHGTMk+u2FWGkB5142crONmZRivziDKzraAZKsNoP6G 6OnQbLqrIuH467qL/RkSRyZpz18P1R4EY3/VmzoPM+/odl5AvZ2FPdOvB/okTA+3J0sS 835DSiAR8uyLn7c8ET1Zy3qTdboBRtSvZMbhPBoAtlzHBYHLLQvT9/n5dFXfcyLN16oe 5JL2Yfoe6MadhTOmyj99kSxf4NmpKso6wRjZ7SMCTpTywso9I1EK/dO19FN+2TRv+13S cor3hZiIinP8yoDpFN1aPIAmmINLwCe27iuRibp903LIlQMOGEJ1vfBvqg7fV5qDNdGU Ljng== 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 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w197si4994298oif.150.2019.12.13.03.50.12; Fri, 13 Dec 2019 03:50:24 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726855AbfLMLsX (ORCPT + 99 others); Fri, 13 Dec 2019 06:48:23 -0500 Received: from foss.arm.com ([217.140.110.172]:56292 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725980AbfLMLsW (ORCPT ); Fri, 13 Dec 2019 06:48:22 -0500 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 5ED401045; Fri, 13 Dec 2019 03:48:22 -0800 (PST) Received: from [10.1.194.37] (e113632-lin.cambridge.arm.com [10.1.194.37]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 0AD1B3F718; Fri, 13 Dec 2019 03:48:20 -0800 (PST) Subject: Re: [PATCH v2] sched/fair: Optimize select_idle_cpu To: Cheng Jian , mingo@kernel.org, peterz@infradead.org, linux-kernel@vger.kernel.org Cc: chenwandun@huawei.com, xiexiuqi@huawei.com, liwei391@huawei.com, huawei.libin@huawei.com, bobo.shaobowang@huawei.com, juri.lelli@redhat.com, vincent.guittot@linaro.org References: <20191213024530.28052-1-cj.chengjian@huawei.com> From: Valentin Schneider Message-ID: Date: Fri, 13 Dec 2019 11:48:20 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.9.0 MIME-Version: 1.0 In-Reply-To: <20191213024530.28052-1-cj.chengjian@huawei.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 13/12/2019 02:45, Cheng Jian wrote: > select_idle_cpu() will scan the LLC domain for idle CPUs, > it's always expensive. so the next commit : > > 1ad3aaf3fcd2 ("sched/core: Implement new approach to scale select_idle_cpu()") > > introduces a way to limit how many CPUs we scan. > > But it consume some CPUs out of 'nr' that are not allowed > for the task and thus waste our attempts. The function > always return nr_cpumask_bits, and we can't find a CPU > which our task is allowed to run. > > Cpumask may be too big, similar to select_idle_core(), use > per_cpu_ptr 'select_idle_mask' to prevent stack overflow. > > Fixes: 1ad3aaf3fcd2 ("sched/core: Implement new approach to scale select_idle_cpu()") > Signed-off-by: Cheng Jian Reviewed-by: Valentin Schneider > --- > kernel/sched/fair.c | 7 ++++--- > 1 file changed, 4 insertions(+), 3 deletions(-) > > diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c > index 08a233e97a01..d48244388ce9 100644 > --- a/kernel/sched/fair.c > +++ b/kernel/sched/fair.c > @@ -5828,6 +5828,7 @@ static inline int select_idle_smt(struct task_struct *p, int target) > */ > static int select_idle_cpu(struct task_struct *p, struct sched_domain *sd, int target) > { > + struct cpumask *cpus = this_cpu_cpumask_var_ptr(select_idle_mask); > struct sched_domain *this_sd; > u64 avg_cost, avg_idle; > u64 time, cost; > @@ -5859,11 +5860,11 @@ static int select_idle_cpu(struct task_struct *p, struct sched_domain *sd, int t > > time = cpu_clock(this); > > - for_each_cpu_wrap(cpu, sched_domain_span(sd), target) { > + cpumask_and(cpus, sched_domain_span(sd), p->cpus_ptr); > + > + for_each_cpu_wrap(cpu, cpus, target) { > if (!--nr) > return si_cpu; > - if (!cpumask_test_cpu(cpu, p->cpus_ptr)) > - continue; > if (available_idle_cpu(cpu)) > break; > if (si_cpu == -1 && sched_idle_cpu(cpu)) >