aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/taskstats.c
diff options
context:
space:
mode:
authorOleg Nesterov <oleg@tv-sign.ru>2006-12-06 23:36:51 -0500
committerLinus Torvalds <torvalds@woody.osdl.org>2006-12-07 11:39:34 -0500
commit115085ea0794c0f339be8f9d25505c7f9861d824 (patch)
tree0b69f20ab8ab53702a4c94c11927e60fa058b509 /kernel/taskstats.c
parent128fb95650b3273a8dc9ba5514b6fe7db8ea30bf (diff)
[PATCH] taskstats: cleanup do_exit() path
do_exit: taskstats_exit_alloc() ... taskstats_exit_send() taskstats_exit_free() I think this is not good, let it be a single function exported to the core kernel, taskstats_exit(), which does alloc + send + free itself. Signed-off-by: Oleg Nesterov <oleg@tv-sign.ru> Cc: Balbir Singh <balbir@in.ibm.com> Cc: Shailabh Nagar <nagar@watson.ibm.com> Cc: Jay Lan <jlan@engr.sgi.com> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'kernel/taskstats.c')
-rw-r--r--kernel/taskstats.c41
1 files changed, 15 insertions, 26 deletions
diff --git a/kernel/taskstats.c b/kernel/taskstats.c
index d9d7c3576238..2654886fe058 100644
--- a/kernel/taskstats.c
+++ b/kernel/taskstats.c
@@ -119,10 +119,10 @@ static int send_reply(struct sk_buff *skb, pid_t pid)
119/* 119/*
120 * Send taskstats data in @skb to listeners registered for @cpu's exit data 120 * Send taskstats data in @skb to listeners registered for @cpu's exit data
121 */ 121 */
122static void send_cpu_listeners(struct sk_buff *skb, unsigned int cpu) 122static void send_cpu_listeners(struct sk_buff *skb,
123 struct listener_list *listeners)
123{ 124{
124 struct genlmsghdr *genlhdr = nlmsg_data((struct nlmsghdr *)skb->data); 125 struct genlmsghdr *genlhdr = nlmsg_data((struct nlmsghdr *)skb->data);
125 struct listener_list *listeners;
126 struct listener *s, *tmp; 126 struct listener *s, *tmp;
127 struct sk_buff *skb_next, *skb_cur = skb; 127 struct sk_buff *skb_next, *skb_cur = skb;
128 void *reply = genlmsg_data(genlhdr); 128 void *reply = genlmsg_data(genlhdr);
@@ -135,7 +135,6 @@ static void send_cpu_listeners(struct sk_buff *skb, unsigned int cpu)
135 } 135 }
136 136
137 rc = 0; 137 rc = 0;
138 listeners = &per_cpu(listener_array, cpu);
139 down_read(&listeners->sem); 138 down_read(&listeners->sem);
140 list_for_each_entry(s, &listeners->list, list) { 139 list_for_each_entry(s, &listeners->list, list) {
141 skb_next = NULL; 140 skb_next = NULL;
@@ -413,28 +412,12 @@ err:
413 return rc; 412 return rc;
414} 413}
415 414
416void taskstats_exit_alloc(struct taskstats **ptidstats, unsigned int *mycpu)
417{
418 struct listener_list *listeners;
419 /*
420 * This is the cpu on which the task is exiting currently and will
421 * be the one for which the exit event is sent, even if the cpu
422 * on which this function is running changes later.
423 */
424 *mycpu = raw_smp_processor_id();
425
426 listeners = &per_cpu(listener_array, *mycpu);
427
428 *ptidstats = NULL;
429 if (!list_empty(&listeners->list))
430 *ptidstats = kmem_cache_zalloc(taskstats_cache, GFP_KERNEL);
431}
432
433/* Send pid data out on exit */ 415/* Send pid data out on exit */
434void taskstats_exit_send(struct task_struct *tsk, struct taskstats *tidstats, 416void taskstats_exit(struct task_struct *tsk, int group_dead)
435 int group_dead, unsigned int mycpu)
436{ 417{
437 int rc; 418 int rc;
419 struct listener_list *listeners;
420 struct taskstats *tidstats;
438 struct sk_buff *rep_skb; 421 struct sk_buff *rep_skb;
439 void *reply; 422 void *reply;
440 size_t size; 423 size_t size;
@@ -458,12 +441,17 @@ void taskstats_exit_send(struct task_struct *tsk, struct taskstats *tidstats,
458 fill_tgid_exit(tsk); 441 fill_tgid_exit(tsk);
459 } 442 }
460 443
444 listeners = &__raw_get_cpu_var(listener_array);
445 if (list_empty(&listeners->list))
446 return;
447
448 tidstats = kmem_cache_zalloc(taskstats_cache, GFP_KERNEL);
461 if (!tidstats) 449 if (!tidstats)
462 return; 450 return;
463 451
464 rc = prepare_reply(NULL, TASKSTATS_CMD_NEW, &rep_skb, &reply, size); 452 rc = prepare_reply(NULL, TASKSTATS_CMD_NEW, &rep_skb, &reply, size);
465 if (rc < 0) 453 if (rc < 0)
466 goto ret; 454 goto free_stats;
467 455
468 rc = fill_pid(tsk->pid, tsk, tidstats); 456 rc = fill_pid(tsk->pid, tsk, tidstats);
469 if (rc < 0) 457 if (rc < 0)
@@ -492,15 +480,16 @@ void taskstats_exit_send(struct task_struct *tsk, struct taskstats *tidstats,
492 nla_nest_end(rep_skb, na); 480 nla_nest_end(rep_skb, na);
493 481
494send: 482send:
495 send_cpu_listeners(rep_skb, mycpu); 483 send_cpu_listeners(rep_skb, listeners);
484free_stats:
485 kmem_cache_free(taskstats_cache, tidstats);
496 return; 486 return;
497 487
498nla_put_failure: 488nla_put_failure:
499 genlmsg_cancel(rep_skb, reply); 489 genlmsg_cancel(rep_skb, reply);
500err_skb: 490err_skb:
501 nlmsg_free(rep_skb); 491 nlmsg_free(rep_skb);
502ret: 492 goto free_stats;
503 return;
504} 493}
505 494
506static struct genl_ops taskstats_ops = { 495static struct genl_ops taskstats_ops = {