blob: 2466e550a41d40beefe6aa1b5ed4560ac076bc29 [file] [log] [blame]
Shailabh Nagarc7572492006-07-14 00:24:40 -07001/* taskstats.h - exporting per-task statistics
2 *
3 * Copyright (C) Shailabh Nagar, IBM Corp. 2006
4 * (C) Balbir Singh, IBM Corp. 2006
Jay Lanf3cef7a2006-09-30 23:28:55 -07005 * (C) Jay Lan, SGI, 2006
Shailabh Nagarc7572492006-07-14 00:24:40 -07006 *
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 Rajput448314f2009-01-30 22:21:19 +053019#include <linux/types.h>
20
Shailabh Nagarc7572492006-07-14 00:24:40 -070021/* 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 Lanf3cef7a2006-09-30 23:28:55 -070035
Jeff Mahoney4be2c952010-12-21 17:24:30 -080036#define TASKSTATS_VERSION 8
Jay Landb5fed262006-09-30 23:29:00 -070037#define TS_COMM_LEN 32 /* should be >= TASK_COMM_LEN
Jay Lanf3cef7a2006-09-30 23:28:55 -070038 * in linux/sched.h */
Shailabh Nagarc7572492006-07-14 00:24:40 -070039
40struct taskstats {
41
Jay Landb5fed262006-09-30 23:29:00 -070042 /* 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 Nagar6f449932006-07-14 00:24:41 -070046 __u16 version;
Jay Landb5fed262006-09-30 23:29:00 -070047 __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 Lanf3cef7a2006-09-30 23:28:55 -070052 __u8 ac_flag; /* Record flags */
53 __u8 ac_nice; /* task_nice */
Shailabh Nagar6f449932006-07-14 00:24:41 -070054
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 Singh7e40f2a2007-04-23 14:41:05 -070071 __u64 cpu_count __attribute__((aligned(8)));
Shailabh Nagar6f449932006-07-14 00:24:41 -070072 __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 Neulingf494f8f2007-10-18 03:06:35 -070090 * and wraps around to zero silently on overflow
Shailabh Nagar6f449932006-07-14 00:24:41 -070091 */
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 Lanf3cef7a2006-09-30 23:28:55 -0700103
104 /* Basic Accounting Fields start */
105 char ac_comm[TS_COMM_LEN]; /* Command name */
Balbir Singh7e40f2a2007-04-23 14:41:05 -0700106 __u8 ac_sched __attribute__((aligned(8)));
107 /* Scheduling discipline */
Jay Lanf3cef7a2006-09-30 23:28:55 -0700108 __u8 ac_pad[3];
Balbir Singh7e40f2a2007-04-23 14:41:05 -0700109 __u32 ac_uid __attribute__((aligned(8)));
110 /* User ID */
Jay Lanf3cef7a2006-09-30 23:28:55 -0700111 __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 Singh7e40f2a2007-04-23 14:41:05 -0700115 __u64 ac_etime __attribute__((aligned(8)));
116 /* Elapsed time [usec] */
Jay Lanf3cef7a2006-09-30 23:28:55 -0700117 __u64 ac_utime; /* User CPU time [usec] */
118 __u64 ac_stime; /* SYstem CPU time [usec] */
Jay Landb5fed262006-09-30 23:29:00 -0700119 __u64 ac_minflt; /* Minor Page Fault Count */
120 __u64 ac_majflt; /* Major Page Fault Count */
Jay Lanf3cef7a2006-09-30 23:28:55 -0700121 /* Basic Accounting Fields end */
Jay Lan9acc1852006-09-30 23:28:58 -0700122
Andrew Mortonf2f1f8a2006-12-10 02:19:50 -0800123 /* Extended accounting fields start */
Jay Landb5fed262006-09-30 23:29:00 -0700124 /* 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 Mortonf2f1f8a2006-12-10 02:19:50 -0800130 __u64 coremem; /* accumulated RSS usage in MB-usec */
Jay Landb5fed262006-09-30 23:29:00 -0700131 /* 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 Mortonf2f1f8a2006-12-10 02:19:50 -0800134 __u64 virtmem; /* accumulated VM usage in MB-usec */
Jay Landb5fed262006-09-30 23:29:00 -0700135
136 /* High watermark of RSS and virtual memory usage in duration of
137 * a task, in KBytes.
138 */
Andrew Mortonf2f1f8a2006-12-10 02:19:50 -0800139 __u64 hiwater_rss; /* High-watermark of RSS usage, in KB */
140 __u64 hiwater_vm; /* High-water VM usage, in KB */
Jay Landb5fed262006-09-30 23:29:00 -0700141
142 /* The following four fields are I/O statistics of a task. */
Andrew Mortonf2f1f8a2006-12-10 02:19:50 -0800143 __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 Morton4a7864c2006-12-10 02:19:53 -0800148
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 Uvarovb663a792007-07-15 23:40:48 -0700154
155 __u64 nvcsw; /* voluntary_ctxt_switches */
156 __u64 nivcsw; /* nonvoluntary_ctxt_switches */
Michael Neulingf494f8f2007-10-18 03:06:35 -0700157
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 Kobayashi016ae212008-07-25 01:48:53 -0700162
163 /* Delay waiting for memory reclaim */
164 __u64 freepages_count;
165 __u64 freepages_delay_total;
Shailabh Nagarc7572492006-07-14 00:24:40 -0700166};
167
168
Shailabh Nagarc7572492006-07-14 00:24:40 -0700169/*
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
175enum {
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
184enum {
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 Mahoney4be2c952010-12-21 17:24:30 -0800191 TASKSTATS_TYPE_NULL, /* contains nothing */
Shailabh Nagarc7572492006-07-14 00:24:40 -0700192 __TASKSTATS_TYPE_MAX,
193};
194
195#define TASKSTATS_TYPE_MAX (__TASKSTATS_TYPE_MAX - 1)
196
197enum {
198 TASKSTATS_CMD_ATTR_UNSPEC = 0,
199 TASKSTATS_CMD_ATTR_PID,
200 TASKSTATS_CMD_ATTR_TGID,
Shailabh Nagarf9fd8912006-07-14 00:24:47 -0700201 TASKSTATS_CMD_ATTR_REGISTER_CPUMASK,
202 TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK,
Shailabh Nagarc7572492006-07-14 00:24:40 -0700203 __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 */