taskstats.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710
  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. #include <linux/kernel.h>
  19. #include <linux/taskstats_kern.h>
  20. #include <linux/tsacct_kern.h>
  21. #include <linux/delayacct.h>
  22. #include <linux/cpumask.h>
  23. #include <linux/percpu.h>
  24. #include <linux/slab.h>
  25. #include <linux/cgroupstats.h>
  26. #include <linux/cgroup.h>
  27. #include <linux/fs.h>
  28. #include <linux/file.h>
  29. #include <linux/pid_namespace.h>
  30. #include <net/genetlink.h>
  31. #include <linux/atomic.h>
  32. #include <linux/sched/cputime.h>
  33. /*
  34. * Maximum length of a cpumask that can be specified in
  35. * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
  36. */
  37. #define TASKSTATS_CPUMASK_MAXLEN (100+6*NR_CPUS)
  38. static DEFINE_PER_CPU(__u32, taskstats_seqnum);
  39. static int family_registered;
  40. struct kmem_cache *taskstats_cache;
  41. static struct genl_family family;
  42. static const struct nla_policy taskstats_cmd_get_policy[TASKSTATS_CMD_ATTR_MAX+1] = {
  43. [TASKSTATS_CMD_ATTR_PID] = { .type = NLA_U32 },
  44. [TASKSTATS_CMD_ATTR_TGID] = { .type = NLA_U32 },
  45. [TASKSTATS_CMD_ATTR_REGISTER_CPUMASK] = { .type = NLA_STRING },
  46. [TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK] = { .type = NLA_STRING },};
  47. /*
  48. * We have to use TASKSTATS_CMD_ATTR_MAX here, it is the maxattr in the family.
  49. * Make sure they are always aligned.
  50. */
  51. static const struct nla_policy cgroupstats_cmd_get_policy[TASKSTATS_CMD_ATTR_MAX+1] = {
  52. [CGROUPSTATS_CMD_ATTR_FD] = { .type = NLA_U32 },
  53. };
  54. struct listener {
  55. struct list_head list;
  56. pid_t pid;
  57. char valid;
  58. };
  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. enum actions {
  65. REGISTER,
  66. DEREGISTER,
  67. CPU_DONT_CARE
  68. };
  69. static int prepare_reply(struct genl_info *info, u8 cmd, struct sk_buff **skbp,
  70. size_t size)
  71. {
  72. struct sk_buff *skb;
  73. void *reply;
  74. /*
  75. * If new attributes are added, please revisit this allocation
  76. */
  77. skb = genlmsg_new(size, GFP_KERNEL);
  78. if (!skb)
  79. return -ENOMEM;
  80. if (!info) {
  81. int seq = this_cpu_inc_return(taskstats_seqnum) - 1;
  82. reply = genlmsg_put(skb, 0, seq, &family, 0, cmd);
  83. } else
  84. reply = genlmsg_put_reply(skb, info, &family, 0, cmd);
  85. if (reply == NULL) {
  86. nlmsg_free(skb);
  87. return -EINVAL;
  88. }
  89. *skbp = skb;
  90. return 0;
  91. }
  92. /*
  93. * Send taskstats data in @skb to listener with nl_pid @pid
  94. */
  95. static int send_reply(struct sk_buff *skb, struct genl_info *info)
  96. {
  97. struct genlmsghdr *genlhdr = nlmsg_data(nlmsg_hdr(skb));
  98. void *reply = genlmsg_data(genlhdr);
  99. genlmsg_end(skb, reply);
  100. return genlmsg_reply(skb, info);
  101. }
  102. /*
  103. * Send taskstats data in @skb to listeners registered for @cpu's exit data
  104. */
  105. static void send_cpu_listeners(struct sk_buff *skb,
  106. struct listener_list *listeners)
  107. {
  108. struct genlmsghdr *genlhdr = nlmsg_data(nlmsg_hdr(skb));
  109. struct listener *s, *tmp;
  110. struct sk_buff *skb_next, *skb_cur = skb;
  111. void *reply = genlmsg_data(genlhdr);
  112. int rc, delcount = 0;
  113. genlmsg_end(skb, reply);
  114. rc = 0;
  115. down_read(&listeners->sem);
  116. list_for_each_entry(s, &listeners->list, list) {
  117. skb_next = NULL;
  118. if (!list_is_last(&s->list, &listeners->list)) {
  119. skb_next = skb_clone(skb_cur, GFP_KERNEL);
  120. if (!skb_next)
  121. break;
  122. }
  123. rc = genlmsg_unicast(&init_net, skb_cur, s->pid);
  124. if (rc == -ECONNREFUSED) {
  125. s->valid = 0;
  126. delcount++;
  127. }
  128. skb_cur = skb_next;
  129. }
  130. up_read(&listeners->sem);
  131. if (skb_cur)
  132. nlmsg_free(skb_cur);
  133. if (!delcount)
  134. return;
  135. /* Delete invalidated entries */
  136. down_write(&listeners->sem);
  137. list_for_each_entry_safe(s, tmp, &listeners->list, list) {
  138. if (!s->valid) {
  139. list_del(&s->list);
  140. kfree(s);
  141. }
  142. }
  143. up_write(&listeners->sem);
  144. }
  145. static void fill_stats(struct user_namespace *user_ns,
  146. struct pid_namespace *pid_ns,
  147. struct task_struct *tsk, struct taskstats *stats)
  148. {
  149. memset(stats, 0, sizeof(*stats));
  150. /*
  151. * Each accounting subsystem adds calls to its functions to
  152. * fill in relevant parts of struct taskstsats as follows
  153. *
  154. * per-task-foo(stats, tsk);
  155. */
  156. delayacct_add_tsk(stats, tsk);
  157. /* fill in basic acct fields */
  158. stats->version = TASKSTATS_VERSION;
  159. stats->nvcsw = tsk->nvcsw;
  160. stats->nivcsw = tsk->nivcsw;
  161. bacct_add_tsk(user_ns, pid_ns, stats, tsk);
  162. /* fill in extended acct fields */
  163. xacct_add_tsk(stats, tsk);
  164. }
  165. static int fill_stats_for_pid(pid_t pid, struct taskstats *stats)
  166. {
  167. struct task_struct *tsk;
  168. tsk = find_get_task_by_vpid(pid);
  169. if (!tsk)
  170. return -ESRCH;
  171. fill_stats(current_user_ns(), task_active_pid_ns(current), tsk, stats);
  172. put_task_struct(tsk);
  173. return 0;
  174. }
  175. static int fill_stats_for_tgid(pid_t tgid, struct taskstats *stats)
  176. {
  177. struct task_struct *tsk, *first;
  178. unsigned long flags;
  179. int rc = -ESRCH;
  180. u64 delta, utime, stime;
  181. u64 start_time;
  182. /*
  183. * Add additional stats from live tasks except zombie thread group
  184. * leaders who are already counted with the dead tasks
  185. */
  186. rcu_read_lock();
  187. first = find_task_by_vpid(tgid);
  188. if (!first || !lock_task_sighand(first, &flags))
  189. goto out;
  190. if (first->signal->stats)
  191. memcpy(stats, first->signal->stats, sizeof(*stats));
  192. else
  193. memset(stats, 0, sizeof(*stats));
  194. tsk = first;
  195. start_time = ktime_get_ns();
  196. do {
  197. if (tsk->exit_state)
  198. continue;
  199. /*
  200. * Accounting subsystem can call its functions here to
  201. * fill in relevant parts of struct taskstsats as follows
  202. *
  203. * per-task-foo(stats, tsk);
  204. */
  205. delayacct_add_tsk(stats, tsk);
  206. /* calculate task elapsed time in nsec */
  207. delta = start_time - tsk->start_time;
  208. /* Convert to micro seconds */
  209. do_div(delta, NSEC_PER_USEC);
  210. stats->ac_etime += delta;
  211. task_cputime(tsk, &utime, &stime);
  212. stats->ac_utime += div_u64(utime, NSEC_PER_USEC);
  213. stats->ac_stime += div_u64(stime, NSEC_PER_USEC);
  214. stats->nvcsw += tsk->nvcsw;
  215. stats->nivcsw += tsk->nivcsw;
  216. } while_each_thread(first, tsk);
  217. unlock_task_sighand(first, &flags);
  218. rc = 0;
  219. out:
  220. rcu_read_unlock();
  221. stats->version = TASKSTATS_VERSION;
  222. /*
  223. * Accounting subsystems can also add calls here to modify
  224. * fields of taskstats.
  225. */
  226. return rc;
  227. }
  228. static void fill_tgid_exit(struct task_struct *tsk)
  229. {
  230. unsigned long flags;
  231. spin_lock_irqsave(&tsk->sighand->siglock, flags);
  232. if (!tsk->signal->stats)
  233. goto ret;
  234. /*
  235. * Each accounting subsystem calls its functions here to
  236. * accumalate its per-task stats for tsk, into the per-tgid structure
  237. *
  238. * per-task-foo(tsk->signal->stats, tsk);
  239. */
  240. delayacct_add_tsk(tsk->signal->stats, tsk);
  241. ret:
  242. spin_unlock_irqrestore(&tsk->sighand->siglock, flags);
  243. return;
  244. }
  245. static int add_del_listener(pid_t pid, const struct cpumask *mask, int isadd)
  246. {
  247. struct listener_list *listeners;
  248. struct listener *s, *tmp, *s2;
  249. unsigned int cpu;
  250. int ret = 0;
  251. if (!cpumask_subset(mask, cpu_possible_mask))
  252. return -EINVAL;
  253. if (current_user_ns() != &init_user_ns)
  254. return -EINVAL;
  255. if (task_active_pid_ns(current) != &init_pid_ns)
  256. return -EINVAL;
  257. if (isadd == REGISTER) {
  258. for_each_cpu(cpu, mask) {
  259. s = kmalloc_node(sizeof(struct listener),
  260. GFP_KERNEL, cpu_to_node(cpu));
  261. if (!s) {
  262. ret = -ENOMEM;
  263. goto cleanup;
  264. }
  265. s->pid = pid;
  266. s->valid = 1;
  267. listeners = &per_cpu(listener_array, cpu);
  268. down_write(&listeners->sem);
  269. list_for_each_entry(s2, &listeners->list, list) {
  270. if (s2->pid == pid && s2->valid)
  271. goto exists;
  272. }
  273. list_add(&s->list, &listeners->list);
  274. s = NULL;
  275. exists:
  276. up_write(&listeners->sem);
  277. kfree(s); /* nop if NULL */
  278. }
  279. return 0;
  280. }
  281. /* Deregister or cleanup */
  282. cleanup:
  283. for_each_cpu(cpu, mask) {
  284. listeners = &per_cpu(listener_array, cpu);
  285. down_write(&listeners->sem);
  286. list_for_each_entry_safe(s, tmp, &listeners->list, list) {
  287. if (s->pid == pid) {
  288. list_del(&s->list);
  289. kfree(s);
  290. break;
  291. }
  292. }
  293. up_write(&listeners->sem);
  294. }
  295. return ret;
  296. }
  297. static int parse(struct nlattr *na, struct cpumask *mask)
  298. {
  299. char *data;
  300. int len;
  301. int ret;
  302. if (na == NULL)
  303. return 1;
  304. len = nla_len(na);
  305. if (len > TASKSTATS_CPUMASK_MAXLEN)
  306. return -E2BIG;
  307. if (len < 1)
  308. return -EINVAL;
  309. data = kmalloc(len, GFP_KERNEL);
  310. if (!data)
  311. return -ENOMEM;
  312. nla_strlcpy(data, na, len);
  313. ret = cpulist_parse(data, mask);
  314. kfree(data);
  315. return ret;
  316. }
  317. static struct taskstats *mk_reply(struct sk_buff *skb, int type, u32 pid)
  318. {
  319. struct nlattr *na, *ret;
  320. int aggr;
  321. aggr = (type == TASKSTATS_TYPE_PID)
  322. ? TASKSTATS_TYPE_AGGR_PID
  323. : TASKSTATS_TYPE_AGGR_TGID;
  324. na = nla_nest_start(skb, aggr);
  325. if (!na)
  326. goto err;
  327. if (nla_put(skb, type, sizeof(pid), &pid) < 0) {
  328. nla_nest_cancel(skb, na);
  329. goto err;
  330. }
  331. ret = nla_reserve_64bit(skb, TASKSTATS_TYPE_STATS,
  332. sizeof(struct taskstats), TASKSTATS_TYPE_NULL);
  333. if (!ret) {
  334. nla_nest_cancel(skb, na);
  335. goto err;
  336. }
  337. nla_nest_end(skb, na);
  338. return nla_data(ret);
  339. err:
  340. return NULL;
  341. }
  342. static int cgroupstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
  343. {
  344. int rc = 0;
  345. struct sk_buff *rep_skb;
  346. struct cgroupstats *stats;
  347. struct nlattr *na;
  348. size_t size;
  349. u32 fd;
  350. struct fd f;
  351. na = info->attrs[CGROUPSTATS_CMD_ATTR_FD];
  352. if (!na)
  353. return -EINVAL;
  354. fd = nla_get_u32(info->attrs[CGROUPSTATS_CMD_ATTR_FD]);
  355. f = fdget(fd);
  356. if (!f.file)
  357. return 0;
  358. size = nla_total_size(sizeof(struct cgroupstats));
  359. rc = prepare_reply(info, CGROUPSTATS_CMD_NEW, &rep_skb,
  360. size);
  361. if (rc < 0)
  362. goto err;
  363. na = nla_reserve(rep_skb, CGROUPSTATS_TYPE_CGROUP_STATS,
  364. sizeof(struct cgroupstats));
  365. if (na == NULL) {
  366. nlmsg_free(rep_skb);
  367. rc = -EMSGSIZE;
  368. goto err;
  369. }
  370. stats = nla_data(na);
  371. memset(stats, 0, sizeof(*stats));
  372. rc = cgroupstats_build(stats, f.file->f_path.dentry);
  373. if (rc < 0) {
  374. nlmsg_free(rep_skb);
  375. goto err;
  376. }
  377. rc = send_reply(rep_skb, info);
  378. err:
  379. fdput(f);
  380. return rc;
  381. }
  382. static int cmd_attr_register_cpumask(struct genl_info *info)
  383. {
  384. cpumask_var_t mask;
  385. int rc;
  386. if (!alloc_cpumask_var(&mask, GFP_KERNEL))
  387. return -ENOMEM;
  388. rc = parse(info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK], mask);
  389. if (rc < 0)
  390. goto out;
  391. rc = add_del_listener(info->snd_portid, mask, REGISTER);
  392. out:
  393. free_cpumask_var(mask);
  394. return rc;
  395. }
  396. static int cmd_attr_deregister_cpumask(struct genl_info *info)
  397. {
  398. cpumask_var_t mask;
  399. int rc;
  400. if (!alloc_cpumask_var(&mask, GFP_KERNEL))
  401. return -ENOMEM;
  402. rc = parse(info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK], mask);
  403. if (rc < 0)
  404. goto out;
  405. rc = add_del_listener(info->snd_portid, mask, DEREGISTER);
  406. out:
  407. free_cpumask_var(mask);
  408. return rc;
  409. }
  410. static size_t taskstats_packet_size(void)
  411. {
  412. size_t size;
  413. size = nla_total_size(sizeof(u32)) +
  414. nla_total_size_64bit(sizeof(struct taskstats)) +
  415. nla_total_size(0);
  416. return size;
  417. }
  418. static int cmd_attr_pid(struct genl_info *info)
  419. {
  420. struct taskstats *stats;
  421. struct sk_buff *rep_skb;
  422. size_t size;
  423. u32 pid;
  424. int rc;
  425. size = taskstats_packet_size();
  426. rc = prepare_reply(info, TASKSTATS_CMD_NEW, &rep_skb, size);
  427. if (rc < 0)
  428. return rc;
  429. rc = -EINVAL;
  430. pid = nla_get_u32(info->attrs[TASKSTATS_CMD_ATTR_PID]);
  431. stats = mk_reply(rep_skb, TASKSTATS_TYPE_PID, pid);
  432. if (!stats)
  433. goto err;
  434. rc = fill_stats_for_pid(pid, stats);
  435. if (rc < 0)
  436. goto err;
  437. return send_reply(rep_skb, info);
  438. err:
  439. nlmsg_free(rep_skb);
  440. return rc;
  441. }
  442. static int cmd_attr_tgid(struct genl_info *info)
  443. {
  444. struct taskstats *stats;
  445. struct sk_buff *rep_skb;
  446. size_t size;
  447. u32 tgid;
  448. int rc;
  449. size = taskstats_packet_size();
  450. rc = prepare_reply(info, TASKSTATS_CMD_NEW, &rep_skb, size);
  451. if (rc < 0)
  452. return rc;
  453. rc = -EINVAL;
  454. tgid = nla_get_u32(info->attrs[TASKSTATS_CMD_ATTR_TGID]);
  455. stats = mk_reply(rep_skb, TASKSTATS_TYPE_TGID, tgid);
  456. if (!stats)
  457. goto err;
  458. rc = fill_stats_for_tgid(tgid, stats);
  459. if (rc < 0)
  460. goto err;
  461. return send_reply(rep_skb, info);
  462. err:
  463. nlmsg_free(rep_skb);
  464. return rc;
  465. }
  466. static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
  467. {
  468. if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
  469. return cmd_attr_register_cpumask(info);
  470. else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
  471. return cmd_attr_deregister_cpumask(info);
  472. else if (info->attrs[TASKSTATS_CMD_ATTR_PID])
  473. return cmd_attr_pid(info);
  474. else if (info->attrs[TASKSTATS_CMD_ATTR_TGID])
  475. return cmd_attr_tgid(info);
  476. else
  477. return -EINVAL;
  478. }
  479. static struct taskstats *taskstats_tgid_alloc(struct task_struct *tsk)
  480. {
  481. struct signal_struct *sig = tsk->signal;
  482. struct taskstats *stats_new, *stats;
  483. /* Pairs with smp_store_release() below. */
  484. stats = smp_load_acquire(&sig->stats);
  485. if (stats || thread_group_empty(tsk))
  486. return stats;
  487. /* No problem if kmem_cache_zalloc() fails */
  488. stats_new = kmem_cache_zalloc(taskstats_cache, GFP_KERNEL);
  489. spin_lock_irq(&tsk->sighand->siglock);
  490. stats = sig->stats;
  491. if (!stats) {
  492. /*
  493. * Pairs with smp_store_release() above and order the
  494. * kmem_cache_zalloc().
  495. */
  496. smp_store_release(&sig->stats, stats_new);
  497. stats = stats_new;
  498. stats_new = NULL;
  499. }
  500. spin_unlock_irq(&tsk->sighand->siglock);
  501. if (stats_new)
  502. kmem_cache_free(taskstats_cache, stats_new);
  503. return stats;
  504. }
  505. /* Send pid data out on exit */
  506. void taskstats_exit(struct task_struct *tsk, int group_dead)
  507. {
  508. int rc;
  509. struct listener_list *listeners;
  510. struct taskstats *stats;
  511. struct sk_buff *rep_skb;
  512. size_t size;
  513. int is_thread_group;
  514. if (!family_registered)
  515. return;
  516. /*
  517. * Size includes space for nested attributes
  518. */
  519. size = taskstats_packet_size();
  520. is_thread_group = !!taskstats_tgid_alloc(tsk);
  521. if (is_thread_group) {
  522. /* PID + STATS + TGID + STATS */
  523. size = 2 * size;
  524. /* fill the tsk->signal->stats structure */
  525. fill_tgid_exit(tsk);
  526. }
  527. listeners = raw_cpu_ptr(&listener_array);
  528. if (list_empty(&listeners->list))
  529. return;
  530. rc = prepare_reply(NULL, TASKSTATS_CMD_NEW, &rep_skb, size);
  531. if (rc < 0)
  532. return;
  533. stats = mk_reply(rep_skb, TASKSTATS_TYPE_PID,
  534. task_pid_nr_ns(tsk, &init_pid_ns));
  535. if (!stats)
  536. goto err;
  537. fill_stats(&init_user_ns, &init_pid_ns, tsk, stats);
  538. /*
  539. * Doesn't matter if tsk is the leader or the last group member leaving
  540. */
  541. if (!is_thread_group || !group_dead)
  542. goto send;
  543. stats = mk_reply(rep_skb, TASKSTATS_TYPE_TGID,
  544. task_tgid_nr_ns(tsk, &init_pid_ns));
  545. if (!stats)
  546. goto err;
  547. memcpy(stats, tsk->signal->stats, sizeof(*stats));
  548. send:
  549. send_cpu_listeners(rep_skb, listeners);
  550. return;
  551. err:
  552. nlmsg_free(rep_skb);
  553. }
  554. static const struct genl_ops taskstats_ops[] = {
  555. {
  556. .cmd = TASKSTATS_CMD_GET,
  557. .doit = taskstats_user_cmd,
  558. .policy = taskstats_cmd_get_policy,
  559. .flags = GENL_ADMIN_PERM,
  560. },
  561. {
  562. .cmd = CGROUPSTATS_CMD_GET,
  563. .doit = cgroupstats_user_cmd,
  564. .policy = cgroupstats_cmd_get_policy,
  565. },
  566. };
  567. static struct genl_family family __ro_after_init = {
  568. .name = TASKSTATS_GENL_NAME,
  569. .version = TASKSTATS_GENL_VERSION,
  570. .maxattr = TASKSTATS_CMD_ATTR_MAX,
  571. .module = THIS_MODULE,
  572. .ops = taskstats_ops,
  573. .n_ops = ARRAY_SIZE(taskstats_ops),
  574. };
  575. /* Needed early in initialization */
  576. void __init taskstats_init_early(void)
  577. {
  578. unsigned int i;
  579. taskstats_cache = KMEM_CACHE(taskstats, SLAB_PANIC);
  580. for_each_possible_cpu(i) {
  581. INIT_LIST_HEAD(&(per_cpu(listener_array, i).list));
  582. init_rwsem(&(per_cpu(listener_array, i).sem));
  583. }
  584. }
  585. static int __init taskstats_init(void)
  586. {
  587. int rc;
  588. rc = genl_register_family(&family);
  589. if (rc)
  590. return rc;
  591. family_registered = 1;
  592. pr_info("registered taskstats version %d\n", TASKSTATS_GENL_VERSION);
  593. return 0;
  594. }
  595. /*
  596. * late initcall ensures initialization of statistics collection
  597. * mechanisms precedes initialization of the taskstats interface
  598. */
  599. late_initcall(taskstats_init);