]>
Commit | Line | Data |
---|---|---|
c757249a SN |
1 | /* |
2 | * taskstats.c - Export per-task statistics to userland | |
3 | * | |
4 | * Copyright (C) Shailabh Nagar, IBM Corp. 2006 | |
5 | * (C) Balbir Singh, IBM Corp. 2006 | |
6 | * | |
7 | * This program is free software; you can redistribute it and/or modify | |
8 | * it under the terms of the GNU General Public License as published by | |
9 | * the Free Software Foundation; either version 2 of the License, or | |
10 | * (at your option) any later version. | |
11 | * | |
12 | * This program is distributed in the hope that it will be useful, | |
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | * GNU General Public License for more details. | |
16 | * | |
17 | */ | |
18 | ||
19 | #include <linux/kernel.h> | |
20 | #include <linux/taskstats_kern.h> | |
f3cef7a9 | 21 | #include <linux/tsacct_kern.h> |
6f44993f | 22 | #include <linux/delayacct.h> |
9acc1853 | 23 | #include <linux/tsacct_kern.h> |
f9fd8914 SN |
24 | #include <linux/cpumask.h> |
25 | #include <linux/percpu.h> | |
c757249a SN |
26 | #include <net/genetlink.h> |
27 | #include <asm/atomic.h> | |
28 | ||
f9fd8914 SN |
29 | /* |
30 | * Maximum length of a cpumask that can be specified in | |
31 | * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute | |
32 | */ | |
33 | #define TASKSTATS_CPUMASK_MAXLEN (100+6*NR_CPUS) | |
34 | ||
c757249a SN |
35 | static DEFINE_PER_CPU(__u32, taskstats_seqnum) = { 0 }; |
36 | static int family_registered; | |
e18b890b | 37 | struct kmem_cache *taskstats_cache; |
c757249a SN |
38 | |
39 | static struct genl_family family = { | |
40 | .id = GENL_ID_GENERATE, | |
41 | .name = TASKSTATS_GENL_NAME, | |
42 | .version = TASKSTATS_GENL_VERSION, | |
43 | .maxattr = TASKSTATS_CMD_ATTR_MAX, | |
44 | }; | |
45 | ||
46 | static struct nla_policy taskstats_cmd_get_policy[TASKSTATS_CMD_ATTR_MAX+1] | |
47 | __read_mostly = { | |
48 | [TASKSTATS_CMD_ATTR_PID] = { .type = NLA_U32 }, | |
49 | [TASKSTATS_CMD_ATTR_TGID] = { .type = NLA_U32 }, | |
f9fd8914 SN |
50 | [TASKSTATS_CMD_ATTR_REGISTER_CPUMASK] = { .type = NLA_STRING }, |
51 | [TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK] = { .type = NLA_STRING },}; | |
52 | ||
53 | struct listener { | |
54 | struct list_head list; | |
55 | pid_t pid; | |
bb129994 | 56 | char valid; |
c757249a SN |
57 | }; |
58 | ||
f9fd8914 SN |
59 | struct listener_list { |
60 | struct rw_semaphore sem; | |
61 | struct list_head list; | |
62 | }; | |
63 | static DEFINE_PER_CPU(struct listener_list, listener_array); | |
64 | ||
65 | enum actions { | |
66 | REGISTER, | |
67 | DEREGISTER, | |
68 | CPU_DONT_CARE | |
69 | }; | |
c757249a SN |
70 | |
71 | static int prepare_reply(struct genl_info *info, u8 cmd, struct sk_buff **skbp, | |
72 | void **replyp, size_t size) | |
73 | { | |
74 | struct sk_buff *skb; | |
75 | void *reply; | |
76 | ||
77 | /* | |
78 | * If new attributes are added, please revisit this allocation | |
79 | */ | |
3dabc715 | 80 | skb = genlmsg_new(size, GFP_KERNEL); |
c757249a SN |
81 | if (!skb) |
82 | return -ENOMEM; | |
83 | ||
84 | if (!info) { | |
85 | int seq = get_cpu_var(taskstats_seqnum)++; | |
86 | put_cpu_var(taskstats_seqnum); | |
87 | ||
17c157c8 | 88 | reply = genlmsg_put(skb, 0, seq, &family, 0, cmd); |
c757249a | 89 | } else |
17c157c8 | 90 | reply = genlmsg_put_reply(skb, info, &family, 0, cmd); |
c757249a SN |
91 | if (reply == NULL) { |
92 | nlmsg_free(skb); | |
93 | return -EINVAL; | |
94 | } | |
95 | ||
96 | *skbp = skb; | |
97 | *replyp = reply; | |
98 | return 0; | |
99 | } | |
100 | ||
f9fd8914 SN |
101 | /* |
102 | * Send taskstats data in @skb to listener with nl_pid @pid | |
103 | */ | |
104 | static int send_reply(struct sk_buff *skb, pid_t pid) | |
c757249a SN |
105 | { |
106 | struct genlmsghdr *genlhdr = nlmsg_data((struct nlmsghdr *)skb->data); | |
f9fd8914 | 107 | void *reply = genlmsg_data(genlhdr); |
c757249a SN |
108 | int rc; |
109 | ||
c757249a SN |
110 | rc = genlmsg_end(skb, reply); |
111 | if (rc < 0) { | |
112 | nlmsg_free(skb); | |
113 | return rc; | |
114 | } | |
115 | ||
c757249a SN |
116 | return genlmsg_unicast(skb, pid); |
117 | } | |
118 | ||
f9fd8914 SN |
119 | /* |
120 | * Send taskstats data in @skb to listeners registered for @cpu's exit data | |
121 | */ | |
115085ea ON |
122 | static void send_cpu_listeners(struct sk_buff *skb, |
123 | struct listener_list *listeners) | |
f9fd8914 SN |
124 | { |
125 | struct genlmsghdr *genlhdr = nlmsg_data((struct nlmsghdr *)skb->data); | |
f9fd8914 SN |
126 | struct listener *s, *tmp; |
127 | struct sk_buff *skb_next, *skb_cur = skb; | |
128 | void *reply = genlmsg_data(genlhdr); | |
d94a0415 | 129 | int rc, delcount = 0; |
f9fd8914 SN |
130 | |
131 | rc = genlmsg_end(skb, reply); | |
132 | if (rc < 0) { | |
133 | nlmsg_free(skb); | |
d94a0415 | 134 | return; |
f9fd8914 SN |
135 | } |
136 | ||
137 | rc = 0; | |
bb129994 | 138 | down_read(&listeners->sem); |
d94a0415 | 139 | list_for_each_entry(s, &listeners->list, list) { |
f9fd8914 SN |
140 | skb_next = NULL; |
141 | if (!list_is_last(&s->list, &listeners->list)) { | |
142 | skb_next = skb_clone(skb_cur, GFP_KERNEL); | |
d94a0415 | 143 | if (!skb_next) |
f9fd8914 | 144 | break; |
f9fd8914 | 145 | } |
d94a0415 SN |
146 | rc = genlmsg_unicast(skb_cur, s->pid); |
147 | if (rc == -ECONNREFUSED) { | |
bb129994 SN |
148 | s->valid = 0; |
149 | delcount++; | |
f9fd8914 SN |
150 | } |
151 | skb_cur = skb_next; | |
152 | } | |
bb129994 | 153 | up_read(&listeners->sem); |
f9fd8914 | 154 | |
d94a0415 SN |
155 | if (skb_cur) |
156 | nlmsg_free(skb_cur); | |
157 | ||
bb129994 | 158 | if (!delcount) |
d94a0415 | 159 | return; |
bb129994 SN |
160 | |
161 | /* Delete invalidated entries */ | |
162 | down_write(&listeners->sem); | |
163 | list_for_each_entry_safe(s, tmp, &listeners->list, list) { | |
164 | if (!s->valid) { | |
165 | list_del(&s->list); | |
166 | kfree(s); | |
167 | } | |
168 | } | |
169 | up_write(&listeners->sem); | |
f9fd8914 SN |
170 | } |
171 | ||
a98b6094 | 172 | static int fill_pid(pid_t pid, struct task_struct *tsk, |
c757249a SN |
173 | struct taskstats *stats) |
174 | { | |
7d94dddd | 175 | int rc = 0; |
c757249a | 176 | |
a98b6094 ON |
177 | if (!tsk) { |
178 | rcu_read_lock(); | |
c757249a | 179 | tsk = find_task_by_pid(pid); |
a98b6094 ON |
180 | if (tsk) |
181 | get_task_struct(tsk); | |
182 | rcu_read_unlock(); | |
183 | if (!tsk) | |
c757249a | 184 | return -ESRCH; |
c757249a SN |
185 | } else |
186 | get_task_struct(tsk); | |
187 | ||
51de4d90 | 188 | memset(stats, 0, sizeof(*stats)); |
c757249a SN |
189 | /* |
190 | * Each accounting subsystem adds calls to its functions to | |
191 | * fill in relevant parts of struct taskstsats as follows | |
192 | * | |
7d94dddd | 193 | * per-task-foo(stats, tsk); |
c757249a SN |
194 | */ |
195 | ||
7d94dddd | 196 | delayacct_add_tsk(stats, tsk); |
f3cef7a9 JL |
197 | |
198 | /* fill in basic acct fields */ | |
6f44993f | 199 | stats->version = TASKSTATS_VERSION; |
f3cef7a9 | 200 | bacct_add_tsk(stats, tsk); |
6f44993f | 201 | |
9acc1853 JL |
202 | /* fill in extended acct fields */ |
203 | xacct_add_tsk(stats, tsk); | |
204 | ||
6f44993f | 205 | /* Define err: label here if needed */ |
c757249a SN |
206 | put_task_struct(tsk); |
207 | return rc; | |
208 | ||
209 | } | |
210 | ||
a98b6094 | 211 | static int fill_tgid(pid_t tgid, struct task_struct *first, |
c757249a SN |
212 | struct taskstats *stats) |
213 | { | |
a98b6094 | 214 | struct task_struct *tsk; |
ad4ecbcb | 215 | unsigned long flags; |
a98b6094 | 216 | int rc = -ESRCH; |
c757249a | 217 | |
ad4ecbcb SN |
218 | /* |
219 | * Add additional stats from live tasks except zombie thread group | |
220 | * leaders who are already counted with the dead tasks | |
221 | */ | |
a98b6094 ON |
222 | rcu_read_lock(); |
223 | if (!first) | |
c757249a | 224 | first = find_task_by_pid(tgid); |
ad4ecbcb | 225 | |
a98b6094 ON |
226 | if (!first || !lock_task_sighand(first, &flags)) |
227 | goto out; | |
ad4ecbcb | 228 | |
a98b6094 ON |
229 | if (first->signal->stats) |
230 | memcpy(stats, first->signal->stats, sizeof(*stats)); | |
51de4d90 ON |
231 | else |
232 | memset(stats, 0, sizeof(*stats)); | |
fca178c0 | 233 | |
a98b6094 | 234 | tsk = first; |
c757249a | 235 | do { |
d7c3f5f2 | 236 | if (tsk->exit_state) |
ad4ecbcb | 237 | continue; |
c757249a | 238 | /* |
ad4ecbcb | 239 | * Accounting subsystem can call its functions here to |
c757249a SN |
240 | * fill in relevant parts of struct taskstsats as follows |
241 | * | |
ad4ecbcb | 242 | * per-task-foo(stats, tsk); |
c757249a | 243 | */ |
ad4ecbcb | 244 | delayacct_add_tsk(stats, tsk); |
6f44993f | 245 | |
c757249a | 246 | } while_each_thread(first, tsk); |
6f44993f | 247 | |
a98b6094 ON |
248 | unlock_task_sighand(first, &flags); |
249 | rc = 0; | |
250 | out: | |
251 | rcu_read_unlock(); | |
252 | ||
253 | stats->version = TASKSTATS_VERSION; | |
c757249a | 254 | /* |
ad4ecbcb SN |
255 | * Accounting subsytems can also add calls here to modify |
256 | * fields of taskstats. | |
c757249a | 257 | */ |
a98b6094 | 258 | return rc; |
ad4ecbcb SN |
259 | } |
260 | ||
261 | ||
262 | static void fill_tgid_exit(struct task_struct *tsk) | |
263 | { | |
264 | unsigned long flags; | |
265 | ||
b8534d7b | 266 | spin_lock_irqsave(&tsk->sighand->siglock, flags); |
ad4ecbcb SN |
267 | if (!tsk->signal->stats) |
268 | goto ret; | |
269 | ||
270 | /* | |
271 | * Each accounting subsystem calls its functions here to | |
272 | * accumalate its per-task stats for tsk, into the per-tgid structure | |
273 | * | |
274 | * per-task-foo(tsk->signal->stats, tsk); | |
275 | */ | |
276 | delayacct_add_tsk(tsk->signal->stats, tsk); | |
277 | ret: | |
b8534d7b | 278 | spin_unlock_irqrestore(&tsk->sighand->siglock, flags); |
ad4ecbcb | 279 | return; |
c757249a SN |
280 | } |
281 | ||
f9fd8914 SN |
282 | static int add_del_listener(pid_t pid, cpumask_t *maskp, int isadd) |
283 | { | |
284 | struct listener_list *listeners; | |
285 | struct listener *s, *tmp; | |
286 | unsigned int cpu; | |
287 | cpumask_t mask = *maskp; | |
ad4ecbcb | 288 | |
f9fd8914 SN |
289 | if (!cpus_subset(mask, cpu_possible_map)) |
290 | return -EINVAL; | |
291 | ||
292 | if (isadd == REGISTER) { | |
293 | for_each_cpu_mask(cpu, mask) { | |
294 | s = kmalloc_node(sizeof(struct listener), GFP_KERNEL, | |
295 | cpu_to_node(cpu)); | |
296 | if (!s) | |
297 | goto cleanup; | |
298 | s->pid = pid; | |
299 | INIT_LIST_HEAD(&s->list); | |
bb129994 | 300 | s->valid = 1; |
f9fd8914 SN |
301 | |
302 | listeners = &per_cpu(listener_array, cpu); | |
303 | down_write(&listeners->sem); | |
304 | list_add(&s->list, &listeners->list); | |
305 | up_write(&listeners->sem); | |
306 | } | |
307 | return 0; | |
308 | } | |
309 | ||
310 | /* Deregister or cleanup */ | |
311 | cleanup: | |
312 | for_each_cpu_mask(cpu, mask) { | |
313 | listeners = &per_cpu(listener_array, cpu); | |
314 | down_write(&listeners->sem); | |
315 | list_for_each_entry_safe(s, tmp, &listeners->list, list) { | |
316 | if (s->pid == pid) { | |
317 | list_del(&s->list); | |
318 | kfree(s); | |
319 | break; | |
320 | } | |
321 | } | |
322 | up_write(&listeners->sem); | |
323 | } | |
324 | return 0; | |
325 | } | |
326 | ||
327 | static int parse(struct nlattr *na, cpumask_t *mask) | |
328 | { | |
329 | char *data; | |
330 | int len; | |
331 | int ret; | |
332 | ||
333 | if (na == NULL) | |
334 | return 1; | |
335 | len = nla_len(na); | |
336 | if (len > TASKSTATS_CPUMASK_MAXLEN) | |
337 | return -E2BIG; | |
338 | if (len < 1) | |
339 | return -EINVAL; | |
340 | data = kmalloc(len, GFP_KERNEL); | |
341 | if (!data) | |
342 | return -ENOMEM; | |
343 | nla_strlcpy(data, na, len); | |
344 | ret = cpulist_parse(data, *mask); | |
345 | kfree(data); | |
346 | return ret; | |
347 | } | |
348 | ||
51de4d90 | 349 | static struct taskstats *mk_reply(struct sk_buff *skb, int type, u32 pid) |
68062b86 | 350 | { |
51de4d90 | 351 | struct nlattr *na, *ret; |
68062b86 ON |
352 | int aggr; |
353 | ||
354 | aggr = TASKSTATS_TYPE_AGGR_TGID; | |
355 | if (type == TASKSTATS_TYPE_PID) | |
356 | aggr = TASKSTATS_TYPE_AGGR_PID; | |
357 | ||
358 | na = nla_nest_start(skb, aggr); | |
51de4d90 ON |
359 | if (nla_put(skb, type, sizeof(pid), &pid) < 0) |
360 | goto err; | |
361 | ret = nla_reserve(skb, TASKSTATS_TYPE_STATS, sizeof(struct taskstats)); | |
362 | if (!ret) | |
363 | goto err; | |
68062b86 ON |
364 | nla_nest_end(skb, na); |
365 | ||
51de4d90 ON |
366 | return nla_data(ret); |
367 | err: | |
368 | return NULL; | |
68062b86 ON |
369 | } |
370 | ||
f9fd8914 | 371 | static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info) |
c757249a SN |
372 | { |
373 | int rc = 0; | |
374 | struct sk_buff *rep_skb; | |
51de4d90 | 375 | struct taskstats *stats; |
c757249a SN |
376 | void *reply; |
377 | size_t size; | |
f9fd8914 SN |
378 | cpumask_t mask; |
379 | ||
380 | rc = parse(info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK], &mask); | |
381 | if (rc < 0) | |
382 | return rc; | |
383 | if (rc == 0) | |
384 | return add_del_listener(info->snd_pid, &mask, REGISTER); | |
385 | ||
386 | rc = parse(info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK], &mask); | |
387 | if (rc < 0) | |
388 | return rc; | |
389 | if (rc == 0) | |
390 | return add_del_listener(info->snd_pid, &mask, DEREGISTER); | |
c757249a SN |
391 | |
392 | /* | |
393 | * Size includes space for nested attributes | |
394 | */ | |
395 | size = nla_total_size(sizeof(u32)) + | |
396 | nla_total_size(sizeof(struct taskstats)) + nla_total_size(0); | |
397 | ||
c757249a SN |
398 | rc = prepare_reply(info, TASKSTATS_CMD_NEW, &rep_skb, &reply, size); |
399 | if (rc < 0) | |
400 | return rc; | |
401 | ||
51de4d90 | 402 | rc = -EINVAL; |
c757249a SN |
403 | if (info->attrs[TASKSTATS_CMD_ATTR_PID]) { |
404 | u32 pid = nla_get_u32(info->attrs[TASKSTATS_CMD_ATTR_PID]); | |
51de4d90 ON |
405 | stats = mk_reply(rep_skb, TASKSTATS_TYPE_PID, pid); |
406 | if (!stats) | |
407 | goto nla_err; | |
c757249a | 408 | |
51de4d90 ON |
409 | rc = fill_pid(pid, NULL, stats); |
410 | if (rc < 0) | |
411 | goto nla_err; | |
c757249a SN |
412 | } else if (info->attrs[TASKSTATS_CMD_ATTR_TGID]) { |
413 | u32 tgid = nla_get_u32(info->attrs[TASKSTATS_CMD_ATTR_TGID]); | |
51de4d90 ON |
414 | stats = mk_reply(rep_skb, TASKSTATS_TYPE_TGID, tgid); |
415 | if (!stats) | |
416 | goto nla_err; | |
c757249a | 417 | |
51de4d90 ON |
418 | rc = fill_tgid(tgid, NULL, stats); |
419 | if (rc < 0) | |
420 | goto nla_err; | |
421 | } else | |
c757249a | 422 | goto err; |
c757249a | 423 | |
f9fd8914 | 424 | return send_reply(rep_skb, info->snd_pid); |
c757249a | 425 | |
51de4d90 ON |
426 | nla_err: |
427 | genlmsg_cancel(rep_skb, reply); | |
c757249a SN |
428 | err: |
429 | nlmsg_free(rep_skb); | |
430 | return rc; | |
431 | } | |
432 | ||
34ec1234 ON |
433 | static struct taskstats *taskstats_tgid_alloc(struct task_struct *tsk) |
434 | { | |
435 | struct signal_struct *sig = tsk->signal; | |
436 | struct taskstats *stats; | |
437 | ||
438 | if (sig->stats || thread_group_empty(tsk)) | |
439 | goto ret; | |
440 | ||
441 | /* No problem if kmem_cache_zalloc() fails */ | |
442 | stats = kmem_cache_zalloc(taskstats_cache, GFP_KERNEL); | |
443 | ||
444 | spin_lock_irq(&tsk->sighand->siglock); | |
445 | if (!sig->stats) { | |
446 | sig->stats = stats; | |
447 | stats = NULL; | |
448 | } | |
449 | spin_unlock_irq(&tsk->sighand->siglock); | |
450 | ||
451 | if (stats) | |
452 | kmem_cache_free(taskstats_cache, stats); | |
453 | ret: | |
454 | return sig->stats; | |
455 | } | |
456 | ||
c757249a | 457 | /* Send pid data out on exit */ |
115085ea | 458 | void taskstats_exit(struct task_struct *tsk, int group_dead) |
c757249a SN |
459 | { |
460 | int rc; | |
115085ea | 461 | struct listener_list *listeners; |
51de4d90 | 462 | struct taskstats *stats; |
c757249a SN |
463 | struct sk_buff *rep_skb; |
464 | void *reply; | |
465 | size_t size; | |
466 | int is_thread_group; | |
c757249a | 467 | |
4a279ff1 | 468 | if (!family_registered) |
c757249a SN |
469 | return; |
470 | ||
c757249a SN |
471 | /* |
472 | * Size includes space for nested attributes | |
473 | */ | |
474 | size = nla_total_size(sizeof(u32)) + | |
475 | nla_total_size(sizeof(struct taskstats)) + nla_total_size(0); | |
476 | ||
34ec1234 | 477 | is_thread_group = !!taskstats_tgid_alloc(tsk); |
4a279ff1 ON |
478 | if (is_thread_group) { |
479 | /* PID + STATS + TGID + STATS */ | |
480 | size = 2 * size; | |
481 | /* fill the tsk->signal->stats structure */ | |
482 | fill_tgid_exit(tsk); | |
483 | } | |
484 | ||
115085ea ON |
485 | listeners = &__raw_get_cpu_var(listener_array); |
486 | if (list_empty(&listeners->list)) | |
487 | return; | |
488 | ||
c757249a SN |
489 | rc = prepare_reply(NULL, TASKSTATS_CMD_NEW, &rep_skb, &reply, size); |
490 | if (rc < 0) | |
51de4d90 | 491 | return; |
c757249a | 492 | |
51de4d90 ON |
493 | stats = mk_reply(rep_skb, TASKSTATS_TYPE_PID, tsk->pid); |
494 | if (!stats) | |
495 | goto nla_err; | |
c757249a | 496 | |
51de4d90 ON |
497 | rc = fill_pid(tsk->pid, tsk, stats); |
498 | if (rc < 0) | |
499 | goto nla_err; | |
c757249a | 500 | |
c757249a | 501 | /* |
ad4ecbcb | 502 | * Doesn't matter if tsk is the leader or the last group member leaving |
c757249a | 503 | */ |
68062b86 | 504 | if (!is_thread_group || !group_dead) |
ad4ecbcb | 505 | goto send; |
c757249a | 506 | |
51de4d90 ON |
507 | stats = mk_reply(rep_skb, TASKSTATS_TYPE_TGID, tsk->tgid); |
508 | if (!stats) | |
509 | goto nla_err; | |
510 | ||
511 | memcpy(stats, tsk->signal->stats, sizeof(*stats)); | |
c757249a | 512 | |
ad4ecbcb | 513 | send: |
115085ea | 514 | send_cpu_listeners(rep_skb, listeners); |
ad4ecbcb | 515 | return; |
c757249a | 516 | |
51de4d90 | 517 | nla_err: |
c757249a | 518 | genlmsg_cancel(rep_skb, reply); |
c757249a | 519 | nlmsg_free(rep_skb); |
c757249a SN |
520 | } |
521 | ||
522 | static struct genl_ops taskstats_ops = { | |
523 | .cmd = TASKSTATS_CMD_GET, | |
f9fd8914 | 524 | .doit = taskstats_user_cmd, |
c757249a SN |
525 | .policy = taskstats_cmd_get_policy, |
526 | }; | |
527 | ||
528 | /* Needed early in initialization */ | |
529 | void __init taskstats_init_early(void) | |
530 | { | |
f9fd8914 SN |
531 | unsigned int i; |
532 | ||
c757249a SN |
533 | taskstats_cache = kmem_cache_create("taskstats_cache", |
534 | sizeof(struct taskstats), | |
535 | 0, SLAB_PANIC, NULL, NULL); | |
f9fd8914 SN |
536 | for_each_possible_cpu(i) { |
537 | INIT_LIST_HEAD(&(per_cpu(listener_array, i).list)); | |
538 | init_rwsem(&(per_cpu(listener_array, i).sem)); | |
539 | } | |
c757249a SN |
540 | } |
541 | ||
542 | static int __init taskstats_init(void) | |
543 | { | |
544 | int rc; | |
545 | ||
546 | rc = genl_register_family(&family); | |
547 | if (rc) | |
548 | return rc; | |
549 | ||
550 | rc = genl_register_ops(&family, &taskstats_ops); | |
551 | if (rc < 0) | |
552 | goto err; | |
553 | ||
554 | family_registered = 1; | |
555 | return 0; | |
556 | err: | |
557 | genl_unregister_family(&family); | |
558 | return rc; | |
559 | } | |
560 | ||
561 | /* | |
562 | * late initcall ensures initialization of statistics collection | |
563 | * mechanisms precedes initialization of the taskstats interface | |
564 | */ | |
565 | late_initcall(taskstats_init); |