Skip to contentSkip to conversation

sched: Add update_current_exec_runtime helper

PATCH Superseded Shang XiaoJing 2 participants 3 messages Aug 24, 2022 Scheduler

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 sched: Add update_current_exec_runtime helper

Wrap repeated code in helper function update_current_exec_runtime for update the exec time of the current.

---
 kernel/sched/deadline.c  |  6 +-----
 kernel/sched/rt.c        |  6 +-----
 kernel/sched/sched.h     | 10 ++++++++++
 kernel/sched/stop_task.c |  6 +-----
 4 files changed, 13 insertions(+), 15 deletions(-)
kernel/sched/deadline.c +1 -5
index daa9a7fb5917..d116d2b9d2f9 100644
@@ -1333,11 +1333,7 @@ static void update_curr_dl(struct rq *rq)
 
 	trace_sched_stat_runtime(curr, delta_exec, 0);
 
-	curr->se.sum_exec_runtime += delta_exec;
-	account_group_exec_runtime(curr, delta_exec);
-
-	curr->se.exec_start = now;
-	cgroup_account_cputime(curr, delta_exec);
+	update_current_exec_runtime(curr, now, delta_exec);
 
 	if (dl_entity_is_special(dl_se))
 		return;
kernel/sched/rt.c +1 -5
index cd07c9367bc2..27e694cf3e37 100644
@@ -1062,11 +1062,7 @@ static void update_curr_rt(struct rq *rq)
 
 	trace_sched_stat_runtime(curr, delta_exec, 0);
 
-	curr->se.sum_exec_runtime += delta_exec;
-	account_group_exec_runtime(curr, delta_exec);
-
-	curr->se.exec_start = now;
-	cgroup_account_cputime(curr, delta_exec);
+	update_current_exec_runtime(curr, now, delta_exec);
 
 	if (!rt_bandwidth_enabled())
 		return;
kernel/sched/sched.h +10 -0
index ddcfc7837595..7ad65f79cb59 100644
@@ -3163,4 +3163,14 @@ extern int sched_dynamic_mode(const char *str);
 extern void sched_dynamic_update(int mode);
 #endif
 
+static inline void update_current_exec_runtime(struct task_struct *curr,
+						u64 now, u64 delta_exec)
+{
+	curr->se.sum_exec_runtime += delta_exec;
+	account_group_exec_runtime(curr, delta_exec);
+
+	curr->se.exec_start = now;
+	cgroup_account_cputime(curr, delta_exec);
+}
+
 #endif /* _KERNEL_SCHED_SCHED_H */
kernel/sched/stop_task.c +1 -5
index d04073a93eb4..027068779126 100644
@@ -80,11 +80,7 @@ static void put_prev_task_stop(struct rq *rq, struct task_struct *prev)
 	schedstat_set(curr->stats.exec_max,
 		      max(curr->stats.exec_max, delta_exec));
 
-	curr->se.sum_exec_runtime += delta_exec;
-	account_group_exec_runtime(curr, delta_exec);
-
-	curr->se.exec_start = rq_clock_task(rq);
-	cgroup_account_cputime(curr, delta_exec);
+	update_current_exec_runtime(curr, rq_clock_task(rq), delta_exec);
 }
 
 /*
Signature · 1 line
2.17.1
maintainer
#1 lore raw

On Wed, Aug 24, 2022 at 02:53:26PM +0800, Shang XiaoJing wrote:

In general I like, however:

Quoted 5 lines
kernel/sched/stop_task.c +0 -0
index d04073a93eb4..027068779126 100644

kernel/sched/stop_task.c static void put_prev_task_stop(struct rq *rq, struct task_struct *prev) · line 84

Quoted 10 lines
kernel/sched/stop_task.c +1 -5
@@ -80,11 +80,7 @@ static void put_prev_task_stop(struct rq *rq, struct task_struct *prev)
 	schedstat_set(curr->stats.exec_max,
 		      max(curr->stats.exec_max, delta_exec));
 
-	curr->se.sum_exec_runtime += delta_exec;
-	account_group_exec_runtime(curr, delta_exec);
-
-	curr->se.exec_start = rq_clock_task(rq);
-	cgroup_account_cputime(curr, delta_exec);
+	update_current_exec_runtime(curr, rq_clock_task(rq), delta_exec);
 }

This already has a rq_clock_task() invocation; please fix it to call it once -- pre-existing issue, but if we're cleaning up we should clean up, right :-)

#2 lore raw
Quoted 12 lines · Peter Zijlstra

On Wed, Aug 24, 2022 at 02:53:26PM +0800, Shang XiaoJing wrote:

In general I like, however:

Quoted 8 lines
kernel/sched/stop_task.c +0 -0
index d04073a93eb4..027068779126 100644
@@ -80,11 +80,7 @@ static void put_prev_task_stop(struct rq *rq, struct task_struct *prev)
  	schedstat_set(curr->stats.exec_max,
  		      max(curr->stats.exec_max, delta_exec));
 
Quoted 10 lines

kernel/sched/stop_task.c static void put_prev_task_stop(struct rq *rq, struct task_struct *prev) · line 84

Quoted 7 lines
kernel/sched/stop_task.c +1 -5
-	curr->se.sum_exec_runtime += delta_exec;
-	account_group_exec_runtime(curr, delta_exec);
-
-	curr->se.exec_start = rq_clock_task(rq);
-	cgroup_account_cputime(curr, delta_exec);
+	update_current_exec_runtime(curr, rq_clock_task(rq), delta_exec);
  }

This already has a rq_clock_task() invocation; please fix it to call it once -- pre-existing issue, but if we're cleaning up we should clean up, right :-)

Right, the redundant invocation of rq_clock_task() will be removed in v2.

Thanks :-) ,

Shang XiaoJing