[PATCH 3/3] taskstats: fix stats->ac_exitcode to work on threads anduse group_exit_code

From: Guillaume Chazarain
Date: Fri Sep 21 2007 - 19:33:35 EST


Threads also have an exit code on their own, so report it in
TASKSTATS_CMD_ATTR_PID.

For TASKSTATS_CMD_ATTR_TGID, instead of relying only on the exit code of the
leader, we use task->signal->group_exit_code if not null as suggested by
Oleg Nesterov.

Also, document that as of this patch, fill_threadgroup() must be called after
add_tsk() as it may overwrite some stats.

Signed-off-by: Guillaume Chazarain <guichaz@xxxxxxxx>
Cc: Balbir Singh <balbir@xxxxxxxxxx>
Cc: Jay Lan <jlan@xxxxxxxxxxxx>
Cc: Jonathan Lim <jlim@xxxxxxx>
Cc: Oleg Nesterov <oleg@xxxxxxxxxx>
---

kernel/taskstats.c | 3 +++
kernel/tsacct.c | 12 +++++++-----
2 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/kernel/taskstats.c b/kernel/taskstats.c
index 42d3110..24d7f62 100644
--- a/kernel/taskstats.c
+++ b/kernel/taskstats.c
@@ -181,6 +181,9 @@ static void send_cpu_listeners(struct sk_buff *skb,
* memory usage), so are taken from the group leader.
* XXX_threadgroup() methods deal with the first type while XXX_add_tsk() with
* the second.
+ *
+ * fill_threadgroup() may overwrite stats from add_tsk(), so it must be called
+ * after add_tsk().
*/
static void fill_threadgroup(struct taskstats *stats, struct task_struct *task,
bool tg_stats)
diff --git a/kernel/tsacct.c b/kernel/tsacct.c
index 24056aa..526b134 100644
--- a/kernel/tsacct.c
+++ b/kernel/tsacct.c
@@ -44,6 +44,8 @@ static void fill_wall_times(struct taskstats *stats, struct task_struct *tsk)
void bacct_fill_threadgroup(struct taskstats *stats, struct task_struct *task,
bool tg_stats)
{
+ int group_exit_code;
+
BUILD_BUG_ON(TS_COMM_LEN < TASK_COMM_LEN);

rcu_read_lock();
@@ -53,11 +55,11 @@ void bacct_fill_threadgroup(struct taskstats *stats, struct task_struct *task,

fill_wall_times(stats, task);

- if (thread_group_leader(task)) {
- stats->ac_exitcode = task->exit_code;
- if (task->flags & PF_FORKNOEXEC)
- stats->ac_flag |= AFORK;
- }
+ if (thread_group_leader(task) && (task->flags & PF_FORKNOEXEC))
+ stats->ac_flag |= AFORK;
+
+ group_exit_code = tg_stats ? task->signal->group_exit_code : 0;
+ stats->ac_exitcode = group_exit_code ? : task->exit_code;

stats->ac_nice = task_nice(task);
stats->ac_sched = task->policy;

-
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/