Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp3206094pxu; Tue, 8 Dec 2020 06:19:36 -0800 (PST) X-Google-Smtp-Source: ABdhPJy+/PzLz1pzlTPfgJ+eIhzVGhjpPKOi5+WTwqFNVqGNubBtmHP47x9AbUNgmoZR3kKiQoq0 X-Received: by 2002:a17:906:7e0b:: with SMTP id e11mr18226673ejr.533.1607437176634; Tue, 08 Dec 2020 06:19:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607437176; cv=none; d=google.com; s=arc-20160816; b=KyYs7GOLBbgy0DaoGpvQ7YAxkIA/RV9pEt/tuxUCPfU4COel5zgowITyhdLluwvfE4 +WNpB1i2ykAPBJ1ExWVzn7NUcn3I2kpOK/V7kRtAhkNAwYyJgl2hBqoNVyfDSDVrSj6A rWo5iHtuvrxneb5omZzFyWNutlJguIQAbIRQB7OeEily+in5BHPvSQ6KK9AHALHHT9NZ hMdsSwA8HTzvFMA1N/PPwPQN1XTDlrStw5IdpszTr4/4Hew3Ogs6kA5JwFSOq5dLxTLQ 5vb4iZIKHDSnQvATln4ElGcRrwFaQCKX3hokYTfL0nPBA8dUskfPsd4meC4ibQ0x51F+ L82Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=3ijEhG8gGEWiXJLW+imhAKg7QjYa3RJ5hrd4zDBUdUg=; b=G0m59UiNW3KOflAhuiMcq4wJgpU0mcAyeq5DY9IF5fFiqOGKW3GPtT1VT82uwaQZX2 ZPWkszj6xPwg9rJ1EV5+UU8D+gMlshW1IEYB1d62QbYpy4tJVUJo7c2NbF0wp0gsz9QG 0EYubUT0LVEebFgGgrpe/gx4wevWoHEfWh0CJu+otI/gWr+Kvsi4LaSVTW/FJCf/0iUY hi8GcdgcxxmGBH8q9z9ryP65Fl6htwAyMbdLRNyReN5/n3SDT7fEOCmK/KJ3K68x9doX JA1N0OC2VBeldnJlFL4rXjG8X8rTKzE3R2krQx00Hy5qfDBeWE1wK3WxqsRk3AxE5uo+ 0bAA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b="e+uAl4/K"; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i2si9962219edd.383.2020.12.08.06.19.13; Tue, 08 Dec 2020 06:19:36 -0800 (PST) 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=@infradead.org header.s=casper.20170209 header.b="e+uAl4/K"; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729771AbgLHORN (ORCPT + 99 others); Tue, 8 Dec 2020 09:17:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35596 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729461AbgLHORM (ORCPT ); Tue, 8 Dec 2020 09:17:12 -0500 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8C5FAC061749 for ; Tue, 8 Dec 2020 06:16:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=3ijEhG8gGEWiXJLW+imhAKg7QjYa3RJ5hrd4zDBUdUg=; b=e+uAl4/KdJgbbqKvi7aFKetu1a k6Skiclz4+Wej1KAIcTA4Y8ZFr+kZ35c0EsE5ujyreFOcN9ktg3MXwi0qUnhTo635gwPH5vLzbOtM 3PPXoKWFJsrkNfvpa9uJqtoE/yPsqsFA86yhtiNS6gO3ru5YxoBaotVJ2Ng5s8ohBU6geAovcNmM2 v4eYWv72A/fR5AJ3mzvNlt2KOyvUjwp6ETknxgxaQYLlEnpW+HsMfJM9IjT93OUaLcxO23+JozKDi kfCblF/gxlmEOlNj5KF2XQeUartcHlT5X/04ymxQWufVn/mUoTDKcQw5gU1LULROjgO28rPNy0t8N 4Ip/dnJw==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1kmdmo-0001PK-4V; Tue, 08 Dec 2020 14:16:14 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 093F7304B92; Tue, 8 Dec 2020 15:16:10 +0100 (CET) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id C78A8200AABBA; Tue, 8 Dec 2020 15:16:10 +0100 (CET) Date: Tue, 8 Dec 2020 15:16:10 +0100 From: Peter Zijlstra To: Aubrey Li Cc: mingo@redhat.com, juri.lelli@redhat.com, vincent.guittot@linaro.org, mgorman@techsingularity.net, valentin.schneider@arm.com, qais.yousef@arm.com, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, tim.c.chen@linux.intel.com, linux-kernel@vger.kernel.org, Mel Gorman , Jiang Biao Subject: Re: [RFC PATCH v6] sched/fair: select idle cpu from idle cpumask for task wakeup Message-ID: <20201208141610.GA2414@hirez.programming.kicks-ass.net> References: <20201208014957.170845-1-aubrey.li@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20201208014957.170845-1-aubrey.li@linux.intel.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Dec 08, 2020 at 09:49:57AM +0800, Aubrey Li wrote: > diff --git a/kernel/sched/core.c b/kernel/sched/core.c > index c4da7e17b906..b8af602dea79 100644 > --- a/kernel/sched/core.c > +++ b/kernel/sched/core.c > @@ -3999,6 +3999,7 @@ void scheduler_tick(void) > rq_lock(rq, &rf); > > update_rq_clock(rq); > + update_idle_cpumask(rq, false); Does that really need to be done with rq->lock held? > thermal_pressure = arch_scale_thermal_pressure(cpu_of(rq)); > update_thermal_load_avg(rq_clock_thermal(rq), rq, thermal_pressure); > @@ -6808,6 +6813,51 @@ balance_fair(struct rq *rq, struct task_struct *prev, struct rq_flags *rf) > } > #endif /* CONFIG_SMP */ > > +/* > + * Update cpu idle state and record this information > + * in sd_llc_shared->idle_cpus_span. > + */ > +void update_idle_cpumask(struct rq *rq, bool set_idle) > +{ > + struct sched_domain *sd; > + int cpu = cpu_of(rq); > + int idle_state; > + > + /* > + * If called from scheduler tick, only update > + * idle cpumask if the CPU is busy, as idle > + * cpumask is also updated on idle entry. > + * > + */ > + if (!set_idle && idle_cpu(cpu)) > + return; scheduler_tick() already calls idle_cpu() when SMP. > + /* > + * Also set SCHED_IDLE cpu in idle cpumask to > + * allow SCHED_IDLE cpu as a wakeup target > + */ > + idle_state = set_idle || sched_idle_cpu(cpu); > + /* > + * No need to update idle cpumask if the state > + * does not change. > + */ > + if (rq->last_idle_state == idle_state) > + return; > + > + rcu_read_lock(); This is called with IRQs disabled, surely we can forgo rcu_read_lock() here. > + sd = rcu_dereference(per_cpu(sd_llc, cpu)); > + if (!sd || !sd->shared) > + goto unlock; I don't think !sd->shared is possible here. > + if (idle_state) > + cpumask_set_cpu(cpu, sds_idle_cpus(sd->shared)); > + else > + cpumask_clear_cpu(cpu, sds_idle_cpus(sd->shared)); > + > + rq->last_idle_state = idle_state; > +unlock: > + rcu_read_unlock(); > +} > + > static unsigned long wakeup_gran(struct sched_entity *se) > { > unsigned long gran = sysctl_sched_wakeup_granularity; > diff --git a/kernel/sched/idle.c b/kernel/sched/idle.c > index f324dc36fc43..f995660edf2b 100644 > --- a/kernel/sched/idle.c > +++ b/kernel/sched/idle.c > @@ -156,6 +156,11 @@ static void cpuidle_idle_call(void) > return; > } > > + /* > + * The CPU is about to go idle, set it in idle cpumask > + * to be a wake up target. > + */ > + update_idle_cpumask(this_rq(), true); This should be in do_idle(), right around arch_cpu_idle_enter(). > /* > * The RCU framework needs to be told that we are entering an idle > * section, so no more rcu read side critical sections and one more > diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h > index 8d1ca65db3b0..db460b20217a 100644 > --- a/kernel/sched/sched.h > +++ b/kernel/sched/sched.h > @@ -1004,6 +1004,7 @@ struct rq { > /* This is used to determine avg_idle's max value */ > u64 max_idle_balance_cost; > #endif /* CONFIG_SMP */ > + unsigned char last_idle_state; All of that is pointless for UP. Also, is this the best location?