initial commit with v2.6.9
[linux-2.6.9-moxart.git] / include / linux / acct.h
bloba6ab17c49aa1586310566073c07782aebac1be9d
1 /*
2 * BSD Process Accounting for Linux - Definitions
4 * Author: Marco van Wieringen (mvw@planets.elm.net)
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.
11 * Copyright (C) 1995 - 1997 Marco van Wieringen - ELM Consultancy B.V.
15 #ifndef _LINUX_ACCT_H
16 #define _LINUX_ACCT_H
18 #include <linux/types.h>
19 #include <asm/param.h>
20 #include <asm/byteorder.h>
22 /*
23 * comp_t is a 16-bit "floating" point number with a 3-bit base 8
24 * exponent and a 13-bit fraction.
25 * comp2_t is 24-bit with 5-bit base 2 exponent and 20 bit fraction
26 * (leading 1 not stored).
27 * See linux/kernel/acct.c for the specific encoding systems used.
30 typedef __u16 comp_t;
31 typedef __u32 comp2_t;
34 * accounting file record
36 * This structure contains all of the information written out to the
37 * process accounting file whenever a process exits.
40 #define ACCT_COMM 16
42 struct acct
44 char ac_flag; /* Flags */
45 char ac_version; /* Always set to ACCT_VERSION */
46 /* for binary compatibility back until 2.0 */
47 __u16 ac_uid16; /* LSB of Real User ID */
48 __u16 ac_gid16; /* LSB of Real Group ID */
49 __u16 ac_tty; /* Control Terminal */
50 __u32 ac_btime; /* Process Creation Time */
51 comp_t ac_utime; /* User Time */
52 comp_t ac_stime; /* System Time */
53 comp_t ac_etime; /* Elapsed Time */
54 comp_t ac_mem; /* Average Memory Usage */
55 comp_t ac_io; /* Chars Transferred */
56 comp_t ac_rw; /* Blocks Read or Written */
57 comp_t ac_minflt; /* Minor Pagefaults */
58 comp_t ac_majflt; /* Major Pagefaults */
59 comp_t ac_swaps; /* Number of Swaps */
60 /* m68k had no padding here. */
61 #if !defined(CONFIG_M68K) || !defined(__KERNEL__)
62 __u16 ac_ahz; /* AHZ */
63 #endif
64 __u32 ac_exitcode; /* Exitcode */
65 char ac_comm[ACCT_COMM + 1]; /* Command Name */
66 __u8 ac_etime_hi; /* Elapsed Time MSB */
67 __u16 ac_etime_lo; /* Elapsed Time LSB */
68 __u32 ac_uid; /* Real User ID */
69 __u32 ac_gid; /* Real Group ID */
72 struct acct_v3
74 char ac_flag; /* Flags */
75 char ac_version; /* Always set to ACCT_VERSION */
76 __u16 ac_tty; /* Control Terminal */
77 __u32 ac_exitcode; /* Exitcode */
78 __u32 ac_uid; /* Real User ID */
79 __u32 ac_gid; /* Real Group ID */
80 __u32 ac_pid; /* Process ID */
81 __u32 ac_ppid; /* Parent Process ID */
82 __u32 ac_btime; /* Process Creation Time */
83 #ifdef __KERNEL__
84 __u32 ac_etime; /* Elapsed Time */
85 #else
86 float ac_etime; /* Elapsed Time */
87 #endif
88 comp_t ac_utime; /* User Time */
89 comp_t ac_stime; /* System Time */
90 comp_t ac_mem; /* Average Memory Usage */
91 comp_t ac_io; /* Chars Transferred */
92 comp_t ac_rw; /* Blocks Read or Written */
93 comp_t ac_minflt; /* Minor Pagefaults */
94 comp_t ac_majflt; /* Major Pagefaults */
95 comp_t ac_swaps; /* Number of Swaps */
96 char ac_comm[ACCT_COMM]; /* Command Name */
100 * accounting flags
102 /* bit set when the process ... */
103 #define AFORK 0x01 /* ... executed fork, but did not exec */
104 #define ASU 0x02 /* ... used super-user privileges */
105 #define ACOMPAT 0x04 /* ... used compatibility mode (VAX only not used) */
106 #define ACORE 0x08 /* ... dumped core */
107 #define AXSIG 0x10 /* ... was killed by a signal */
109 #ifdef __BIG_ENDIAN
110 #define ACCT_BYTEORDER 0x80 /* accounting file is big endian */
111 #else
112 #define ACCT_BYTEORDER 0x00 /* accounting file is little endian */
113 #endif
115 #ifdef __KERNEL__
117 #include <linux/config.h>
119 #ifdef CONFIG_BSD_PROCESS_ACCT
120 struct super_block;
121 extern void acct_auto_close(struct super_block *sb);
122 extern void acct_process(long exitcode);
123 #else
124 #define acct_auto_close(x) do { } while (0)
125 #define acct_process(x) do { } while (0)
126 #endif
129 * ACCT_VERSION numbers as yet defined:
130 * 0: old format (until 2.6.7) with 16 bit uid/gid
131 * 1: extended variant (binary compatible on M68K)
132 * 2: extended variant (binary compatible on everything except M68K)
133 * 3: new binary incompatible format (64 bytes)
134 * 4: new binary incompatible format (128 bytes)
135 * 5: new binary incompatible format (128 bytes, second half)
139 #ifdef CONFIG_BSD_PROCESS_ACCT_V3
140 #define ACCT_VERSION 3
141 #define AHZ 100
142 typedef struct acct_v3 acct_t;
143 #else
144 #ifdef CONFIG_M68K
145 #define ACCT_VERSION 1
146 #else
147 #define ACCT_VERSION 2
148 #endif
149 #define AHZ (USER_HZ)
150 typedef struct acct acct_t;
151 #endif
153 #else
154 #define ACCT_VERSION 2
155 #define AHZ (HZ)
156 #endif /* __KERNEL */
158 #ifdef __KERNEL__
160 * Yet another set of HZ to *HZ helper functions.
161 * See <linux/times.h> for the original.
164 static inline u32 jiffies_to_AHZ(unsigned long x)
166 #if (TICK_NSEC % (NSEC_PER_SEC / AHZ)) == 0
167 return x / (HZ / USER_HZ);
168 #else
169 u64 tmp = (u64)x * TICK_NSEC;
170 do_div(tmp, (NSEC_PER_SEC / AHZ));
171 return (long)tmp;
172 #endif
175 static inline u64 nsec_to_AHZ(u64 x)
177 #if (NSEC_PER_SEC % AHZ) == 0
178 do_div(x, (NSEC_PER_SEC / AHZ));
179 #elif (AHZ % 512) == 0
180 x *= AHZ/512;
181 do_div(x, (NSEC_PER_SEC / 512));
182 #else
184 * max relative error 5.7e-8 (1.8s per year) for AHZ <= 1024,
185 * overflow after 64.99 years.
186 * exact for AHZ=60, 72, 90, 120, 144, 180, 300, 600, 900, ...
188 x *= 9;
189 do_div(x, (unsigned long)((9ull * NSEC_PER_SEC + (AHZ/2))
190 / AHZ));
191 #endif
192 return x;
195 #endif /* __KERNEL */
197 #endif /* _LINUX_ACCT_H */