taskstats.c 16 KB

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