blob: 9a66401073fc1b8ff8e90b2d70d020c032a9900e [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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 Mortonff6ed402005-11-13 16:07:38 -080019#include <linux/jiffies.h>
20
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#include <asm/param.h>
22#include <asm/byteorder.h>
23
24/*
25 * comp_t is a 16-bit "floating" point number with a 3-bit base 8
26 * exponent and a 13-bit fraction.
27 * comp2_t is 24-bit with 5-bit base 2 exponent and 20 bit fraction
28 * (leading 1 not stored).
29 * See linux/kernel/acct.c for the specific encoding systems used.
30 */
31
32typedef __u16 comp_t;
33typedef __u32 comp2_t;
34
35/*
36 * accounting file record
37 *
38 * This structure contains all of the information written out to the
39 * process accounting file whenever a process exits.
40 */
41
42#define ACCT_COMM 16
43
44struct acct
45{
46 char ac_flag; /* Flags */
47 char ac_version; /* Always set to ACCT_VERSION */
48 /* for binary compatibility back until 2.0 */
49 __u16 ac_uid16; /* LSB of Real User ID */
50 __u16 ac_gid16; /* LSB of Real Group ID */
51 __u16 ac_tty; /* Control Terminal */
52 __u32 ac_btime; /* Process Creation Time */
53 comp_t ac_utime; /* User Time */
54 comp_t ac_stime; /* System Time */
55 comp_t ac_etime; /* Elapsed Time */
56 comp_t ac_mem; /* Average Memory Usage */
57 comp_t ac_io; /* Chars Transferred */
58 comp_t ac_rw; /* Blocks Read or Written */
59 comp_t ac_minflt; /* Minor Pagefaults */
60 comp_t ac_majflt; /* Major Pagefaults */
61 comp_t ac_swaps; /* Number of Swaps */
62/* m68k had no padding here. */
63#if !defined(CONFIG_M68K) || !defined(__KERNEL__)
64 __u16 ac_ahz; /* AHZ */
65#endif
66 __u32 ac_exitcode; /* Exitcode */
67 char ac_comm[ACCT_COMM + 1]; /* Command Name */
68 __u8 ac_etime_hi; /* Elapsed Time MSB */
69 __u16 ac_etime_lo; /* Elapsed Time LSB */
70 __u32 ac_uid; /* Real User ID */
71 __u32 ac_gid; /* Real Group ID */
72};
73
74struct acct_v3
75{
76 char ac_flag; /* Flags */
77 char ac_version; /* Always set to ACCT_VERSION */
78 __u16 ac_tty; /* Control Terminal */
79 __u32 ac_exitcode; /* Exitcode */
80 __u32 ac_uid; /* Real User ID */
81 __u32 ac_gid; /* Real Group ID */
82 __u32 ac_pid; /* Process ID */
83 __u32 ac_ppid; /* Parent Process ID */
84 __u32 ac_btime; /* Process Creation Time */
85#ifdef __KERNEL__
86 __u32 ac_etime; /* Elapsed Time */
87#else
88 float ac_etime; /* Elapsed Time */
89#endif
90 comp_t ac_utime; /* User Time */
91 comp_t ac_stime; /* System Time */
92 comp_t ac_mem; /* Average Memory Usage */
93 comp_t ac_io; /* Chars Transferred */
94 comp_t ac_rw; /* Blocks Read or Written */
95 comp_t ac_minflt; /* Minor Pagefaults */
96 comp_t ac_majflt; /* Major Pagefaults */
97 comp_t ac_swaps; /* Number of Swaps */
98 char ac_comm[ACCT_COMM]; /* Command Name */
99};
100
101/*
102 * accounting flags
103 */
104 /* bit set when the process ... */
105#define AFORK 0x01 /* ... executed fork, but did not exec */
106#define ASU 0x02 /* ... used super-user privileges */
107#define ACOMPAT 0x04 /* ... used compatibility mode (VAX only not used) */
108#define ACORE 0x08 /* ... dumped core */
109#define AXSIG 0x10 /* ... was killed by a signal */
110
111#ifdef __BIG_ENDIAN
112#define ACCT_BYTEORDER 0x80 /* accounting file is big endian */
113#else
114#define ACCT_BYTEORDER 0x00 /* accounting file is little endian */
115#endif
116
117#ifdef __KERNEL__
118
119#include <linux/config.h>
120
121#ifdef CONFIG_BSD_PROCESS_ACCT
Al Viro7b7b1ac2005-11-07 17:13:39 -0500122struct vfsmount;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123struct super_block;
Al Viro7b7b1ac2005-11-07 17:13:39 -0500124extern void acct_auto_close_mnt(struct vfsmount *m);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125extern void acct_auto_close(struct super_block *sb);
126extern void acct_process(long exitcode);
127extern void acct_update_integrals(struct task_struct *tsk);
128extern void acct_clear_integrals(struct task_struct *tsk);
129#else
Al Viro7b7b1ac2005-11-07 17:13:39 -0500130#define acct_auto_close_mnt(x) do { } while (0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131#define acct_auto_close(x) do { } while (0)
132#define acct_process(x) do { } while (0)
133#define acct_update_integrals(x) do { } while (0)
134#define acct_clear_integrals(task) do { } while (0)
135#endif
136
137/*
138 * ACCT_VERSION numbers as yet defined:
139 * 0: old format (until 2.6.7) with 16 bit uid/gid
140 * 1: extended variant (binary compatible on M68K)
141 * 2: extended variant (binary compatible on everything except M68K)
142 * 3: new binary incompatible format (64 bytes)
143 * 4: new binary incompatible format (128 bytes)
144 * 5: new binary incompatible format (128 bytes, second half)
145 *
146 */
147
148#ifdef CONFIG_BSD_PROCESS_ACCT_V3
149#define ACCT_VERSION 3
150#define AHZ 100
151typedef struct acct_v3 acct_t;
152#else
153#ifdef CONFIG_M68K
154#define ACCT_VERSION 1
155#else
156#define ACCT_VERSION 2
157#endif
158#define AHZ (USER_HZ)
159typedef struct acct acct_t;
160#endif
161
162#else
163#define ACCT_VERSION 2
164#define AHZ (HZ)
165#endif /* __KERNEL */
166
167#ifdef __KERNEL__
168/*
169 * Yet another set of HZ to *HZ helper functions.
Tim Schmielaue26148d2005-10-14 15:59:05 -0700170 * See <linux/jiffies.h> for the original.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171 */
172
173static inline u32 jiffies_to_AHZ(unsigned long x)
174{
175#if (TICK_NSEC % (NSEC_PER_SEC / AHZ)) == 0
Tim Schmielaue26148d2005-10-14 15:59:05 -0700176 return x / (HZ / AHZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177#else
178 u64 tmp = (u64)x * TICK_NSEC;
179 do_div(tmp, (NSEC_PER_SEC / AHZ));
180 return (long)tmp;
181#endif
182}
183
184static inline u64 nsec_to_AHZ(u64 x)
185{
186#if (NSEC_PER_SEC % AHZ) == 0
187 do_div(x, (NSEC_PER_SEC / AHZ));
188#elif (AHZ % 512) == 0
189 x *= AHZ/512;
190 do_div(x, (NSEC_PER_SEC / 512));
191#else
192 /*
193 * max relative error 5.7e-8 (1.8s per year) for AHZ <= 1024,
194 * overflow after 64.99 years.
195 * exact for AHZ=60, 72, 90, 120, 144, 180, 300, 600, 900, ...
196 */
197 x *= 9;
198 do_div(x, (unsigned long)((9ull * NSEC_PER_SEC + (AHZ/2))
199 / AHZ));
200#endif
201 return x;
202}
203
204#endif /* __KERNEL */
205
206#endif /* _LINUX_ACCT_H */