All of lore.kernel.org
 help / color / mirror / Atom feed
From: "tip-bot2 for Andrey Ryabinin" <tip-bot2@linutronix.de>
To: linux-tip-commits@vger.kernel.org
Cc: Andrey Ryabinin <arbn@yandex-team.com>,
	"Peter Zijlstra (Intel)" <peterz@infradead.org>,
	Daniel Jordan <daniel.m.jordan@oracle.com>,
	Tejun Heo <tj@kernel.org>,
	x86@kernel.org, linux-kernel@vger.kernel.org
Subject: [tip: sched/core] sched/cpuacct: Make user/system times in cpuacct.stat more precise
Date: Tue, 23 Nov 2021 11:01:55 -0000	[thread overview]
Message-ID: <163766531523.11128.10280253346273305725.tip-bot2@tip-bot2> (raw)
In-Reply-To: <20211115164607.23784-4-arbn@yandex-team.com>

The following commit has been merged into the sched/core branch of tip:

Commit-ID:     8c92606ab81086db00cbb73347d124b4eb169b7e
Gitweb:        https://git.kernel.org/tip/8c92606ab81086db00cbb73347d124b4eb169b7e
Author:        Andrey Ryabinin <arbn@yandex-team.com>
AuthorDate:    Mon, 15 Nov 2021 19:46:07 +03:00
Committer:     Peter Zijlstra <peterz@infradead.org>
CommitterDate: Tue, 23 Nov 2021 09:55:22 +01:00

sched/cpuacct: Make user/system times in cpuacct.stat more precise

cpuacct.stat shows user time based on raw random precision tick
based counters. Use cputime_addjust() to scale these values against the
total runtime accounted by the scheduler, like we already do
for user/system times in /proc/<pid>/stat.

Signed-off-by: Andrey Ryabinin <arbn@yandex-team.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Reviewed-by: Daniel Jordan <daniel.m.jordan@oracle.com>
Acked-by: Tejun Heo <tj@kernel.org>
Link: https://lore.kernel.org/r/20211115164607.23784-4-arbn@yandex-team.com
---
 kernel/sched/cpuacct.c | 25 +++++++++++++++----------
 1 file changed, 15 insertions(+), 10 deletions(-)

diff --git a/kernel/sched/cpuacct.c b/kernel/sched/cpuacct.c
index 9de7dd5..3d06c5e 100644
--- a/kernel/sched/cpuacct.c
+++ b/kernel/sched/cpuacct.c
@@ -261,25 +261,30 @@ static int cpuacct_all_seq_show(struct seq_file *m, void *V)
 static int cpuacct_stats_show(struct seq_file *sf, void *v)
 {
 	struct cpuacct *ca = css_ca(seq_css(sf));
-	s64 val[CPUACCT_STAT_NSTATS];
+	struct task_cputime cputime;
+	u64 val[CPUACCT_STAT_NSTATS];
 	int cpu;
 	int stat;
 
-	memset(val, 0, sizeof(val));
+	memset(&cputime, 0, sizeof(cputime));
 	for_each_possible_cpu(cpu) {
 		u64 *cpustat = per_cpu_ptr(ca->cpustat, cpu)->cpustat;
 
-		val[CPUACCT_STAT_USER]   += cpustat[CPUTIME_USER];
-		val[CPUACCT_STAT_USER]   += cpustat[CPUTIME_NICE];
-		val[CPUACCT_STAT_SYSTEM] += cpustat[CPUTIME_SYSTEM];
-		val[CPUACCT_STAT_SYSTEM] += cpustat[CPUTIME_IRQ];
-		val[CPUACCT_STAT_SYSTEM] += cpustat[CPUTIME_SOFTIRQ];
+		cputime.utime += cpustat[CPUTIME_USER];
+		cputime.utime += cpustat[CPUTIME_NICE];
+		cputime.stime += cpustat[CPUTIME_SYSTEM];
+		cputime.stime += cpustat[CPUTIME_IRQ];
+		cputime.stime += cpustat[CPUTIME_SOFTIRQ];
+
+		cputime.sum_exec_runtime += *per_cpu_ptr(ca->cpuusage, cpu);
 	}
 
+	cputime_adjust(&cputime, &seq_css(sf)->cgroup->prev_cputime,
+		&val[CPUACCT_STAT_USER], &val[CPUACCT_STAT_SYSTEM]);
+
 	for (stat = 0; stat < CPUACCT_STAT_NSTATS; stat++) {
-		seq_printf(sf, "%s %lld\n",
-			   cpuacct_stat_desc[stat],
-			   (long long)nsec_to_clock_t(val[stat]));
+		seq_printf(sf, "%s %llu\n", cpuacct_stat_desc[stat],
+			nsec_to_clock_t(val[stat]));
 	}
 
 	return 0;

  reply	other threads:[~2021-11-23 11:02 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-15 16:46 [PATCH v3 1/4] cputime, cpuacct: Include guest time in user time in cpuacct.stat Andrey Ryabinin
2021-11-15 16:46 ` [PATCH v3 2/4] cpuacct: convert BUG_ON() to WARN_ON_ONCE() Andrey Ryabinin
2021-11-15 16:46   ` Andrey Ryabinin
2021-11-23 11:01   ` [tip: sched/core] cpuacct: Convert " tip-bot2 for Andrey Ryabinin
2021-11-15 16:46 ` [PATCH v3 3/4] sched/cpuacct: fix user/system in shown cpuacct.usage* Andrey Ryabinin
2021-11-15 16:46   ` Andrey Ryabinin
2021-11-23 11:01   ` [tip: sched/core] sched/cpuacct: Fix " tip-bot2 for Andrey Ryabinin
2021-11-15 16:46 ` [PATCH v3 4/4] sched/cpuacct: Make user/system times in cpuacct.stat more precise Andrey Ryabinin
2021-11-15 16:46   ` Andrey Ryabinin
2021-11-23 11:01   ` tip-bot2 for Andrey Ryabinin [this message]
2021-11-15 21:06 ` [PATCH v3 1/4] cputime, cpuacct: Include guest time in user time in cpuacct.stat Tejun Heo
2021-11-18 14:29   ` Peter Zijlstra
2021-11-23 11:01 ` [tip: sched/core] " tip-bot2 for Andrey Ryabinin

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=163766531523.11128.10280253346273305725.tip-bot2@tip-bot2 \
    --to=tip-bot2@linutronix.de \
    --cc=arbn@yandex-team.com \
    --cc=daniel.m.jordan@oracle.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tip-commits@vger.kernel.org \
    --cc=peterz@infradead.org \
    --cc=tj@kernel.org \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.