taskstats.c 16 KB

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