mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: K Prateek Nayak <kprateek.nayak@amd.com>
To: Ingo Molnar <mingo@redhat.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Juri Lelli <juri.lelli@redhat.com>,
	Vincent Guittot <vincent.guittot@linaro.org>,
	Chen Yu <yu.c.chen@intel.com>, <linux-kernel@vger.kernel.org>
Cc: Dietmar Eggemann <dietmar.eggemann@arm.com>,
	Steven Rostedt <rostedt@goodmis.org>,
	Ben Segall <bsegall@google.com>, Mel Gorman <mgorman@suse.de>,
	Valentin Schneider <vschneid@redhat.com>,
	David Vernet <void@manifault.com>,
	"Gautham R. Shenoy" <gautham.shenoy@amd.com>,
	"Swapnil Sapkal" <swapnil.sapkal@amd.com>,
	Shrikanth Hegde <sshegde@linux.ibm.com>,
	"K Prateek Nayak" <kprateek.nayak@amd.com>
Subject: [RFC PATCH 5/8] sched/topology: Define sg_lb_stats_prop and embed it inside sched_domain_shared
Date: Thu, 13 Mar 2025 09:37:43 +0000	[thread overview]
Message-ID: <20250313093746.6760-6-kprateek.nayak@amd.com> (raw)
In-Reply-To: <20250313093746.6760-1-kprateek.nayak@amd.com>

"struct sg_lb_stats_prop" is a container around "sg_lb_stats" to help
propagate the load balancing stats up the sched domain hierarchy. Embed
the same in "sched_domain_shared" for concurrent load balancing
instances to reuse the statistics collected for domains below.

Signed-off-by: K Prateek Nayak <kprateek.nayak@amd.com>
---
 include/linux/sched/topology.h |  9 +++++----
 kernel/sched/sched.h           | 11 +++++++++++
 kernel/sched/topology.c        | 26 +++++++++++++++++++++++---
 3 files changed, 39 insertions(+), 7 deletions(-)

diff --git a/include/linux/sched/topology.h b/include/linux/sched/topology.h
index 7f3dbafe1817..a16d7d9dd9d3 100644
--- a/include/linux/sched/topology.h
+++ b/include/linux/sched/topology.h
@@ -78,10 +78,11 @@ extern int sched_domain_level_max;
 struct sched_group;
 
 struct sched_domain_shared {
-	atomic_t	ref;
-	atomic_t	nr_busy_cpus;
-	int		has_idle_cores;
-	int		nr_idle_scan;
+	atomic_t		ref;
+	atomic_t		nr_busy_cpus;
+	int			has_idle_cores;
+	int			nr_idle_scan;
+	void			*private;	/* lb stats propagation field */
 };
 
 struct sched_domain {
diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
index 9372a75ab3cf..391c4180eeb3 100644
--- a/kernel/sched/sched.h
+++ b/kernel/sched/sched.h
@@ -2170,6 +2170,17 @@ struct sg_lb_stats {
 #endif
 };
 
+/*
+ * sg_lb_stats_prop - Load balancer stats propagation container.
+ * This is embedded in sg->shared->private and is used to propagate
+ * sched_domain load balancing statistics up the hierarchy.
+ */
+struct sg_lb_stats_prop {
+	raw_spinlock_t          stats_lock;	/* Lock for updating the cached stats */
+	unsigned long		last_update;	/* Time when stats was last updated (jiffies) */
+	struct sg_lb_stats	sg_stats;	/* Cached sched_group stats */
+};
+
 static inline struct cpumask *sched_group_span(struct sched_group *sg)
 {
 	return to_cpumask(sg->cpumask);
diff --git a/kernel/sched/topology.c b/kernel/sched/topology.c
index 508ee8aa492b..aeb55f66e8d6 100644
--- a/kernel/sched/topology.c
+++ b/kernel/sched/topology.c
@@ -621,10 +621,19 @@ static void link_sg_shared(struct sched_group *sg, struct sched_domain_shared *s
 	atomic_inc(&sds->ref);
 }
 
+static void free_sched_domain_shared(struct sched_domain_shared *sd_shared)
+{
+	if (!sd_shared)
+		return;
+
+	kfree(sd_shared->private);
+	kfree(sd_shared);
+}
+
 static void free_sg_shared(struct sched_group *sg)
 {
 	if (sg->shared && atomic_dec_and_test(&sg->shared->ref))
-		kfree(sg->shared);
+		free_sched_domain_shared(sg->shared);
 
 	sg->shared = NULL;
 }
@@ -661,7 +670,7 @@ static void destroy_sched_domain(struct sched_domain *sd)
 	free_sched_groups(sd->groups, 1);
 
 	if (sd->shared && atomic_dec_and_test(&sd->shared->ref))
-		kfree(sd->shared);
+		free_sched_domain_shared(sd->shared);
 	kfree(sd);
 }
 
@@ -2273,6 +2282,7 @@ static int __sdt_alloc(const struct cpumask *cpu_map)
 			struct sched_domain_shared *sds;
 			struct sched_group *sg;
 			struct sched_group_capacity *sgc;
+			struct sg_lb_stats_prop *sg_stats;
 
 			sd = kzalloc_node(sizeof(struct sched_domain) + cpumask_size(),
 					GFP_KERNEL, cpu_to_node(j));
@@ -2288,6 +2298,16 @@ static int __sdt_alloc(const struct cpumask *cpu_map)
 
 			*per_cpu_ptr(sdd->sds, j) = sds;
 
+			sg_stats = kzalloc_node(sizeof(struct sg_lb_stats_prop),
+					GFP_KERNEL, cpu_to_node(j));
+
+			if (!sg_stats)
+				return -ENOMEM;
+
+			raw_spin_lock_init(&sg_stats->stats_lock);
+			sg_stats->last_update = 0;
+			sds->private = (void *)sg_stats;
+
 			sg = kzalloc_node(sizeof(struct sched_group) + cpumask_size(),
 					GFP_KERNEL, cpu_to_node(j));
 			if (!sg)
@@ -2332,7 +2352,7 @@ static void __sdt_free(const struct cpumask *cpu_map)
 			}
 
 			if (sdd->sds)
-				kfree(*per_cpu_ptr(sdd->sds, j));
+				free_sched_domain_shared(*per_cpu_ptr(sdd->sds, j));
 			if (sdd->sg)
 				kfree(*per_cpu_ptr(sdd->sg, j));
 			if (sdd->sgc)
-- 
2.43.0


  parent reply	other threads:[~2025-03-13  9:39 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-13  9:37 [RFC PATCH 0/8] sched/fair: Propagate load balancing stats up the sched domain hierarchy K Prateek Nayak
2025-03-13  9:37 ` [RFC PATCH 1/8] sched/topology: Assign sd_share for all non NUMA sched domains K Prateek Nayak
2025-03-13  9:37 ` [RFC PATCH 2/8] sched/topology: Introduce sg->shared K Prateek Nayak
2025-03-13  9:37 ` [RFC PATCH 3/8] sched/fair: Move "struct sg_lb_stats" and its dependencies to sched.h K Prateek Nayak
2025-03-13  9:37 ` [RFC PATCH 4/8] sched/fair: Move sg_{overloaded,overutilized} calculation to sg_lb_stats K Prateek Nayak
2025-03-13  9:37 ` K Prateek Nayak [this message]
2025-03-13  9:37 ` [RFC PATCH 6/8] sched/fair: Increase probability of lb stats being reused K Prateek Nayak
2025-03-17 18:07   ` Chen, Yu C
2025-03-19  6:51     ` K Prateek Nayak
2025-03-13  9:37 ` [RFC PATCH 7/8] sched/fair: Retrieve cached group stats from sg_lb_stats_prop K Prateek Nayak
2025-03-17 18:04   ` Chen, Yu C
2025-03-19  6:42     ` K Prateek Nayak
2025-03-13  9:37 ` [RFC PATCH 8/8] sched/fair: Update stats for sched_domain using the sched_group stats K Prateek Nayak
2025-03-16 10:29 ` [RFC PATCH 09/08] [ANNOTATE] sched/fair: Stats versioning and invalidation K Prateek Nayak
2025-03-16 10:29 ` [RFC PATCH 10/08] sched/fair: Compute nr_{numa,preferred}_running for non-NUMA domains K Prateek Nayak
2025-03-16 10:29 ` [RFC PATCH 11/08] sched/fair: Move from "last_update" to stats versioning K Prateek Nayak
2025-03-16 10:29 ` [RFC PATCH 12/08] sched/fair: Record the cpu that updated the stats last K Prateek Nayak
2025-03-16 10:29 ` [RFC PATCH 13/08] sched/fair: Invalidate stats once the load balancing instance is done K Prateek Nayak
2025-03-16 10:29 ` [RFC PATCH 14/08] [DEBUG] sched/fair: Add more lb_stats around lb_time and stats reuse K Prateek Nayak
2025-03-16 10:29 ` [RFC PATCH 15/08] [DEBUG] tools/lib/perf: Extend schedstats v17 headers to include the new debug fields K Prateek Nayak
2025-03-17 17:25 ` [RFC PATCH 0/8] sched/fair: Propagate load balancing stats up the sched domain hierarchy Peter Zijlstra
2025-03-17 18:23   ` Chen, Yu C
2025-03-21 10:04 ` Libo Chen
2025-03-24  3:58   ` K Prateek Nayak

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250313093746.6760-6-kprateek.nayak@amd.com \
    --to=kprateek.nayak@amd.com \
    --cc=bsegall@google.com \
    --cc=dietmar.eggemann@arm.com \
    --cc=gautham.shenoy@amd.com \
    --cc=juri.lelli@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mgorman@suse.de \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=sshegde@linux.ibm.com \
    --cc=swapnil.sapkal@amd.com \
    --cc=vincent.guittot@linaro.org \
    --cc=void@manifault.com \
    --cc=vschneid@redhat.com \
    --cc=yu.c.chen@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®