ia64/linux-2.6.18-xen.hg

annotate kernel/taskstats.c @ 240:3e8752eb6d9c

Apply patch for 2.6.18.8.

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