From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0029E2D0C90 for ; Tue, 9 Dec 2025 11:22:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.50.34 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765279331; cv=none; b=Jb3H2h03aLiMyNQx5beU5TrwZKJdOpe6tMBrEV/HAk4rmNyOhuy5JogtvvytPISiukE3TaWPZNyKCQdkO0S1iO91qtmjIlHBBnMH3+Bb+x12KWUeScjSxFJzwR6pUBrAp1KjtWg+1nqnAaUrgIQpCm3ZuAoUYOU5+QMgvRsRHeQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765279331; c=relaxed/simple; bh=aW9zT+a3f3upNq6HjuLZusvUe/OVe977MBDyiWXMKLo=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=tEgjZZ6ZKoe+zEq2P7Gu56oQ5mGGYVHoeTilfz6M257Sy/33Et3KeDNNStuZacWxtprCKn9ywg5OiDO1Jror2q1Z03srmd1eIa6Xgzh5tbcmHdocIdf8UFy6nhWtF8AdkqGjneI9IUHXGj8QufSflWAi55sR3ceStZNRf6ZVg6M= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=infradead.org; spf=none smtp.mailfrom=infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=iHFZc/EG; arc=none smtp.client-ip=90.155.50.34 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="iHFZc/EG" 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=KOYSdxdKYCbQ/66KHfNGE+tHd4lvcwmyyBGaCQFfnQo=; b=iHFZc/EG+nGanYH/p9Rm1/+NYe pgMkBI4AZkW9KfcDvxC14ioN5STVaB8lidzo4GAh+66yU74a9NKmg9898LdJ62anW0IJjndiydySv vQ2Plbcx8k9K4LQT5weIFFsC8uHAxJmP7bm+UQRxXOxorJ8x6NLjbUcfgokZnXHlqiitaEUiJ0I6w 2nbkLnN0oVecaTKDlMIxbyjHe22zHDRDoooPdTt2iIw8JseklCq0IrvXQxYNPmlqm4edoyKnKNA2g LRCh9rQ7zfh282wZ2znqbcCh7AEUUhcKR6yHYSEEQpjXd+CEJVWXrHHjNGktFmlGSYWdeRYZsLbHZ tprs7OUQ==; Received: from 2001-1c00-8d85-5700-266e-96ff-fe07-7dcc.cable.dynamic.v6.ziggo.nl ([2001:1c00:8d85:5700:266e:96ff:fe07:7dcc] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.98.2 #2 (Red Hat Linux)) id 1vSvmh-0000000B8nk-0mHg; Tue, 09 Dec 2025 11:21:35 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 1000) id 6963A30045C; Tue, 09 Dec 2025 12:21:34 +0100 (CET) Date: Tue, 9 Dec 2025 12:21:34 +0100 From: Peter Zijlstra To: Tim Chen Cc: Ingo Molnar , K Prateek Nayak , "Gautham R . Shenoy" , Vincent Guittot , Chen Yu , Juri Lelli , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Valentin Schneider , Madadi Vineeth Reddy , Hillf Danton , Shrikanth Hegde , Jianyong Wu , Yangyu Chen , Tingyin Duan , Vern Hao , Vern Hao , Len Brown , Aubrey Li , Zhao Liu , Chen Yu , Adam Li , Aaron Lu , Tim Chen , linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 02/23] sched/cache: Record per-LLC utilization to guide cache-aware scheduling decisions Message-ID: <20251209112134.GK3707891@noisy.programming.kicks-ass.net> References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: On Wed, Dec 03, 2025 at 03:07:21PM -0800, Tim Chen wrote: > diff --git a/include/linux/sched/topology.h b/include/linux/sched/topology.h > index bbcfdf12aa6e..0ba4697d74ba 100644 > --- a/include/linux/sched/topology.h > +++ b/include/linux/sched/topology.h > @@ -68,6 +68,10 @@ struct sched_domain_shared { > atomic_t nr_busy_cpus; > int has_idle_cores; > int nr_idle_scan; > +#ifdef CONFIG_SCHED_CACHE > + unsigned long util_avg; > + unsigned long capacity ____cacheline_aligned_in_smp; This cacheline annotation confuses me, see below. > +#endif > }; > > struct sched_domain { > diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c > index cb82f558dc5b..b9f336300f14 100644 > --- a/kernel/sched/fair.c > +++ b/kernel/sched/fair.c > @@ -9622,6 +9622,29 @@ static inline int task_is_ineligible_on_dst_cpu(struct task_struct *p, int dest_ > return 0; > } > > +#ifdef CONFIG_SCHED_CACHE > +/* Called from load balancing paths with rcu_read_lock held */ > +static __maybe_unused bool get_llc_stats(int cpu, unsigned long *util, > + unsigned long *cap) > +{ > + struct sched_domain_shared *sd_share; > + > + sd_share = rcu_dereference(per_cpu(sd_llc_shared, cpu)); > + if (!sd_share) > + return false; > + > + *util = READ_ONCE(sd_share->util_avg); > + *cap = READ_ONCE(sd_share->capacity); You placed capacity on a separate line, forcing the above to be 2 distinct lines. That seems... sub-optimal? > + > + return true; > +} > +#else > +static inline bool get_llc_stats(int cpu, unsigned long *util, > + unsigned long *cap) > +{ > + return false; > +} > +#endif > /* > * can_migrate_task - may task p from runqueue rq be migrated to this_cpu? > */ > @@ -10592,6 +10615,51 @@ sched_reduced_capacity(struct rq *rq, struct sched_domain *sd) > return check_cpu_capacity(rq, sd); > } > > +#ifdef CONFIG_SCHED_CACHE > +/* > + * Record the statistics for this scheduler group for later > + * use. These values guide load balancing on aggregating tasks > + * to a LLC. > + */ > +static void record_sg_llc_stats(struct lb_env *env, > + struct sg_lb_stats *sgs, > + struct sched_group *group) > +{ > + struct sched_domain_shared *sd_share; > + > + if (!sched_cache_enabled() || env->idle == CPU_NEWLY_IDLE) > + return; > + > + /* Only care about sched domain spanning multiple LLCs */ > + if (env->sd->child != rcu_dereference(per_cpu(sd_llc, env->dst_cpu))) > + return; > + > + /* > + * At this point we know this group spans a LLC domain. > + * Record the statistic of this group in its corresponding > + * shared LLC domain. > + * Note: sd_share cannot be obtained via sd->child->shared, because > + * it refers to the domain that covers the local group, while > + * sd_share could represent any of the LLC group. > + */ > + sd_share = rcu_dereference(per_cpu(sd_llc_shared, > + cpumask_first(sched_group_span(group)))); > + if (!sd_share) > + return; > + > + if (READ_ONCE(sd_share->util_avg) != sgs->group_util) > + WRITE_ONCE(sd_share->util_avg, sgs->group_util); > + > + if (unlikely(READ_ONCE(sd_share->capacity) != sgs->group_capacity)) > + WRITE_ONCE(sd_share->capacity, sgs->group_capacity); And same here. > +} > +#else > +static inline void record_sg_llc_stats(struct lb_env *env, struct sg_lb_stats *sgs, > + struct sched_group *group) > +{ > +} > +#endif