19 #include <linux/kernel.h>
25 #include <linux/slab.h>
38 #define TASKSTATS_CPUMASK_MAXLEN (100+6*NR_CPUS)
41 static int family_registered;
97 reply = genlmsg_put_reply(skb, info, &family, 0, cmd);
112 struct genlmsghdr *genlhdr = nlmsg_data(nlmsg_hdr(skb));
113 void *reply = genlmsg_data(genlhdr);
116 rc = genlmsg_end(skb, reply);
122 return genlmsg_reply(skb, info);
128 static void send_cpu_listeners(
struct sk_buff *skb,
131 struct genlmsghdr *genlhdr = nlmsg_data(nlmsg_hdr(skb));
134 void *reply = genlmsg_data(genlhdr);
135 int rc, delcount = 0;
137 rc = genlmsg_end(skb, reply);
147 if (!list_is_last(&s->
list, &listeners->
list)) {
182 memset(stats, 0,
sizeof(*stats));
190 delayacct_add_tsk(stats, tsk);
199 xacct_add_tsk(stats, tsk);
214 put_task_struct(tsk);
231 if (!first || !lock_task_sighand(first, &flags))
237 memset(stats, 0,
sizeof(*stats));
249 delayacct_add_tsk(stats, tsk);
255 unlock_task_sighand(first, &flags);
268 static void fill_tgid_exit(
struct task_struct *tsk)
282 delayacct_add_tsk(tsk->
signal->stats, tsk);
284 spin_unlock_irqrestore(&tsk->
sighand->siglock, flags);
288 static int add_del_listener(
pid_t pid,
const struct cpumask *
mask,
int isadd)
294 if (!cpumask_subset(mask, cpu_possible_mask))
305 s = kmalloc_node(
sizeof(
struct listener),
313 listeners = &
per_cpu(listener_array, cpu);
319 list_add(&s->
list, &listeners->
list);
331 listeners = &
per_cpu(listener_array, cpu);
362 ret = cpulist_parse(data, mask);
367 #if defined(CONFIG_64BIT) && !defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS)
368 #define TASKSTATS_NEEDS_PADDING 1
399 #ifdef TASKSTATS_NEEDS_PADDING
403 na = nla_nest_start(skb, aggr);
407 if (
nla_put(skb, type,
sizeof(pid), &pid) < 0)
412 nla_nest_end(skb, na);
414 return nla_data(ret);
419 static int cgroupstats_user_cmd(
struct sk_buff *skb,
struct genl_info *info)
453 stats = nla_data(na);
454 memset(stats, 0,
sizeof(*stats));
462 rc = send_reply(rep_skb, info);
469 static int cmd_attr_register_cpumask(
struct genl_info *info)
481 free_cpumask_var(mask);
485 static int cmd_attr_deregister_cpumask(
struct genl_info *info)
497 free_cpumask_var(mask);
501 static size_t taskstats_packet_size(
void)
505 size = nla_total_size(
sizeof(
u32)) +
506 nla_total_size(
sizeof(
struct taskstats)) + nla_total_size(0);
507 #ifdef TASKSTATS_NEEDS_PADDING
508 size += nla_total_size(0);
513 static int cmd_attr_pid(
struct genl_info *info)
521 size = taskstats_packet_size();
533 rc = fill_stats_for_pid(pid, stats);
536 return send_reply(rep_skb, info);
542 static int cmd_attr_tgid(
struct genl_info *info)
550 size = taskstats_packet_size();
562 rc = fill_stats_for_tgid(tgid, stats);
565 return send_reply(rep_skb, info);
574 return cmd_attr_register_cpumask(info);
576 return cmd_attr_deregister_cpumask(info);
578 return cmd_attr_pid(info);
580 return cmd_attr_tgid(info);
590 if (sig->stats || thread_group_empty(tsk))
594 stats = kmem_cache_zalloc(taskstats_cache,
GFP_KERNEL);
596 spin_lock_irq(&tsk->
sighand->siglock);
601 spin_unlock_irq(&tsk->
sighand->siglock);
619 if (!family_registered)
625 size = taskstats_packet_size();
627 is_thread_group = !!taskstats_tgid_alloc(tsk);
628 if (is_thread_group) {
636 if (list_empty(&listeners->
list))
653 if (!is_thread_group || !group_dead)
664 send_cpu_listeners(rep_skb, listeners);
670 static struct genl_ops taskstats_ops = {
672 .doit = taskstats_user_cmd,
673 .policy = taskstats_cmd_get_policy,
677 static struct genl_ops cgroupstats_ops = {
679 .doit = cgroupstats_user_cmd,
680 .policy = cgroupstats_cmd_get_policy,
690 INIT_LIST_HEAD(&(
per_cpu(listener_array, i).
list));
695 static int __init taskstats_init(
void)
711 family_registered = 1;