Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * BSD Process Accounting for Linux - Definitions |
| 3 | * |
| 4 | * Author: Marco van Wieringen (mvw@planets.elm.net) |
| 5 | * |
| 6 | * This header file contains the definitions needed to implement |
| 7 | * BSD-style process accounting. The kernel accounting code and all |
| 8 | * user-level programs that try to do something useful with the |
| 9 | * process accounting log must include this file. |
| 10 | * |
| 11 | * Copyright (C) 1995 - 1997 Marco van Wieringen - ELM Consultancy B.V. |
| 12 | * |
| 13 | */ |
| 14 | |
| 15 | #ifndef _LINUX_ACCT_H |
| 16 | #define _LINUX_ACCT_H |
| 17 | |
| 18 | #include <linux/types.h> |
Andrew Morton | ff6ed40 | 2005-11-13 16:07:38 -0800 | [diff] [blame] | 19 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | #include <asm/param.h> |
| 21 | #include <asm/byteorder.h> |
| 22 | |
| 23 | /* |
| 24 | * comp_t is a 16-bit "floating" point number with a 3-bit base 8 |
| 25 | * exponent and a 13-bit fraction. |
| 26 | * comp2_t is 24-bit with 5-bit base 2 exponent and 20 bit fraction |
| 27 | * (leading 1 not stored). |
| 28 | * See linux/kernel/acct.c for the specific encoding systems used. |
| 29 | */ |
| 30 | |
| 31 | typedef __u16 comp_t; |
| 32 | typedef __u32 comp2_t; |
| 33 | |
| 34 | /* |
| 35 | * accounting file record |
| 36 | * |
| 37 | * This structure contains all of the information written out to the |
| 38 | * process accounting file whenever a process exits. |
| 39 | */ |
| 40 | |
| 41 | #define ACCT_COMM 16 |
| 42 | |
| 43 | struct acct |
| 44 | { |
| 45 | char ac_flag; /* Flags */ |
| 46 | char ac_version; /* Always set to ACCT_VERSION */ |
| 47 | /* for binary compatibility back until 2.0 */ |
| 48 | __u16 ac_uid16; /* LSB of Real User ID */ |
| 49 | __u16 ac_gid16; /* LSB of Real Group ID */ |
| 50 | __u16 ac_tty; /* Control Terminal */ |
| 51 | __u32 ac_btime; /* Process Creation Time */ |
| 52 | comp_t ac_utime; /* User Time */ |
| 53 | comp_t ac_stime; /* System Time */ |
| 54 | comp_t ac_etime; /* Elapsed Time */ |
| 55 | comp_t ac_mem; /* Average Memory Usage */ |
| 56 | comp_t ac_io; /* Chars Transferred */ |
| 57 | comp_t ac_rw; /* Blocks Read or Written */ |
| 58 | comp_t ac_minflt; /* Minor Pagefaults */ |
| 59 | comp_t ac_majflt; /* Major Pagefaults */ |
| 60 | comp_t ac_swaps; /* Number of Swaps */ |
| 61 | /* m68k had no padding here. */ |
| 62 | #if !defined(CONFIG_M68K) || !defined(__KERNEL__) |
| 63 | __u16 ac_ahz; /* AHZ */ |
| 64 | #endif |
| 65 | __u32 ac_exitcode; /* Exitcode */ |
| 66 | char ac_comm[ACCT_COMM + 1]; /* Command Name */ |
| 67 | __u8 ac_etime_hi; /* Elapsed Time MSB */ |
| 68 | __u16 ac_etime_lo; /* Elapsed Time LSB */ |
| 69 | __u32 ac_uid; /* Real User ID */ |
| 70 | __u32 ac_gid; /* Real Group ID */ |
| 71 | }; |
| 72 | |
| 73 | struct acct_v3 |
| 74 | { |
| 75 | char ac_flag; /* Flags */ |
| 76 | char ac_version; /* Always set to ACCT_VERSION */ |
| 77 | __u16 ac_tty; /* Control Terminal */ |
| 78 | __u32 ac_exitcode; /* Exitcode */ |
| 79 | __u32 ac_uid; /* Real User ID */ |
| 80 | __u32 ac_gid; /* Real Group ID */ |
| 81 | __u32 ac_pid; /* Process ID */ |
| 82 | __u32 ac_ppid; /* Parent Process ID */ |
| 83 | __u32 ac_btime; /* Process Creation Time */ |
| 84 | #ifdef __KERNEL__ |
| 85 | __u32 ac_etime; /* Elapsed Time */ |
| 86 | #else |
| 87 | float ac_etime; /* Elapsed Time */ |
| 88 | #endif |
| 89 | comp_t ac_utime; /* User Time */ |
| 90 | comp_t ac_stime; /* System Time */ |
| 91 | comp_t ac_mem; /* Average Memory Usage */ |
| 92 | comp_t ac_io; /* Chars Transferred */ |
| 93 | comp_t ac_rw; /* Blocks Read or Written */ |
| 94 | comp_t ac_minflt; /* Minor Pagefaults */ |
| 95 | comp_t ac_majflt; /* Major Pagefaults */ |
| 96 | comp_t ac_swaps; /* Number of Swaps */ |
| 97 | char ac_comm[ACCT_COMM]; /* Command Name */ |
| 98 | }; |
| 99 | |
| 100 | /* |
| 101 | * accounting flags |
| 102 | */ |
| 103 | /* bit set when the process ... */ |
| 104 | #define AFORK 0x01 /* ... executed fork, but did not exec */ |
| 105 | #define ASU 0x02 /* ... used super-user privileges */ |
| 106 | #define ACOMPAT 0x04 /* ... used compatibility mode (VAX only not used) */ |
| 107 | #define ACORE 0x08 /* ... dumped core */ |
| 108 | #define AXSIG 0x10 /* ... was killed by a signal */ |
| 109 | |
| 110 | #ifdef __BIG_ENDIAN |
| 111 | #define ACCT_BYTEORDER 0x80 /* accounting file is big endian */ |
| 112 | #else |
| 113 | #define ACCT_BYTEORDER 0x00 /* accounting file is little endian */ |
| 114 | #endif |
| 115 | |
| 116 | #ifdef __KERNEL__ |
| 117 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | |
| 119 | #ifdef CONFIG_BSD_PROCESS_ACCT |
Al Viro | 7b7b1ac | 2005-11-07 17:13:39 -0500 | [diff] [blame] | 120 | struct vfsmount; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | struct super_block; |
Al Viro | f6a5703 | 2006-10-18 01:47:25 -0400 | [diff] [blame] | 122 | struct pacct_struct; |
Pavel Emelyanov | 0b6b030 | 2008-07-25 01:48:47 -0700 | [diff] [blame] | 123 | struct pid_namespace; |
Al Viro | 7b7b1ac | 2005-11-07 17:13:39 -0500 | [diff] [blame] | 124 | extern void acct_auto_close_mnt(struct vfsmount *m); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | extern void acct_auto_close(struct super_block *sb); |
KaiGai Kohei | 0e46481 | 2006-06-25 05:49:24 -0700 | [diff] [blame] | 126 | extern void acct_init_pacct(struct pacct_struct *pacct); |
KaiGai Kohei | f6ec29a | 2006-06-25 05:49:25 -0700 | [diff] [blame] | 127 | extern void acct_collect(long exitcode, int group_dead); |
| 128 | extern void acct_process(void); |
Pavel Emelyanov | 0b6b030 | 2008-07-25 01:48:47 -0700 | [diff] [blame] | 129 | extern void acct_exit_ns(struct pid_namespace *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | #else |
Al Viro | 7b7b1ac | 2005-11-07 17:13:39 -0500 | [diff] [blame] | 131 | #define acct_auto_close_mnt(x) do { } while (0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | #define acct_auto_close(x) do { } while (0) |
KaiGai Kohei | 0e46481 | 2006-06-25 05:49:24 -0700 | [diff] [blame] | 133 | #define acct_init_pacct(x) do { } while (0) |
KaiGai Kohei | f6ec29a | 2006-06-25 05:49:25 -0700 | [diff] [blame] | 134 | #define acct_collect(x,y) do { } while (0) |
| 135 | #define acct_process() do { } while (0) |
Pavel Emelyanov | 0b6b030 | 2008-07-25 01:48:47 -0700 | [diff] [blame] | 136 | #define acct_exit_ns(ns) do { } while (0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | #endif |
| 138 | |
| 139 | /* |
| 140 | * ACCT_VERSION numbers as yet defined: |
| 141 | * 0: old format (until 2.6.7) with 16 bit uid/gid |
| 142 | * 1: extended variant (binary compatible on M68K) |
| 143 | * 2: extended variant (binary compatible on everything except M68K) |
| 144 | * 3: new binary incompatible format (64 bytes) |
| 145 | * 4: new binary incompatible format (128 bytes) |
| 146 | * 5: new binary incompatible format (128 bytes, second half) |
| 147 | * |
| 148 | */ |
| 149 | |
| 150 | #ifdef CONFIG_BSD_PROCESS_ACCT_V3 |
| 151 | #define ACCT_VERSION 3 |
| 152 | #define AHZ 100 |
| 153 | typedef struct acct_v3 acct_t; |
| 154 | #else |
| 155 | #ifdef CONFIG_M68K |
| 156 | #define ACCT_VERSION 1 |
| 157 | #else |
| 158 | #define ACCT_VERSION 2 |
| 159 | #endif |
| 160 | #define AHZ (USER_HZ) |
| 161 | typedef struct acct acct_t; |
| 162 | #endif |
| 163 | |
| 164 | #else |
| 165 | #define ACCT_VERSION 2 |
| 166 | #define AHZ (HZ) |
| 167 | #endif /* __KERNEL */ |
| 168 | |
| 169 | #ifdef __KERNEL__ |
David Woodhouse | a1ff0ea | 2006-04-25 13:57:44 +0100 | [diff] [blame] | 170 | #include <linux/jiffies.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | /* |
| 172 | * Yet another set of HZ to *HZ helper functions. |
Tim Schmielau | e26148d | 2005-10-14 15:59:05 -0700 | [diff] [blame] | 173 | * See <linux/jiffies.h> for the original. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | */ |
| 175 | |
| 176 | static inline u32 jiffies_to_AHZ(unsigned long x) |
| 177 | { |
| 178 | #if (TICK_NSEC % (NSEC_PER_SEC / AHZ)) == 0 |
David Fries | 6ffc787 | 2008-02-06 01:38:04 -0800 | [diff] [blame] | 179 | # if HZ < AHZ |
| 180 | return x * (AHZ / HZ); |
| 181 | # else |
Tim Schmielau | e26148d | 2005-10-14 15:59:05 -0700 | [diff] [blame] | 182 | return x / (HZ / AHZ); |
David Fries | 6ffc787 | 2008-02-06 01:38:04 -0800 | [diff] [blame] | 183 | # endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | #else |
| 185 | u64 tmp = (u64)x * TICK_NSEC; |
| 186 | do_div(tmp, (NSEC_PER_SEC / AHZ)); |
| 187 | return (long)tmp; |
| 188 | #endif |
| 189 | } |
| 190 | |
| 191 | static inline u64 nsec_to_AHZ(u64 x) |
| 192 | { |
| 193 | #if (NSEC_PER_SEC % AHZ) == 0 |
| 194 | do_div(x, (NSEC_PER_SEC / AHZ)); |
| 195 | #elif (AHZ % 512) == 0 |
| 196 | x *= AHZ/512; |
| 197 | do_div(x, (NSEC_PER_SEC / 512)); |
| 198 | #else |
| 199 | /* |
| 200 | * max relative error 5.7e-8 (1.8s per year) for AHZ <= 1024, |
| 201 | * overflow after 64.99 years. |
| 202 | * exact for AHZ=60, 72, 90, 120, 144, 180, 300, 600, 900, ... |
| 203 | */ |
| 204 | x *= 9; |
| 205 | do_div(x, (unsigned long)((9ull * NSEC_PER_SEC + (AHZ/2)) |
| 206 | / AHZ)); |
| 207 | #endif |
| 208 | return x; |
| 209 | } |
| 210 | |
| 211 | #endif /* __KERNEL */ |
| 212 | |
| 213 | #endif /* _LINUX_ACCT_H */ |