[PATCH v3 2/2] cputime: remove extra cost in task_cputime

From: Hiroshi Shimamoto
Date: Thu Oct 29 2015 - 20:49:30 EST


From: Hiroshi Shimamoto <h-shimamoto@xxxxxxxxxxxxx>

There is an extra cost in task_cputime() and task_cputime_scaled() when
nohz_full is not activated. This patch removes that cost. When vtime
accounting is not enabled, we don't need to get deltas of utime and stime
with seqlock.

This patch adds a shortcut route if vtime accounting is not enabled.

Use context_tracking_is_enabled() to check if the vtime accounting on
current cpu. In future we should check the state of cpu which is running
target thread.

Signed-off-by: Hiroshi Shimamoto <h-shimamoto@xxxxxxxxxxxxx>
Cc: stable@xxxxxxxxxxxxxxx
---
v3: this patch is newly added for related issue.

kernel/sched/cputime.c | 16 ++++++++++++++++
1 file changed, 16 insertions(+)

diff --git a/kernel/sched/cputime.c b/kernel/sched/cputime.c
index 63904e7..ff0365d 100644
--- a/kernel/sched/cputime.c
+++ b/kernel/sched/cputime.c
@@ -851,6 +851,14 @@ void task_cputime(struct task_struct *t, cputime_t *utime, cputime_t *stime)
{
cputime_t udelta, sdelta;

+ if (!context_tracking_is_enabled()) {
+ if (utime)
+ *utime = t->utime;
+ if (stime)
+ *stime = t->stime;
+ return;
+ }
+
fetch_task_cputime(t, utime, stime, &t->utime,
&t->stime, &udelta, &sdelta);
if (utime)
@@ -864,6 +872,14 @@ void task_cputime_scaled(struct task_struct *t,
{
cputime_t udelta, sdelta;

+ if (!context_tracking_is_enabled()) {
+ if (utimescaled)
+ *utimescaled = t->utimescaled;
+ if (stimescaled)
+ *stimescaled = t->stimescaled;
+ return;
+ }
+
fetch_task_cputime(t, utimescaled, stimescaled,
&t->utimescaled, &t->stimescaled, &udelta, &sdelta);
if (utimescaled)
--
1.8.3.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/