Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: LGPL-2.1 WITH Linux-syscall-note */
0002 /* taskstats.h - exporting per-task statistics
0003  *
0004  * Copyright (C) Shailabh Nagar, IBM Corp. 2006
0005  *           (C) Balbir Singh,   IBM Corp. 2006
0006  *           (C) Jay Lan,        SGI, 2006
0007  *
0008  * This program is free software; you can redistribute it and/or modify it
0009  * under the terms of version 2.1 of the GNU Lesser General Public License
0010  * as published by the Free Software Foundation.
0011  *
0012  * This program is distributed in the hope that it would be useful, but
0013  * WITHOUT ANY WARRANTY; without even the implied warranty of
0014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
0015  */
0016 
0017 #ifndef _LINUX_TASKSTATS_H
0018 #define _LINUX_TASKSTATS_H
0019 
0020 #include <linux/types.h>
0021 
0022 /* Format for per-task data returned to userland when
0023  *  - a task exits
0024  *  - listener requests stats for a task
0025  *
0026  * The struct is versioned. Newer versions should only add fields to
0027  * the bottom of the struct to maintain backward compatibility.
0028  *
0029  *
0030  * To add new fields
0031  *  a) bump up TASKSTATS_VERSION
0032  *  b) add comment indicating new version number at end of struct
0033  *  c) add new fields after version comment; maintain 64-bit alignment
0034  */
0035 
0036 
0037 #define TASKSTATS_VERSION   13
0038 #define TS_COMM_LEN     32  /* should be >= TASK_COMM_LEN
0039                      * in linux/sched.h */
0040 
0041 struct taskstats {
0042 
0043     /* The version number of this struct. This field is always set to
0044      * TAKSTATS_VERSION, which is defined in <linux/taskstats.h>.
0045      * Each time the struct is changed, the value should be incremented.
0046      */
0047     __u16   version;
0048     __u32   ac_exitcode;        /* Exit status */
0049 
0050     /* The accounting flags of a task as defined in <linux/acct.h>
0051      * Defined values are AFORK, ASU, ACOMPAT, ACORE, AXSIG, and AGROUP.
0052      * (AGROUP since version 12).
0053      */
0054     __u8    ac_flag;        /* Record flags */
0055     __u8    ac_nice;        /* task_nice */
0056 
0057     /* Delay accounting fields start
0058      *
0059      * All values, until comment "Delay accounting fields end" are
0060      * available only if delay accounting is enabled, even though the last
0061      * few fields are not delays
0062      *
0063      * xxx_count is the number of delay values recorded
0064      * xxx_delay_total is the corresponding cumulative delay in nanoseconds
0065      *
0066      * xxx_delay_total wraps around to zero on overflow
0067      * xxx_count incremented regardless of overflow
0068      */
0069 
0070     /* Delay waiting for cpu, while runnable
0071      * count, delay_total NOT updated atomically
0072      */
0073     __u64   cpu_count __attribute__((aligned(8)));
0074     __u64   cpu_delay_total;
0075 
0076     /* Following four fields atomically updated using task->delays->lock */
0077 
0078     /* Delay waiting for synchronous block I/O to complete
0079      * does not account for delays in I/O submission
0080      */
0081     __u64   blkio_count;
0082     __u64   blkio_delay_total;
0083 
0084     /* Delay waiting for page fault I/O (swap in only) */
0085     __u64   swapin_count;
0086     __u64   swapin_delay_total;
0087 
0088     /* cpu "wall-clock" running time
0089      * On some architectures, value will adjust for cpu time stolen
0090      * from the kernel in involuntary waits due to virtualization.
0091      * Value is cumulative, in nanoseconds, without a corresponding count
0092      * and wraps around to zero silently on overflow
0093      */
0094     __u64   cpu_run_real_total;
0095 
0096     /* cpu "virtual" running time
0097      * Uses time intervals seen by the kernel i.e. no adjustment
0098      * for kernel's involuntary waits due to virtualization.
0099      * Value is cumulative, in nanoseconds, without a corresponding count
0100      * and wraps around to zero silently on overflow
0101      */
0102     __u64   cpu_run_virtual_total;
0103     /* Delay accounting fields end */
0104     /* version 1 ends here */
0105 
0106     /* Basic Accounting Fields start */
0107     char    ac_comm[TS_COMM_LEN];   /* Command name */
0108     __u8    ac_sched __attribute__((aligned(8)));
0109                     /* Scheduling discipline */
0110     __u8    ac_pad[3];
0111     __u32   ac_uid __attribute__((aligned(8)));
0112                     /* User ID */
0113     __u32   ac_gid;         /* Group ID */
0114     __u32   ac_pid;         /* Process ID */
0115     __u32   ac_ppid;        /* Parent process ID */
0116     /* __u32 range means times from 1970 to 2106 */
0117     __u32   ac_btime;       /* Begin time [sec since 1970] */
0118     __u64   ac_etime __attribute__((aligned(8)));
0119                     /* Elapsed time [usec] */
0120     __u64   ac_utime;       /* User CPU time [usec] */
0121     __u64   ac_stime;       /* SYstem CPU time [usec] */
0122     __u64   ac_minflt;      /* Minor Page Fault Count */
0123     __u64   ac_majflt;      /* Major Page Fault Count */
0124     /* Basic Accounting Fields end */
0125 
0126     /* Extended accounting fields start */
0127     /* Accumulated RSS usage in duration of a task, in MBytes-usecs.
0128      * The current rss usage is added to this counter every time
0129      * a tick is charged to a task's system time. So, at the end we
0130      * will have memory usage multiplied by system time. Thus an
0131      * average usage per system time unit can be calculated.
0132      */
0133     __u64   coremem;        /* accumulated RSS usage in MB-usec */
0134     /* Accumulated virtual memory usage in duration of a task.
0135      * Same as acct_rss_mem1 above except that we keep track of VM usage.
0136      */
0137     __u64   virtmem;        /* accumulated VM  usage in MB-usec */
0138 
0139     /* High watermark of RSS and virtual memory usage in duration of
0140      * a task, in KBytes.
0141      */
0142     __u64   hiwater_rss;        /* High-watermark of RSS usage, in KB */
0143     __u64   hiwater_vm;     /* High-water VM usage, in KB */
0144 
0145     /* The following four fields are I/O statistics of a task. */
0146     __u64   read_char;      /* bytes read */
0147     __u64   write_char;     /* bytes written */
0148     __u64   read_syscalls;      /* read syscalls */
0149     __u64   write_syscalls;     /* write syscalls */
0150     /* Extended accounting fields end */
0151 
0152 #define TASKSTATS_HAS_IO_ACCOUNTING
0153     /* Per-task storage I/O accounting starts */
0154     __u64   read_bytes;     /* bytes of read I/O */
0155     __u64   write_bytes;        /* bytes of write I/O */
0156     __u64   cancelled_write_bytes;  /* bytes of cancelled write I/O */
0157 
0158     __u64  nvcsw;           /* voluntary_ctxt_switches */
0159     __u64  nivcsw;          /* nonvoluntary_ctxt_switches */
0160 
0161     /* time accounting for SMT machines */
0162     __u64   ac_utimescaled;     /* utime scaled on frequency etc */
0163     __u64   ac_stimescaled;     /* stime scaled on frequency etc */
0164     __u64   cpu_scaled_run_real_total; /* scaled cpu_run_real_total */
0165 
0166     /* Delay waiting for memory reclaim */
0167     __u64   freepages_count;
0168     __u64   freepages_delay_total;
0169 
0170     /* Delay waiting for thrashing page */
0171     __u64   thrashing_count;
0172     __u64   thrashing_delay_total;
0173 
0174     /* v10: 64-bit btime to avoid overflow */
0175     __u64   ac_btime64;     /* 64-bit begin time */
0176 
0177     /* v11: Delay waiting for memory compact */
0178     __u64   compact_count;
0179     __u64   compact_delay_total;
0180 
0181     /* v12 begin */
0182     __u32   ac_tgid;    /* thread group ID */
0183     /* Thread group walltime up to now. This is total process walltime if
0184      * AGROUP flag is set.
0185      */
0186     __u64   ac_tgetime __attribute__((aligned(8)));
0187     /* Lightweight information to identify process binary files.
0188      * This leaves userspace to match this to a file system path, using
0189      * MAJOR() and MINOR() macros to identify a device and mount point,
0190      * the inode to identify the executable file. This is /proc/self/exe
0191      * at the end, so matching the most recent exec(). Values are zero
0192      * for kernel threads.
0193      */
0194     __u64   ac_exe_dev;     /* program binary device ID */
0195     __u64   ac_exe_inode;   /* program binary inode number */
0196     /* v12 end */
0197 
0198     /* v13: Delay waiting for write-protect copy */
0199     __u64    wpcopy_count;
0200     __u64    wpcopy_delay_total;
0201 };
0202 
0203 
0204 /*
0205  * Commands sent from userspace
0206  * Not versioned. New commands should only be inserted at the enum's end
0207  * prior to __TASKSTATS_CMD_MAX
0208  */
0209 
0210 enum {
0211     TASKSTATS_CMD_UNSPEC = 0,   /* Reserved */
0212     TASKSTATS_CMD_GET,      /* user->kernel request/get-response */
0213     TASKSTATS_CMD_NEW,      /* kernel->user event */
0214     __TASKSTATS_CMD_MAX,
0215 };
0216 
0217 #define TASKSTATS_CMD_MAX (__TASKSTATS_CMD_MAX - 1)
0218 
0219 enum {
0220     TASKSTATS_TYPE_UNSPEC = 0,  /* Reserved */
0221     TASKSTATS_TYPE_PID,     /* Process id */
0222     TASKSTATS_TYPE_TGID,        /* Thread group id */
0223     TASKSTATS_TYPE_STATS,       /* taskstats structure */
0224     TASKSTATS_TYPE_AGGR_PID,    /* contains pid + stats */
0225     TASKSTATS_TYPE_AGGR_TGID,   /* contains tgid + stats */
0226     TASKSTATS_TYPE_NULL,        /* contains nothing */
0227     __TASKSTATS_TYPE_MAX,
0228 };
0229 
0230 #define TASKSTATS_TYPE_MAX (__TASKSTATS_TYPE_MAX - 1)
0231 
0232 enum {
0233     TASKSTATS_CMD_ATTR_UNSPEC = 0,
0234     TASKSTATS_CMD_ATTR_PID,
0235     TASKSTATS_CMD_ATTR_TGID,
0236     TASKSTATS_CMD_ATTR_REGISTER_CPUMASK,
0237     TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK,
0238     __TASKSTATS_CMD_ATTR_MAX,
0239 };
0240 
0241 #define TASKSTATS_CMD_ATTR_MAX (__TASKSTATS_CMD_ATTR_MAX - 1)
0242 
0243 /* NETLINK_GENERIC related info */
0244 
0245 #define TASKSTATS_GENL_NAME "TASKSTATS"
0246 #define TASKSTATS_GENL_VERSION  0x1
0247 
0248 #endif /* _LINUX_TASKSTATS_H */