linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: Ricardo Neri <ricardo.neri-calderon@linux.intel.com>
Cc: Juri Lelli <juri.lelli@redhat.com>,
	Vincent Guittot <vincent.guittot@linaro.org>,
	Ricardo Neri <ricardo.neri@intel.com>,
	"Ravi V. Shankar" <ravi.v.shankar@intel.com>,
	Ben Segall <bsegall@google.com>,
	Daniel Bristot de Oliveira <bristot@redhat.com>,
	Dietmar Eggemann <dietmar.eggemann@arm.com>,
	Len Brown <len.brown@intel.com>, Mel Gorman <mgorman@suse.de>,
	"Rafael J. Wysocki" <rafael.j.wysocki@intel.com>,
	Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>,
	Steven Rostedt <rostedt@goodmis.org>,
	Tim Chen <tim.c.chen@linux.intel.com>,
	Valentin Schneider <vschneid@redhat.com>,
	x86@kernel.org, linux-kernel@vger.kernel.org,
	"Tim C . Chen" <tim.c.chen@intel.com>
Subject: Re: [RFC PATCH 08/23] sched/fair: Compute task-class performance scores for load balancing
Date: Tue, 27 Sep 2022 11:15:46 +0200	[thread overview]
Message-ID: <YzK/QisKmix6hrKG@hirez.programming.kicks-ass.net> (raw)
In-Reply-To: <20220909231205.14009-9-ricardo.neri-calderon@linux.intel.com>

On Fri, Sep 09, 2022 at 04:11:50PM -0700, Ricardo Neri wrote:

> +static void compute_ilb_sg_task_class_scores(struct sg_lb_task_class_stats *class_sgs,
> +					     struct sg_lb_stats *sgs,
> +					     int dst_cpu)
> +{
> +	int group_score, group_score_without, score_on_dst_cpu;
> +	int busy_cpus = sgs->group_weight - sgs->idle_cpus;
> +
> +	if (!sched_task_classes_enabled())
> +		return;
> +
> +	/* No busy CPUs in the group. No tasks to move. */
> +	if (!busy_cpus)
> +		return;
> +
> +	score_on_dst_cpu = arch_get_task_class_score(class_sgs->p_min_score->class,
> +						     dst_cpu);
> +
> +	/*
> +	 * The simpest case. The single busy CPU in the current group will
> +	 * become idle after pulling its current task. The destination CPU is
> +	 * idle.
> +	 */
> +	if (busy_cpus == 1) {
> +		sgs->task_class_score_before = class_sgs->sum_score;
> +		sgs->task_class_score_after = score_on_dst_cpu;
> +		return;
> +	}
> +
> +	/*
> +	 * Now compute the group score with and without the task with the
> +	 * lowest score. We assume that the tasks that remain in the group share
> +	 * the CPU resources equally.
> +	 */
> +	group_score = class_sgs->sum_score / busy_cpus;
> +
> +	group_score_without =  (class_sgs->sum_score - class_sgs->min_score) /
> +			       (busy_cpus - 1);
> +
> +	sgs->task_class_score_after = group_score_without + score_on_dst_cpu;
> +	sgs->task_class_score_before = group_score;
> +}

That's just plain broken; also lots of cleanups done...

---
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -8405,12 +8405,14 @@ struct sg_lb_stats {
 	enum group_type group_type;
 	unsigned int group_asym_packing; /* Tasks should be moved to preferred CPU */
 	unsigned long group_misfit_task_load; /* A CPU has a task too big for its capacity */
-	long task_class_score_after; /* Prospective task-class score after load balancing */
-	long task_class_score_before; /* Task-class score before load balancing */
 #ifdef CONFIG_NUMA_BALANCING
 	unsigned int nr_numa_running;
 	unsigned int nr_preferred_running;
 #endif
+#ifdef CONFIG_SCHED_TASK_CLASSES
+	long task_class_score_after;  /* Prospective task-class score after load balancing */
+	long task_class_score_before; /* Task-class score before load balancing */
+#endif
 };
 
 /*
@@ -8689,58 +8691,54 @@ group_type group_classify(unsigned int i
 }
 
 struct sg_lb_task_class_stats {
-	/*
-	 * Score of the task with lowest score among the current tasks (i.e.,
-	 * runqueue::curr) of all runqueues in the scheduling group.
-	 */
-	int min_score;
-	/*
-	 * Sum of the scores of the current tasks of all runqueues in the
-	 * scheduling group.
-	 */
-	long sum_score;
-	/* The task with score equal to @min_score */
-	struct task_struct *p_min_score;
+	int min_score;                   /* Min(rq->curr->score) */
+	int min_class;
+	long sum_score;                  /* Sum(rq->curr->score) */
 };
 
 #ifdef CONFIG_SCHED_TASK_CLASSES
