Shailabh Nagar | c757249 | 2006-07-14 00:24:40 -0700 | [diff] [blame] | 1 | /* taskstats.h - exporting per-task statistics |
| 2 | * |
| 3 | * Copyright (C) Shailabh Nagar, IBM Corp. 2006 |
| 4 | * (C) Balbir Singh, IBM Corp. 2006 |
Jay Lan | f3cef7a | 2006-09-30 23:28:55 -0700 | [diff] [blame] | 5 | * (C) Jay Lan, SGI, 2006 |
Shailabh Nagar | c757249 | 2006-07-14 00:24:40 -0700 | [diff] [blame] | 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify it |
| 8 | * under the terms of version 2.1 of the GNU Lesser General Public License |
| 9 | * as published by the Free Software Foundation. |
| 10 | * |
| 11 | * This program is distributed in the hope that it would be useful, but |
| 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 14 | */ |
| 15 | |
| 16 | #ifndef _LINUX_TASKSTATS_H |
| 17 | #define _LINUX_TASKSTATS_H |
| 18 | |
Jaswinder Singh Rajput | 448314f | 2009-01-30 22:21:19 +0530 | [diff] [blame] | 19 | #include <linux/types.h> |
| 20 | |
Shailabh Nagar | c757249 | 2006-07-14 00:24:40 -0700 | [diff] [blame] | 21 | /* Format for per-task data returned to userland when |
| 22 | * - a task exits |
| 23 | * - listener requests stats for a task |
| 24 | * |
| 25 | * The struct is versioned. Newer versions should only add fields to |
| 26 | * the bottom of the struct to maintain backward compatibility. |
| 27 | * |
| 28 | * |
| 29 | * To add new fields |
| 30 | * a) bump up TASKSTATS_VERSION |
| 31 | * b) add comment indicating new version number at end of struct |
| 32 | * c) add new fields after version comment; maintain 64-bit alignment |
| 33 | */ |
| 34 | |
Jay Lan | f3cef7a | 2006-09-30 23:28:55 -0700 | [diff] [blame] | 35 | |
Jeff Mahoney | 4be2c95 | 2010-12-21 17:24:30 -0800 | [diff] [blame] | 36 | #define TASKSTATS_VERSION 8 |
Jay Lan | db5fed26 | 2006-09-30 23:29:00 -0700 | [diff] [blame] | 37 | #define TS_COMM_LEN 32 /* should be >= TASK_COMM_LEN |
Jay Lan | f3cef7a | 2006-09-30 23:28:55 -0700 | [diff] [blame] | 38 | * in linux/sched.h */ |
Shailabh Nagar | c757249 | 2006-07-14 00:24:40 -0700 | [diff] [blame] | 39 | |
| 40 | struct taskstats { |
| 41 | |
Jay Lan | db5fed26 | 2006-09-30 23:29:00 -0700 | [diff] [blame] | 42 | /* The version number of this struct. This field is always set to |
| 43 | * TAKSTATS_VERSION, which is defined in <linux/taskstats.h>. |
| 44 | * Each time the struct is changed, the value should be incremented. |
| 45 | */ |
Shailabh Nagar | 6f44993 | 2006-07-14 00:24:41 -0700 | [diff] [blame] | 46 | __u16 version; |
Jay Lan | db5fed26 | 2006-09-30 23:29:00 -0700 | [diff] [blame] | 47 | __u32 ac_exitcode; /* Exit status */ |
| 48 | |
| 49 | /* The accounting flags of a task as defined in <linux/acct.h> |
| 50 | * Defined values are AFORK, ASU, ACOMPAT, ACORE, and AXSIG. |
| 51 | */ |
Jay Lan | f3cef7a | 2006-09-30 23:28:55 -0700 | [diff] [blame] | 52 | __u8 ac_flag; /* Record flags */ |
| 53 | __u8 ac_nice; /* task_nice */ |
Shailabh Nagar | 6f44993 | 2006-07-14 00:24:41 -0700 | [diff] [blame] | 54 | |
| 55 | /* Delay accounting fields start |
| 56 | * |
| 57 | * All values, until comment "Delay accounting fields end" are |
| 58 | * available only if delay accounting is enabled, even though the last |
| 59 | * few fields are not delays |
| 60 | * |
| 61 | * xxx_count is the number of delay values recorded |
| 62 | * xxx_delay_total is the corresponding cumulative delay in nanoseconds |
| 63 | * |
| 64 | * xxx_delay_total wraps around to zero on overflow |
| 65 | * xxx_count incremented regardless of overflow |
| 66 | */ |
| 67 | |
| 68 | /* Delay waiting for cpu, while runnable |
| 69 | * count, delay_total NOT updated atomically |
| 70 | */ |
Balbir Singh | 7e40f2a | 2007-04-23 14:41:05 -0700 | [diff] [blame] | 71 | __u64 cpu_count __attribute__((aligned(8))); |
Shailabh Nagar | 6f44993 | 2006-07-14 00:24:41 -0700 | [diff] [blame] | 72 | __u64 cpu_delay_total; |
| 73 | |
| 74 | /* Following four fields atomically updated using task->delays->lock */ |
| 75 | |
| 76 | /* Delay waiting for synchronous block I/O to complete |
| 77 | * does not account for delays in I/O submission |
| 78 | */ |
| 79 | __u64 blkio_count; |
| 80 | __u64 blkio_delay_total; |
| 81 | |
| 82 | /* Delay waiting for page fault I/O (swap in only) */ |
| 83 | __u64 swapin_count; |
| 84 | __u64 swapin_delay_total; |
| 85 | |
| 86 | /* cpu "wall-clock" running time |
| 87 | * On some architectures, value will adjust for cpu time stolen |
| 88 | * from the kernel in involuntary waits due to virtualization. |
| 89 | * Value is cumulative, in nanoseconds, without a corresponding count |
Michael Neuling | f494f8f | 2007-10-18 03:06:35 -0700 | [diff] [blame] | 90 | * and wraps around to zero silently on overflow |
Shailabh Nagar | 6f44993 | 2006-07-14 00:24:41 -0700 | [diff] [blame] | 91 | */ |
| 92 | __u64 cpu_run_real_total; |
| 93 | |
| 94 | /* cpu "virtual" running time |
| 95 | * Uses time intervals seen by the kernel i.e. no adjustment |
| 96 | * for kernel's involuntary waits due to virtualization. |
| 97 | * Value is cumulative, in nanoseconds, without a corresponding count |
| 98 | * and wraps around to zero silently on overflow |
| 99 | */ |
| 100 | __u64 cpu_run_virtual_total; |
| 101 | /* Delay accounting fields end */ |
| 102 | /* version 1 ends here */ |
Jay Lan | f3cef7a | 2006-09-30 23:28:55 -0700 | [diff] [blame] | 103 | |
| 104 | /* Basic Accounting Fields start */ |
| 105 | char ac_comm[TS_COMM_LEN]; /* Command name */ |
Balbir Singh | 7e40f2a | 2007-04-23 14:41:05 -0700 | [diff] [blame] | 106 | __u8 ac_sched __attribute__((aligned(8))); |
| 107 | /* Scheduling discipline */ |
Jay Lan | f3cef7a | 2006-09-30 23:28:55 -0700 | [diff] [blame] | 108 | __u8 ac_pad[3]; |
Balbir Singh | 7e40f2a | 2007-04-23 14:41:05 -0700 | [diff] [blame] | 109 | __u32 ac_uid __attribute__((aligned(8))); |
| 110 | /* User ID */ |
Jay Lan | f3cef7a | 2006-09-30 23:28:55 -0700 | [diff] [blame] | 111 | __u32 ac_gid; /* Group ID */ |
| 112 | __u32 ac_pid; /* Process ID */ |
| 113 | __u32 ac_ppid; /* Parent process ID */ |
| 114 | __u32 ac_btime; /* Begin time [sec since 1970] */ |
Balbir Singh | 7e40f2a | 2007-04-23 14:41:05 -0700 | [diff] [blame] | 115 | __u64 ac_etime __attribute__((aligned(8))); |
| 116 | /* Elapsed time [usec] */ |
Jay Lan | f3cef7a | 2006-09-30 23:28:55 -0700 | [diff] [blame] | 117 | __u64 ac_utime; /* User CPU time [usec] */ |
| 118 | __u64 ac_stime; /* SYstem CPU time [usec] */ |
Jay Lan | db5fed26 | 2006-09-30 23:29:00 -0700 | [diff] [blame] | 119 | __u64 ac_minflt; /* Minor Page Fault Count */ |
| 120 | __u64 ac_majflt; /* Major Page Fault Count */ |
Jay Lan | f3cef7a | 2006-09-30 23:28:55 -0700 | [diff] [blame] | 121 | /* Basic Accounting Fields end */ |
Jay Lan | 9acc185 | 2006-09-30 23:28:58 -0700 | [diff] [blame] | 122 | |
Andrew Morton | f2f1f8a | 2006-12-10 02:19:50 -0800 | [diff] [blame] | 123 | /* Extended accounting fields start */ |
Jay Lan | db5fed26 | 2006-09-30 23:29:00 -0700 | [diff] [blame] | 124 | /* Accumulated RSS usage in duration of a task, in MBytes-usecs. |
| 125 | * The current rss usage is added to this counter every time |
| 126 | * a tick is charged to a task's system time. So, at the end we |
| 127 | * will have memory usage multiplied by system time. Thus an |
| 128 | * average usage per system time unit can be calculated. |
| 129 | */ |
Andrew Morton | f2f1f8a | 2006-12-10 02:19:50 -0800 | [diff] [blame] | 130 | __u64 coremem; /* accumulated RSS usage in MB-usec */ |
Jay Lan | db5fed26 | 2006-09-30 23:29:00 -0700 | [diff] [blame] | 131 | /* Accumulated virtual memory usage in duration of a task. |
| 132 | * Same as acct_rss_mem1 above except that we keep track of VM usage. |
| 133 | */ |
Andrew Morton | f2f1f8a | 2006-12-10 02:19:50 -0800 | [diff] [blame] | 134 | __u64 virtmem; /* accumulated VM usage in MB-usec */ |
Jay Lan | db5fed26 | 2006-09-30 23:29:00 -0700 | [diff] [blame] | 135 | |
| 136 | /* High watermark of RSS and virtual memory usage in duration of |
| 137 | * a task, in KBytes. |
| 138 | */ |
Andrew Morton | f2f1f8a | 2006-12-10 02:19:50 -0800 | [diff] [blame] | 139 | __u64 hiwater_rss; /* High-watermark of RSS usage, in KB */ |
| 140 | __u64 hiwater_vm; /* High-water VM usage, in KB */ |
Jay Lan | db5fed26 | 2006-09-30 23:29:00 -0700 | [diff] [blame] | 141 | |
| 142 | /* The following four fields are I/O statistics of a task. */ |
Andrew Morton | f2f1f8a | 2006-12-10 02:19:50 -0800 | [diff] [blame] | 143 | __u64 read_char; /* bytes read */ |
| 144 | __u64 write_char; /* bytes written */ |
| 145 | __u64 read_syscalls; /* read syscalls */ |
| 146 | __u64 write_syscalls; /* write syscalls */ |
| 147 | /* Extended accounting fields end */ |
Andrew Morton | 4a7864c | 2006-12-10 02:19:53 -0800 | [diff] [blame] | 148 | |
| 149 | #define TASKSTATS_HAS_IO_ACCOUNTING |
| 150 | /* Per-task storage I/O accounting starts */ |
| 151 | __u64 read_bytes; /* bytes of read I/O */ |
| 152 | __u64 write_bytes; /* bytes of write I/O */ |
| 153 | __u64 cancelled_write_bytes; /* bytes of cancelled write I/O */ |
Maxim Uvarov | b663a79 | 2007-07-15 23:40:48 -0700 | [diff] [blame] | 154 | |
| 155 | __u64 nvcsw; /* voluntary_ctxt_switches */ |
| 156 | __u64 nivcsw; /* nonvoluntary_ctxt_switches */ |
Michael Neuling | f494f8f | 2007-10-18 03:06:35 -0700 | [diff] [blame] | 157 | |
| 158 | /* time accounting for SMT machines */ |
| 159 | __u64 ac_utimescaled; /* utime scaled on frequency etc */ |
| 160 | __u64 ac_stimescaled; /* stime scaled on frequency etc */ |
| 161 | __u64 cpu_scaled_run_real_total; /* scaled cpu_run_real_total */ |
Keika Kobayashi | 016ae21 | 2008-07-25 01:48:53 -0700 | [diff] [blame] | 162 | |
| 163 | /* Delay waiting for memory reclaim */ |
| 164 | __u64 freepages_count; |
| 165 | __u64 freepages_delay_total; |
Shailabh Nagar | c757249 | 2006-07-14 00:24:40 -0700 | [diff] [blame] | 166 | }; |
| 167 | |
| 168 | |
Shailabh Nagar | c757249 | 2006-07-14 00:24:40 -0700 | [diff] [blame] | 169 | /* |
| 170 | * Commands sent from userspace |
| 171 | * Not versioned. New commands should only be inserted at the enum's end |
| 172 | * prior to __TASKSTATS_CMD_MAX |
| 173 | */ |
| 174 | |
| 175 | enum { |
| 176 | TASKSTATS_CMD_UNSPEC = 0, /* Reserved */ |
| 177 | TASKSTATS_CMD_GET, /* user->kernel request/get-response */ |
| 178 | TASKSTATS_CMD_NEW, /* kernel->user event */ |
| 179 | __TASKSTATS_CMD_MAX, |
| 180 | }; |
| 181 | |
| 182 | #define TASKSTATS_CMD_MAX (__TASKSTATS_CMD_MAX - 1) |
| 183 | |
| 184 | enum { |
| 185 | TASKSTATS_TYPE_UNSPEC = 0, /* Reserved */ |
| 186 | TASKSTATS_TYPE_PID, /* Process id */ |
| 187 | TASKSTATS_TYPE_TGID, /* Thread group id */ |
| 188 | TASKSTATS_TYPE_STATS, /* taskstats structure */ |
| 189 | TASKSTATS_TYPE_AGGR_PID, /* contains pid + stats */ |
| 190 | TASKSTATS_TYPE_AGGR_TGID, /* contains tgid + stats */ |
Jeff Mahoney | 4be2c95 | 2010-12-21 17:24:30 -0800 | [diff] [blame] | 191 | TASKSTATS_TYPE_NULL, /* contains nothing */ |
Shailabh Nagar | c757249 | 2006-07-14 00:24:40 -0700 | [diff] [blame] | 192 | __TASKSTATS_TYPE_MAX, |
| 193 | }; |
| 194 | |
| 195 | #define TASKSTATS_TYPE_MAX (__TASKSTATS_TYPE_MAX - 1) |
| 196 | |
| 197 | enum { |
| 198 | TASKSTATS_CMD_ATTR_UNSPEC = 0, |
| 199 | TASKSTATS_CMD_ATTR_PID, |
| 200 | TASKSTATS_CMD_ATTR_TGID, |
Shailabh Nagar | f9fd891 | 2006-07-14 00:24:47 -0700 | [diff] [blame] | 201 | TASKSTATS_CMD_ATTR_REGISTER_CPUMASK, |
| 202 | TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK, |
Shailabh Nagar | c757249 | 2006-07-14 00:24:40 -0700 | [diff] [blame] | 203 | __TASKSTATS_CMD_ATTR_MAX, |
| 204 | }; |
| 205 | |
| 206 | #define TASKSTATS_CMD_ATTR_MAX (__TASKSTATS_CMD_ATTR_MAX - 1) |
| 207 | |
| 208 | /* NETLINK_GENERIC related info */ |
| 209 | |
| 210 | #define TASKSTATS_GENL_NAME "TASKSTATS" |
| 211 | #define TASKSTATS_GENL_VERSION 0x1 |
| 212 | |
| 213 | #endif /* _LINUX_TASKSTATS_H */ |