6c2bd56773f00e036b0d7abd12cbbeb98b0f945f
[linux-2.6.git] / include / linux / acct.h
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>
19 #include <asm/param.h>
20
21 /* 
22  *  comp_t is a 16-bit "floating" point number with a 3-bit base 8
23  *  exponent and a 13-bit fraction.
24  *  comp2_t is 24-bit with 5-bit base 2 exponent and 20 bit fraction
25  *  (leading 1 not stored).
26  *  See linux/kernel/acct.c for the specific encoding systems used.
27  */
28
29 typedef __u16   comp_t;
30 typedef __u32   comp2_t;
31
32 /*
33  *   accounting file record
34  *
35  *   This structure contains all of the information written out to the
36  *   process accounting file whenever a process exits.
37  */
38
39 #define ACCT_COMM       16
40
41 struct acct
42 {
43         char            ac_flag;                /* Flags */
44         char            ac_version;             /* Always set to ACCT_VERSION */
45         /* for binary compatibility back until 2.0 */
46         __u16           ac_uid16;               /* LSB of Real User ID */
47         __u16           ac_gid16;               /* LSB of Real Group ID */
48         __u16           ac_tty;                 /* Control Terminal */
49         __u32           ac_btime;               /* Process Creation Time */
50         comp_t          ac_utime;               /* User Time */
51         comp_t          ac_stime;               /* System Time */
52         comp_t          ac_etime;               /* Elapsed Time */
53         comp_t          ac_mem;                 /* Average Memory Usage */
54         comp_t          ac_io;                  /* Chars Transferred */
55         comp_t          ac_rw;                  /* Blocks Read or Written */
56         comp_t          ac_minflt;              /* Minor Pagefaults */
57         comp_t          ac_majflt;              /* Major Pagefaults */
58         comp_t          ac_swaps;               /* Number of Swaps */
59 /* m68k had no padding here. */
60 #if !defined(CONFIG_M68K) || !defined(__KERNEL__)
61         __u16           ac_ahz;                 /* AHZ */
62 #endif
63         __u32           ac_exitcode;            /* Exitcode */
64         char            ac_comm[ACCT_COMM + 1]; /* Command Name */
65         __u8            ac_etime_hi;            /* Elapsed Time MSB */
66         __u16           ac_etime_lo;            /* Elapsed Time LSB */
67         __u32           ac_uid;                 /* Real User ID */
68         __u32           ac_gid;                 /* Real Group ID */
69 };
70
71 struct acct_v3
72 {
73         char            ac_flag;                /* Flags */
74         char            ac_version;             /* Always set to ACCT_VERSION */
75         __u16           ac_tty;                 /* Control Terminal */
76         __u32           ac_exitcode;            /* Exitcode */
77         __u32           ac_uid;                 /* Real User ID */
78         __u32           ac_gid;                 /* Real Group ID */
79         __u32           ac_pid;                 /* Process ID */
80         __u32           ac_ppid;                /* Parent Process ID */
81         __u32           ac_btime;               /* Process Creation Time */
82 #ifdef __KERNEL__
83         __u32           ac_etime;               /* Elapsed Time */
84 #else
85         float           ac_etime;               /* Elapsed Time */
86 #endif
87         comp_t          ac_utime;               /* User Time */
88         comp_t          ac_stime;               /* System Time */
89         comp_t          ac_mem;                 /* Average Memory Usage */
90         comp_t          ac_io;                  /* Chars Transferred */
91         comp_t          ac_rw;                  /* Blocks Read or Written */
92         comp_t          ac_minflt;              /* Minor Pagefaults */
93         comp_t          ac_majflt;              /* Major Pagefaults */
94         comp_t          ac_swaps;               /* Number of Swaps */
95         char            ac_comm[ACCT_COMM];     /* Command Name */
96 };
97
98 /*
99  *  accounting flags
100  */
101                                 /* bit set when the process ... */
102 #define AFORK           0x01    /* ... executed fork, but did not exec */
103 #define ASU             0x02    /* ... used super-user privileges */
104 #define ACOMPAT         0x04    /* ... used compatibility mode (VAX only not used) */
105 #define ACORE           0x08    /* ... dumped core */
106 #define AXSIG           0x10    /* ... was killed by a signal */
107 #define ABYTESEX        0x80    /* always set, allows to detect byteorder */
108
109 #ifdef __KERNEL__
110
111 #include <linux/config.h>
112
113 #ifdef CONFIG_BSD_PROCESS_ACCT
114 struct super_block;
115 extern void acct_auto_close(struct super_block *sb);
116 extern void acct_process(long exitcode);
117 #else
118 #define acct_auto_close(x)      do { } while (0)
119 #define acct_process(x)         do { } while (0)
120 #endif
121
122 /*
123  * ACCT_VERSION numbers as yet defined:
124  * 0: old format (until 2.6.7) with 16 bit uid/gid
125  * 1: extended variant (binary compatible on M68K)
126  * 2: extended variant (binary compatible on everything except M68K)
127  * 3: new binary incompatible format (64 bytes)
128  * 4: new binary incompatible format (128 bytes)
129  * 5: new binary incompatible format (128 bytes, second half)
130  *
131  */
132
133 #ifdef CONFIG_BSD_PROCESS_ACCT_V3
134 #define ACCT_VERSION    3
135 #define AHZ             100
136 typedef struct acct_v3 acct_t;
137 #else
138 #ifdef CONFIG_M68K
139 #define ACCT_VERSION    1
140 #else
141 #define ACCT_VERSION    2
142 #endif
143 #define AHZ             (USER_HZ)
144 typedef struct acct acct_t;
145 #endif
146
147 #else
148 #define ACCT_VERSION    2
149 #define AHZ             (HZ)
150 #endif  /* __KERNEL */
151
152 #ifdef __KERNEL__
153 /*
154  * Yet another set of HZ to *HZ helper functions.
155  * See <linux/times.h> for the original.
156  */
157
158 static inline u32 jiffies_to_AHZ(unsigned long x)
159 {
160 #if (TICK_NSEC % (NSEC_PER_SEC / AHZ)) == 0
161         return x / (HZ / USER_HZ);
162 #else
163         u64 tmp = (u64)x * TICK_NSEC;
164         do_div(tmp, (NSEC_PER_SEC / AHZ));
165         return (long)tmp;
166 #endif
167 }
168
169 static inline u64 jiffies_64_to_AHZ(u64 x)
170 {
171 #if (TICK_NSEC % (NSEC_PER_SEC / AHZ)) == 0
172 #if HZ != AHZ
173         do_div(x, HZ / AHZ);
174 #endif
175 #else
176         x *= TICK_NSEC;
177         do_div(x, (NSEC_PER_SEC / AHZ));
178 #endif
179        return x;
180 }
181
182 #endif  /* __KERNEL */
183
184 #endif  /* _LINUX_ACCT_H */