From: Andrew Morton <akpm@linux-foundation.org>
To: Zhang Xiao <xiao.zhang@windriver.com>
Cc: <bsingharora@gmail.com>, <linux-kernel@vger.kernel.org>,
Oleg Nesterov <oleg@redhat.com>
Subject: Re: [PATCH] taskstats: Add e/u/stime for TGID command
Date: Mon, 6 Mar 2017 14:40:17 -0800 [thread overview]
Message-ID: <20170306144017.1a2cec98a3fe3855fd0504c6@linux-foundation.org> (raw)
In-Reply-To: <1488508424-12322-1-git-send-email-xiao.zhang@windriver.com>
On Fri, 3 Mar 2017 10:33:44 +0800 Zhang Xiao <xiao.zhang@windriver.com> wrote:
> Add elapsed time, user CPU time and system CPU time to
> thread group status request.
>
> --- a/kernel/taskstats.c
> +++ b/kernel/taskstats.c
> @@ -210,6 +210,7 @@ static int fill_stats_for_tgid(pid_t tgid, struct taskstats *stats)
> struct task_struct *tsk, *first;
> unsigned long flags;
> int rc = -ESRCH;
> + u64 delta, utime, stime;
>
> /*
> * Add additional stats from live tasks except zombie thread group
> @@ -238,6 +239,16 @@ static int fill_stats_for_tgid(pid_t tgid, struct taskstats *stats)
> */
> delayacct_add_tsk(stats, tsk);
>
> + /* calculate task elapsed time in nsec */
> + delta = ktime_get_ns() - tsk->start_time;
> + /* Convert to micro seconds */
> + do_div(delta, NSEC_PER_USEC);
> + stats->ac_etime += delta;
> +
> + task_cputime(tsk, &utime, &stime);
> + stats->ac_utime += div_u64(utime, NSEC_PER_USEC);
> + stats->ac_stime += div_u64(stime, NSEC_PER_USEC);
> +
> stats->nvcsw += tsk->nvcsw;
> stats->nivcsw += tsk->nivcsw;
> } while_each_thread(first, tsk);
hm, OK, we were just leaving these at zero. Seems sane to me.
It would be more efficient and perhaps more deterministic to sample
ktime just once?
--- a/kernel/taskstats.c~taskstats-add-e-u-stime-for-tgid-command-fix
+++ a/kernel/taskstats.c
@@ -211,6 +211,7 @@ static int fill_stats_for_tgid(pid_t tgi
unsigned long flags;
int rc = -ESRCH;
u64 delta, utime, stime;
+ u64 start_time;
/*
* Add additional stats from live tasks except zombie thread group
@@ -228,6 +229,7 @@ static int fill_stats_for_tgid(pid_t tgi
memset(stats, 0, sizeof(*stats));
tsk = first;
+ start_time = ktime_get_ns();
do {
if (tsk->exit_state)
continue;
@@ -240,7 +242,7 @@ static int fill_stats_for_tgid(pid_t tgi
delayacct_add_tsk(stats, tsk);
/* calculate task elapsed time in nsec */
- delta = ktime_get_ns() - tsk->start_time;
+ delta = start_time - tsk->start_time;
/* Convert to micro seconds */
do_div(delta, NSEC_PER_USEC);
stats->ac_etime += delta;
_
next prev parent reply other threads:[~2017-03-06 23:46 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-03-03 2:33 [PATCH] taskstats: Add e/u/stime for TGID command Zhang Xiao
2017-03-06 22:40 ` Andrew Morton [this message]
2017-03-07 1:12 ` ZhangXiao
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=20170306144017.1a2cec98a3fe3855fd0504c6@linux-foundation.org \
--to=akpm@linux-foundation.org \
--cc=bsingharora@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=oleg@redhat.com \
--cc=xiao.zhang@windriver.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox