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