From nobody Thu Apr 2 16:57:53 2026 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.9]) (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 A359733ADAE for ; Tue, 10 Feb 2026 22:13:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.9 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770761596; cv=none; b=ZiLlxFLRXf6ZR0gbEOkS/uDl5Vi/+sRD2xax1CmOz+7Ft/6E0+V9Z3z0JO7QLZbveE3FS+nUQ/8EKSwWDFhgVUSrpetH5G0pybVfE30FfrO17My8gFdH7RqAIJzPPrhbbtQkg7o9AaJYuxf7QbyQmNyZYXnls6XWpjG1IVYWD5U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770761596; c=relaxed/simple; bh=n35wV+hjZT+VOHWA+vniVGH39bA/Nsa9EOYs7IP5CVQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=KaY45y/gFg5jFUm7NxTA2cXz9LcPn+p2LcQkNF048Kx9auWOHK9HQvD36mhlXbtwZRJOB4xumAs10DnUbDNPJQc4VhocIDiv4K4G7RwJ3mxgZsmtVhqIrbrbiSLbzWSEcFGsCD+LZ21L8+c+0N+g+aDC3Y/8mBuqJ1x0E7T9vZE= 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=SjW+0o9S; arc=none smtp.client-ip=192.198.163.9 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="SjW+0o9S" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1770761596; x=1802297596; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=n35wV+hjZT+VOHWA+vniVGH39bA/Nsa9EOYs7IP5CVQ=; b=SjW+0o9STo+/ZVX3CoiEIOvLvgyUq7DuReyDQ1eyn5uYWvaeIlnEJq9n 7eZW09bZwenzGCKluCD7+cGUtQuPlc2125UjJcb4jHT0f8/QQQwE5CB83 GEHxz4FXzda9AslVoMOnwYXf0jHV0dDYoujN/Uw03OrOO+cinMwGnRz+Y GNrewwEtuPB+SIKV3+DAKJgherHO/KwxxxjAjiGUEfXntNmpEQoqDOW+z cskL2aUjMabb4y37gmp2mCtzwUw+t9Pv+VwFXQHgzj91S3goxNC/wVX3h /xIm1knRZaazXh2kl62JiK5vjLE7sshChcEIjnBolERRjCUnqdPtJSDOz w==; X-CSE-ConnectionGUID: M8o50/DbRAux2rv+KOpUqA== X-CSE-MsgGUID: M5eKDl3tTQ+c5DhxMgbngw== X-IronPort-AV: E=McAfee;i="6800,10657,11697"; a="82631334" X-IronPort-AV: E=Sophos;i="6.21,283,1763452800"; d="scan'208";a="82631334" Received: from fmviesa004.fm.intel.com ([10.60.135.144]) by fmvoesa103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Feb 2026 14:13:15 -0800 X-CSE-ConnectionGUID: o0TDk7zeTQiLM83McRAh4Q== X-CSE-MsgGUID: MJMqV7wXTHiht5R0O8PTfw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.21,283,1763452800"; d="scan'208";a="216373911" Received: from b04f130c83f2.jf.intel.com ([10.165.154.98]) by fmviesa004.fm.intel.com with ESMTP; 10 Feb 2026 14:13:13 -0800 From: Tim Chen To: Peter Zijlstra , Ingo Molnar , K Prateek Nayak , "Gautham R . Shenoy" , Vincent Guittot Cc: Tim Chen , 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 , Chen Yu , Adam Li , Aaron Lu , Tim Chen , Josh Don , Gavin Guo , Qais Yousef , Libo Chen , linux-kernel@vger.kernel.org Subject: [PATCH v3 06/21] sched/cache: Track LLC-preferred tasks per runqueue Date: Tue, 10 Feb 2026 14:18:46 -0800 Message-Id: X-Mailer: git-send-email 2.32.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" For each runqueue, track the number of tasks with an LLC preference and how many of them are running on their preferred LLC. This mirrors nr_numa_running and nr_preferred_running for NUMA balancing, and will be used by cache-aware load balancing in later patches. Co-developed-by: Chen Yu Signed-off-by: Chen Yu Signed-off-by: Tim Chen --- Notes: v2->v3: Remove the sched_cache_enabled() check and make the account_llc_{en,de}queue() depending on CONFIG_SCHED_CACHE, so sched_llc_active in v2 can be removed. (Peter Zijlstra) kernel/sched/core.c | 5 +++++ kernel/sched/fair.c | 48 +++++++++++++++++++++++++++++++++++++++++--- kernel/sched/sched.h | 6 ++++++ 3 files changed, 56 insertions(+), 3 deletions(-) diff --git a/kernel/sched/core.c b/kernel/sched/core.c index c6efa71cf500..c464e370576f 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -532,6 +532,11 @@ void __trace_set_current_state(int state_value) } EXPORT_SYMBOL(__trace_set_current_state); =20 +int task_llc(const struct task_struct *p) +{ + return per_cpu(sd_llc_id, task_cpu(p)); +} + /* * Serialization rules: * diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 0b4ed0f2809d..6ad9ad2f918f 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -1199,6 +1199,30 @@ static int llc_id(int cpu) return per_cpu(sd_llc_id, cpu); } =20 +static void account_llc_enqueue(struct rq *rq, struct task_struct *p) +{ + int pref_llc; + + pref_llc =3D p->preferred_llc; + if (pref_llc < 0) + return; + + rq->nr_llc_running++; + rq->nr_pref_llc_running +=3D (pref_llc =3D=3D task_llc(p)); +} + +static void account_llc_dequeue(struct rq *rq, struct task_struct *p) +{ + int pref_llc; + + pref_llc =3D p->preferred_llc; + if (pref_llc < 0) + return; + + rq->nr_llc_running--; + rq->nr_pref_llc_running -=3D (pref_llc =3D=3D task_llc(p)); +} + void mm_init_sched(struct mm_struct *mm, struct sched_cache_time __percpu *_pcpu_sched) { @@ -1304,6 +1328,8 @@ static int get_pref_llc(struct task_struct *p, struct= mm_struct *mm) return mm_sched_llc; } =20 +static unsigned int task_running_on_cpu(int cpu, struct task_struct *p); + static inline void account_mm_sched(struct rq *rq, struct task_struct *p, s64 delta_exec) { @@ -1346,8 +1372,13 @@ void account_mm_sched(struct rq *rq, struct task_str= uct *p, s64 delta_exec) =20 mm_sched_llc =3D get_pref_llc(p, mm); =20 - if (p->preferred_llc !=3D mm_sched_llc) + /* task not on rq accounted later in account_entity_enqueue() */ + if (task_running_on_cpu(rq->cpu, p) && + p->preferred_llc !=3D mm_sched_llc) { + account_llc_dequeue(rq, p); p->preferred_llc =3D mm_sched_llc; + account_llc_enqueue(rq, p); + } } =20 static void task_tick_cache(struct rq *rq, struct task_struct *p) @@ -1482,6 +1513,11 @@ static inline int get_pref_llc(struct task_struct *p, { return -1; } + +static void account_llc_enqueue(struct rq *rq, struct task_struct *p) {} + +static void account_llc_dequeue(struct rq *rq, struct task_struct *p) {} + #endif =20 /* @@ -3970,9 +4006,11 @@ account_entity_enqueue(struct cfs_rq *cfs_rq, struct= sched_entity *se) { update_load_add(&cfs_rq->load, se->load.weight); if (entity_is_task(se)) { + struct task_struct *p =3D task_of(se); struct rq *rq =3D rq_of(cfs_rq); =20 - account_numa_enqueue(rq, task_of(se)); + account_numa_enqueue(rq, p); + account_llc_enqueue(rq, p); list_add(&se->group_node, &rq->cfs_tasks); } cfs_rq->nr_queued++; @@ -3983,7 +4021,11 @@ account_entity_dequeue(struct cfs_rq *cfs_rq, struct= sched_entity *se) { update_load_sub(&cfs_rq->load, se->load.weight); if (entity_is_task(se)) { - account_numa_dequeue(rq_of(cfs_rq), task_of(se)); + struct task_struct *p =3D task_of(se); + struct rq *rq =3D rq_of(cfs_rq); + + account_numa_dequeue(rq, p); + account_llc_dequeue(rq, p); list_del_init(&se->group_node); } cfs_rq->nr_queued--; diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h index de5b701c3950..35cea6aa32a4 100644 --- a/kernel/sched/sched.h +++ b/kernel/sched/sched.h @@ -1128,6 +1128,10 @@ struct rq { unsigned int nr_preferred_running; unsigned int numa_migrate_on; #endif +#ifdef CONFIG_SCHED_CACHE + unsigned int nr_pref_llc_running; + unsigned int nr_llc_running; +#endif #ifdef CONFIG_NO_HZ_COMMON unsigned long last_blocked_load_update_tick; unsigned int has_blocked_load; @@ -1996,6 +2000,8 @@ init_numa_balancing(u64 clone_flags, struct task_stru= ct *p) =20 #endif /* !CONFIG_NUMA_BALANCING */ =20 +int task_llc(const struct task_struct *p); + static inline void queue_balance_callback(struct rq *rq, struct balance_callback *head, --=20 2.32.0