taskstats.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701
  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 = 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;
  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), GFP_KERNEL,
  254. cpu_to_node(cpu));
  255. if (!s)
  256. goto cleanup;
  257. s->pid = pid;
  258. INIT_LIST_HEAD(&s->list);
  259. s->valid = 1;
  260. listeners = &per_cpu(listener_array, cpu);
  261. down_write(&listeners->sem);
  262. list_add(&s->list, &listeners->list);
  263. up_write(&listeners->sem);
  264. }
  265. return 0;
  266. }
  267. /* Deregister or cleanup */
  268. cleanup:
  269. for_each_cpu(cpu, mask) {
  270. listeners = &per_cpu(listener_array, cpu);
  271. down_write(&listeners->sem);
  272. list_for_each_entry_safe(s, tmp, &listeners->list, list) {
  273. if (s->pid == pid) {
  274. list_del(&s->list);
  275. kfree(s);
  276. break;
  277. }
  278. }
  279. up_write(&listeners->sem);
  280. }
  281. return 0;
  282. }
  283. static int parse(struct nlattr *na, struct cpumask *mask)
  284. {
  285. char *data;
  286. int len;
  287. int ret;
  288. if (na == NULL)
  289. return 1;
  290. len = nla_len(na);
  291. if (len > TASKSTATS_CPUMASK_MAXLEN)
  292. return -E2BIG;
  293. if (len < 1)
  294. return -EINVAL;
  295. data = kmalloc(len, GFP_KERNEL);
  296. if (!data)
  297. return -ENOMEM;
  298. nla_strlcpy(data, na, len);
  299. ret = cpulist_parse(data, mask);
  300. kfree(data);
  301. return ret;
  302. }
  303. #if defined(CONFIG_64BIT) && !defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS)
  304. #define TASKSTATS_NEEDS_PADDING 1
  305. #endif
  306. static struct taskstats *mk_reply(struct sk_buff *skb, int type, u32 pid)
  307. {
  308. struct nlattr *na, *ret;
  309. int aggr;
  310. aggr = (type == TASKSTATS_TYPE_PID)
  311. ? TASKSTATS_TYPE_AGGR_PID
  312. : TASKSTATS_TYPE_AGGR_TGID;
  313. /*
  314. * The taskstats structure is internally aligned on 8 byte
  315. * boundaries but the layout of the aggregrate reply, with
  316. * two NLA headers and the pid (each 4 bytes), actually
  317. * force the entire structure to be unaligned. This causes
  318. * the kernel to issue unaligned access warnings on some
  319. * architectures like ia64. Unfortunately, some software out there
  320. * doesn't properly unroll the NLA packet and assumes that the start
  321. * of the taskstats structure will always be 20 bytes from the start
  322. * of the netlink payload. Aligning the start of the taskstats
  323. * structure breaks this software, which we don't want. So, for now
  324. * the alignment only happens on architectures that require it
  325. * and those users will have to update to fixed versions of those
  326. * packages. Space is reserved in the packet only when needed.
  327. * This ifdef should be removed in several years e.g. 2012 once
  328. * we can be confident that fixed versions are installed on most
  329. * systems. We add the padding before the aggregate since the
  330. * aggregate is already a defined type.
  331. */
  332. #ifdef TASKSTATS_NEEDS_PADDING
  333. if (nla_put(skb, TASKSTATS_TYPE_NULL, 0, NULL) < 0)
  334. goto err;
  335. #endif
  336. na = nla_nest_start(skb, aggr);
  337. if (!na)
  338. goto err;
  339. if (nla_put(skb, type, sizeof(pid), &pid) < 0)
  340. goto err;
  341. ret = nla_reserve(skb, TASKSTATS_TYPE_STATS, sizeof(struct taskstats));
  342. if (!ret)
  343. goto err;
  344. nla_nest_end(skb, na);
  345. return nla_data(ret);
  346. err:
  347. return NULL;
  348. }
  349. static int cgroupstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
  350. {
  351. int rc = 0;
  352. struct sk_buff *rep_skb;
  353. struct cgroupstats *stats;
  354. struct nlattr *na;
  355. size_t size;
  356. u32 fd;
  357. struct file *file;
  358. int fput_needed;
  359. na = info->attrs[CGROUPSTATS_CMD_ATTR_FD];
  360. if (!na)
  361. return -EINVAL;
  362. fd = nla_get_u32(info->attrs[CGROUPSTATS_CMD_ATTR_FD]);
  363. file = fget_light(fd, &fput_needed);
  364. if (!file)
  365. return 0;
  366. size = nla_total_size(sizeof(struct cgroupstats));
  367. rc = prepare_reply(info, CGROUPSTATS_CMD_NEW, &rep_skb,
  368. size);
  369. if (rc < 0)
  370. goto err;
  371. na = nla_reserve(rep_skb, CGROUPSTATS_TYPE_CGROUP_STATS,
  372. sizeof(struct cgroupstats));
  373. stats = nla_data(na);
  374. memset(stats, 0, sizeof(*stats));
  375. rc = cgroupstats_build(stats, file->f_dentry);
  376. if (rc < 0) {
  377. nlmsg_free(rep_skb);
  378. goto err;
  379. }
  380. rc = send_reply(rep_skb, info);
  381. err:
  382. fput_light(file, fput_needed);
  383. return rc;
  384. }
  385. static int cmd_attr_register_cpumask(struct genl_info *info)
  386. {
  387. cpumask_var_t mask;
  388. int rc;
  389. if (!alloc_cpumask_var(&mask, GFP_KERNEL))
  390. return -ENOMEM;
  391. rc = parse(info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK], mask);
  392. if (rc < 0)
  393. goto out;
  394. rc = add_del_listener(info->snd_pid, mask, REGISTER);
  395. out:
  396. free_cpumask_var(mask);
  397. return rc;
  398. }
  399. static int cmd_attr_deregister_cpumask(struct genl_info *info)
  400. {
  401. cpumask_var_t mask;
  402. int rc;
  403. if (!alloc_cpumask_var(&mask, GFP_KERNEL))
  404. return -ENOMEM;
  405. rc = parse(info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK], mask);
  406. if (rc < 0)
  407. goto out;
  408. rc = add_del_listener(info->snd_pid, mask, DEREGISTER);
  409. out:
  410. free_cpumask_var(mask);
  411. return rc;
  412. }
  413. static size_t taskstats_packet_size(void)
  414. {
  415. size_t size;
  416. size = nla_total_size(sizeof(u32)) +
  417. nla_total_size(sizeof(struct taskstats)) + nla_total_size(0);
  418. #ifdef TASKSTATS_NEEDS_PADDING
  419. size += nla_total_size(0); /* Padding for alignment */
  420. #endif
  421. return size;
  422. }
  423. static int cmd_attr_pid(struct genl_info *info)
  424. {
  425. struct taskstats *stats;
  426. struct sk_buff *rep_skb;
  427. size_t size;
  428. u32 pid;
  429. int rc;
  430. size = taskstats_packet_size();
  431. rc = prepare_reply(info, TASKSTATS_CMD_NEW, &rep_skb, size);
  432. if (rc < 0)
  433. return rc;
  434. rc = -EINVAL;
  435. pid = nla_get_u32(info->attrs[TASKSTATS_CMD_ATTR_PID]);
  436. stats = mk_reply(rep_skb, TASKSTATS_TYPE_PID, pid);
  437. if (!stats)
  438. goto err;
  439. rc = fill_stats_for_pid(pid, stats);
  440. if (rc < 0)
  441. goto err;
  442. return send_reply(rep_skb, info);
  443. err:
  444. nlmsg_free(rep_skb);
  445. return rc;
  446. }
  447. static int cmd_attr_tgid(struct genl_info *info)
  448. {
  449. struct taskstats *stats;
  450. struct sk_buff *rep_skb;
  451. size_t size;
  452. u32 tgid;
  453. int rc;
  454. size = taskstats_packet_size();
  455. rc = prepare_reply(info, TASKSTATS_CMD_NEW, &rep_skb, size);
  456. if (rc < 0)
  457. return rc;
  458. rc = -EINVAL;
  459. tgid = nla_get_u32(info->attrs[TASKSTATS_CMD_ATTR_TGID]);
  460. stats = mk_reply(rep_skb, TASKSTATS_TYPE_TGID, tgid);
  461. if (!stats)
  462. goto err;
  463. rc = fill_stats_for_tgid(tgid, stats);
  464. if (rc < 0)
  465. goto err;
  466. return send_reply(rep_skb, info);
  467. err:
  468. nlmsg_free(rep_skb);
  469. return rc;
  470. }
  471. static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
  472. {
  473. if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
  474. return cmd_attr_register_cpumask(info);
  475. else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
  476. return cmd_attr_deregister_cpumask(info);
  477. else if (info->attrs[TASKSTATS_CMD_ATTR_PID])
  478. return cmd_attr_pid(info);
  479. else if (info->attrs[TASKSTATS_CMD_ATTR_TGID])
  480. return cmd_attr_tgid(info);
  481. else
  482. return -EINVAL;
  483. }
  484. static struct taskstats *taskstats_tgid_alloc(struct task_struct *tsk)
  485. {
  486. struct signal_struct *sig = tsk->signal;
  487. struct taskstats *stats;
  488. if (sig->stats || thread_group_empty(tsk))
  489. goto ret;
  490. /* No problem if kmem_cache_zalloc() fails */
  491. stats = kmem_cache_zalloc(taskstats_cache, GFP_KERNEL);
  492. spin_lock_irq(&tsk->sighand->siglock);
  493. if (!sig->stats) {
  494. sig->stats = stats;
  495. stats = NULL;
  496. }
  497. spin_unlock_irq(&tsk->sighand->siglock);
  498. if (stats)
  499. kmem_cache_free(taskstats_cache, stats);
  500. ret:
  501. return sig->stats;
  502. }
  503. /* Send pid data out on exit */
  504. void taskstats_exit(struct task_struct *tsk, int group_dead)
  505. {
  506. int rc;
  507. struct listener_list *listeners;
  508. struct taskstats *stats;
  509. struct sk_buff *rep_skb;
  510. size_t size;
  511. int is_thread_group;
  512. if (!family_registered)
  513. return;
  514. /*
  515. * Size includes space for nested attributes
  516. */
  517. size = taskstats_packet_size();
  518. is_thread_group = !!taskstats_tgid_alloc(tsk);
  519. if (is_thread_group) {
  520. /* PID + STATS + TGID + STATS */
  521. size = 2 * size;
  522. /* fill the tsk->signal->stats structure */
  523. fill_tgid_exit(tsk);
  524. }
  525. listeners = __this_cpu_ptr(&listener_array);
  526. if (list_empty(&listeners->list))
  527. return;
  528. rc = prepare_reply(NULL, TASKSTATS_CMD_NEW, &rep_skb, size);
  529. if (rc < 0)
  530. return;
  531. stats = mk_reply(rep_skb, TASKSTATS_TYPE_PID, tsk->pid);
  532. if (!stats)
  533. goto err;
  534. fill_stats(tsk, stats);
  535. /*
  536. * Doesn't matter if tsk is the leader or the last group member leaving
  537. */
  538. if (!is_thread_group || !group_dead)
  539. goto send;
  540. stats = mk_reply(rep_skb, TASKSTATS_TYPE_TGID, tsk->tgid);
  541. if (!stats)
  542. goto err;
  543. memcpy(stats, tsk->signal->stats, sizeof(*stats));
  544. send:
  545. send_cpu_listeners(rep_skb, listeners);
  546. return;
  547. err:
  548. nlmsg_free(rep_skb);
  549. }
  550. static struct genl_ops taskstats_ops = {
  551. .cmd = TASKSTATS_CMD_GET,
  552. .doit = taskstats_user_cmd,
  553. .policy = taskstats_cmd_get_policy,
  554. };
  555. static struct genl_ops cgroupstats_ops = {
  556. .cmd = CGROUPSTATS_CMD_GET,
  557. .doit = cgroupstats_user_cmd,
  558. .policy = cgroupstats_cmd_get_policy,
  559. };
  560. /* Needed early in initialization */
  561. void __init taskstats_init_early(void)
  562. {
  563. unsigned int i;
  564. taskstats_cache = KMEM_CACHE(taskstats, SLAB_PANIC);
  565. for_each_possible_cpu(i) {
  566. INIT_LIST_HEAD(&(per_cpu(listener_array, i).list));
  567. init_rwsem(&(per_cpu(listener_array, i).sem));
  568. }
  569. }
  570. static int __init taskstats_init(void)
  571. {
  572. int rc;
  573. rc = genl_register_family(&family);
  574. if (rc)
  575. return rc;
  576. rc = genl_register_ops(&family, &taskstats_ops);
  577. if (rc < 0)
  578. goto err;
  579. rc = genl_register_ops(&family, &cgroupstats_ops);
  580. if (rc < 0)
  581. goto err_cgroup_ops;
  582. family_registered = 1;
  583. printk("registered taskstats version %d\n", TASKSTATS_GENL_VERSION);
  584. return 0;
  585. err_cgroup_ops:
  586. genl_unregister_ops(&family, &taskstats_ops);
  587. err:
  588. genl_unregister_family(&family);
  589. return rc;
  590. }
  591. /*
  592. * late initcall ensures initialization of statistics collection
  593. * mechanisms precedes initialization of the taskstats interface
  594. */
  595. late_initcall(taskstats_init);