[PATCH v6 12/20] sched: Fix runtime accounting w/ split exec & sched contexts

John Stultz posted 20 patches 2 years, 1 month ago
[PATCH v6 12/20] sched: Fix runtime accounting w/ split exec & sched contexts
Posted by John Stultz 2 years, 1 month ago
The idea here is we want to charge the scheduler-context task's
vruntime but charge the execution-context task's sum_exec_runtime.

This way cputime accounting goes against the task actually running
but vruntime accounting goes against the selected task so we get
proper fairness.

Cc: Joel Fernandes <joelaf@google.com>
Cc: Qais Yousef <qyousef@google.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Juri Lelli <juri.lelli@redhat.com>
Cc: Vincent Guittot <vincent.guittot@linaro.org>
Cc: Dietmar Eggemann <dietmar.eggemann@arm.com>
Cc: Valentin Schneider <vschneid@redhat.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Ben Segall <bsegall@google.com>
Cc: Zimuzo Ezeozue <zezeozue@google.com>
Cc: Youssef Esmat <youssefesmat@google.com>
Cc: Mel Gorman <mgorman@suse.de>
Cc: Daniel Bristot de Oliveira <bristot@redhat.com>
Cc: Will Deacon <will@kernel.org>
Cc: Waiman Long <longman@redhat.com>
Cc: Boqun Feng <boqun.feng@gmail.com>
Cc: "Paul E . McKenney" <paulmck@kernel.org>
Cc: kernel-team@android.com
Signed-off-by: John Stultz <jstultz@google.com>
---
 kernel/sched/fair.c | 24 +++++++++++++++++++-----
 1 file changed, 19 insertions(+), 5 deletions(-)

diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 3d5c1ec34bf7..1aca675985b2 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -1144,22 +1144,36 @@ static void update_tg_load_avg(struct cfs_rq *cfs_rq)
 }
 #endif /* CONFIG_SMP */
 
