xref: /linux-6.15/include/linux/acct.h (revision efb170c2)
1 /*
2  *  BSD Process Accounting for Linux - Definitions
3  *
4  *  Author: Marco van Wieringen ([email protected])
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 #ifndef _LINUX_ACCT_H
15 #define _LINUX_ACCT_H
16 
17 #include <uapi/linux/acct.h>
18 
19 
20 
21 #ifdef CONFIG_BSD_PROCESS_ACCT
22 struct vfsmount;
23 struct super_block;
24 struct pacct_struct;
25 struct pid_namespace;
26 extern int acct_parm[]; /* for sysctl */
27 extern void acct_collect(long exitcode, int group_dead);
28 extern void acct_process(void);
29 extern void acct_exit_ns(struct pid_namespace *);
30 #else
31 #define acct_collect(x,y)	do { } while (0)
32 #define acct_process()		do { } while (0)
33 #define acct_exit_ns(ns)	do { } while (0)
34 #endif
35 extern void acct_auto_close(struct hlist_head *);
36 extern void acct_auto_close_mnt(struct hlist_head *);
37 
38 /*
39  * ACCT_VERSION numbers as yet defined:
40  * 0: old format (until 2.6.7) with 16 bit uid/gid
41  * 1: extended variant (binary compatible on M68K)
42  * 2: extended variant (binary compatible on everything except M68K)
43  * 3: new binary incompatible format (64 bytes)
44  * 4: new binary incompatible format (128 bytes)
45  * 5: new binary incompatible format (128 bytes, second half)
46  *
47  */
48 
49 #undef ACCT_VERSION
50 #undef AHZ
51 
52 #ifdef CONFIG_BSD_PROCESS_ACCT_V3
53 #define ACCT_VERSION	3
54 #define AHZ		100
55 typedef struct acct_v3 acct_t;
56 #else
57 #ifdef CONFIG_M68K
58 #define ACCT_VERSION	1
59 #else
60 #define ACCT_VERSION	2
61 #endif
62 #define AHZ		(USER_HZ)
63 typedef struct acct acct_t;
64 #endif
65 
66 #include <linux/jiffies.h>
67 /*
68  * Yet another set of HZ to *HZ helper functions.
69  * See <linux/jiffies.h> for the original.
70  */
71 
72 static inline u32 jiffies_to_AHZ(unsigned long x)
73 {
74 #if (TICK_NSEC % (NSEC_PER_SEC / AHZ)) == 0
75 # if HZ < AHZ
76 	return x * (AHZ / HZ);
77 # else
78 	return x / (HZ / AHZ);
79 # endif
80 #else
81         u64 tmp = (u64)x * TICK_NSEC;
82         do_div(tmp, (NSEC_PER_SEC / AHZ));
83         return (long)tmp;
84 #endif
85 }
86 
87 static inline u64 nsec_to_AHZ(u64 x)
88 {
89 #if (NSEC_PER_SEC % AHZ) == 0
90 	do_div(x, (NSEC_PER_SEC / AHZ));
91 #elif (AHZ % 512) == 0
92 	x *= AHZ/512;
93 	do_div(x, (NSEC_PER_SEC / 512));
94 #else
95 	/*
96          * max relative error 5.7e-8 (1.8s per year) for AHZ <= 1024,
97          * overflow after 64.99 years.
98          * exact for AHZ=60, 72, 90, 120, 144, 180, 300, 600, 900, ...
99          */
100 	x *= 9;
101 	do_div(x, (unsigned long)((9ull * NSEC_PER_SEC + (AHZ/2))
102 	                          / AHZ));
103 #endif
104 	return x;
105 }
106 
107 #endif	/* _LINUX_ACCT_H */
108