From: Michael Holzheu <holzheu@linux.vnet.ibm.com>
To: Oleg Nesterov <oleg@redhat.com>
Cc: Shailabh Nagar <nagar1234@in.ibm.com>,
Andrew Morton <akpm@linux-foundation.org>,
Venkatesh Pallipadi <venki@google.com>,
Peter Zijlstra <a.p.zijlstra@chello.nl>,
Suresh Siddha <suresh.b.siddha@intel.com>,
John stultz <johnstul@us.ibm.com>,
Thomas Gleixner <tglx@linutronix.de>,
Balbir Singh <balbir@linux.vnet.ibm.com>,
Ingo Molnar <mingo@elte.hu>,
Heiko Carstens <heiko.carstens@de.ibm.com>,
Martin Schwidefsky <schwidefsky@de.ibm.com>,
linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [RFC][PATCH 09/10] taskstats: Fix exit CPU time accounting
Date: Fri, 24 Sep 2010 14:18:08 +0200 [thread overview]
Message-ID: <1285330688.2179.305.camel@holzheu-laptop> (raw)
In-Reply-To: <20100923171025.GA26623@redhat.com>
Hello Oleg,
On Thu, 2010-09-23 at 19:10 +0200, Oleg Nesterov wrote:
> Sorry, I didn't look at other patches, but this one looks strange
> to me...
>
> On 09/23, Michael Holzheu wrote:
> >
> > Currently there are code pathes (e.g. for kthreads) where the consumed
> > CPU time is not accounted to the parents cumulative counters.
>
> Could you explain more?
I think one place was "khelper" (kmod.c). It is created with
kernel_thread() and it exits without having accounted the times with
sys_wait() to the parent's ctimes (see second kernel_thread() invocation
below in kmod.c):
if (wait == UMH_WAIT_PROC)
pid = kernel_thread(wait_for_helper, sub_info,
CLONE_FS | CLONE_FILES | SIGCHLD);
else
pid = kernel_thread(____call_usermodehelper, sub_info,
CLONE_VFORK | SIGCHLD);
<snip>
> > void release_task(struct task_struct * p)
> > {
> > struct task_struct *leader;
> > int zap_leader;
> > +
> > + if (!p->exit_accounting_done)
> > + account_to_parent(p);
> > repeat:
> > tracehook_prepare_release_task(p);
> > /* don't need to get the RCU readlock here - the process is dead and
> > @@ -1279,6 +1313,7 @@
> > psig->cmaxrss = maxrss;
> > task_io_accounting_add(&psig->ioac, &p->ioac);
> > task_io_accounting_add(&psig->ioac, &sig->ioac);
> > + p->exit_accounting_done = 1;
>
> Can't understand.
>
> Suppose that a thread T exits and reaps itself (calls release_task).
> Now we call account_to_parent() which accounts T->signal->XXX + T->XXX.
> After that T calls __exit_signal and does T->signal->XXX += T->XXX.
>
> If another thread exits it does the same and we account the already
> exited thread T again?
>
> When the last thread exits, wait_task_zombie() accounts T->signal
> once again.
>
> IOW, this looks like the over-accounting to me, no?
I think you are right and this patch is not correct here.
I had the wrong idea, because I thought that for every exited thread the
parent will do a sys_wait() and the thread's CPU times will be added to
the parent's ctime. This happens only for the thread group leader,
correct? Other threads just exit and add their times to the signal
struct of the process in __exit_signal(). When a sys_wait() is done for
a dead thread group leader, all the times that have been accumulated in
the signal struct are added to the ctime fields of the waiting parent.
I wanted to use the cumulative times (cutime, cstime, csttime) for ptop
in order to show all consumed CPU time in the last interval.
E.g. for the case that between ptop snapshot 1 and 2 a task "X" forked
and also exited, ptop can't see this task, because it is neither in
snapshot 1 nor in snapshot 2. But ptop can still show X's consumed CPU
time in the interval by subtracting the cumulative times of X's parent.
If a task "Y" is in snapshot 1, but not in snapshot 2, we search for the
parent of "Y" and calculate it's ctimes for the last interval as follows
(user time in this example):
parent->cuser_diff =
parent->snap2->cutime - Y->snap1->utime -
Y->snap1->cutime - parent->snap1->cutime
The result is the CPU time that Y consumed in the last interval.
Example (ptop):
VVVVV VVVV VVVV
pid user sys ste cuser csys cste total Elap+ Name
(#) (%) (%) (%) (%) (%) (%) (%) (hm) (str)
8374 75.48 0.41 1.34 0.00 0.00 0.00 77.24 0:01 loop
>> 10093 0.17 0.30 0.00 25.90 38.19 0.52 65.07 0:00 make <<
ptop shows cuser, csys and cste for the last interval. In this example
it is the time that dead children of "make" consumed in the last
interval.
Ok, the problem is that I did not consider exiting threads that are no
thread group leaders. When they exit the ctime of the parent is not
updated. Instead the time is accumulated in the signal struct.
To fix this we could also add the signal_struct times (e.g. tguser,
tgsys and tgste) to taskstats. When a task "Z" exits (is in snapshot 1,
but not in snapshot 2), we first check, if the thread group leader is
still in snapshot 2. If this is the case, we do the following
calculation:
tgleader->tguser_diff =
tgleader->snap2->sig->utime - Z->snap1->utime -
tgleader->snap1->sig->utime
If add CPU time diffs, cummulated parent diffs and thread group CPU time
diffs, we should get again 100% of the consumed CPU time in the last
ptop interval.
Does this make sense?
Michael
next prev parent reply other threads:[~2010-09-24 12:18 UTC|newest]
Thread overview: 58+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-09-23 13:48 [RFC][PATCH 00/10] taskstats: Enhancements for precise accounting Michael Holzheu
2010-09-23 14:00 ` [RFC][PATCH 01/10] taskstats: Use real microsecond granularity for CPU times Michael Holzheu
2010-10-07 5:08 ` Balbir Singh
2010-10-08 15:08 ` Michael Holzheu
2010-10-08 16:39 ` Balbir Singh
2010-09-23 14:01 ` [RFC][PATCH 02/10] taskstats: Separate taskstats commands Michael Holzheu
2010-09-27 9:32 ` Balbir Singh
2010-10-11 7:40 ` Balbir Singh
2010-09-23 14:01 ` [RFC][PATCH 03/10] taskstats: Split fill_pid function Michael Holzheu
2010-09-23 17:33 ` Oleg Nesterov
2010-09-27 9:33 ` Balbir Singh
2010-10-11 8:31 ` Balbir Singh
2010-09-23 14:01 ` [RFC][PATCH 04/10] taskstats: Add new taskstats command TASKSTATS_CMD_ATTR_PIDS Michael Holzheu
2010-09-23 14:01 ` [RFC][PATCH 05/10] taskstats: Add "/proc/taskstats" Michael Holzheu
2010-09-23 14:01 ` [RFC][PATCH 06/10] taskstats: Add thread group ID to taskstats structure Michael Holzheu
2010-09-23 14:01 ` [RFC][PATCH 07/10] taskstats: Add per task steal time accounting Michael Holzheu
2010-09-23 14:02 ` [RFC][PATCH 08/10] taskstats: Add cumulative CPU time (user, system and steal) Michael Holzheu
2010-09-23 14:02 ` [RFC][PATCH 09/10] taskstats: Fix exit CPU time accounting Michael Holzheu
2010-09-23 17:10 ` Oleg Nesterov
2010-09-24 12:18 ` Michael Holzheu [this message]
2010-09-26 18:11 ` Oleg Nesterov
2010-09-27 13:23 ` Michael Holzheu
2010-09-27 13:42 ` Martin Schwidefsky
2010-09-27 16:51 ` Oleg Nesterov
2010-09-28 7:09 ` Martin Schwidefsky
2010-09-29 19:19 ` Roland McGrath
2010-09-30 13:47 ` Michael Holzheu
2010-10-05 8:57 ` Roland McGrath
2010-10-06 9:29 ` Michael Holzheu
2010-10-06 15:26 ` Oleg Nesterov
2010-10-07 15:06 ` Michael Holzheu
2010-10-11 12:37 ` Oleg Nesterov
2010-10-12 13:10 ` Michael Holzheu
2010-10-14 13:47 ` Oleg Nesterov
2010-10-15 14:34 ` Michael Holzheu
2010-10-19 14:17 ` Oleg Nesterov
2010-10-22 16:53 ` Michael Holzheu
2010-09-28 8:36 ` Balbir Singh
2010-09-28 9:08 ` Martin Schwidefsky
2010-09-28 9:23 ` Balbir Singh
2010-09-28 10:36 ` Martin Schwidefsky
2010-09-28 10:39 ` Balbir Singh
2010-09-28 8:21 ` Balbir Singh
2010-09-28 16:50 ` Michael Holzheu
2010-09-23 14:04 ` [RFC][PATCH 10/10] taststats: User space with ptop tool Michael Holzheu
2010-09-23 20:11 ` [RFC][PATCH 00/10] taskstats: Enhancements for precise accounting Andrew Morton
2010-09-23 22:11 ` Matt Helsley
2010-09-24 12:39 ` Michael Holzheu
2010-09-25 18:19 ` Serge E. Hallyn
2010-09-24 9:10 ` Michael Holzheu
2010-09-24 18:50 ` Andrew Morton
2010-09-27 9:18 ` Michael Holzheu
2010-09-27 20:02 ` Andrew Morton
2010-09-28 8:17 ` Balbir Singh
2010-09-27 10:49 ` Balbir Singh
2010-09-24 9:16 ` Balbir Singh
2010-09-30 8:38 ` Andi Kleen
2010-09-30 13:56 ` Michael Holzheu
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=1285330688.2179.305.camel@holzheu-laptop \
--to=holzheu@linux.vnet.ibm.com \
--cc=a.p.zijlstra@chello.nl \
--cc=akpm@linux-foundation.org \
--cc=balbir@linux.vnet.ibm.com \
--cc=heiko.carstens@de.ibm.com \
--cc=johnstul@us.ibm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-s390@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=nagar1234@in.ibm.com \
--cc=oleg@redhat.com \
--cc=schwidefsky@de.ibm.com \
--cc=suresh.b.siddha@intel.com \
--cc=tglx@linutronix.de \
--cc=venki@google.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
all inboxes | Powered by JetHome®