-static void init_rq_task_classes_stats(struct sg_lb_task_class_stats *class_sgs)
+static void init_sg_lb_task_class_stats(struct sg_lb_task_class_stats *sgcs)
 {
-	class_sgs->min_score = INT_MAX;
-	class_sgs->sum_score = 0;
-	class_sgs->p_min_score = NULL;
+	*sgcs = (struct sg_lb_task_class_stats){
+		.min_score = INT_MAX,
+	};
 }
 
 /** Called only if cpu_of(@rq) is not idle and has tasks running. */
-static void update_rq_task_classes_stats(struct sg_lb_task_class_stats *class_sgs,
-					 struct rq *rq)
+static void update_sg_lb_task_class_stats(struct sg_lb_task_class_stats *sgcs,
+					  struct rq *rq)
 {
-	int score;
+	struct task_struct *curr;
+	int class, score;
 
 	if (!sched_task_classes_enabled())
 		return;
 
+	curr = rcu_dereference(rq->curr);
+	if (!curr || (curr->flags & PF_EXITING) || is_idle_task(curr))
+		return;
+
 	/*
 	 * TODO: if nr_running > 1 we may want go through all the tasks behind
 	 * rq->curr.
 	 */
-	score = arch_get_task_class_score(rq->curr->class, cpu_of(rq));
-
-	class_sgs->sum_score += score;
+	class = curr->class;
+	score = arch_get_task_class_score(class, cpu_of(rq));
 
-	if (score >= class_sgs->min_score)
-		return;
+	sgcs->sum_score += score;
 
-	class_sgs->min_score = score;
-	class_sgs->p_min_score = rq->curr;
+	if (score < sgcs->min_score) {
+		sgcs->min_score = score;
+		sgcs->min_class = class;
+	}
 }
 
-static void compute_ilb_sg_task_class_scores(struct sg_lb_task_class_stats *class_sgs,
-					     struct sg_lb_stats *sgs,
-					     int dst_cpu)
+static void update_sg_lb_stats_scores(struct sg_lb_task_class_stats *sgcs,
+				      struct sg_lb_stats *sgs,
+				      int dst_cpu)
 {
-	int group_score, group_score_without, score_on_dst_cpu;
 	int busy_cpus = sgs->group_weight - sgs->idle_cpus;
+	long before, after;
 
 	if (!sched_task_classes_enabled())
 		return;
@@ -8749,32 +8747,18 @@ static void compute_ilb_sg_task_class_sc
 	if (!busy_cpus)
 		return;
 
-	score_on_dst_cpu = arch_get_task_class_score(class_sgs->p_min_score->class,
-						     dst_cpu);
+	score_on_dst_cpu = arch_get_task_class_score(sgcs->min_class, dst_cpu);
 
-	/*
-	 * The simpest case. The single busy CPU in the current group will
-	 * become idle after pulling its current task. The destination CPU is
-	 * idle.
-	 */
-	if (busy_cpus == 1) {
-		sgs->task_class_score_before = class_sgs->sum_score;
-		sgs->task_class_score_after = score_on_dst_cpu;
-		return;
-	}
+	before = sgcs->sum_score
+	after  = before - sgcs->min_score + score_on_dst_cpu;
 
-	/*
-	 * Now compute the group score with and without the task with the
-	 * lowest score. We assume that the tasks that remain in the group share
-	 * the CPU resources equally.
-	 */
-	group_score = class_sgs->sum_score / busy_cpus;
-
-	group_score_without =  (class_sgs->sum_score - class_sgs->min_score) /
-			       (busy_cpus - 1);
+	if (busy_cpus > 1) {
+		before /= busy_cpus;
+		after  /= busy_cpus;
+	}
 
-	sgs->task_class_score_after = group_score_without + score_on_dst_cpu;
-	sgs->task_class_score_before = group_score;
+	sgs->task_class_score_before = before;
+	sgs->task_class_score_after  = after;
 }
 
 /**
@@ -8832,18 +8816,19 @@ static bool sched_asym_class_pick(struct
 }
 
 #else /* CONFIG_SCHED_TASK_CLASSES */
-static void update_rq_task_classes_stats(struct sg_lb_task_class_stats *class_sgs,
-					 struct rq *rq)
+
+static void init_sg_lb_task_class_stats(struct sg_lb_task_class_stats *sgcs)
 {
 }
 
-static void init_rq_task_classes_stats(struct sg_lb_task_class_stats *class_sgs)
+static void update_sg_lb_task_class_stats(struct sg_lb_task_class_stats *sgcs,
+					  struct rq *rq)
 {
 }
 
-static void compute_ilb_sg_task_class_scores(struct sg_lb_task_class_stats *class_sgs,
-					     struct sg_lb_stats *sgs,
-					     int dst_cpu)
+static void update_sg_lb_stats_scores(struct sg_lb_task_class_stats *sgcs,
+				      struct sg_lb_stats *sgs,
+				      int dst_cpu)
 {
 }
 
@@ -8854,7 +8839,6 @@ static bool sched_asym_class_pick(struct
 {
 	return false;
 }
-
 #endif /* CONFIG_SCHED_TASK_CLASSES */
 
 /**
@@ -8979,11 +8963,11 @@ static inline void update_sg_lb_stats(st
 				      struct sg_lb_stats *sgs,
 				      int *sg_status)
 {
-	struct sg_lb_task_class_stats class_stats;
+	struct sg_lb_task_class_stats sgcs;
 	int i, nr_running, local_group;
 
 	memset(sgs, 0, sizeof(*sgs));
-	init_rq_task_classes_stats(&class_stats);
+	init_sg_lb_task_class_stats(&sgcs);
 
 	local_group = group == sds->local;
 
@@ -9034,7 +9018,7 @@ static inline void update_sg_lb_stats(st
 				sgs->group_misfit_task_load = load;
 		}
 
-		update_rq_task_classes_stats(&class_stats, rq);
+		update_sg_lb_task_class_stats(&sgcs, rq);
 	}
 
 	sgs->group_capacity = group->sgc->capacity;
@@ -9045,7 +9029,7 @@ static inline void update_sg_lb_stats(st
 	if (!local_group && env->sd->flags & SD_ASYM_PACKING &&
 	    env->idle != CPU_NOT_IDLE && sgs->sum_h_nr_running &&
 	    sched_asym(env, sds, sgs, group)) {
-		compute_ilb_sg_task_class_scores(&class_stats, sgs, env->dst_cpu);
+		update_sg_lb_stats_scores(&sgcs, sgs, env->dst_cpu);
 		sgs->group_asym_packing = 1;
 	}
 

  reply	other threads:[~2022-09-27  9:16 UTC|newest]

Thread overview: 78+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-09 23:11 [RFC PATCH 00/23] sched: Introduce classes of tasks for load balance Ricardo Neri
2022-09-09 23:11 ` [RFC PATCH 01/23] sched/task_struct: Introduce classes of tasks Ricardo Neri
2022-09-14 13:46   ` Peter Zijlstra
2022-09-16 14:41     ` Ricardo Neri
2022-09-27 13:01       ` Peter Zijlstra
2022-10-02 22:32         ` Ricardo Neri
2022-09-09 23:11 ` [RFC PATCH 02/23] sched: Add interfaces for " Ricardo Neri
2022-09-09 23:11 ` [RFC PATCH 03/23] sched/core: Initialize the class of a new task Ricardo Neri
2022-09-26 14:57   ` Joel Fernandes
2022-09-26 21:53     ` Ricardo Neri
2022-09-27 13:04     ` Peter Zijlstra
2022-09-27 15:48       ` Joel Fernandes
2022-10-01 20:32       ` Ricardo Neri
2022-09-09 23:11 ` [RFC PATCH 04/23] sched/core: Add user_tick as argument to scheduler_tick() Ricardo Neri
2022-09-09 23:11 ` [RFC PATCH 05/23] sched/core: Move is_core_idle() out of fair.c Ricardo Neri
2022-09-09 23:11 ` [RFC PATCH 06/23] sched/core: Update the classification of the current task Ricardo Neri
2022-09-14 13:44   ` Peter Zijlstra
2022-09-16 14:42     ` Ricardo Neri
2022-09-09 23:11 ` [RFC PATCH 07/23] sched/fair: Collect load-balancing stats for task classes Ricardo Neri
2022-09-09 23:11 ` [RFC PATCH 08/23] sched/fair: Compute task-class performance scores for load balancing Ricardo Neri
2022-09-27  9:15   ` Peter Zijlstra [this message]
2022-10-26  3:57     ` Ricardo Neri
2022-10-26  8:55       ` Peter Zijlstra
2022-10-27  3:30         ` Ricardo Neri
2022-09-09 23:11 ` [RFC PATCH 09/23] sched/fair: Use task-class performance score to pick the busiest group Ricardo Neri
2022-09-27 11:01   ` Peter Zijlstra
2022-10-05 23:38     ` Ricardo Neri
2022-10-06  8:37       ` Peter Zijlstra
2022-10-06 19:07         ` Ricardo Neri
2022-09-09 23:11 ` [RFC PATCH 10/23] sched/fair: Use classes of tasks when selecting a busiest runqueue Ricardo Neri
2022-09-27 11:25   ` Peter Zijlstra
2022-10-07 23:36     ` Ricardo Neri
2022-09-09 23:11 ` [RFC PATCH 11/23] thermal: intel: hfi: Introduce Hardware Feedback Interface classes Ricardo Neri
2022-09-09 23:11 ` [RFC PATCH 12/23] thermal: intel: hfi: Convert table_lock to use flags-handling variants Ricardo Neri
2022-09-27 11:34   ` Peter Zijlstra
2022-09-27 11:36     ` Peter Zijlstra
2022-10-26  3:59       ` Ricardo Neri
2022-10-26  3:58     ` Ricardo Neri
2022-09-09 23:11 ` [RFC PATCH 13/23] x86/cpufeatures: Add the Intel Thread Director feature definitions Ricardo Neri
2022-09-09 23:11 ` [RFC PATCH 14/23] thermal: intel: hfi: Update the class of the current task Ricardo Neri
2022-09-27 11:46   ` Peter Zijlstra
2022-10-07 20:34     ` Ricardo Neri
2022-09-09 23:11 ` [RFC PATCH 15/23] thermal: intel: hfi: Report per-cpu class-specific performance scores Ricardo Neri
2022-09-27 11:59   ` Peter Zijlstra
2022-10-05 23:59     ` Ricardo Neri
2022-10-06  8:52       ` Peter Zijlstra
2022-10-06  9:14         ` Peter Zijlstra
2022-10-06 15:05           ` Brown, Len
2022-10-06 16:14             ` Peter Zijlstra
2022-10-07 11:20               ` Len Brown
2022-09-09 23:11 ` [RFC PATCH 16/23] thermal: intel: hfi: Define a default classification for unclassified tasks Ricardo Neri
2022-09-09 23:11 ` [RFC PATCH 17/23] thermal: intel: hfi: Enable the Intel Thread Director Ricardo Neri
2022-09-27 12:00   ` Peter Zijlstra
2022-10-06  1:50     ` Ricardo Neri
2022-09-09 23:12 ` [RFC PATCH 18/23] sched/task_struct: Add helpers for task classification Ricardo Neri
2022-09-27 11:52   ` Peter Zijlstra
2022-10-08  0:38     ` Ricardo Neri
2022-09-09 23:12 ` [RFC PATCH 19/23] sched/core: Initialize helpers of " Ricardo Neri
2022-09-09 23:12 ` [RFC PATCH 20/23] thermal: intel: hfi: Implement model-specific checks for " Ricardo Neri
2022-09-09 23:12 ` [RFC PATCH 21/23] x86/cpufeatures: Add feature bit for HRESET Ricardo Neri
2022-09-09 23:12 ` [RFC PATCH 22/23] x86/hreset: Configure history reset Ricardo Neri
2022-09-27 12:03   ` Peter Zijlstra
2022-10-02 22:34     ` Ricardo Neri
2022-09-09 23:12 ` [RFC PATCH 23/23] x86/process: Reset hardware history in context switch Ricardo Neri
2022-09-27 12:52   ` Peter Zijlstra
2022-10-03 23:07     ` Ricardo Neri
2022-10-06  8:35       ` Peter Zijlstra
2022-10-06 22:55         ` Ricardo Neri
2022-09-27 12:53   ` Peter Zijlstra
2022-10-02 22:02     ` Ricardo Neri
2022-09-27 13:15   ` Borislav Petkov
2022-10-02 22:12     ` Ricardo Neri
2022-10-02 22:15       ` Borislav Petkov
2022-10-03 19:49         ` Ricardo Neri
2022-10-03 19:55           ` Borislav Petkov
     [not found] ` <20220910072120.2651-1-hdanton@sina.com>
2022-09-16 14:51   ` [RFC PATCH 06/23] sched/core: Update the classification of the current task Ricardo Neri
2022-10-11 19:12 ` Trying to apply patch set Carlos Bilbao
2022-10-18  2:31   ` Ricardo Neri

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=YzK/QisKmix6hrKG@hirez.programming.kicks-ass.net \
    --to=peterz@infradead.org \
    --cc=bristot@redhat.com \
    --cc=bsegall@google.com \
    --cc=dietmar.eggemann@arm.com \
    --cc=juri.lelli@redhat.com \
    --cc=len.brown@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mgorman@suse.de \
    --cc=rafael.j.wysocki@intel.com \
    --cc=ravi.v.shankar@intel.com \
    --cc=ricardo.neri-calderon@linux.intel.com \
    --cc=ricardo.neri@intel.com \
    --cc=rostedt@goodmis.org \
    --cc=srinivas.pandruvada@linux.intel.com \
    --cc=tim.c.chen@intel.com \
    --cc=tim.c.chen@linux.intel.com \
    --cc=vincent.guittot@linaro.org \
    --cc=vschneid@redhat.com \
    --cc=x86@kernel.org \
    /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;
as well as URLs for NNTP newsgroup(s).