Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp321458ybl; Thu, 12 Dec 2019 19:08:26 -0800 (PST) X-Google-Smtp-Source: APXvYqx3gHKN0lDzq5UvMYyiyxYXFDq79pw2KCBzK1L+5E25OxmRutjncyZcbzWRSwSDVX2OY9sg X-Received: by 2002:a05:6830:14d3:: with SMTP id t19mr12537020otq.278.1576206506608; Thu, 12 Dec 2019 19:08:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576206506; cv=none; d=google.com; s=arc-20160816; b=Mp9sGCqMbO8sdr02nXtGjEd7JwU/EbiKayFgYqEgGjjkqWXgM4uLJak+KmNtQsQAuS lJ7cgGmNQtqfgKPpM348QGc5euXnuKly/eXEQNfI3zYWS6ymZun84mv8r4XcoX1WgvT2 D3/eerX26Kvhdke6iyXw+OEJUQS8DP7khyPw93CLDHhe+AFA1dR5lDwwz5JkXFS0J+pU MnGJp0ofMJBym6IZLG5X3yEEpPMmK4t9eaAXPT7TL/nWOGcSFN7N6zC5NUkLBdEsrcKB X1djsu7klL05aE+W4KHJodh2J6ghMnrn+cVuKUVCQ4RaBB6K1M08xNTovGhct5NakpFs 6OQQ== 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:mime-version :message-id:date:subject:cc:to:from; bh=ES2HJpxRNpiSoKpY4svEaxLsNJ8Ezo0qanXH3NcClDg=; b=xqq2bHKZTXmmtMwkEVfdoFbBdpKOrkLoIoo0IHBC+j4+uesy4sZQwP5gwD1ddk+qn2 mQxdH0ErBQ0A2d33NK5gYDrZdSlrlenUGUUARxfq438Z3hkdgU4KJzla/BLdguotaMrd +h/9stJmlu9Jwda90FKulqOgU5q7cAexmKO99+EcAowrFMPep2qzDt9IBcdYkjNAnkqa M2RoIPl3fp6xaNIVP6xvGF0JufH+YNBsP/nZo7h7XkA2RiqlY/+VJQWInmlbgb03n+22 68P8d23tYNVe9gM0VkY255GOp0ClC5b25cZizSsGx9C4QMhyR3YA5L2pnczxY5prwiiH DctQ== 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 n7si4383978otk.277.2019.12.12.19.08.14; Thu, 12 Dec 2019 19:08:26 -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 S1731706AbfLMCsZ (ORCPT + 99 others); Thu, 12 Dec 2019 21:48:25 -0500 Received: from szxga04-in.huawei.com ([45.249.212.190]:7682 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727605AbfLMCsY (ORCPT ); Thu, 12 Dec 2019 21:48:24 -0500 Received: from DGGEMS414-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 072C86DF541975F469D4; Fri, 13 Dec 2019 10:48:21 +0800 (CST) Received: from huawei.com (10.175.113.25) by DGGEMS414-HUB.china.huawei.com (10.3.19.214) with Microsoft SMTP Server id 14.3.439.0; Fri, 13 Dec 2019 10:48:12 +0800 From: Cheng Jian To: , , CC: , , , , , , , Subject: [PATCH v2] sched/fair: Optimize select_idle_cpu Date: Fri, 13 Dec 2019 10:45:30 +0800 Message-ID: <20191213024530.28052-1-cj.chengjian@huawei.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.175.113.25] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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)) -- 2.20.1