1e2be04c7SGreg Kroah-Hartman /* SPDX-License-Identifier: LGPL-2.1 WITH Linux-syscall-note */ 2607ca46eSDavid Howells /* taskstats.h - exporting per-task statistics 3607ca46eSDavid Howells * 4607ca46eSDavid Howells * Copyright (C) Shailabh Nagar, IBM Corp. 2006 5607ca46eSDavid Howells * (C) Balbir Singh, IBM Corp. 2006 6607ca46eSDavid Howells * (C) Jay Lan, SGI, 2006 7607ca46eSDavid Howells * 8607ca46eSDavid Howells * This program is free software; you can redistribute it and/or modify it 9607ca46eSDavid Howells * under the terms of version 2.1 of the GNU Lesser General Public License 10607ca46eSDavid Howells * as published by the Free Software Foundation. 11607ca46eSDavid Howells * 12607ca46eSDavid Howells * This program is distributed in the hope that it would be useful, but 13607ca46eSDavid Howells * WITHOUT ANY WARRANTY; without even the implied warranty of 14607ca46eSDavid Howells * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 15607ca46eSDavid Howells */ 16607ca46eSDavid Howells 17607ca46eSDavid Howells #ifndef _LINUX_TASKSTATS_H 18607ca46eSDavid Howells #define _LINUX_TASKSTATS_H 19607ca46eSDavid Howells 20607ca46eSDavid Howells #include <linux/types.h> 21607ca46eSDavid Howells 22607ca46eSDavid Howells /* Format for per-task data returned to userland when 23607ca46eSDavid Howells * - a task exits 24607ca46eSDavid Howells * - listener requests stats for a task 25607ca46eSDavid Howells * 26607ca46eSDavid Howells * The struct is versioned. Newer versions should only add fields to 27607ca46eSDavid Howells * the bottom of the struct to maintain backward compatibility. 28607ca46eSDavid Howells * 29607ca46eSDavid Howells * 30607ca46eSDavid Howells * To add new fields 31607ca46eSDavid Howells * a) bump up TASKSTATS_VERSION 32607ca46eSDavid Howells * b) add comment indicating new version number at end of struct 33607ca46eSDavid Howells * c) add new fields after version comment; maintain 64-bit alignment 34607ca46eSDavid Howells */ 35607ca46eSDavid Howells 36607ca46eSDavid Howells 37*0bf2d838SWang Yaxin #define TASKSTATS_VERSION 16 38607ca46eSDavid Howells #define TS_COMM_LEN 32 /* should be >= TASK_COMM_LEN 39607ca46eSDavid Howells * in linux/sched.h */ 40607ca46eSDavid Howells 41607ca46eSDavid Howells struct taskstats { 42607ca46eSDavid Howells 43607ca46eSDavid Howells /* The version number of this struct. This field is always set to 44607ca46eSDavid Howells * TAKSTATS_VERSION, which is defined in <linux/taskstats.h>. 45607ca46eSDavid Howells * Each time the struct is changed, the value should be incremented. 46607ca46eSDavid Howells */ 47607ca46eSDavid Howells __u16 version; 48607ca46eSDavid Howells __u32 ac_exitcode; /* Exit status */ 49607ca46eSDavid Howells 50607ca46eSDavid Howells /* The accounting flags of a task as defined in <linux/acct.h> 510e0af57eSDr. Thomas Orgis * Defined values are AFORK, ASU, ACOMPAT, ACORE, AXSIG, and AGROUP. 520e0af57eSDr. Thomas Orgis * (AGROUP since version 12). 53607ca46eSDavid Howells */ 54607ca46eSDavid Howells __u8 ac_flag; /* Record flags */ 55607ca46eSDavid Howells __u8 ac_nice; /* task_nice */ 56607ca46eSDavid Howells 57607ca46eSDavid Howells /* Delay accounting fields start 58607ca46eSDavid Howells * 59607ca46eSDavid Howells * All values, until comment "Delay accounting fields end" are 60607ca46eSDavid Howells * available only if delay accounting is enabled, even though the last 61607ca46eSDavid Howells * few fields are not delays 62607ca46eSDavid Howells * 63607ca46eSDavid Howells * xxx_count is the number of delay values recorded 64607ca46eSDavid Howells * xxx_delay_total is the corresponding cumulative delay in nanoseconds 65607ca46eSDavid Howells * 66607ca46eSDavid Howells * xxx_delay_total wraps around to zero on overflow 67607ca46eSDavid Howells * xxx_count incremented regardless of overflow 68607ca46eSDavid Howells */ 69607ca46eSDavid Howells 70607ca46eSDavid Howells /* Delay waiting for cpu, while runnable 71607ca46eSDavid Howells * count, delay_total NOT updated atomically 72607ca46eSDavid Howells */ 73607ca46eSDavid Howells __u64 cpu_count __attribute__((aligned(8))); 74607ca46eSDavid Howells __u64 cpu_delay_total; 75607ca46eSDavid Howells 76607ca46eSDavid Howells /* Following four fields atomically updated using task->delays->lock */ 77607ca46eSDavid Howells 78607ca46eSDavid Howells /* Delay waiting for synchronous block I/O to complete 79607ca46eSDavid Howells * does not account for delays in I/O submission 80607ca46eSDavid Howells */ 81607ca46eSDavid Howells __u64 blkio_count; 82607ca46eSDavid Howells __u64 blkio_delay_total; 83607ca46eSDavid Howells 84607ca46eSDavid Howells /* Delay waiting for page fault I/O (swap in only) */ 85607ca46eSDavid Howells __u64 swapin_count; 86607ca46eSDavid Howells __u64 swapin_delay_total; 87607ca46eSDavid Howells 88607ca46eSDavid Howells /* cpu "wall-clock" running time 89607ca46eSDavid Howells * On some architectures, value will adjust for cpu time stolen 90607ca46eSDavid Howells * from the kernel in involuntary waits due to virtualization. 91607ca46eSDavid Howells * Value is cumulative, in nanoseconds, without a corresponding count 92607ca46eSDavid Howells * and wraps around to zero silently on overflow 93607ca46eSDavid Howells */ 94607ca46eSDavid Howells __u64 cpu_run_real_total; 95607ca46eSDavid Howells 96607ca46eSDavid Howells /* cpu "virtual" running time 97607ca46eSDavid Howells * Uses time intervals seen by the kernel i.e. no adjustment 98607ca46eSDavid Howells * for kernel's involuntary waits due to virtualization. 99607ca46eSDavid Howells * Value is cumulative, in nanoseconds, without a corresponding count 100607ca46eSDavid Howells * and wraps around to zero silently on overflow 101607ca46eSDavid Howells */ 102607ca46eSDavid Howells __u64 cpu_run_virtual_total; 103607ca46eSDavid Howells /* Delay accounting fields end */ 104607ca46eSDavid Howells /* version 1 ends here */ 105607ca46eSDavid Howells 106607ca46eSDavid Howells /* Basic Accounting Fields start */ 107607ca46eSDavid Howells char ac_comm[TS_COMM_LEN]; /* Command name */ 108607ca46eSDavid Howells __u8 ac_sched __attribute__((aligned(8))); 109607ca46eSDavid Howells /* Scheduling discipline */ 110607ca46eSDavid Howells __u8 ac_pad[3]; 111607ca46eSDavid Howells __u32 ac_uid __attribute__((aligned(8))); 112607ca46eSDavid Howells /* User ID */ 113607ca46eSDavid Howells __u32 ac_gid; /* Group ID */ 114607ca46eSDavid Howells __u32 ac_pid; /* Process ID */ 115607ca46eSDavid Howells __u32 ac_ppid; /* Parent process ID */ 1162d602bf2SArnd Bergmann /* __u32 range means times from 1970 to 2106 */ 117607ca46eSDavid Howells __u32 ac_btime; /* Begin time [sec since 1970] */ 118607ca46eSDavid Howells __u64 ac_etime __attribute__((aligned(8))); 119607ca46eSDavid Howells /* Elapsed time [usec] */ 120607ca46eSDavid Howells __u64 ac_utime; /* User CPU time [usec] */ 121607ca46eSDavid Howells __u64 ac_stime; /* SYstem CPU time [usec] */ 122607ca46eSDavid Howells __u64 ac_minflt; /* Minor Page Fault Count */ 123607ca46eSDavid Howells __u64 ac_majflt; /* Major Page Fault Count */ 124607ca46eSDavid Howells /* Basic Accounting Fields end */ 125607ca46eSDavid Howells 126607ca46eSDavid Howells /* Extended accounting fields start */ 127607ca46eSDavid Howells /* Accumulated RSS usage in duration of a task, in MBytes-usecs. 128607ca46eSDavid Howells * The current rss usage is added to this counter every time 129607ca46eSDavid Howells * a tick is charged to a task's system time. So, at the end we 130607ca46eSDavid Howells * will have memory usage multiplied by system time. Thus an 131607ca46eSDavid Howells * average usage per system time unit can be calculated. 132607ca46eSDavid Howells */ 133607ca46eSDavid Howells __u64 coremem; /* accumulated RSS usage in MB-usec */ 134607ca46eSDavid Howells /* Accumulated virtual memory usage in duration of a task. 135607ca46eSDavid Howells * Same as acct_rss_mem1 above except that we keep track of VM usage. 136607ca46eSDavid Howells */ 137607ca46eSDavid Howells __u64 virtmem; /* accumulated VM usage in MB-usec */ 138607ca46eSDavid Howells 139607ca46eSDavid Howells /* High watermark of RSS and virtual memory usage in duration of 140607ca46eSDavid Howells * a task, in KBytes. 141607ca46eSDavid Howells */ 142607ca46eSDavid Howells __u64 hiwater_rss; /* High-watermark of RSS usage, in KB */ 143607ca46eSDavid Howells __u64 hiwater_vm; /* High-water VM usage, in KB */ 144607ca46eSDavid Howells 145607ca46eSDavid Howells /* The following four fields are I/O statistics of a task. */ 146607ca46eSDavid Howells __u64 read_char; /* bytes read */ 147607ca46eSDavid Howells __u64 write_char; /* bytes written */ 148607ca46eSDavid Howells __u64 read_syscalls; /* read syscalls */ 149607ca46eSDavid Howells __u64 write_syscalls; /* write syscalls */ 150607ca46eSDavid Howells /* Extended accounting fields end */ 151607ca46eSDavid Howells 152607ca46eSDavid Howells #define TASKSTATS_HAS_IO_ACCOUNTING 153607ca46eSDavid Howells /* Per-task storage I/O accounting starts */ 154607ca46eSDavid Howells __u64 read_bytes; /* bytes of read I/O */ 155607ca46eSDavid Howells __u64 write_bytes; /* bytes of write I/O */ 156607ca46eSDavid Howells __u64 cancelled_write_bytes; /* bytes of cancelled write I/O */ 157607ca46eSDavid Howells 158607ca46eSDavid Howells __u64 nvcsw; /* voluntary_ctxt_switches */ 159607ca46eSDavid Howells __u64 nivcsw; /* nonvoluntary_ctxt_switches */ 160607ca46eSDavid Howells 161607ca46eSDavid Howells /* time accounting for SMT machines */ 162607ca46eSDavid Howells __u64 ac_utimescaled; /* utime scaled on frequency etc */ 163607ca46eSDavid Howells __u64 ac_stimescaled; /* stime scaled on frequency etc */ 164607ca46eSDavid Howells __u64 cpu_scaled_run_real_total; /* scaled cpu_run_real_total */ 165607ca46eSDavid Howells 166607ca46eSDavid Howells /* Delay waiting for memory reclaim */ 167607ca46eSDavid Howells __u64 freepages_count; 168607ca46eSDavid Howells __u64 freepages_delay_total; 169*0bf2d838SWang Yaxin 170b1d29ba8SJohannes Weiner 171b1d29ba8SJohannes Weiner /* Delay waiting for thrashing page */ 172b1d29ba8SJohannes Weiner __u64 thrashing_count; 173b1d29ba8SJohannes Weiner __u64 thrashing_delay_total; 174352c912bSArnd Bergmann 175352c912bSArnd Bergmann /* v10: 64-bit btime to avoid overflow */ 176352c912bSArnd Bergmann __u64 ac_btime64; /* 64-bit begin time */ 1775bf18281Swangyong 1780e0af57eSDr. Thomas Orgis /* v11: Delay waiting for memory compact */ 1795bf18281Swangyong __u64 compact_count; 1805bf18281Swangyong __u64 compact_delay_total; 1810e0af57eSDr. Thomas Orgis 1820e0af57eSDr. Thomas Orgis /* v12 begin */ 1830e0af57eSDr. Thomas Orgis __u32 ac_tgid; /* thread group ID */ 1840e0af57eSDr. Thomas Orgis /* Thread group walltime up to now. This is total process walltime if 1850e0af57eSDr. Thomas Orgis * AGROUP flag is set. 1860e0af57eSDr. Thomas Orgis */ 1870e0af57eSDr. Thomas Orgis __u64 ac_tgetime __attribute__((aligned(8))); 1880e0af57eSDr. Thomas Orgis /* Lightweight information to identify process binary files. 1890e0af57eSDr. Thomas Orgis * This leaves userspace to match this to a file system path, using 1900e0af57eSDr. Thomas Orgis * MAJOR() and MINOR() macros to identify a device and mount point, 1910e0af57eSDr. Thomas Orgis * the inode to identify the executable file. This is /proc/self/exe 1920e0af57eSDr. Thomas Orgis * at the end, so matching the most recent exec(). Values are zero 1930e0af57eSDr. Thomas Orgis * for kernel threads. 1940e0af57eSDr. Thomas Orgis */ 1950e0af57eSDr. Thomas Orgis __u64 ac_exe_dev; /* program binary device ID */ 1960e0af57eSDr. Thomas Orgis __u64 ac_exe_inode; /* program binary inode number */ 1970e0af57eSDr. Thomas Orgis /* v12 end */ 198662ce1dcSYang Yang 199662ce1dcSYang Yang /* v13: Delay waiting for write-protect copy */ 200662ce1dcSYang Yang __u64 wpcopy_count; 201662ce1dcSYang Yang __u64 wpcopy_delay_total; 202a3b2aeacSYang Yang 203a3b2aeacSYang Yang /* v14: Delay waiting for IRQ/SOFTIRQ */ 204a3b2aeacSYang Yang __u64 irq_count; 205a3b2aeacSYang Yang __u64 irq_delay_total; 206*0bf2d838SWang Yaxin 207*0bf2d838SWang Yaxin /* v15: add Delay max and Delay min */ 208*0bf2d838SWang Yaxin 209*0bf2d838SWang Yaxin /* v16: move Delay max and Delay min to the end of taskstat */ 210*0bf2d838SWang Yaxin __u64 cpu_delay_max; 211*0bf2d838SWang Yaxin __u64 cpu_delay_min; 212*0bf2d838SWang Yaxin 213*0bf2d838SWang Yaxin __u64 blkio_delay_max; 214*0bf2d838SWang Yaxin __u64 blkio_delay_min; 215*0bf2d838SWang Yaxin 216*0bf2d838SWang Yaxin __u64 swapin_delay_max; 217*0bf2d838SWang Yaxin __u64 swapin_delay_min; 218*0bf2d838SWang Yaxin 219*0bf2d838SWang Yaxin __u64 freepages_delay_max; 220*0bf2d838SWang Yaxin __u64 freepages_delay_min; 221*0bf2d838SWang Yaxin 222*0bf2d838SWang Yaxin __u64 thrashing_delay_max; 223*0bf2d838SWang Yaxin __u64 thrashing_delay_min; 224*0bf2d838SWang Yaxin 225*0bf2d838SWang Yaxin __u64 compact_delay_max; 226*0bf2d838SWang Yaxin __u64 compact_delay_min; 227*0bf2d838SWang Yaxin 228*0bf2d838SWang Yaxin __u64 wpcopy_delay_max; 229*0bf2d838SWang Yaxin __u64 wpcopy_delay_min; 230*0bf2d838SWang Yaxin 231658eb5abSWang Yaxin __u64 irq_delay_max; 232f65c64f3SWang Yaxin __u64 irq_delay_min; 233607ca46eSDavid Howells }; 234607ca46eSDavid Howells 235607ca46eSDavid Howells 236607ca46eSDavid Howells /* 237607ca46eSDavid Howells * Commands sent from userspace 238607ca46eSDavid Howells * Not versioned. New commands should only be inserted at the enum's end 239607ca46eSDavid Howells * prior to __TASKSTATS_CMD_MAX 240607ca46eSDavid Howells */ 241607ca46eSDavid Howells 242607ca46eSDavid Howells enum { 243607ca46eSDavid Howells TASKSTATS_CMD_UNSPEC = 0, /* Reserved */ 244607ca46eSDavid Howells TASKSTATS_CMD_GET, /* user->kernel request/get-response */ 245607ca46eSDavid Howells TASKSTATS_CMD_NEW, /* kernel->user event */ 246607ca46eSDavid Howells __TASKSTATS_CMD_MAX, 247607ca46eSDavid Howells }; 248607ca46eSDavid Howells 249607ca46eSDavid Howells #define TASKSTATS_CMD_MAX (__TASKSTATS_CMD_MAX - 1) 250607ca46eSDavid Howells 251607ca46eSDavid Howells enum { 252607ca46eSDavid Howells TASKSTATS_TYPE_UNSPEC = 0, /* Reserved */ 253607ca46eSDavid Howells TASKSTATS_TYPE_PID, /* Process id */ 254607ca46eSDavid Howells TASKSTATS_TYPE_TGID, /* Thread group id */ 255607ca46eSDavid Howells TASKSTATS_TYPE_STATS, /* taskstats structure */ 256607ca46eSDavid Howells TASKSTATS_TYPE_AGGR_PID, /* contains pid + stats */ 257607ca46eSDavid Howells TASKSTATS_TYPE_AGGR_TGID, /* contains tgid + stats */ 258607ca46eSDavid Howells TASKSTATS_TYPE_NULL, /* contains nothing */ 259607ca46eSDavid Howells __TASKSTATS_TYPE_MAX, 260607ca46eSDavid Howells }; 261607ca46eSDavid Howells 262607ca46eSDavid Howells #define TASKSTATS_TYPE_MAX (__TASKSTATS_TYPE_MAX - 1) 263607ca46eSDavid Howells 264607ca46eSDavid Howells enum { 265607ca46eSDavid Howells TASKSTATS_CMD_ATTR_UNSPEC = 0, 266607ca46eSDavid Howells TASKSTATS_CMD_ATTR_PID, 267607ca46eSDavid Howells TASKSTATS_CMD_ATTR_TGID, 268607ca46eSDavid Howells TASKSTATS_CMD_ATTR_REGISTER_CPUMASK, 269607ca46eSDavid Howells TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK, 270607ca46eSDavid Howells __TASKSTATS_CMD_ATTR_MAX, 271607ca46eSDavid Howells }; 272607ca46eSDavid Howells 273607ca46eSDavid Howells #define TASKSTATS_CMD_ATTR_MAX (__TASKSTATS_CMD_ATTR_MAX - 1) 274607ca46eSDavid Howells 275607ca46eSDavid Howells /* NETLINK_GENERIC related info */ 276607ca46eSDavid Howells 277607ca46eSDavid Howells #define TASKSTATS_GENL_NAME "TASKSTATS" 278607ca46eSDavid Howells #define TASKSTATS_GENL_VERSION 0x1 279607ca46eSDavid Howells 280607ca46eSDavid Howells #endif /* _LINUX_TASKSTATS_H */ 281