taskstats.c (c757249af152c59fd74b85e52e8c090acb33d9c0) | taskstats.c (6f44993fe1d7b2b097f6ac60cd5835c6f5ca0874) |
---|---|
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 --- 4 unchanged lines hidden (view full) --- 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 19#include <linux/kernel.h> 20#include <linux/taskstats_kern.h> | 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 --- 4 unchanged lines hidden (view full) --- 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 19#include <linux/kernel.h> 20#include <linux/taskstats_kern.h> |
21#include <linux/delayacct.h> |
|
21#include <net/genetlink.h> 22#include <asm/atomic.h> 23 24static DEFINE_PER_CPU(__u32, taskstats_seqnum) = { 0 }; 25static int family_registered; 26kmem_cache_t *taskstats_cache; | 22#include <net/genetlink.h> 23#include <asm/atomic.h> 24 25static DEFINE_PER_CPU(__u32, taskstats_seqnum) = { 0 }; 26static int family_registered; 27kmem_cache_t *taskstats_cache; |
27static DEFINE_MUTEX(taskstats_exit_mutex); | |
28 29static struct genl_family family = { 30 .id = GENL_ID_GENERATE, 31 .name = TASKSTATS_GENL_NAME, 32 .version = TASKSTATS_GENL_VERSION, 33 .maxattr = TASKSTATS_CMD_ATTR_MAX, 34}; 35 --- 79 unchanged lines hidden (view full) --- 115 * Each accounting subsystem adds calls to its functions to 116 * fill in relevant parts of struct taskstsats as follows 117 * 118 * rc = per-task-foo(stats, tsk); 119 * if (rc) 120 * goto err; 121 */ 122 | 28 29static struct genl_family family = { 30 .id = GENL_ID_GENERATE, 31 .name = TASKSTATS_GENL_NAME, 32 .version = TASKSTATS_GENL_VERSION, 33 .maxattr = TASKSTATS_CMD_ATTR_MAX, 34}; 35 --- 79 unchanged lines hidden (view full) --- 115 * Each accounting subsystem adds calls to its functions to 116 * fill in relevant parts of struct taskstsats as follows 117 * 118 * rc = per-task-foo(stats, tsk); 119 * if (rc) 120 * goto err; 121 */ 122 |
123err: | 123 rc = delayacct_add_tsk(stats, tsk); 124 stats->version = TASKSTATS_VERSION; 125 126 /* Define err: label here if needed */ |
124 put_task_struct(tsk); 125 return rc; 126 127} 128 129static int fill_tgid(pid_t tgid, struct task_struct *tgidtsk, 130 struct taskstats *stats) 131{ --- 15 unchanged lines hidden (view full) --- 147 * Each accounting subsystem adds calls its functions to 148 * fill in relevant parts of struct taskstsats as follows 149 * 150 * rc = per-task-foo(stats, tsk); 151 * if (rc) 152 * break; 153 */ 154 | 127 put_task_struct(tsk); 128 return rc; 129 130} 131 132static int fill_tgid(pid_t tgid, struct task_struct *tgidtsk, 133 struct taskstats *stats) 134{ --- 15 unchanged lines hidden (view full) --- 150 * Each accounting subsystem adds calls its functions to 151 * fill in relevant parts of struct taskstsats as follows 152 * 153 * rc = per-task-foo(stats, tsk); 154 * if (rc) 155 * break; 156 */ 157 |
158 rc = delayacct_add_tsk(stats, tsk); 159 if (rc) 160 break; 161 |
|
155 } while_each_thread(first, tsk); 156 read_unlock(&tasklist_lock); | 162 } while_each_thread(first, tsk); 163 read_unlock(&tasklist_lock); |
164 stats->version = TASKSTATS_VERSION; |
|
157 | 165 |
166 |
|
158 /* 159 * Accounting subsytems can also add calls here if they don't 160 * wish to aggregate statistics for per-tgid stats 161 */ 162 163 return rc; 164} 165 --- 62 unchanged lines hidden (view full) --- 228 void *reply; 229 size_t size; 230 int is_thread_group; 231 struct nlattr *na; 232 233 if (!family_registered || !tidstats) 234 return; 235 | 167 /* 168 * Accounting subsytems can also add calls here if they don't 169 * wish to aggregate statistics for per-tgid stats 170 */ 171 172 return rc; 173} 174 --- 62 unchanged lines hidden (view full) --- 237 void *reply; 238 size_t size; 239 int is_thread_group; 240 struct nlattr *na; 241 242 if (!family_registered || !tidstats) 243 return; 244 |
236 mutex_lock(&taskstats_exit_mutex); 237 | |
238 is_thread_group = !thread_group_empty(tsk); 239 rc = 0; 240 241 /* 242 * Size includes space for nested attributes 243 */ 244 size = nla_total_size(sizeof(u32)) + 245 nla_total_size(sizeof(struct taskstats)) + nla_total_size(0); --- 41 unchanged lines hidden (view full) --- 287 goto ret; 288 289nla_put_failure: 290 genlmsg_cancel(rep_skb, reply); 291 goto ret; 292err_skb: 293 nlmsg_free(rep_skb); 294ret: | 245 is_thread_group = !thread_group_empty(tsk); 246 rc = 0; 247 248 /* 249 * Size includes space for nested attributes 250 */ 251 size = nla_total_size(sizeof(u32)) + 252 nla_total_size(sizeof(struct taskstats)) + nla_total_size(0); --- 41 unchanged lines hidden (view full) --- 294 goto ret; 295 296nla_put_failure: 297 genlmsg_cancel(rep_skb, reply); 298 goto ret; 299err_skb: 300 nlmsg_free(rep_skb); 301ret: |
295 mutex_unlock(&taskstats_exit_mutex); | |
296 return; 297} 298 299static struct genl_ops taskstats_ops = { 300 .cmd = TASKSTATS_CMD_GET, 301 .doit = taskstats_send_stats, 302 .policy = taskstats_cmd_get_policy, 303}; --- 33 unchanged lines hidden --- | 302 return; 303} 304 305static struct genl_ops taskstats_ops = { 306 .cmd = TASKSTATS_CMD_GET, 307 .doit = taskstats_send_stats, 308 .policy = taskstats_cmd_get_policy, 309}; --- 33 unchanged lines hidden --- |