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