From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.10]) (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 C4F9A2F84F for ; Fri, 20 Feb 2026 00:11:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.10 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771546312; cv=none; b=MzInAjavjWf0/R5W36wVfeb6a8Eu8sYupYs3y5iNMSRxCZYWIMVe7OTGqtWUYTXjIhFq72CpKtkI0l1mAv7bvsHmvCvlOt5mGgHVzHVk3L0Nhj66sMCk6xeMR3sIx046SKKIyhgNyNDp2fglYRlP5ulW77mI8AXU1pJ3D5eXPMc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771546312; c=relaxed/simple; bh=s/oO5u2/lvTitMkgfNvl4U1kl6QzWdMdFj1WxgPvdwk=; h=Message-ID:Subject:From:To:Cc:Date:In-Reply-To:References: Content-Type:MIME-Version; b=DlBJU8H9DKIdm24Ls+NyX1ZlxBO6HICuoxfxnvLBV7D/3V3bgj5GtQsTNrZjlv6ivHY9Z8O94+II9rX9hMT4m1k+oJ+YTCuJLwAXEkLVpY//JjmyETVvGdu3rSkKy53iSUJ/YMQ/++7VcR/56ietzuv2nwQ2dZ9qqetCi9j2cEY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=pass smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=gBXk0Y1s; arc=none smtp.client-ip=198.175.65.10 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="gBXk0Y1s" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1771546309; x=1803082309; h=message-id:subject:from:to:cc:date:in-reply-to: references:content-transfer-encoding:mime-version; bh=s/oO5u2/lvTitMkgfNvl4U1kl6QzWdMdFj1WxgPvdwk=; b=gBXk0Y1s5A3nrbm8m26dlDmjoxHEniENFSU4ixhfCQ2UA0XpJwc+V9AO sL1bB+daMFl0tsTRwS2Gjrm1ukOVP0AP1z3qvhUoHZ2EQxwE7TQuFacVt +fPo0q420aagJalyaC1ycNEgZvH+GOiqY3Y4UiTqh0nGu2Z9LZCJHnPEw gZWnNTViZ0KA5abBZ9uwMf4ZJBNei5UJGshAATGjAz6DY1odPtaw6JINL 0oXsbPd28NpwCQBZVTvSlYgx4xVg9PhTJNCtjdO9m1XRxmnQ7xiREH3vo b2Sxh9mBHHJyR1E4ax/1463jh9Qcju3LfQgLYJFJdSVoUF/Bkgv0hpLbI A==; X-CSE-ConnectionGUID: BcQ8KpP/R9OZoDdjyCvESg== X-CSE-MsgGUID: KKRw0CbTTXethXOY7K45JQ== X-IronPort-AV: E=McAfee;i="6800,10657,11706"; a="90054573" X-IronPort-AV: E=Sophos;i="6.21,300,1763452800"; d="scan'208";a="90054573" Received: from orviesa006.jf.intel.com ([10.64.159.146]) by orvoesa102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Feb 2026 16:11:48 -0800 X-CSE-ConnectionGUID: FdNIUzr+RQmltc3ypHPGfw== X-CSE-MsgGUID: cK6osGyWR52I085rPlBMlQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.21,300,1763452800"; d="scan'208";a="213809418" Received: from unknown (HELO [10.241.243.83]) ([10.241.243.83]) by orviesa006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Feb 2026 16:11:47 -0800 Message-ID: Subject: Re: [PATCH v3 04/21] sched/cache: Make LLC id continuous From: Tim Chen To: K Prateek Nayak , "Chen, Yu C" Cc: 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 , Josh Don , Gavin Guo , Qais Yousef , Libo Chen , linux-kernel@vger.kernel.org, Peter Zijlstra , "Gautham R . Shenoy" , Vincent Guittot , Ingo Molnar Date: Thu, 19 Feb 2026 16:11:47 -0800 In-Reply-To: <3de1e4ff-2da5-4a58-a4ea-03accf4b7572@amd.com> References: <60a05a3f50d14a7bf3b968f62cca87893c5c552c.1770760558.git.tim.c.chen@linux.intel.com> <79755f7d-cc68-4189-b6d8-850378e54017@amd.com> <95923e36-4117-4209-97aa-a92b60f2bd49@intel.com> <6a73ac0d-1fc9-49a7-87a2-65951ab2c844@amd.com> <8df218ecf39015830856c7b1053a0f777cc1ea42.camel@linux.intel.com> <579c9039-cd66-41c3-8a72-e73d6f836ee8@amd.com> <3de1e4ff-2da5-4a58-a4ea-03accf4b7572@amd.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.58.1 (3.58.1-1.fc43) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 On Thu, 2026-02-19 at 11:42 +0530, K Prateek Nayak wrote: > Hello Tim, >=20 > Thank you for the patch. >=20 > On 2/19/2026 4:51 AM, Tim Chen wrote: > > diff --git a/init/Kconfig b/init/Kconfig > > index 9848de949afa..4ddf54ab9cf7 100644 > > --- a/init/Kconfig > > +++ b/init/Kconfig > > @@ -987,6 +987,7 @@ config SCHED_CACHE > > bool "Cache aware load balance" > > default y > > depends on SMP > > + depends on SCHED_MC > > help > > When enabled, the scheduler will attempt to aggregate tasks from > > the same process onto a single Last Level Cache (LLC) domain when > > diff --git a/kernel/sched/core.c b/kernel/sched/core.c > > index 48626c81ba8e..75ba4e0bfcd3 100644 > > --- a/kernel/sched/core.c > > +++ b/kernel/sched/core.c > > @@ -8474,6 +8474,8 @@ int sched_cpu_deactivate(unsigned int cpu) > > */ > > synchronize_rcu(); > > =20 > > + sched_domains_free_llc_id(cpu); > > + > > sched_set_rq_offline(rq, cpu); > > =20 > > scx_rq_deactivate(rq); > > diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h > > index 6cbc56e9adfc..04f42526e6f0 100644 > > --- a/kernel/sched/sched.h > > +++ b/kernel/sched/sched.h > > @@ -3862,6 +3862,7 @@ static inline bool sched_cache_enabled(void) > > extern void sched_cache_active_set_unlocked(void); > > #endif > > extern void init_sched_mm(struct task_struct *p); > > +void sched_domains_free_llc_id(int cpu); > > =20 > > extern u64 avg_vruntime(struct cfs_rq *cfs_rq); > > extern int entity_eligible(struct cfs_rq *cfs_rq, struct sched_entity = *se); > > diff --git a/kernel/sched/topology.c b/kernel/sched/topology.c > > index 580fb2fbc900..5e59340ad9a9 100644 > > --- a/kernel/sched/topology.c > > +++ b/kernel/sched/topology.c > > @@ -18,6 +18,7 @@ void sched_domains_mutex_unlock(void) > > } > > =20 > > /* Protected by sched_domains_mutex: */ > > +static cpumask_var_t sched_domains_llc_id_allocmask; > > static cpumask_var_t sched_domains_tmpmask; > > static cpumask_var_t sched_domains_tmpmask2; > > static int tl_max_llcs; > > @@ -2590,6 +2591,57 @@ static bool topology_span_sane(const struct cpum= ask *cpu_map) > > return true; > > } > > =20 > > +static int __sched_domains_alloc_llc_id(void) > > +{ > > + int lid; > > + > > + lockdep_assert_held(&sched_domains_mutex); > > + > > + lid =3D cpumask_first_zero(sched_domains_llc_id_allocmask); > > + if (lid >=3D tl_max_llcs) > > + tl_max_llcs =3D lid + 1; > > + > > + /* > > + * llc_id space should never grow larger than the > > + * possible number of CPUs in the system. > > + */ > > + if (!unlikely(WARN_ON_ONCE(lid >=3D nr_cpumask_bits))) > > + cpumask_set_cpu(lid, sched_domains_llc_id_allocmask); > > + return lid; > > +} > > + > > +static void __sched_domains_free_llc_id(int cpu) > > +{ > > + int i, lid; > > + > > + lockdep_assert_held(&sched_domains_mutex); > > + > > + lid =3D per_cpu(sd_llc_id, cpu); > > + if (lid =3D=3D -1) > > + return; > > + > > + per_cpu(sd_llc_id, cpu) =3D -1; > > + > > + for_each_online_cpu(i) { > > + /* An online CPU owns the llc_id. */ > > + if (per_cpu(sd_llc_id, i) =3D=3D lid) > > + return; > > + } >=20 > We should perhaps warn and skip clearing lid from cpumask if lid was > found to be larger than "nr_cpumask_bits". Shouldn't happen but just > as a precaution. Will do >=20 > > + > > + cpumask_clear_cpu(lid, sched_domains_llc_id_allocmask); > > + > > + /* shrink max LLC size to save memory */ > > + if (lid =3D=3D tl_max_llcs - 1) > > + lid =3D tl_max_llcs--; >=20 > No need to assign the local "lid" variable here; Simple decrement > should do. Good point >=20 > > +} > > + > > +void sched_domains_free_llc_id(int cpu) > > +{ > > + sched_domains_mutex_lock(); > > + __sched_domains_free_llc_id(cpu); > > + sched_domains_mutex_unlock(); > > +} > > + > > /* > > * Build sched domains for a given set of CPUs and attach the sched do= mains > > * to the individual CPUs > > @@ -2615,18 +2667,11 @@ build_sched_domains(const struct cpumask *cpu_m= ap, struct sched_domain_attr *att > > =20 > > /* Set up domains for CPUs specified by the cpu_map: */ > > for_each_cpu(i, cpu_map) { > > - struct sched_domain_topology_level *tl, *tl_llc =3D NULL; > > + struct sched_domain_topology_level *tl; > > int lid; > > =20 > > sd =3D NULL; > > for_each_sd_topology(tl) { > > - int flags =3D 0; > > - > > - if (tl->sd_flags) > > - flags =3D (*tl->sd_flags)(); > > - > > - if (flags & SD_SHARE_LLC) > > - tl_llc =3D tl; > > =20 > > sd =3D build_sched_domain(tl, cpu_map, attr, sd, i); > > =20 > > @@ -2642,18 +2687,19 @@ build_sched_domains(const struct cpumask *cpu_m= ap, struct sched_domain_attr *att > > if (lid =3D=3D -1) { > > int j; > > =20 > > + j =3D cpumask_first(cpu_coregroup_mask(i)); > > /* > > * Assign the llc_id to the CPUs that do not > > * have an LLC. > > */ > > - if (!tl_llc) { > > - per_cpu(sd_llc_id, i) =3D tl_max_llcs++; > > + if (j >=3D nr_cpu_ids) { > > + per_cpu(sd_llc_id, i) =3D __sched_domains_alloc_llc_id(); > > =20 > > continue; > > } >=20 > I don't think we need to special case this out since: >=20 > for_each_cpu(j, cpu_coregroup_mask(i)) { > ... > } >=20 > would bail out if no CPU is set (also CPU "i" would definitely be > set on it since it must be online) and the "if" after the loop will > see "lid" as "-1" and DTRT. That's right. Will take out the non-needed code. Also found out that cpu_coregroup_mask() is not defined for config without CONFIG_SMP. So will put the llc id assignment code under CONFIG_SMP. Thanks for the code reviews and suggestions. Tim >=20 > > =20 > > /* try to reuse the llc_id of its siblings */ > > - for_each_cpu(j, tl_llc->mask(tl_llc, i)) { > > + for (; j < nr_cpu_ids; j =3D cpumask_next(j, cpu_coregroup_mask(i))= ) { > > if (i =3D=3D j) > > continue; > > =20 > > @@ -2668,7 +2714,7 @@ build_sched_domains(const struct cpumask *cpu_map= , struct sched_domain_attr *att > > =20 > > /* a new LLC is detected */ > > if (lid =3D=3D -1) > > - per_cpu(sd_llc_id, i) =3D tl_max_llcs++; > > + per_cpu(sd_llc_id, i) =3D __sched_domains_alloc_llc_id(); > > } > > } > > =20 > > @@ -2869,6 +2915,7 @@ int __init sched_init_domains(const struct cpumas= k *cpu_map) > > { > > int err; > > =20 > > + zalloc_cpumask_var(&sched_domains_llc_id_allocmask, GFP_KERNEL); > > zalloc_cpumask_var(&sched_domains_tmpmask, GFP_KERNEL); > > zalloc_cpumask_var(&sched_domains_tmpmask2, GFP_KERNEL); > > zalloc_cpumask_var(&fallback_doms, GFP_KERNEL);