Skip to content

Commit

Permalink
[PATCH] taskstats: fix sub-threads accounting
Browse files Browse the repository at this point in the history
If there are no listeners, taskstats_exit_send() just returns because
taskstats_exit_alloc() didn't allocate *tidstats.  This is wrong, each
sub-thread should do fill_tgid_exit() on exit, otherwise its ->delays is
not recorded in ->signal->stats and lost.

Q: We don't send TASKSTATS_TYPE_AGGR_TGID when single-threaded process
exits.  Is it good?  How can the listener figure out that it was actually a
process exit, not sub-thread?

Signed-off-by: Oleg Nesterov <[email protected]>
Cc: Balbir Singh <[email protected]>
Acked-by: Shailabh Nagar <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
Oleg Nesterov authored and Linus Torvalds committed Oct 31, 2006
1 parent 525fdb6 commit 4a279ff
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions kernel/taskstats.c
Original file line number Diff line number Diff line change
Expand Up @@ -455,19 +455,25 @@ void taskstats_exit_send(struct task_struct *tsk, struct taskstats *tidstats,
int is_thread_group;
struct nlattr *na;

if (!family_registered || !tidstats)
if (!family_registered)
return;

rc = 0;
/*
* Size includes space for nested attributes
*/
size = nla_total_size(sizeof(u32)) +
nla_total_size(sizeof(struct taskstats)) + nla_total_size(0);

is_thread_group = (tsk->signal->stats != NULL);
if (is_thread_group)
size = 2 * size; /* PID + STATS + TGID + STATS */
if (is_thread_group) {
/* PID + STATS + TGID + STATS */
size = 2 * size;
/* fill the tsk->signal->stats structure */
fill_tgid_exit(tsk);
}

if (!tidstats)
return;

rc = prepare_reply(NULL, TASKSTATS_CMD_NEW, &rep_skb, &reply, size);
if (rc < 0)
Expand All @@ -487,11 +493,8 @@ void taskstats_exit_send(struct task_struct *tsk, struct taskstats *tidstats,
goto send;

/*
* tsk has/had a thread group so fill the tsk->signal->stats structure
* Doesn't matter if tsk is the leader or the last group member leaving
*/

fill_tgid_exit(tsk);
if (!group_dead)
goto send;

Expand Down

0 comments on commit 4a279ff

Please sign in to comment.