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 37b1d29ba8SJohannes Weiner #define TASKSTATS_VERSION 9 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> 51607ca46eSDavid Howells * Defined values are AFORK, ASU, ACOMPAT, ACORE, and AXSIG. 52607ca46eSDavid Howells */ 53607ca46eSDavid Howells __u8 ac_flag; /* Record flags */ 54607ca46eSDavid Howells __u8 ac_nice; /* task_nice */ 55607ca46eSDavid Howells 56607ca46eSDavid Howells /* Delay accounting fields start 57607ca46eSDavid Howells * 58607ca46eSDavid Howells * All values, until comment "Delay accounting fields end" are 59607ca46eSDavid Howells * available only if delay accounting is enabled, even though the last 60607ca46eSDavid Howells * few fields are not delays 61607ca46eSDavid Howells * 62607ca46eSDavid Howells * xxx_count is the number of delay values recorded 63607ca46eSDavid Howells * xxx_delay_total is the corresponding cumulative delay in nanoseconds 64607ca46eSDavid Howells * 65607ca46eSDavid Howells * xxx_delay_total wraps around to zero on overflow 66607ca46eSDavid Howells * xxx_count incremented regardless of overflow 67607ca46eSDavid Howells */ 68607ca46eSDavid Howells 69607ca46eSDavid Howells /* Delay waiting for cpu, while runnable 70607ca46eSDavid Howells * count, delay_total NOT updated atomically 71607ca46eSDavid Howells */ 72607ca46eSDavid Howells __u64 cpu_count __attribute__((aligned(8))); 73607ca46eSDavid Howells __u64 cpu_delay_total; 74607ca46eSDavid Howells 75607ca46eSDavid Howells /* Following four fields atomically updated using task->delays->lock */ 76607ca46eSDavid Howells 77607ca46eSDavid Howells /* Delay waiting for synchronous block I/O to complete 78607ca46eSDavid Howells * does not account for delays in I/O submission 79607ca46eSDavid Howells */ 80607ca46eSDavid Howells __u64 blkio_count; 81607ca46eSDavid Howells __u64 blkio_delay_total; 82607ca46eSDavid Howells 83607ca46eSDavid Howells /* Delay waiting for page fault I/O (swap in only) */ 84607ca46eSDavid Howells __u64 swapin_count; 85607ca46eSDavid Howells __u64 swapin_delay_total; 86607ca46eSDavid Howells 87607ca46eSDavid Howells /* cpu "wall-clock" running time 88607ca46eSDavid Howells * On some architectures, value will adjust for cpu time stolen 89607ca46eSDavid Howells * from the kernel in involuntary waits due to virtualization. 90607ca46eSDavid Howells * Value is cumulative, in nanoseconds, without a corresponding count 91607ca46eSDavid Howells * and wraps around to zero silently on overflow 92607ca46eSDavid Howells */ 93607ca46eSDavid Howells __u64 cpu_run_real_total; 94607ca46eSDavid Howells 95607ca46eSDavid Howells /* cpu "virtual" running time 96607ca46eSDavid Howells * Uses time intervals seen by the kernel i.e. no adjustment 97607ca46eSDavid Howells * for kernel's involuntary waits due to virtualization. 98607ca46eSDavid Howells * Value is cumulative, in nanoseconds, without a corresponding count 99607ca46eSDavid Howells * and wraps around to zero silently on overflow 100607ca46eSDavid Howells */ 101607ca46eSDavid Howells __u64 cpu_run_virtual_total; 102607ca46eSDavid Howells /* Delay accounting fields end */ 103607ca46eSDavid Howells /* version 1 ends here */ 104607ca46eSDavid Howells 105607ca46eSDavid Howells /* Basic Accounting Fields start */ 106607ca46eSDavid Howells char ac_comm[TS_COMM_LEN]; /* Command name */ 107607ca46eSDavid Howells __u8 ac_sched __attribute__((aligned(8))); 108607ca46eSDavid Howells /* Scheduling discipline */ 109607ca46eSDavid Howells __u8 ac_pad[3]; 110607ca46eSDavid Howells __u32 ac_uid __attribute__((aligned(8))); 111607ca46eSDavid Howells /* User ID */ 112607ca46eSDavid Howells __u32 ac_gid; /* Group ID */ 113607ca46eSDavid Howells __u32 ac_pid; /* Process ID */ 114607ca46eSDavid Howells __u32 ac_ppid; /* Parent process ID */ 115*2d602bf2SArnd Bergmann /* __u32 range means times from 1970 to 2106 */ 116607ca46eSDavid Howells __u32 ac_btime; /* Begin time [sec since 1970] */ 117607ca46eSDavid Howells __u64 ac_etime __attribute__((aligned(8))); 118607ca46eSDavid Howells /* Elapsed time [usec] */ 119607ca46eSDavid Howells __u64 ac_utime; /* User CPU time [usec] */ 120607ca46eSDavid Howells __u64 ac_stime; /* SYstem CPU time [usec] */ 121607ca46eSDavid Howells __u64 ac_minflt; /* Minor Page Fault Count */ 122607ca46eSDavid Howells __u64 ac_majflt; /* Major Page Fault Count */ 123607ca46eSDavid Howells /* Basic Accounting Fields end */ 124607ca46eSDavid Howells 125607ca46eSDavid Howells /* Extended accounting fields start */ 126607ca46eSDavid Howells /* Accumulated RSS usage in duration of a task, in MBytes-usecs. 127607ca46eSDavid Howells * The current rss usage is added to this counter every time 128607ca46eSDavid Howells * a tick is charged to a task's system time. So, at the end we 129607ca46eSDavid Howells * will have memory usage multiplied by system time. Thus an 130607ca46eSDavid Howells * average usage per system time unit can be calculated. 131607ca46eSDavid Howells */ 132607ca46eSDavid Howells __u64 coremem; /* accumulated RSS usage in MB-usec */ 133607ca46eSDavid Howells /* Accumulated virtual memory usage in duration of a task. 134607ca46eSDavid Howells * Same as acct_rss_mem1 above except that we keep track of VM usage. 135607ca46eSDavid Howells */ 136607ca46eSDavid Howells __u64 virtmem; /* accumulated VM usage in MB-usec */ 137607ca46eSDavid Howells 138607ca46eSDavid Howells /* High watermark of RSS and virtual memory usage in duration of 139607ca46eSDavid Howells * a task, in KBytes. 140607ca46eSDavid Howells */ 141607ca46eSDavid Howells __u64 hiwater_rss; /* High-watermark of RSS usage, in KB */ 142607ca46eSDavid Howells __u64 hiwater_vm; /* High-water VM usage, in KB */ 143607ca46eSDavid Howells 144607ca46eSDavid Howells /* The following four fields are I/O statistics of a task. */ 145607ca46eSDavid Howells __u64 read_char; /* bytes read */ 146607ca46eSDavid Howells __u64 write_char; /* bytes written */ 147607ca46eSDavid Howells __u64 read_syscalls; /* read syscalls */ 148607ca46eSDavid Howells __u64 write_syscalls; /* write syscalls */ 149607ca46eSDavid Howells /* Extended accounting fields end */ 150607ca46eSDavid Howells 151607ca46eSDavid Howells #define TASKSTATS_HAS_IO_ACCOUNTING 152607ca46eSDavid Howells /* Per-task storage I/O accounting starts */ 153607ca46eSDavid Howells __u64 read_bytes; /* bytes of read I/O */ 154607ca46eSDavid Howells __u64 write_bytes; /* bytes of write I/O */ 155607ca46eSDavid Howells __u64 cancelled_write_bytes; /* bytes of cancelled write I/O */ 156607ca46eSDavid Howells 157607ca46eSDavid Howells __u64 nvcsw; /* voluntary_ctxt_switches */ 158607ca46eSDavid Howells __u64 nivcsw; /* nonvoluntary_ctxt_switches */ 159607ca46eSDavid Howells 160607ca46eSDavid Howells /* time accounting for SMT machines */ 161607ca46eSDavid Howells __u64 ac_utimescaled; /* utime scaled on frequency etc */ 162607ca46eSDavid Howells __u64 ac_stimescaled; /* stime scaled on frequency etc */ 163607ca46eSDavid Howells __u64 cpu_scaled_run_real_total; /* scaled cpu_run_real_total */ 164607ca46eSDavid Howells 165607ca46eSDavid Howells /* Delay waiting for memory reclaim */ 166607ca46eSDavid Howells __u64 freepages_count; 167607ca46eSDavid Howells __u64 freepages_delay_total; 168b1d29ba8SJohannes Weiner 169b1d29ba8SJohannes Weiner /* Delay waiting for thrashing page */ 170b1d29ba8SJohannes Weiner __u64 thrashing_count; 171b1d29ba8SJohannes Weiner __u64 thrashing_delay_total; 172607ca46eSDavid Howells }; 173607ca46eSDavid Howells 174607ca46eSDavid Howells 175607ca46eSDavid Howells /* 176607ca46eSDavid Howells * Commands sent from userspace 177607ca46eSDavid Howells * Not versioned. New commands should only be inserted at the enum's end 178607ca46eSDavid Howells * prior to __TASKSTATS_CMD_MAX 179607ca46eSDavid Howells */ 180607ca46eSDavid Howells 181607ca46eSDavid Howells enum { 182607ca46eSDavid Howells TASKSTATS_CMD_UNSPEC = 0, /* Reserved */ 183607ca46eSDavid Howells TASKSTATS_CMD_GET, /* user->kernel request/get-response */ 184607ca46eSDavid Howells TASKSTATS_CMD_NEW, /* kernel->user event */ 185607ca46eSDavid Howells __TASKSTATS_CMD_MAX, 186607ca46eSDavid Howells }; 187607ca46eSDavid Howells 188607ca46eSDavid Howells #define TASKSTATS_CMD_MAX (__TASKSTATS_CMD_MAX - 1) 189607ca46eSDavid Howells 190607ca46eSDavid Howells enum { 191607ca46eSDavid Howells TASKSTATS_TYPE_UNSPEC = 0, /* Reserved */ 192607ca46eSDavid Howells TASKSTATS_TYPE_PID, /* Process id */ 193607ca46eSDavid Howells TASKSTATS_TYPE_TGID, /* Thread group id */ 194607ca46eSDavid Howells TASKSTATS_TYPE_STATS, /* taskstats structure */ 195607ca46eSDavid Howells TASKSTATS_TYPE_AGGR_PID, /* contains pid + stats */ 196607ca46eSDavid Howells TASKSTATS_TYPE_AGGR_TGID, /* contains tgid + stats */ 197607ca46eSDavid Howells TASKSTATS_TYPE_NULL, /* contains nothing */ 198607ca46eSDavid Howells __TASKSTATS_TYPE_MAX, 199607ca46eSDavid Howells }; 200607ca46eSDavid Howells 201607ca46eSDavid Howells #define TASKSTATS_TYPE_MAX (__TASKSTATS_TYPE_MAX - 1) 202607ca46eSDavid Howells 203607ca46eSDavid Howells enum { 204607ca46eSDavid Howells TASKSTATS_CMD_ATTR_UNSPEC = 0, 205607ca46eSDavid Howells TASKSTATS_CMD_ATTR_PID, 206607ca46eSDavid Howells TASKSTATS_CMD_ATTR_TGID, 207607ca46eSDavid Howells TASKSTATS_CMD_ATTR_REGISTER_CPUMASK, 208607ca46eSDavid Howells TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK, 209607ca46eSDavid Howells __TASKSTATS_CMD_ATTR_MAX, 210607ca46eSDavid Howells }; 211607ca46eSDavid Howells 212607ca46eSDavid Howells #define TASKSTATS_CMD_ATTR_MAX (__TASKSTATS_CMD_ATTR_MAX - 1) 213607ca46eSDavid Howells 214607ca46eSDavid Howells /* NETLINK_GENERIC related info */ 215607ca46eSDavid Howells 216607ca46eSDavid Howells #define TASKSTATS_GENL_NAME "TASKSTATS" 217607ca46eSDavid Howells #define TASKSTATS_GENL_VERSION 0x1 218607ca46eSDavid Howells 219607ca46eSDavid Howells #endif /* _LINUX_TASKSTATS_H */ 220