The rt entity can be a task group. We will account execution time for
each task. For consistency, we don't need to account execution time for
task group.
Pass a parameter to update_current_exec_runtime, let the caller decide
whether account execution time.
Signed-off-by: Yajun Deng <yajun.deng@linux.dev>
Suggested-by: Peter Zijlstra <peterz@infradead.org>
---
v3: Pass a parameter to update_current_exec_runtime.
v2: Add the missing '#endif'.
v1: https://lore.kernel.org/all/20231023065418.1548239-1-yajun.deng@linux.dev/
---
kernel/sched/deadline.c | 2 +-
kernel/sched/rt.c | 3 ++-
kernel/sched/sched.h | 10 ++++++----
kernel/sched/stop_task.c | 2 +-
4 files changed, 10 insertions(+), 7 deletions(-)
diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c
index b28114478b82..a9f84428c4b5 100644
--- a/kernel/sched/deadline.c
+++ b/kernel/sched/deadline.c
@@ -1303,7 +1303,7 @@ static void update_curr_dl(struct rq *rq)
trace_sched_stat_runtime(curr, delta_exec, 0);
- update_current_exec_runtime(curr, now, delta_exec);
+ update_current_exec_runtime(curr, now, delta_exec, true);
if (dl_entity_is_special(dl_se))
return;
diff --git a/kernel/sched/rt.c b/kernel/sched/rt.c
index 6aaf0a3d6081..79cf80d73822 100644
--- a/kernel/sched/rt.c
+++ b/kernel/sched/rt.c
@@ -1018,7 +1018,8 @@ static void update_curr_rt(struct rq *rq)
trace_sched_stat_runtime(curr, delta_exec, 0);
- update_current_exec_runtime(curr, now, delta_exec);
+ update_current_exec_runtime(curr, now, delta_exec,
+ rt_entity_is_task(rt_se));
if (!rt_bandwidth_enabled())
return;
diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
index 2e5a95486a42..6f0169d9b306 100644
--- a/kernel/sched/sched.h
+++ b/kernel/sched/sched.h
@@ -3262,13 +3262,15 @@ extern void sched_dynamic_update(int mode);
#endif
static inline void update_current_exec_runtime(struct task_struct *curr,
- u64 now, u64 delta_exec)
+ u64 now, u64 delta_exec, bool task)
{
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);
+
+ if (task) {
+ account_group_exec_runtime(curr, delta_exec);
+ cgroup_account_cputime(curr, delta_exec);
+ }
}
#ifdef CONFIG_SCHED_MM_CID
diff --git a/kernel/sched/stop_task.c b/kernel/sched/stop_task.c
index 6cf7304e6449..1bec2af7ce8d 100644
--- a/kernel/sched/stop_task.c
+++ b/kernel/sched/stop_task.c
@@ -81,7 +81,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));
- update_current_exec_runtime(curr, now, delta_exec);
+ update_current_exec_runtime(curr, now, delta_exec, true);
}
/*
--
2.25.1
On Tue, Oct 31, 2023 at 08:59:26PM +0800, Yajun Deng wrote: > The rt entity can be a task group. We will account execution time for > each task. For consistency, we don't need to account execution time for > task group. > > Pass a parameter to update_current_exec_runtime, let the caller decide > whether account execution time. > > diff --git a/kernel/sched/rt.c b/kernel/sched/rt.c > index 6aaf0a3d6081..79cf80d73822 100644 > --- a/kernel/sched/rt.c > +++ b/kernel/sched/rt.c > @@ -1018,7 +1018,8 @@ static void update_curr_rt(struct rq *rq) > > trace_sched_stat_runtime(curr, delta_exec, 0); > > - update_current_exec_runtime(curr, now, delta_exec); > + update_current_exec_runtime(curr, now, delta_exec, > + rt_entity_is_task(rt_se)); > > if (!rt_bandwidth_enabled()) > return; ok, I think I've managed to confuse myself again. But at this point rt_se := &rq->curr->rt, which is *always* a task, no?
On 2023/11/6 20:49, Peter Zijlstra wrote: > On Tue, Oct 31, 2023 at 08:59:26PM +0800, Yajun Deng wrote: >> The rt entity can be a task group. We will account execution time for >> each task. For consistency, we don't need to account execution time for >> task group. >> >> Pass a parameter to update_current_exec_runtime, let the caller decide >> whether account execution time. >> >> diff --git a/kernel/sched/rt.c b/kernel/sched/rt.c >> index 6aaf0a3d6081..79cf80d73822 100644 >> --- a/kernel/sched/rt.c >> +++ b/kernel/sched/rt.c >> @@ -1018,7 +1018,8 @@ static void update_curr_rt(struct rq *rq) >> >> trace_sched_stat_runtime(curr, delta_exec, 0); >> >> - update_current_exec_runtime(curr, now, delta_exec); >> + update_current_exec_runtime(curr, now, delta_exec, >> + rt_entity_is_task(rt_se)); >> >> if (!rt_bandwidth_enabled()) >> return; > ok, I think I've managed to confuse myself again. > > But at this point rt_se := &rq->curr->rt, which is *always* a task, no? I think so, but it can be safer to use rt_entity_is_task().
© 2016 - 2025 Red Hat, Inc.