Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp625554ybl; Fri, 13 Dec 2019 01:59:22 -0800 (PST) X-Google-Smtp-Source: APXvYqyLymFWbBXl8v0SIfrFOgR3kQB1mK/SK1YWaaekyRYChTngD8ALEJAFm7OSMwJ3ZnDfSAko X-Received: by 2002:a05:6830:12d0:: with SMTP id a16mr14091121otq.8.1576231162290; Fri, 13 Dec 2019 01:59:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576231162; cv=none; d=google.com; s=arc-20160816; b=pxT9TiVXMNvwR6Zi6KTqkRnNcvv/aMCTYn1vah7EqCfjsnnTKRxE6YnRovG8WXIX5Z xjXqkpjyvWTvsq9cEnx+2TTpVXKmlUslZNunFmcb0iUFIZNx8DDJbUiWqPllCG8SiPL4 vgsRjRRTBDcRlBnrPjy+9zze3EKDxRHnNs6CgLdgd9I0Sgj2d0pxSYFwqqTYxFnuyIIG F/M3FYxq53xGDUP5kdPpRkkPZ+T6eNHNRWsaPU0uVXFwRbVCZiJwn9UKLDj3bD7eesn2 KsaQr13xUWsLq8lp3GapDJ2sDjp1RLkzv2EtF+wegwBZFs1SDWPQQPy+chTD+1P0j+Js 090w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=rOBjko1K3yM9WWg0tMnXnGSj0/i0LTQDm48MjP6baw8=; b=knlFq7xHWQfte/fYGHaDJuo45ZfULNanUmck0uzSbbo0KnFA72wQCVQBqemxC2mJ5d sL09epp4i8/6gm8EhsVwImJ6r0Wl1c4FARZK16NSSfUc1OxBweGAaaZwfEUsmZ1PcHj/ dCrbP+Hxf2KdjWLfztVetx/9MlfqQ1tVhw2FJiyQsd91AOCPFifLzFw/T6q0tVziHvHw ZYjqRQ7IQ30jwAQYkPJGMcexcIJmVHEquw1rauT8VLFHqSBn8LgO+KL75yBwRjsaxvyq 5hDxEM54cnqh/ejeIWggb88ZvHlbRxbZXzpl429OeA5LDSo+OBGFeSqh5jlQuc0eXndO JX2Q== 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 z23si4597781otk.166.2019.12.13.01.59.10; Fri, 13 Dec 2019 01:59:22 -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 S1726368AbfLMJ50 (ORCPT + 99 others); Fri, 13 Dec 2019 04:57:26 -0500 Received: from szxga06-in.huawei.com ([45.249.212.32]:46132 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725747AbfLMJ50 (ORCPT ); Fri, 13 Dec 2019 04:57:26 -0500 Received: from DGGEMS403-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id ED9E138D1922D1532078; Fri, 13 Dec 2019 17:57:23 +0800 (CST) Received: from [127.0.0.1] (10.133.217.236) by DGGEMS403-HUB.china.huawei.com (10.3.19.203) with Microsoft SMTP Server id 14.3.439.0; Fri, 13 Dec 2019 17:57:17 +0800 Subject: Re: [PATCH] sched/fair: Optimize select_idle_cpu To: Peter Zijlstra CC: , , , , , , , , , "chengjian (D)" References: <20191212144102.181510-1-cj.chengjian@huawei.com> <20191212152406.GB2827@hirez.programming.kicks-ass.net> From: "chengjian (D)" Message-ID: Date: Fri, 13 Dec 2019 17:57:15 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:68.0) Gecko/20100101 Thunderbird/68.3.0 MIME-Version: 1.0 In-Reply-To: <20191212152406.GB2827@hirez.programming.kicks-ass.net> Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US X-Originating-IP: [10.133.217.236] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2019/12/12 23:24, Peter Zijlstra wrote: > On Thu, Dec 12, 2019 at 10:41:02PM +0800, Cheng Jian wrote: > >> Fixes: 1ad3aaf3fcd2 ("sched/core: Implement new approach to scale select_idle_cpu()") > The 'funny' thing is that select_idle_core() actually does the right > thing. > > Copying that should work: > > > diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c > index 08a233e97a01..416d574dcebf 100644 > --- a/kernel/sched/fair.c > +++ b/kernel/sched/fair.c > @@ -5828,6 +5837,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 +5869,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)) > > . in select_idle_smt() /*  * Scan the local SMT mask for idle CPUs.  */ static int select_idle_smt(struct task_struct *p, int target) {     int cpu, si_cpu = -1;     if (!static_branch_likely(&sched_smt_present))         return -1;     for_each_cpu(cpu, cpu_smt_mask(target)) {         if (!cpumask_test_cpu(cpu, p->cpus_ptr))             continue;         if (available_idle_cpu(cpu))             return cpu;         if (si_cpu == -1 && sched_idle_cpu(cpu))             si_cpu = cpu;     }     return si_cpu; } Why don't we do the same thing in this function, although cpu_smt_present () often has few CPUs. it is better to determine the 'p->cpus_ptr' first.