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

!MAILaRCHIVE_VOTE_RePLACE
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: Andrew Morton <akpm@...>, Oleg Nesterov <oleg@...>, Balbir Singh <balbir@...>, Jonathan Lim <jlim@...>, Jay Lan <jlan@...>, Linux Kernel Mailing List <linux-kernel@...>
Date: Friday, September 21, 2007 - 7:30 pm

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@yahoo.fr>
Cc: Balbir Singh <balbir@in.ibm.com>
Cc: Jay Lan <jlan@engr.sgi.com>
Cc: Jonathan Lim <jlim@sgi.com>
Cc: Oleg Nesterov <oleg@tv-sign.ru>
---

 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;

-
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH 1/3] taskstats: separate PID/TGID stats producers to ..., Guillaume Chazarain, (Fri Sep 21, 7:30 pm)
Re: [PATCH 1/3] taskstats: separate PID/TGID stats producers..., Guillaume Chazarain, (Wed Sep 26, 1:32 pm)
[PATCH 2/3] taskstats: tell fill_thread_group() whether it r..., Guillaume Chazarain, (Fri Sep 21, 7:30 pm)
[PATCH 3/3] taskstats: fix stats->ac_exitcode to work on ..., Guillaume Chazarain, (Fri Sep 21, 7:30 pm)