Send statistics even if thread group leader exits
PATCH 1/1 Send statistics even if thread group leader exits
Hi, Andrew,
The following problem was found during the usage of the per-task delay accounting code.
When a thread group leader exits, the statistics of the remaining threads in the thread group are not sent on exit. delayacct_add_tsk() would fail for the thread group leader. This fix causes statistics collected for the pid to be sent out, even if collection of tgid statistics fail.
Test Program Psuedocode
1. Main program
creates two threads called t1 and t2
calls pthread_exit()
2. t1
sleeps for a while
calls pthread_exit()
3. t2
sleeps for a while
calls pthread_exit()
Earlier no stats were being sent for t1 and t2.
The pid statistics are being sent to user space after the fix.
Signed-off-by Balbir Singh <[email protected]>
---
kernel/taskstats.c | 11 +++++++++-- 1 files changed, 9 insertions(+), 2 deletions(-)
kernel/taskstats.c renamed from kernel/taskstats.c~taskstats-thread-group-leader-exits-first-fix +9 -2
@@ -277,8 +277,15 @@ void taskstats_exit_send(struct task_str } rc =fill_tgid (tsk->pid, tsk, tgidstats); -if (rc <0 ) - goto err_skb; +/* +* If fill_tgid() failed then one probable reason could be that the +* thread group leader has exited. fill_tgid() will fail, send out +* the pid statistics collected earlier. +*/ +if (rc <0 ) { +send_reply (rep_skb,0 ,TASKSTATS_MSG_MULTICAST ); + goto ret; + } na =nla_nest_start (rep_skb,TASKSTATS_TYPE_AGGR_TGID );NLA_PUT_U32 (rep_skb,TASKSTATS_TYPE_TGID , (u32 )tsk->tgid);
_
Signature · 3 lines
Balbir Singh, Linux Technology Center, IBM Software Labs