blob: 19f70462b3be6f9cdd3abdbb07f4b646370b7aeb [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>
19#include <asm/param.h>
20#include <asm/byteorder.h>
21
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.
28 */
29
30typedef __u16 comp_t;
31typedef __u32 comp2_t;
32
33/*
34 * accounting file record
35 *
36 * This structure contains all of the information written out to the
37 * process accounting file whenever a process exits.
38 */
39
40#define ACCT_COMM 16
41
42struct acct
43{
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 */
70};
71
72struct acct_v3
73{
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 */
97};
98
99/*
100 * accounting flags
101 */
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 */
108
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
114
115#ifdef __KERNEL__
116
117#include <linux/config.h>
118
119#ifdef CONFIG_BSD_PROCESS_ACCT
120struct super_block;
121extern void acct_auto_close(struct super_block *sb);
122extern void acct_process(long exitcode);
123extern void acct_update_integrals(struct task_struct *tsk);
124extern void acct_clear_integrals(struct task_struct *tsk);
125#else
126#define acct_auto_close(x) do { } while (0)
127#define acct_process(x) do { } while (0)
128#define acct_update_integrals(x) do { } while (0)
129#define acct_clear_integrals(task) do { } while (0)
130#endif
131
132/*
133 * ACCT_VERSION numbers as yet defined:
134 * 0: old format (until 2.6.7) with 16 bit uid/gid
135 * 1: extended variant (binary compatible on M68K)
136 * 2: extended variant (binary compatible on everything except M68K)
137 * 3: new binary incompatible format (64 bytes)
138 * 4: new binary incompatible format (128 bytes)
139 * 5: new binary incompatible format (128 bytes, second half)
140 *
141 */
142
143#ifdef CONFIG_BSD_PROCESS_ACCT_V3
144#define ACCT_VERSION 3
145#define AHZ 100
146typedef struct acct_v3 acct_t;
147#else
148#ifdef CONFIG_M68K
149#define ACCT_VERSION 1
150#else
151#define ACCT_VERSION 2
152#endif
153#define AHZ (USER_HZ)
154typedef struct acct acct_t;
155#endif
156
157#else
158#define ACCT_VERSION 2
159#define AHZ (HZ)
160#endif /* __KERNEL */
161
162#ifdef __KERNEL__
163/*
164 * Yet another set of HZ to *HZ helper functions.
Tim Schmielaue26148d2005-10-14 15:59:05 -0700165 * See <linux/jiffies.h> for the original.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166 */
167
168static inline u32 jiffies_to_AHZ(unsigned long x)
169{
170#if (TICK_NSEC % (NSEC_PER_SEC / AHZ)) == 0
Tim Schmielaue26148d2005-10-14 15:59:05 -0700171 return x / (HZ / AHZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172#else
173 u64 tmp = (u64)x * TICK_NSEC;
174 do_div(tmp, (NSEC_PER_SEC / AHZ));
175 return (long)tmp;
176#endif
177}
178
179static inline u64 nsec_to_AHZ(u64 x)
180{
181#if (NSEC_PER_SEC % AHZ) == 0
182 do_div(x, (NSEC_PER_SEC / AHZ));
183#elif (AHZ % 512) == 0
184 x *= AHZ/512;
185 do_div(x, (NSEC_PER_SEC / 512));
186#else
187 /*
188 * max relative error 5.7e-8 (1.8s per year) for AHZ <= 1024,
189 * overflow after 64.99 years.
190 * exact for AHZ=60, 72, 90, 120, 144, 180, 300, 600, 900, ...
191 */
192 x *= 9;
193 do_div(x, (unsigned long)((9ull * NSEC_PER_SEC + (AHZ/2))
194 / AHZ));
195#endif
196 return x;
197}
198
199#endif /* __KERNEL */
200
201#endif /* _LINUX_ACCT_H */