Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4331042pxj; Tue, 8 Jun 2021 11:41:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyj5AepTXDYupVTbAT4r3uzqQ/52gmX5YY1y/Tnsmxhl53BeNwda131KLRqrqmp/ehHVH3y X-Received: by 2002:a17:906:3e8d:: with SMTP id a13mr24900695ejj.463.1623177696684; Tue, 08 Jun 2021 11:41:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623177696; cv=none; d=google.com; s=arc-20160816; b=yoUQwXhozJHr2xwbyOnR4S/BSxL8NgFOjUxY4APsAtvr93uxzgClVvHyBW/ABkUMcA ZQDDn8rjhKGG3Fvm7XY/wSmx3k6g58SVLlwqUmr2869sdbi0LCOu+I1ik4cw/uk/U6/g qxXulNUYOFpfHdknd3p5sARjLK9yneQFUOaocyrJl9cauqE0cwb0raWf14rCs7J/Xrlm PLGcXWmsnBSUYPLsjHtzw1JqJrzbGCh7irzdfD1LdBKjDAZ/1Q97kmP6vx+2x72ryUwg OSgNXHf50MiHYnXrscaxROsCzWcnm3ol+6eSQF3x1gM0HL6M98L8gBJGQ5sd38Newm2Q e7wg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=zw5JW18Y4uAULQOUhIMfo00UHmi/uXWGyU6VwcTqwy8=; b=DkE/Rf6PKRFa0LtsroLYrC3W/8SMmn/hkS9nOONdTvqg2BTMGJRo3eTBHaBi+ODAGo UaJxbZzBuvTn1Ph05UoMzZ/CKf4SFUsSev79Ixp7i8l0kYsUHqtEdjbafPdxkM3I20w3 xnQltspdxa3lSb7SkJkS42yLzI8Zi5mIEfZEKMe9euQqAOXu5Wv5Ezee464YFd9TMl+j 0tfyfNOH157CQbS/5MqUbZWO154UyPPi5cFLTyH73D92TQOQyS2iivFOMu9E1oht0/gX 4ZzRysVCCwtZFA8gPQtnZTrdSr+5dzOFcWP5cb8GSY79ta7cSznViJl/ml5mQmlHrH2s 1InQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="orHyf/g3"; spf=pass (google.com: 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q11si367951ejs.90.2021.06.08.11.41.13; Tue, 08 Jun 2021 11:41:36 -0700 (PDT) Received-SPF: pass (google.com: 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; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="orHyf/g3"; spf=pass (google.com: 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234965AbhFHShf (ORCPT + 99 others); Tue, 8 Jun 2021 14:37:35 -0400 Received: from mail.kernel.org ([198.145.29.99]:57560 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234858AbhFHSf1 (ORCPT ); Tue, 8 Jun 2021 14:35:27 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 6CD3A613F9; Tue, 8 Jun 2021 18:32:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1623177139; bh=shz5xA4uenEmO6NUnq5K3dZdPpj+Lg6KmyzudpB8yJQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=orHyf/g370ppLl4oP0LHq/IHZw6Z4EGGjiXOIgawjtPLWl23OxYRs+0QDl8DztRA9 Nsi9MO16qeF3oFdUDCQ91Ju16x8DciuwOpgf6jLhjGCoq9Pfwh4578kF3zcAjAh+a3 1hFEeOqQTC4hXnNZ3ICQ7tvKktlXrjA0dvB/AQlk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Cheng Jian , "Peter Zijlstra (Intel)" , Srikar Dronamraju , Vincent Guittot , Valentin Schneider , Yang Wei Subject: [PATCH 4.14 46/47] sched/fair: Optimize select_idle_cpu Date: Tue, 8 Jun 2021 20:27:29 +0200 Message-Id: <20210608175932.005035051@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210608175930.477274100@linuxfoundation.org> References: <20210608175930.477274100@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Cheng Jian commit 60588bfa223ff675b95f866249f90616613fbe31 upstream. 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 Signed-off-by: Peter Zijlstra (Intel) Reviewed-by: Srikar Dronamraju Reviewed-by: Vincent Guittot Reviewed-by: Valentin Schneider Link: https://lkml.kernel.org/r/20191213024530.28052-1-cj.chengjian@huawei.com Signed-off-by: Yang Wei Tested-by: Yang Wei Signed-off-by: Greg Kroah-Hartman --- kernel/sched/fair.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -5779,6 +5779,7 @@ static inline int select_idle_smt(struct */ 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; @@ -5809,11 +5810,11 @@ static int select_idle_cpu(struct task_s time = local_clock(); - for_each_cpu_wrap(cpu, sched_domain_span(sd), target) { + cpumask_and(cpus, sched_domain_span(sd), &p->cpus_allowed); + + for_each_cpu_wrap(cpu, cpus, target) { if (!--nr) return -1; - if (!cpumask_test_cpu(cpu, &p->cpus_allowed)) - continue; if (idle_cpu(cpu)) break; }