* [PATCH] Add all thread stats for TASKSTATS_CMD_ATTR_TGID
@ 2007-08-02 13:34 Guillaume Chazarain
0 siblings, 0 replies; 13+ messages in thread
From: Guillaume Chazarain @ 2007-08-02 13:34 UTC (permalink / raw)
To: Shailabh Nagar, Linux Kernel Mailing List
Hi,
This patch adds all thread accounting stats for the global tgid stats.
As a shameless plug, this fixes iotop -P (http://guichaz.free.fr/misc/iotop.py).
Signed-off-by: Guillaume Chazarain <guichaz@yahoo.fr>
---
diff -r 22708012ca6e kernel/taskstats.c
--- a/kernel/taskstats.c Tue Jul 31 21:12:07 2007 -0700
+++ b/kernel/taskstats.c Wed Aug 01 17:43:54 2007 +0200
@@ -233,6 +233,7 @@ static int fill_tgid(pid_t tgid, struct
memset(stats, 0, sizeof(*stats));
tsk = first;
+ bacct_add_tsk(stats, first);
do {
if (tsk->exit_state)
continue;
@@ -246,6 +247,7 @@ static int fill_tgid(pid_t tgid, struct
stats->nvcsw += tsk->nvcsw;
stats->nivcsw += tsk->nivcsw;
+ xacct_add_tsk(stats, tsk);
} while_each_thread(first, tsk);
unlock_task_sighand(first, &flags);
diff -r 22708012ca6e kernel/tsacct.c
--- a/kernel/tsacct.c Tue Jul 31 21:12:07 2007 -0700
+++ b/kernel/tsacct.c Wed Aug 01 17:41:40 2007 +0200
@@ -81,8 +81,8 @@ void xacct_add_tsk(struct taskstats *sta
struct mm_struct *mm;
/* convert pages-jiffies to Mbyte-usec */
- stats->coremem = jiffies_to_usecs(p->acct_rss_mem1) * PAGE_SIZE / MB;
- stats->virtmem = jiffies_to_usecs(p->acct_vm_mem1) * PAGE_SIZE / MB;
+ stats->coremem += jiffies_to_usecs(p->acct_rss_mem1) * PAGE_SIZE / MB;
+ stats->virtmem += jiffies_to_usecs(p->acct_vm_mem1) * PAGE_SIZE / MB;
mm = get_task_mm(p);
if (mm) {
/* adjust to KB unit */
@@ -90,18 +90,14 @@ void xacct_add_tsk(struct taskstats *sta
stats->hiwater_vm = mm->hiwater_vm * PAGE_SIZE / KB;
mmput(mm);
}
- stats->read_char = p->rchar;
- stats->write_char = p->wchar;
- stats->read_syscalls = p->syscr;
- stats->write_syscalls = p->syscw;
+ stats->read_char += p->rchar;
+ stats->write_char += p->wchar;
+ stats->read_syscalls += p->syscr;
+ stats->write_syscalls += p->syscw;
#ifdef CONFIG_TASK_IO_ACCOUNTING
- stats->read_bytes = p->ioac.read_bytes;
- stats->write_bytes = p->ioac.write_bytes;
- stats->cancelled_write_bytes = p->ioac.cancelled_write_bytes;
-#else
- stats->read_bytes = 0;
- stats->write_bytes = 0;
- stats->cancelled_write_bytes = 0;
+ stats->read_bytes += p->ioac.read_bytes;
+ stats->write_bytes += p->ioac.write_bytes;
+ stats->cancelled_write_bytes += p->ioac.cancelled_write_bytes;
#endif
}
#undef KB
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH] Add all thread stats for TASKSTATS_CMD_ATTR_TGID
2007-09-07 23:37 ` Jonathan Lim
@ 2007-09-10 13:03 ` Guillaume Chazarain
0 siblings, 0 replies; 13+ messages in thread
From: Guillaume Chazarain @ 2007-09-10 13:03 UTC (permalink / raw)
To: Jonathan Lim; +Cc: balbir, Andrew Morton, Linux Kernel Mailing List, Jay Lan
Le Fri, 7 Sep 2007 16:37:57 -0700 (PDT),
Jonathan Lim <jlim@sgi.com> a écrit :
> > Excellent, so can Guillaume change ac_btime to be just
> > tsk->start_time?
>
> I don't think so. Current time (xtime) is relative to the epoch;
> uptime and tsk->start_time (jiffies) are both relative to some boot
> time. So you need to subtract uptime from xtime to get the boot time
> relative to the epoch, then add tsk->start_time. The result is what
> ac_btime should be set to.
>
> I think his recent changes are as follows:
>
> --- a/kernel/tsacct.c Fri Aug 31 01:42:23 2007 -0700
> +++ b/kernel/tsacct.c Tue Aug 28 20:35:27 2007 +0200
> ...
> -void bacct_add_tsk(struct taskstats *stats, struct task_struct *tsk)
> +static void fill_wall_times(struct taskstats *stats, struct
> task_struct *task) ...
> - ts = timespec_sub(uptime, tsk->start_time);
> + ts = timespec_sub(uptime, task->start_time);
> ...
> - stats->ac_btime = get_seconds() - ts.tv_sec;
> ...
> + stats->ac_btime = get_seconds() - ts.tv_sec;
>
> So really no different from before, which is correct.
Yes, I just tried to make it clearer that the computations were needed
to get a wall time. Otherwise, as CSA seems to start using taskstats,
do my changes make sense for your usage?
Thanks.
--
Guillaume
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH] Add all thread stats for TASKSTATS_CMD_ATTR_TGID
2007-08-31 7:24 ` Balbir Singh
@ 2007-09-07 23:37 ` Jonathan Lim
2007-09-10 13:03 ` Guillaume Chazarain
0 siblings, 1 reply; 13+ messages in thread
From: Jonathan Lim @ 2007-09-07 23:37 UTC (permalink / raw)
To: balbir
Cc: Guillaume Chazarain, Andrew Morton, Linux Kernel Mailing List, Jay Lan
On Fri Aug 31 00:24:47 2007, balbir@linux.vnet.ibm.com wrote:
>
> Jonathan Lim wrote:
> > On Sat Aug 25 21:58:44 2007, balbir@linux.vnet.ibm.com wrote:
> >>> Also, I don't understand why the code to update btime:
> >>>
> >>> /* calculate task elapsed time in timespec */
> >>> do_posix_clock_monotonic_gettime(&uptime);
> >>> ts = timespec_sub(uptime, tsk->start_time);
> >>> ...
> >>> stats->ac_btime = get_seconds() - ts.tv_sec;
> >>>
> >>> does not simply use tsk->start_time or tsk->real_start_time without
> >>> comparing it to the current time.
> >> From what I understand, task->start_time and task->real_start_time
> >> are taken from the realtime clock. The accounting in CSA seems
> >> to be very similar to the accounting done in do_acct_process()
> >> (kernel/acct.c).
> >
> > In CSA 3.0 ...
> >
> > csa_acct_eop(int exitcode, struct task_struct *p)
> >
> > csa->ac_btime = boottime +
> > ((p->start_time.tv_nsec < NSEC_PER_SEC/2) ?
> > p->start_time.tv_sec :
> > p->start_time.tv_sec +1);
> >
> > where
> >
> > do_posix_clock_monotonic_gettime(&uptime);
> > boottime = xtime.tv_sec - uptime.tv_sec;
> >
> > In an upcoming version of CSA ...
> >
> > csa_acct_eop(struct taskstats *p)
> >
> > csa->ac_btime = p->ac_btime;
> >
> > where
> >
> > do_posix_clock_monotonic_gettime(&uptime);
> > ts = uptime - tsk->start_time;
> > p->ac_btime = get_seconds() - ts.tv_sec;
> > = xtime.tv_sec - (uptime - tsk->start_time);
> > = (xtime.tv_sec - uptime) + tsk->start_time;
> >
> > So they're basically equivalent.
>
> Excellent, so can Guillaume change ac_btime to be just tsk->start_time?
I don't think so. Current time (xtime) is relative to the epoch; uptime and
tsk->start_time (jiffies) are both relative to some boot time. So you need to
subtract uptime from xtime to get the boot time relative to the epoch, then add
tsk->start_time. The result is what ac_btime should be set to.
I think his recent changes are as follows:
--- a/kernel/tsacct.c Fri Aug 31 01:42:23 2007 -0700
+++ b/kernel/tsacct.c Tue Aug 28 20:35:27 2007 +0200
...
-void bacct_add_tsk(struct taskstats *stats, struct task_struct *tsk)
+static void fill_wall_times(struct taskstats *stats, struct task_struct *task)
...
- ts = timespec_sub(uptime, tsk->start_time);
+ ts = timespec_sub(uptime, task->start_time);
...
- stats->ac_btime = get_seconds() - ts.tv_sec;
...
+ stats->ac_btime = get_seconds() - ts.tv_sec;
So really no different from before, which is correct.
Jonathan
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH] Add all thread stats for TASKSTATS_CMD_ATTR_TGID
2007-08-31 3:02 ` Jonathan Lim
@ 2007-08-31 7:24 ` Balbir Singh
2007-09-07 23:37 ` Jonathan Lim
0 siblings, 1 reply; 13+ messages in thread
From: Balbir Singh @ 2007-08-31 7:24 UTC (permalink / raw)
To: Jonathan Lim
Cc: Guillaume Chazarain, Andrew Morton, Linux Kernel Mailing List, Jay Lan
Jonathan Lim wrote:
> On Sat Aug 25 21:58:44 2007, balbir@linux.vnet.ibm.com wrote:
>>> Also, I don't understand why the code to update btime:
>>>
>>> /* calculate task elapsed time in timespec */
>>> do_posix_clock_monotonic_gettime(&uptime);
>>> ts = timespec_sub(uptime, tsk->start_time);
>>> ...
>>> stats->ac_btime = get_seconds() - ts.tv_sec;
>>>
>>> does not simply use tsk->start_time or tsk->real_start_time without
>>> comparing it to the current time.
>> From what I understand, task->start_time and task->real_start_time
>> are taken from the realtime clock. The accounting in CSA seems
>> to be very similar to the accounting done in do_acct_process()
>> (kernel/acct.c).
>
> In CSA 3.0 ...
>
> csa_acct_eop(int exitcode, struct task_struct *p)
>
> csa->ac_btime = boottime +
> ((p->start_time.tv_nsec < NSEC_PER_SEC/2) ?
> p->start_time.tv_sec :
> p->start_time.tv_sec +1);
>
> where
>
> do_posix_clock_monotonic_gettime(&uptime);
> boottime = xtime.tv_sec - uptime.tv_sec;
>
> In an upcoming version of CSA ...
>
> csa_acct_eop(struct taskstats *p)
>
> csa->ac_btime = p->ac_btime;
>
> where
>
> do_posix_clock_monotonic_gettime(&uptime);
> ts = uptime - tsk->start_time;
> p->ac_btime = get_seconds() - ts.tv_sec;
> = xtime.tv_sec - (uptime - tsk->start_time);
> = (xtime.tv_sec - uptime) + tsk->start_time;
>
> So they're basically equivalent.
Excellent, so can Guillaume change ac_btime to be just tsk->start_time?
--
Warm Regards,
Balbir Singh
Linux Technology Center
IBM, ISTL
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH] Add all thread stats for TASKSTATS_CMD_ATTR_TGID
2007-08-26 4:58 ` Balbir Singh
2007-08-26 9:44 ` Guillaume Chazarain
@ 2007-08-31 3:02 ` Jonathan Lim
2007-08-31 7:24 ` Balbir Singh
1 sibling, 1 reply; 13+ messages in thread
From: Jonathan Lim @ 2007-08-31 3:02 UTC (permalink / raw)
To: balbir
Cc: Guillaume Chazarain, Andrew Morton, Linux Kernel Mailing List, Jay Lan
On Sat Aug 25 21:58:44 2007, balbir@linux.vnet.ibm.com wrote:
>
> > Also, I don't understand why the code to update btime:
> >
> > /* calculate task elapsed time in timespec */
> > do_posix_clock_monotonic_gettime(&uptime);
> > ts = timespec_sub(uptime, tsk->start_time);
> > ...
> > stats->ac_btime = get_seconds() - ts.tv_sec;
> >
> > does not simply use tsk->start_time or tsk->real_start_time without
> > comparing it to the current time.
>
> From what I understand, task->start_time and task->real_start_time
> are taken from the realtime clock. The accounting in CSA seems
> to be very similar to the accounting done in do_acct_process()
> (kernel/acct.c).
In CSA 3.0 ...
csa_acct_eop(int exitcode, struct task_struct *p)
csa->ac_btime = boottime +
((p->start_time.tv_nsec < NSEC_PER_SEC/2) ?
p->start_time.tv_sec :
p->start_time.tv_sec +1);
where
do_posix_clock_monotonic_gettime(&uptime);
boottime = xtime.tv_sec - uptime.tv_sec;
In an upcoming version of CSA ...
csa_acct_eop(struct taskstats *p)
csa->ac_btime = p->ac_btime;
where
do_posix_clock_monotonic_gettime(&uptime);
ts = uptime - tsk->start_time;
p->ac_btime = get_seconds() - ts.tv_sec;
= xtime.tv_sec - (uptime - tsk->start_time);
= (xtime.tv_sec - uptime) + tsk->start_time;
So they're basically equivalent.
Jonathan
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH] Add all thread stats for TASKSTATS_CMD_ATTR_TGID
2007-08-26 4:58 ` Balbir Singh
@ 2007-08-26 9:44 ` Guillaume Chazarain
2007-08-31 3:02 ` Jonathan Lim
1 sibling, 0 replies; 13+ messages in thread
From: Guillaume Chazarain @ 2007-08-26 9:44 UTC (permalink / raw)
To: balbir; +Cc: Andrew Morton, Linux Kernel Mailing List, Jay Lan, Jonathan Lim
Le Sun, 26 Aug 2007 10:28:44 +0530,
Balbir Singh <balbir@linux.vnet.ibm.com> a écrit :
> From what I understand, task->start_time and task->real_start_time
> are taken from the realtime clock. The accounting in CSA seems
> to be very similar to the accounting done in do_acct_process()
> (kernel/acct.c).
>
> Jay/Jonathan any comments?
Thanks, I see it is used to have a wall time version of btime.
Here is my current version of the refactoring for information.
The testcase is coming.
diff -r 27877ed82082 include/linux/tsacct_kern.h
--- a/include/linux/tsacct_kern.h Sat Aug 25 22:17:19 2007 +0200
+++ b/include/linux/tsacct_kern.h Sat Aug 25 21:48:51 2007 +0200
@@ -10,17 +10,23 @@
#include <linux/taskstats.h>
#ifdef CONFIG_TASKSTATS
-extern void bacct_add_tsk(struct taskstats *stats, struct task_struct *tsk);
+void bacct_fill_threadgroup(struct taskstats *stats, struct task_struct *task);
+void bacct_add_tsk(struct taskstats *stats, struct task_struct *task);
#else
-static inline void bacct_add_tsk(struct taskstats *stats, struct task_struct *tsk)
+static inline void bacct_fill_threadgroup(struct taskstats *stats, struct task_struct *task)
+{}
+static inline void bacct_add_tsk(struct taskstats *stats, struct task_struct *task)
{}
#endif /* CONFIG_TASKSTATS */
#ifdef CONFIG_TASK_XACCT
-extern void xacct_add_tsk(struct taskstats *stats, struct task_struct *p);
+void xacct_fill_threadgroup(struct taskstats *stats, struct task_struct *task);
+void xacct_add_tsk(struct taskstats *stats, struct task_struct *p);
extern void acct_update_integrals(struct task_struct *tsk);
extern void acct_clear_integrals(struct task_struct *tsk);
#else
+static inline void xacct_fill_threadgroup(struct taskstats *stats, struct task_struct *task)
+{}
static inline void xacct_add_tsk(struct taskstats *stats, struct task_struct *p)
{}
static inline void acct_update_integrals(struct task_struct *tsk)
diff -r 27877ed82082 kernel/taskstats.c
--- a/kernel/taskstats.c Sat Aug 25 22:17:19 2007 +0200
+++ b/kernel/taskstats.c Sat Aug 25 22:11:23 2007 +0200
@@ -168,6 +168,55 @@ static void send_cpu_listeners(struct sk
up_write(&listeners->sem);
}
+/*
+ * Common stats for each thread in the thread group, @task is not necessarily
+ * a thread group leader.
+ */
+static void fill_threadgroup(struct taskstats *stats, struct task_struct *task)
+{
+ /*
+ * Each accounting subsystem adds calls to its functions to initialize
+ * relevant parts of struct taskstsats for a single tgid as follows:
+ *
+ * per-task-foo-fill_threadgroup(stats, task);
+ */
+
+ stats->version = TASKSTATS_VERSION;
+
+ /* fill in basic acct fields */
+ bacct_fill_threadgroup(stats, task);
+
+ /* fill in extended acct fields */
+ xacct_fill_threadgroup(stats, task);
+}
+
+/*
+ * Stats specific to each thread in the thread group. add_tsk() works in
+ * conjunction with fill_threadgroup(), both may write to the same field, so
+ * the ordering of these two calls indicates if the caller wants stats for the
+ * whole thread group or a specific thread.
+ */
+static void add_tsk(struct taskstats *stats, struct task_struct *task)
+{
+ /*
+ * Each accounting subsystem adds calls to its functions to combine
+ * relevant parts of struct taskstsats for a single pid as follows:
+ *
+ * per-task-foo-add_tsk(stats, task);
+ */
+ stats->nvcsw += task->nvcsw;
+ stats->nivcsw += task->nivcsw;
+
+ /* fill in delay acct fields */
+ delayacct_add_tsk(stats, task);
+
+ /* fill in basic acct fields */
+ bacct_add_tsk(stats, task);
+
+ /* fill in extended acct fields */
+ xacct_add_tsk(stats, task);
+}
+
static int fill_pid(pid_t pid, struct task_struct *tsk,
struct taskstats *stats)
{
@@ -185,23 +234,8 @@ static int fill_pid(pid_t pid, struct ta
get_task_struct(tsk);
memset(stats, 0, sizeof(*stats));
- /*
- * Each accounting subsystem adds calls to its functions to
- * fill in relevant parts of struct taskstsats as follows
- *
- * per-task-foo(stats, tsk);
- */
-
- delayacct_add_tsk(stats, tsk);
-
- /* fill in basic acct fields */
- stats->version = TASKSTATS_VERSION;
- stats->nvcsw = tsk->nvcsw;
- stats->nivcsw = tsk->nivcsw;
- bacct_add_tsk(stats, tsk);
-
- /* fill in extended acct fields */
- xacct_add_tsk(stats, tsk);
+ fill_threadgroup(stats, tsk);
+ add_tsk(stats, tsk);
/* Define err: label here if needed */
put_task_struct(tsk);
@@ -233,31 +267,16 @@ static int fill_tgid(pid_t tgid, struct
memset(stats, 0, sizeof(*stats));
tsk = first;
- do {
- if (tsk->exit_state)
- continue;
- /*
- * Accounting subsystem can call its functions here to
- * fill in relevant parts of struct taskstsats as follows
- *
- * per-task-foo(stats, tsk);
- */
- delayacct_add_tsk(stats, tsk);
-
- stats->nvcsw += tsk->nvcsw;
- stats->nivcsw += tsk->nivcsw;
- } while_each_thread(first, tsk);
-
+ do
+ if (!tsk->exit_state)
+ add_tsk(stats, tsk);
+ while_each_thread(first, tsk);
+
+ fill_threadgroup(stats, first);
unlock_task_sighand(first, &flags);
rc = 0;
out:
rcu_read_unlock();
-
- stats->version = TASKSTATS_VERSION;
- /*
- * Accounting subsytems can also add calls here to modify
- * fields of taskstats.
- */
return rc;
}
@@ -265,21 +284,16 @@ static void fill_tgid_exit(struct task_s
static void fill_tgid_exit(struct task_struct *tsk)
{
unsigned long flags;
+ struct taskstats *tg_stats;
spin_lock_irqsave(&tsk->sighand->siglock, flags);
- if (!tsk->signal->stats)
- goto ret;
-
- /*
- * Each accounting subsystem calls its functions here to
- * accumalate its per-task stats for tsk, into the per-tgid structure
- *
- * per-task-foo(tsk->signal->stats, tsk);
- */
- delayacct_add_tsk(tsk->signal->stats, tsk);
-ret:
+ tg_stats = tsk->signal->stats;
+
+ /* fill_threadgroup() will be called by the stats requester */
+ if (tg_stats)
+ add_tsk(tg_stats, tsk);
+
spin_unlock_irqrestore(&tsk->sighand->siglock, flags);
- return;
}
static int add_del_listener(pid_t pid, cpumask_t *maskp, int isadd)
diff -r 27877ed82082 kernel/tsacct.c
--- a/kernel/tsacct.c Sat Aug 25 22:17:19 2007 +0200
+++ b/kernel/tsacct.c Sat Aug 25 21:48:51 2007 +0200
@@ -22,50 +22,71 @@
#include <linux/acct.h>
#include <linux/jiffies.h>
-/*
- * fill in basic accounting fields
- */
-void bacct_add_tsk(struct taskstats *stats, struct task_struct *tsk)
+static void fill_wall_time(struct taskstats *stats, struct task_struct *task)
{
struct timespec uptime, ts;
s64 ac_etime;
+ /* calculate task elapsed time in timespec */
+ do_posix_clock_monotonic_gettime(&uptime);
+ ts = timespec_sub(uptime, task->start_time);
+
+ stats->ac_btime = get_seconds() - ts.tv_sec;
+
+ ac_etime = timespec_to_ns(&ts);
+ do_div(ac_etime, NSEC_PER_USEC);
+ stats->ac_etime = ac_etime;
+}
+
+/*
+ * fill in basic accounting fields
+ */
+
+void bacct_fill_threadgroup(struct taskstats *stats, struct task_struct *task)
+{
+ struct task_struct *leader;
+
BUILD_BUG_ON(TS_COMM_LEN < TASK_COMM_LEN);
- /* calculate task elapsed time in timespec */
- do_posix_clock_monotonic_gettime(&uptime);
- ts = timespec_sub(uptime, tsk->start_time);
- /* rebase elapsed time to usec */
- ac_etime = timespec_to_ns(&ts);
- do_div(ac_etime, NSEC_PER_USEC);
- stats->ac_etime = ac_etime;
- stats->ac_btime = get_seconds() - ts.tv_sec;
- if (thread_group_leader(tsk)) {
- stats->ac_exitcode = tsk->exit_code;
- if (tsk->flags & PF_FORKNOEXEC)
+ rcu_read_lock();
+ stats->ac_ppid = pid_alive(task) ?
+ rcu_dereference(task->real_parent)->tgid : 0;
+ rcu_read_unlock();
+
+ leader = task->group_leader;
+ get_task_struct(leader);
+ fill_wall_time(stats, leader);
+ put_task_struct(leader);
+
+ stats->ac_nice = task_nice(task);
+ stats->ac_sched = task->policy;
+ stats->ac_uid = task->uid;
+ stats->ac_gid = task->gid;
+ stats->ac_pid = task->pid;
+
+ strncpy(stats->ac_comm, task->comm, sizeof(stats->ac_comm));
+}
+
+void bacct_add_tsk(struct taskstats *stats, struct task_struct *task)
+{
+ if (thread_group_leader(task)) {
+ stats->ac_exitcode = task->exit_code;
+ if (task->flags & PF_FORKNOEXEC)
stats->ac_flag |= AFORK;
}
- if (tsk->flags & PF_SUPERPRIV)
+ if (task->flags & PF_SUPERPRIV)
stats->ac_flag |= ASU;
- if (tsk->flags & PF_DUMPCORE)
+ if (task->flags & PF_DUMPCORE)
stats->ac_flag |= ACORE;
- if (tsk->flags & PF_SIGNALED)
+ if (task->flags & PF_SIGNALED)
stats->ac_flag |= AXSIG;
- stats->ac_nice = task_nice(tsk);
- stats->ac_sched = tsk->policy;
- stats->ac_uid = tsk->uid;
- stats->ac_gid = tsk->gid;
- stats->ac_pid = tsk->pid;
- rcu_read_lock();
- stats->ac_ppid = pid_alive(tsk) ?
- rcu_dereference(tsk->real_parent)->tgid : 0;
- rcu_read_unlock();
- stats->ac_utime = cputime_to_msecs(tsk->utime) * USEC_PER_MSEC;
- stats->ac_stime = cputime_to_msecs(tsk->stime) * USEC_PER_MSEC;
- stats->ac_minflt = tsk->min_flt;
- stats->ac_majflt = tsk->maj_flt;
- strncpy(stats->ac_comm, tsk->comm, sizeof(stats->ac_comm));
+ fill_wall_time(stats, task);
+
+ stats->ac_utime += cputime_to_msecs(task->utime) * USEC_PER_MSEC;
+ stats->ac_stime += cputime_to_msecs(task->stime) * USEC_PER_MSEC;
+ stats->ac_minflt += task->min_flt;
+ stats->ac_majflt += task->maj_flt;
}
@@ -76,32 +97,34 @@ void bacct_add_tsk(struct taskstats *sta
/*
* fill in extended accounting fields
*/
-void xacct_add_tsk(struct taskstats *stats, struct task_struct *p)
+void xacct_fill_threadgroup(struct taskstats *stats, struct task_struct *task)
{
struct mm_struct *mm;
- /* convert pages-jiffies to Mbyte-usec */
- stats->coremem = jiffies_to_usecs(p->acct_rss_mem1) * PAGE_SIZE / MB;
- stats->virtmem = jiffies_to_usecs(p->acct_vm_mem1) * PAGE_SIZE / MB;
- mm = get_task_mm(p);
+ mm = get_task_mm(task);
if (mm) {
/* adjust to KB unit */
stats->hiwater_rss = mm->hiwater_rss * PAGE_SIZE / KB;
- stats->hiwater_vm = mm->hiwater_vm * PAGE_SIZE / KB;
+ stats->hiwater_vm = mm->hiwater_vm * PAGE_SIZE / KB;
mmput(mm);
}
- stats->read_char = p->rchar;
- stats->write_char = p->wchar;
- stats->read_syscalls = p->syscr;
- stats->write_syscalls = p->syscw;
+}
+
+void xacct_add_tsk(struct taskstats *stats, struct task_struct *p)
+{
+ /* convert pages-jiffies to Mbyte-usec */
+ stats->coremem += jiffies_to_usecs(p->acct_rss_mem1) * PAGE_SIZE / MB;
+ stats->virtmem += jiffies_to_usecs(p->acct_vm_mem1) * PAGE_SIZE / MB;
+
+ stats->read_char += p->rchar;
+ stats->write_char += p->wchar;
+ stats->read_syscalls += p->syscr;
+ stats->write_syscalls += p->syscw;
+
#ifdef CONFIG_TASK_IO_ACCOUNTING
- stats->read_bytes = p->ioac.read_bytes;
- stats->write_bytes = p->ioac.write_bytes;
- stats->cancelled_write_bytes = p->ioac.cancelled_write_bytes;
-#else
- stats->read_bytes = 0;
- stats->write_bytes = 0;
- stats->cancelled_write_bytes = 0;
+ stats->read_bytes += p->ioac.read_bytes;
+ stats->write_bytes += p->ioac.write_bytes;
+ stats->cancelled_write_bytes += p->ioac.cancelled_write_bytes;
#endif
}
#undef KB
--
Guillaume
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH] Add all thread stats for TASKSTATS_CMD_ATTR_TGID
2007-08-25 15:10 ` Guillaume Chazarain
@ 2007-08-26 4:58 ` Balbir Singh
2007-08-26 9:44 ` Guillaume Chazarain
2007-08-31 3:02 ` Jonathan Lim
0 siblings, 2 replies; 13+ messages in thread
From: Balbir Singh @ 2007-08-26 4:58 UTC (permalink / raw)
To: Guillaume Chazarain
Cc: Andrew Morton, Linux Kernel Mailing List, Jay Lan, Jonathan Lim
Guillaume Chazarain wrote:
> Le Mon, 20 Aug 2007 22:31:08 +0530,
> Balbir Singh <balbir@linux.vnet.ibm.com> a écrit :
>
>>> --- a/kernel/taskstats.c Sat Aug 18 17:15:17 2007 -0700
>>> +++ b/kernel/taskstats.c Sun Aug 19 17:20:15 2007 +0200
>>> @@ -246,6 +246,8 @@ static int fill_tgid(pid_t tgid, struct
>>>
>>> stats->nvcsw += tsk->nvcsw;
>>> stats->nivcsw += tsk->nivcsw;
>>> + bacct_add_tsk(stats, tsk);
>>> + xacct_add_tsk(stats, tsk);
>> I'm afraid this is still not good enough. bacct_add_tsk() will assign
>> values and do nothing in the loop (HINT: no summation).
>
> Hi Balbir, thank you for your review. I agree with everything you said
> and am on my way to do it as time permits, but I have some trouble
> understanding this part. You stated that bacct_add_tsk() would overwrite
> the stats of each thread in the tgid stats, but the other part of the
> patch is the (actually wrong) combination of stats in xxx_add_tsk()
> using min/max/sum.
>
Hi, Guillaume,
The CSA code was written by Jay Lan, but I'll see if I can answer your
questions. In the current implementation, CSA does not use TGID exit
notifications. In fill_pid(), both bacct_add_tsk() and xacct_add_tsk()
are called (which is correct), they complement each other.
The code needs refactoring to ensure that they can work together
in the fill_tgid() scenario.
> Also, I don't understand why the code to update btime:
>
> /* calculate task elapsed time in timespec */
> do_posix_clock_monotonic_gettime(&uptime);
> ts = timespec_sub(uptime, tsk->start_time);
> ...
> stats->ac_btime = get_seconds() - ts.tv_sec;
>
> does not simply use tsk->start_time or tsk->real_start_time without
> comparing it to the current time.
>
>From what I understand, task->start_time and task->real_start_time
are taken from the realtime clock. The accounting in CSA seems
to be very similar to the accounting done in do_acct_process()
(kernel/acct.c).
Jay/Jonathan any comments?
--
Warm Regards,
Balbir Singh
Linux Technology Center
IBM, ISTL
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH] Add all thread stats for TASKSTATS_CMD_ATTR_TGID
2007-08-20 17:01 ` Balbir Singh
@ 2007-08-25 15:10 ` Guillaume Chazarain
2007-08-26 4:58 ` Balbir Singh
0 siblings, 1 reply; 13+ messages in thread
From: Guillaume Chazarain @ 2007-08-25 15:10 UTC (permalink / raw)
To: balbir; +Cc: Andrew Morton, Linux Kernel Mailing List, Jay Lan, Jonathan Lim
Le Mon, 20 Aug 2007 22:31:08 +0530,
Balbir Singh <balbir@linux.vnet.ibm.com> a écrit :
> > --- a/kernel/taskstats.c Sat Aug 18 17:15:17 2007 -0700
> > +++ b/kernel/taskstats.c Sun Aug 19 17:20:15 2007 +0200
> > @@ -246,6 +246,8 @@ static int fill_tgid(pid_t tgid, struct
> >
> > stats->nvcsw += tsk->nvcsw;
> > stats->nivcsw += tsk->nivcsw;
> > + bacct_add_tsk(stats, tsk);
> > + xacct_add_tsk(stats, tsk);
>
> I'm afraid this is still not good enough. bacct_add_tsk() will assign
> values and do nothing in the loop (HINT: no summation).
Hi Balbir, thank you for your review. I agree with everything you said
and am on my way to do it as time permits, but I have some trouble
understanding this part. You stated that bacct_add_tsk() would overwrite
the stats of each thread in the tgid stats, but the other part of the
patch is the (actually wrong) combination of stats in xxx_add_tsk()
using min/max/sum.
Also, I don't understand why the code to update btime:
/* calculate task elapsed time in timespec */
do_posix_clock_monotonic_gettime(&uptime);
ts = timespec_sub(uptime, tsk->start_time);
...
stats->ac_btime = get_seconds() - ts.tv_sec;
does not simply use tsk->start_time or tsk->real_start_time without
comparing it to the current time.
Thanks.
--
Guillaume
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH] Add all thread stats for TASKSTATS_CMD_ATTR_TGID
2007-08-19 19:34 ` Guillaume Chazarain
@ 2007-08-20 17:01 ` Balbir Singh
2007-08-25 15:10 ` Guillaume Chazarain
0 siblings, 1 reply; 13+ messages in thread
From: Balbir Singh @ 2007-08-20 17:01 UTC (permalink / raw)
To: Guillaume Chazarain
Cc: Andrew Morton, Linux Kernel Mailing List, Jay Lan, Jonathan Lim
Guillaume Chazarain wrote:
> TASKSTATS_CMD_ATTR_TGID used to return only the delay accounting stats,
> not the basic and extended accounting. With this patch,
> TASKSTATS_CMD_ATTR_TGID returns also the min, max or sum (depending on
> the semantic of the field) of the accounting info for all threads of a
> thread group. This makes TASKSTATS_CMD_ATTR_TGID usable in a similar
> fashion to TASKSTATS_CMD_ATTR_PID, for commands like iotop -P
> (http://guichaz.free.fr/misc/iotop.py).
>
> Changelog since V1 (http://lkml.org/lkml/2007/8/2/185):
> - Update combined stats of exited threads in fill_tgid_exit() as
> suggested by Balbir Singh.
> - Very light cleanup of fill_tgid_exit() by the way.
> - bacct fields are also combined for all threads.
> - Instead of assuming memory stats are identical for all threads, we
> take the max of all threads (hiwater_rss and hiwater_vm).
>
> Signed-off-by: Guillaume Chazarain <guichaz@yahoo.fr>
> Cc: Balbir Singh <balbir@in.ibm.com>
> Cc: Jay Lan <jlan@engr.sgi.com>
> Cc: Jonathan Lim <jlim@sgi.com>
> ---
>
> kernel/taskstats.c | 15 ++++++++++-----
> kernel/tsacct.c | 43 ++++++++++++++++++++++---------------------
> 2 files changed, 32 insertions(+), 26 deletions(-)
>
> diff -r 73eff559debc kernel/taskstats.c
> --- a/kernel/taskstats.c Sat Aug 18 17:15:17 2007 -0700
> +++ b/kernel/taskstats.c Sun Aug 19 17:20:15 2007 +0200
> @@ -246,6 +246,8 @@ static int fill_tgid(pid_t tgid, struct
>
> stats->nvcsw += tsk->nvcsw;
> stats->nivcsw += tsk->nivcsw;
> + bacct_add_tsk(stats, tsk);
> + xacct_add_tsk(stats, tsk);
I'm afraid this is still not good enough. bacct_add_tsk() will assign
values and do nothing in the loop (HINT: no summation). Ideally,
we should split up bacct_add_tsk(), so that the initialization
code is split up from values that can summed.
> } while_each_thread(first, tsk);
>
> unlock_task_sighand(first, &flags);
> @@ -265,21 +267,24 @@ static void fill_tgid_exit(struct task_s
> static void fill_tgid_exit(struct task_struct *tsk)
> {
> unsigned long flags;
> + struct taskstats *tg_stats;
>
> spin_lock_irqsave(&tsk->sighand->siglock, flags);
> - if (!tsk->signal->stats)
> + tg_stats = tsk->signal->stats;
> + if (!tg_stats)
> goto ret;
>
> /*
> * Each accounting subsystem calls its functions here to
> * accumalate its per-task stats for tsk, into the per-tgid structure
> *
> - * per-task-foo(tsk->signal->stats, tsk);
> - */
> - delayacct_add_tsk(tsk->signal->stats, tsk);
> + * per-task-foo(tg_stats, tsk);
> + */
> + bacct_add_tsk(tg_stats, tsk);
Ditto.. see above
> + xacct_add_tsk(tg_stats, tsk);
> + delayacct_add_tsk(tg_stats, tsk);
> ret:
> spin_unlock_irqrestore(&tsk->sighand->siglock, flags);
> - return;
> }
>
> static int add_del_listener(pid_t pid, cpumask_t *maskp, int isadd)
> diff -r 73eff559debc kernel/tsacct.c
> --- a/kernel/tsacct.c Sat Aug 18 17:15:17 2007 -0700
> +++ b/kernel/tsacct.c Sun Aug 19 17:20:43 2007 +0200
> @@ -38,8 +38,9 @@ void bacct_add_tsk(struct taskstats *sta
> /* rebase elapsed time to usec */
> ac_etime = timespec_to_ns(&ts);
> do_div(ac_etime, NSEC_PER_USEC);
> - stats->ac_etime = ac_etime;
> - stats->ac_btime = get_seconds() - ts.tv_sec;
> + stats->ac_etime = max_t(u64, stats->ac_etime, ac_etime);
> + stats->ac_btime = min_t(u32, stats->ac_btime,
> + get_seconds() - ts.tv_sec);
I am not sure why we get the max value, ideally we should
be summing up utime, stime into the stats structure.
Could you please write a simple test case and ensure that the
summed up stats are indeed correct for TGID's?
--
Warm Regards,
Balbir Singh
Linux Technology Center
IBM, ISTL
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH] Add all thread stats for TASKSTATS_CMD_ATTR_TGID
2007-08-02 19:04 ` Andrew Morton
@ 2007-08-19 19:34 ` Guillaume Chazarain
2007-08-20 17:01 ` Balbir Singh
0 siblings, 1 reply; 13+ messages in thread
From: Guillaume Chazarain @ 2007-08-19 19:34 UTC (permalink / raw)
To: Andrew Morton
Cc: Balbir Singh, Linux Kernel Mailing List, Jay Lan, Jonathan Lim
TASKSTATS_CMD_ATTR_TGID used to return only the delay accounting stats,
not the basic and extended accounting. With this patch,
TASKSTATS_CMD_ATTR_TGID returns also the min, max or sum (depending on
the semantic of the field) of the accounting info for all threads of a
thread group. This makes TASKSTATS_CMD_ATTR_TGID usable in a similar
fashion to TASKSTATS_CMD_ATTR_PID, for commands like iotop -P
(http://guichaz.free.fr/misc/iotop.py).
Changelog since V1 (http://lkml.org/lkml/2007/8/2/185):
- Update combined stats of exited threads in fill_tgid_exit() as
suggested by Balbir Singh.
- Very light cleanup of fill_tgid_exit() by the way.
- bacct fields are also combined for all threads.
- Instead of assuming memory stats are identical for all threads, we
take the max of all threads (hiwater_rss and hiwater_vm).
Signed-off-by: Guillaume Chazarain <guichaz@yahoo.fr>
Cc: Balbir Singh <balbir@in.ibm.com>
Cc: Jay Lan <jlan@engr.sgi.com>
Cc: Jonathan Lim <jlim@sgi.com>
---
kernel/taskstats.c | 15 ++++++++++-----
kernel/tsacct.c | 43 ++++++++++++++++++++++---------------------
2 files changed, 32 insertions(+), 26 deletions(-)
diff -r 73eff559debc kernel/taskstats.c
--- a/kernel/taskstats.c Sat Aug 18 17:15:17 2007 -0700
+++ b/kernel/taskstats.c Sun Aug 19 17:20:15 2007 +0200
@@ -246,6 +246,8 @@ static int fill_tgid(pid_t tgid, struct
stats->nvcsw += tsk->nvcsw;
stats->nivcsw += tsk->nivcsw;
+ bacct_add_tsk(stats, tsk);
+ xacct_add_tsk(stats, tsk);
} while_each_thread(first, tsk);
unlock_task_sighand(first, &flags);
@@ -265,21 +267,24 @@ static void fill_tgid_exit(struct task_s
static void fill_tgid_exit(struct task_struct *tsk)
{
unsigned long flags;
+ struct taskstats *tg_stats;
spin_lock_irqsave(&tsk->sighand->siglock, flags);
- if (!tsk->signal->stats)
+ tg_stats = tsk->signal->stats;
+ if (!tg_stats)
goto ret;
/*
* Each accounting subsystem calls its functions here to
* accumalate its per-task stats for tsk, into the per-tgid structure
*
- * per-task-foo(tsk->signal->stats, tsk);
- */
- delayacct_add_tsk(tsk->signal->stats, tsk);
+ * per-task-foo(tg_stats, tsk);
+ */
+ bacct_add_tsk(tg_stats, tsk);
+ xacct_add_tsk(tg_stats, tsk);
+ delayacct_add_tsk(tg_stats, tsk);
ret:
spin_unlock_irqrestore(&tsk->sighand->siglock, flags);
- return;
}
static int add_del_listener(pid_t pid, cpumask_t *maskp, int isadd)
diff -r 73eff559debc kernel/tsacct.c
--- a/kernel/tsacct.c Sat Aug 18 17:15:17 2007 -0700
+++ b/kernel/tsacct.c Sun Aug 19 17:20:43 2007 +0200
@@ -38,8 +38,9 @@ void bacct_add_tsk(struct taskstats *sta
/* rebase elapsed time to usec */
ac_etime = timespec_to_ns(&ts);
do_div(ac_etime, NSEC_PER_USEC);
- stats->ac_etime = ac_etime;
- stats->ac_btime = get_seconds() - ts.tv_sec;
+ stats->ac_etime = max_t(u64, stats->ac_etime, ac_etime);
+ stats->ac_btime = min_t(u32, stats->ac_btime,
+ get_seconds() - ts.tv_sec);
if (thread_group_leader(tsk)) {
stats->ac_exitcode = tsk->exit_code;
if (tsk->flags & PF_FORKNOEXEC)
@@ -60,10 +61,12 @@ void bacct_add_tsk(struct taskstats *sta
stats->ac_ppid = pid_alive(tsk) ?
rcu_dereference(tsk->real_parent)->tgid : 0;
rcu_read_unlock();
- stats->ac_utime = cputime_to_msecs(tsk->utime) * USEC_PER_MSEC;
- stats->ac_stime = cputime_to_msecs(tsk->stime) * USEC_PER_MSEC;
- stats->ac_minflt = tsk->min_flt;
- stats->ac_majflt = tsk->maj_flt;
+ stats->ac_utime = max_t(u64, stats->ac_utime,
+ cputime_to_msecs(tsk->utime) * USEC_PER_MSEC);
+ stats->ac_stime = max_t(u64, stats->ac_stime,
+ cputime_to_msecs(tsk->stime) * USEC_PER_MSEC);
+ stats->ac_minflt = max_t(u64, stats->ac_minflt, tsk->min_flt);
+ stats->ac_majflt = max_t(u64, stats->ac_majflt, tsk->maj_flt);
strncpy(stats->ac_comm, tsk->comm, sizeof(stats->ac_comm));
}
@@ -81,27 +84,25 @@ void xacct_add_tsk(struct taskstats *sta
struct mm_struct *mm;
/* convert pages-jiffies to Mbyte-usec */
- stats->coremem = jiffies_to_usecs(p->acct_rss_mem1) * PAGE_SIZE / MB;
- stats->virtmem = jiffies_to_usecs(p->acct_vm_mem1) * PAGE_SIZE / MB;
+ stats->coremem += jiffies_to_usecs(p->acct_rss_mem1) * PAGE_SIZE / MB;
+ stats->virtmem += jiffies_to_usecs(p->acct_vm_mem1) * PAGE_SIZE / MB;
mm = get_task_mm(p);
if (mm) {
/* adjust to KB unit */
- stats->hiwater_rss = mm->hiwater_rss * PAGE_SIZE / KB;
- stats->hiwater_vm = mm->hiwater_vm * PAGE_SIZE / KB;
+ stats->hiwater_rss = max_t(u64, stats->hiwater_rss,
+ mm->hiwater_rss * PAGE_SIZE / KB);
+ stats->hiwater_vm = max_t(u64, stats->hiwater_vm,
+ mm->hiwater_vm * PAGE_SIZE / KB);
mmput(mm);
}
- stats->read_char = p->rchar;
- stats->write_char = p->wchar;
- stats->read_syscalls = p->syscr;
- stats->write_syscalls = p->syscw;
+ stats->read_char += p->rchar;
+ stats->write_char += p->wchar;
+ stats->read_syscalls += p->syscr;
+ stats->write_syscalls += p->syscw;
#ifdef CONFIG_TASK_IO_ACCOUNTING
- stats->read_bytes = p->ioac.read_bytes;
- stats->write_bytes = p->ioac.write_bytes;
- stats->cancelled_write_bytes = p->ioac.cancelled_write_bytes;
-#else
- stats->read_bytes = 0;
- stats->write_bytes = 0;
- stats->cancelled_write_bytes = 0;
+ stats->read_bytes += p->ioac.read_bytes;
+ stats->write_bytes += p->ioac.write_bytes;
+ stats->cancelled_write_bytes += p->ioac.cancelled_write_bytes;
#endif
}
#undef KB
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH] Add all thread stats for TASKSTATS_CMD_ATTR_TGID
2007-08-02 13:53 Guillaume Chazarain
2007-08-02 19:04 ` Andrew Morton
@ 2007-08-15 7:15 ` Balbir Singh
1 sibling, 0 replies; 13+ messages in thread
From: Balbir Singh @ 2007-08-15 7:15 UTC (permalink / raw)
To: Guillaume Chazarain; +Cc: Andrew Morton, Linux Kernel Mailing List
Guillaume Chazarain wrote:
> [Resent with different recipients as nagar@watson.ibm.com bounced with
> a User unknown]
>
> Hi,
>
> This patch adds all thread accounting stats for the global tgid stats.
> As a shameless plug, this fixes iotop -P (http://guichaz.free.fr/misc/iotop.py).
>
Since this changes CSA behaviour, it would be nice to get Jay Lan
to confirm if the change looks ok to him..
> Signed-off-by: Guillaume Chazarain <guichaz@yahoo.fr>
> ---
>
> diff -r 22708012ca6e kernel/taskstats.c
> --- a/kernel/taskstats.c Tue Jul 31 21:12:07 2007 -0700
> +++ b/kernel/taskstats.c Wed Aug 01 17:43:54 2007 +0200
> @@ -233,6 +233,7 @@ static int fill_tgid(pid_t tgid, struct
> memset(stats, 0, sizeof(*stats));
>
> tsk = first;
> + bacct_add_tsk(stats, first);
> do {
> if (tsk->exit_state)
> continue;
> @@ -246,6 +247,7 @@ static int fill_tgid(pid_t tgid, struct
>
> stats->nvcsw += tsk->nvcsw;
> stats->nivcsw += tsk->nivcsw;
> + xacct_add_tsk(stats, tsk);
> } while_each_thread(first, tsk);
>
using bacct and xacct might not work well in this case. You'll end
up with basic accounting data for the thread group leader (utime,
stime. For delay accounting, we accumulate data of tasks that have
exited the thread group in fill_tgid_exit(), that way when we
sum up data, we continue storing data of all tasks that exited.
You might want to revisit the code to do that as well.
> unlock_task_sighand(first, &flags);
> diff -r 22708012ca6e kernel/tsacct.c
> --- a/kernel/tsacct.c Tue Jul 31 21:12:07 2007 -0700
> +++ b/kernel/tsacct.c Wed Aug 01 17:41:40 2007 +0200
> @@ -81,8 +81,8 @@ void xacct_add_tsk(struct taskstats *sta
> struct mm_struct *mm;
>
> /* convert pages-jiffies to Mbyte-usec */
> - stats->coremem = jiffies_to_usecs(p->acct_rss_mem1) * PAGE_SIZE / MB;
> - stats->virtmem = jiffies_to_usecs(p->acct_vm_mem1) * PAGE_SIZE / MB;
> + stats->coremem += jiffies_to_usecs(p->acct_rss_mem1) * PAGE_SIZE / MB;
> + stats->virtmem += jiffies_to_usecs(p->acct_vm_mem1) * PAGE_SIZE / MB;
> mm = get_task_mm(p);
> if (mm) {
> /* adjust to KB unit */
> @@ -90,18 +90,14 @@ void xacct_add_tsk(struct taskstats *sta
> stats->hiwater_vm = mm->hiwater_vm * PAGE_SIZE / KB;
> mmput(mm);
> }
> - stats->read_char = p->rchar;
> - stats->write_char = p->wchar;
> - stats->read_syscalls = p->syscr;
> - stats->write_syscalls = p->syscw;
> + stats->read_char += p->rchar;
> + stats->write_char += p->wchar;
> + stats->read_syscalls += p->syscr;
> + stats->write_syscalls += p->syscw;
> #ifdef CONFIG_TASK_IO_ACCOUNTING
> - stats->read_bytes = p->ioac.read_bytes;
> - stats->write_bytes = p->ioac.write_bytes;
> - stats->cancelled_write_bytes = p->ioac.cancelled_write_bytes;
> -#else
> - stats->read_bytes = 0;
> - stats->write_bytes = 0;
> - stats->cancelled_write_bytes = 0;
> + stats->read_bytes += p->ioac.read_bytes;
> + stats->write_bytes += p->ioac.write_bytes;
> + stats->cancelled_write_bytes += p->ioac.cancelled_write_bytes;
> #endif
> }
> #undef KB
--
Warm Regards,
Balbir Singh
Linux Technology Center
IBM, ISTL
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH] Add all thread stats for TASKSTATS_CMD_ATTR_TGID
2007-08-02 13:53 Guillaume Chazarain
@ 2007-08-02 19:04 ` Andrew Morton
2007-08-19 19:34 ` Guillaume Chazarain
2007-08-15 7:15 ` Balbir Singh
1 sibling, 1 reply; 13+ messages in thread
From: Andrew Morton @ 2007-08-02 19:04 UTC (permalink / raw)
To: Guillaume Chazarain
Cc: Balbir Singh, Linux Kernel Mailing List, Shailabh Nagar, Jay Lan,
Jonathan Lim
On Thu, 2 Aug 2007 15:53:13 +0200
"Guillaume Chazarain" <guichaz@yahoo.fr> wrote:
> [Resent with different recipients as nagar@watson.ibm.com bounced with
> a User unknown]
>
> Hi,
>
> This patch adds all thread accounting stats for the global tgid stats.
> As a shameless plug, this fixes iotop -P (http://guichaz.free.fr/misc/iotop.py).
uhm, that's a fairly skimpy changelog for a fairly significant functional
change.
> Signed-off-by: Guillaume Chazarain <guichaz@yahoo.fr>
> ---
>
> diff -r 22708012ca6e kernel/taskstats.c
> --- a/kernel/taskstats.c Tue Jul 31 21:12:07 2007 -0700
> +++ b/kernel/taskstats.c Wed Aug 01 17:43:54 2007 +0200
> @@ -233,6 +233,7 @@ static int fill_tgid(pid_t tgid, struct
> memset(stats, 0, sizeof(*stats));
>
> tsk = first;
> + bacct_add_tsk(stats, first);
> do {
> if (tsk->exit_state)
> continue;
> @@ -246,6 +247,7 @@ static int fill_tgid(pid_t tgid, struct
>
> stats->nvcsw += tsk->nvcsw;
> stats->nivcsw += tsk->nivcsw;
> + xacct_add_tsk(stats, tsk);
> } while_each_thread(first, tsk);
>
> unlock_task_sighand(first, &flags);
> diff -r 22708012ca6e kernel/tsacct.c
> --- a/kernel/tsacct.c Tue Jul 31 21:12:07 2007 -0700
> +++ b/kernel/tsacct.c Wed Aug 01 17:41:40 2007 +0200
> @@ -81,8 +81,8 @@ void xacct_add_tsk(struct taskstats *sta
> struct mm_struct *mm;
>
> /* convert pages-jiffies to Mbyte-usec */
> - stats->coremem = jiffies_to_usecs(p->acct_rss_mem1) * PAGE_SIZE / MB;
> - stats->virtmem = jiffies_to_usecs(p->acct_vm_mem1) * PAGE_SIZE / MB;
> + stats->coremem += jiffies_to_usecs(p->acct_rss_mem1) * PAGE_SIZE / MB;
> + stats->virtmem += jiffies_to_usecs(p->acct_vm_mem1) * PAGE_SIZE / MB;
> mm = get_task_mm(p);
> if (mm) {
> /* adjust to KB unit */
> @@ -90,18 +90,14 @@ void xacct_add_tsk(struct taskstats *sta
> stats->hiwater_vm = mm->hiwater_vm * PAGE_SIZE / KB;
How come hiwater_rss and hiwater_vm weren't similarly treated?
> mmput(mm);
> }
> - stats->read_char = p->rchar;
> - stats->write_char = p->wchar;
> - stats->read_syscalls = p->syscr;
> - stats->write_syscalls = p->syscw;
> + stats->read_char += p->rchar;
> + stats->write_char += p->wchar;
> + stats->read_syscalls += p->syscr;
> + stats->write_syscalls += p->syscw;
> #ifdef CONFIG_TASK_IO_ACCOUNTING
> - stats->read_bytes = p->ioac.read_bytes;
> - stats->write_bytes = p->ioac.write_bytes;
> - stats->cancelled_write_bytes = p->ioac.cancelled_write_bytes;
> -#else
> - stats->read_bytes = 0;
> - stats->write_bytes = 0;
> - stats->cancelled_write_bytes = 0;
> + stats->read_bytes += p->ioac.read_bytes;
> + stats->write_bytes += p->ioac.write_bytes;
> + stats->cancelled_write_bytes += p->ioac.cancelled_write_bytes;
> #endif
Suitable cc's added. Guys, please have a think about the implications of
this change? In particular, why didn't we do this on day one? It's so
obvious that I have a feeling we must have had a reason?
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH] Add all thread stats for TASKSTATS_CMD_ATTR_TGID
@ 2007-08-02 13:53 Guillaume Chazarain
2007-08-02 19:04 ` Andrew Morton
2007-08-15 7:15 ` Balbir Singh
0 siblings, 2 replies; 13+ messages in thread
From: Guillaume Chazarain @ 2007-08-02 13:53 UTC (permalink / raw)
To: Andrew Morton, Balbir Singh, Linux Kernel Mailing List
[Resent with different recipients as nagar@watson.ibm.com bounced with
a User unknown]
Hi,
This patch adds all thread accounting stats for the global tgid stats.
As a shameless plug, this fixes iotop -P (http://guichaz.free.fr/misc/iotop.py).
Signed-off-by: Guillaume Chazarain <guichaz@yahoo.fr>
---
diff -r 22708012ca6e kernel/taskstats.c
--- a/kernel/taskstats.c Tue Jul 31 21:12:07 2007 -0700
+++ b/kernel/taskstats.c Wed Aug 01 17:43:54 2007 +0200
@@ -233,6 +233,7 @@ static int fill_tgid(pid_t tgid, struct
memset(stats, 0, sizeof(*stats));
tsk = first;
+ bacct_add_tsk(stats, first);
do {
if (tsk->exit_state)
continue;
@@ -246,6 +247,7 @@ static int fill_tgid(pid_t tgid, struct
stats->nvcsw += tsk->nvcsw;
stats->nivcsw += tsk->nivcsw;
+ xacct_add_tsk(stats, tsk);
} while_each_thread(first, tsk);
unlock_task_sighand(first, &flags);
diff -r 22708012ca6e kernel/tsacct.c
--- a/kernel/tsacct.c Tue Jul 31 21:12:07 2007 -0700
+++ b/kernel/tsacct.c Wed Aug 01 17:41:40 2007 +0200
@@ -81,8 +81,8 @@ void xacct_add_tsk(struct taskstats *sta
struct mm_struct *mm;
/* convert pages-jiffies to Mbyte-usec */
- stats->coremem = jiffies_to_usecs(p->acct_rss_mem1) * PAGE_SIZE / MB;
- stats->virtmem = jiffies_to_usecs(p->acct_vm_mem1) * PAGE_SIZE / MB;
+ stats->coremem += jiffies_to_usecs(p->acct_rss_mem1) * PAGE_SIZE / MB;
+ stats->virtmem += jiffies_to_usecs(p->acct_vm_mem1) * PAGE_SIZE / MB;
mm = get_task_mm(p);
if (mm) {
/* adjust to KB unit */
@@ -90,18 +90,14 @@ void xacct_add_tsk(struct taskstats *sta
stats->hiwater_vm = mm->hiwater_vm * PAGE_SIZE / KB;
mmput(mm);
}
- stats->read_char = p->rchar;
- stats->write_char = p->wchar;
- stats->read_syscalls = p->syscr;
- stats->write_syscalls = p->syscw;
+ stats->read_char += p->rchar;
+ stats->write_char += p->wchar;
+ stats->read_syscalls += p->syscr;
+ stats->write_syscalls += p->syscw;
#ifdef CONFIG_TASK_IO_ACCOUNTING
- stats->read_bytes = p->ioac.read_bytes;
- stats->write_bytes = p->ioac.write_bytes;
- stats->cancelled_write_bytes = p->ioac.cancelled_write_bytes;
-#else
- stats->read_bytes = 0;
- stats->write_bytes = 0;
- stats->cancelled_write_bytes = 0;
+ stats->read_bytes += p->ioac.read_bytes;
+ stats->write_bytes += p->ioac.write_bytes;
+ stats->cancelled_write_bytes += p->ioac.cancelled_write_bytes;
#endif
}
#undef KB
^ permalink raw reply [flat|nested] 13+ messages in thread
end of thread, other threads:[~2007-09-10 13:04 UTC | newest]
Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-08-02 13:34 [PATCH] Add all thread stats for TASKSTATS_CMD_ATTR_TGID Guillaume Chazarain
2007-08-02 13:53 Guillaume Chazarain
2007-08-02 19:04 ` Andrew Morton
2007-08-19 19:34 ` Guillaume Chazarain
2007-08-20 17:01 ` Balbir Singh
2007-08-25 15:10 ` Guillaume Chazarain
2007-08-26 4:58 ` Balbir Singh
2007-08-26 9:44 ` Guillaume Chazarain
2007-08-31 3:02 ` Jonathan Lim
2007-08-31 7:24 ` Balbir Singh
2007-09-07 23:37 ` Jonathan Lim
2007-09-10 13:03 ` Guillaume Chazarain
2007-08-15 7:15 ` Balbir Singh
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®