-static s64 update_curr_se(struct rq *rq, struct sched_entity *curr)
+static s64 update_curr_se(struct rq *rq, struct sched_entity *se)
 {
 	u64 now = rq_clock_task(rq);
 	s64 delta_exec;
 
-	delta_exec = now - curr->exec_start;
+	/* Calculate the delta from selected se */
+	delta_exec = now - se->exec_start;
 	if (unlikely(delta_exec <= 0))
 		return delta_exec;
 
-	curr->exec_start = now;
-	curr->sum_exec_runtime += delta_exec;
+	/* Update selected se's exec_start */
+	se->exec_start = now;
+	if (entity_is_task(se)) {
+		struct task_struct *running = rq->curr;
+		/*
+		 * If se is a task, we account the time
+		 * against the running task, as w/ proxy-exec
+		 * they may not be the same.
+		 */
+		running->se.exec_start = now;
+		running->se.sum_exec_runtime += delta_exec;
+	} else {
+		/* If not task, account the time against se */
+		se->sum_exec_runtime += delta_exec;
+	}
 
 	if (schedstat_enabled()) {
 		struct sched_statistics *stats;
 
-		stats = __schedstats_from_se(curr);
+		stats = __schedstats_from_se(se);
 		__schedstat_set(stats->exec_max,
 				max(delta_exec, stats->exec_max));
 	}
-- 
2.42.0.869.gea05f2083d-goog
Re: [PATCH v6 12/20] sched: Fix runtime accounting w/ split exec & sched contexts
Posted by kernel test robot 2 years, 1 month ago
Hi John,

kernel test robot noticed the following build warnings:

[auto build test WARNING on tip/locking/core]
[also build test WARNING on v6.6]
[cannot apply to tip/sched/core tip/master linus/master tip/auto-latest next-20231110]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/John-Stultz/sched-Unify-runtime-accounting-across-classes/20231107-033946
base:   tip/locking/core
patch link:    https://lore.kernel.org/r/20231106193524.866104-13-jstultz%40google.com
patch subject: [PATCH v6 12/20] sched: Fix runtime accounting w/ split exec & sched contexts
config: x86_64-randconfig-121-20231111 (https://download.01.org/0day-ci/archive/20231111/202311111917.FfLLB7kQ-lkp@intel.com/config)
compiler: gcc-12 (Debian 12.2.0-14) 12.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231111/202311111917.FfLLB7kQ-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202311111917.FfLLB7kQ-lkp@intel.com/

sparse warnings: (new ones prefixed by >>)
>> kernel/sched/fair.c:1116:49: sparse: sparse: incorrect type in initializer (different address spaces) @@     expected struct task_struct *running @@     got struct task_struct [noderef] __rcu *curr @@
   kernel/sched/fair.c:1116:49: sparse:     expected struct task_struct *running
   kernel/sched/fair.c:1116:49: sparse:     got struct task_struct [noderef] __rcu *curr
   kernel/sched/fair.c:1145:36: sparse: sparse: incorrect type in initializer (different address spaces) @@     expected struct task_struct *curr @@     got struct task_struct [noderef] __rcu *curr @@
   kernel/sched/fair.c:1145:36: sparse:     expected struct task_struct *curr
   kernel/sched/fair.c:1145:36: sparse:     got struct task_struct [noderef] __rcu *curr
   kernel/sched/fair.c:1191:32: sparse: sparse: incorrect type in argument 1 (different address spaces) @@     expected struct sched_entity const *se @@     got struct sched_entity [noderef] __rcu * @@
   kernel/sched/fair.c:1191:32: sparse:     expected struct sched_entity const *se
   kernel/sched/fair.c:1191:32: sparse:     got struct sched_entity [noderef] __rcu *
   kernel/sched/fair.c:8053:36: sparse: sparse: incorrect type in initializer (different address spaces) @@     expected struct task_struct *curr @@     got struct task_struct [noderef] __rcu *curr @@
   kernel/sched/fair.c:8053:36: sparse:     expected struct task_struct *curr
   kernel/sched/fair.c:8053:36: sparse:     got struct task_struct [noderef] __rcu *curr
   kernel/sched/fair.c:8086:37: sparse: sparse: incorrect type in argument 1 (different address spaces) @@     expected struct task_struct *tsk @@     got struct task_struct [noderef] __rcu *curr @@
   kernel/sched/fair.c:8086:37: sparse:     expected struct task_struct *tsk
   kernel/sched/fair.c:8086:37: sparse:     got struct task_struct [noderef] __rcu *curr
   kernel/sched/fair.c:8333:38: sparse: sparse: incorrect type in initializer (different address spaces) @@     expected struct task_struct *curr @@     got struct task_struct [noderef] __rcu *curr @@
   kernel/sched/fair.c:8333:38: sparse:     expected struct task_struct *curr
   kernel/sched/fair.c:8333:38: sparse:     got struct task_struct [noderef] __rcu *curr
   kernel/sched/fair.c:6369:35: sparse: sparse: marked inline, but without a definition
   kernel/sched/fair.c: note: in included file:
   kernel/sched/sched.h:2344:9: sparse: sparse: incompatible types in comparison expression (different address spaces):
   kernel/sched/sched.h:2344:9: sparse:    struct task_struct [noderef] __rcu *
   kernel/sched/sched.h:2344:9: sparse:    struct task_struct *
   kernel/sched/sched.h:2166:32: sparse: sparse: incompatible types in comparison expression (different address spaces):
   kernel/sched/sched.h:2166:32: sparse:    struct task_struct [noderef] __rcu *
   kernel/sched/sched.h:2166:32: sparse:    struct task_struct *
   kernel/sched/sched.h:2166:32: sparse: sparse: incompatible types in comparison expression (different address spaces):
   kernel/sched/sched.h:2166:32: sparse:    struct task_struct [noderef] __rcu *
   kernel/sched/sched.h:2166:32: sparse:    struct task_struct *

vim +1116 kernel/sched/fair.c

  1102	
  1103	static s64 update_curr_se(struct rq *rq, struct sched_entity *se)
  1104	{
  1105		u64 now = rq_clock_task(rq);
  1106		s64 delta_exec;
  1107	
  1108		/* Calculate the delta from selected se */
  1109		delta_exec = now - se->exec_start;
  1110		if (unlikely(delta_exec <= 0))
  1111			return delta_exec;
  1112	
  1113		/* Update selected se's exec_start */
  1114		se->exec_start = now;
  1115		if (entity_is_task(se)) {
> 1116			struct task_struct *running = rq->curr;
  1117			/*
  1118			 * If se is a task, we account the time
  1119			 * against the running task, as w/ proxy-exec
  1120			 * they may not be the same.
  1121			 */
  1122			running->se.exec_start = now;
  1123			running->se.sum_exec_runtime += delta_exec;
  1124		} else {
  1125			/* If not task, account the time against se */
  1126			se->sum_exec_runtime += delta_exec;
  1127		}
  1128	
  1129		if (schedstat_enabled()) {
  1130			struct sched_statistics *stats;
  1131	
  1132			stats = __schedstats_from_se(se);
  1133			__schedstat_set(stats->exec_max,
  1134					max(delta_exec, stats->exec_max));
  1135		}
  1136	
  1137		return delta_exec;
  1138	}
  1139	

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki