xref: /OK3568_Linux_fs/kernel/include/linux/acct.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0 */
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun  *  BSD Process Accounting for Linux - Definitions
4*4882a593Smuzhiyun  *
5*4882a593Smuzhiyun  *  Author: Marco van Wieringen (mvw@planets.elm.net)
6*4882a593Smuzhiyun  *
7*4882a593Smuzhiyun  *  This header file contains the definitions needed to implement
8*4882a593Smuzhiyun  *  BSD-style process accounting. The kernel accounting code and all
9*4882a593Smuzhiyun  *  user-level programs that try to do something useful with the
10*4882a593Smuzhiyun  *  process accounting log must include this file.
11*4882a593Smuzhiyun  *
12*4882a593Smuzhiyun  *  Copyright (C) 1995 - 1997 Marco van Wieringen - ELM Consultancy B.V.
13*4882a593Smuzhiyun  *
14*4882a593Smuzhiyun  */
15*4882a593Smuzhiyun #ifndef _LINUX_ACCT_H
16*4882a593Smuzhiyun #define _LINUX_ACCT_H
17*4882a593Smuzhiyun 
18*4882a593Smuzhiyun #include <uapi/linux/acct.h>
19*4882a593Smuzhiyun 
20*4882a593Smuzhiyun 
21*4882a593Smuzhiyun 
22*4882a593Smuzhiyun #ifdef CONFIG_BSD_PROCESS_ACCT
23*4882a593Smuzhiyun struct pid_namespace;
24*4882a593Smuzhiyun extern int acct_parm[]; /* for sysctl */
25*4882a593Smuzhiyun extern void acct_collect(long exitcode, int group_dead);
26*4882a593Smuzhiyun extern void acct_process(void);
27*4882a593Smuzhiyun extern void acct_exit_ns(struct pid_namespace *);
28*4882a593Smuzhiyun #else
29*4882a593Smuzhiyun #define acct_collect(x,y)	do { } while (0)
30*4882a593Smuzhiyun #define acct_process()		do { } while (0)
31*4882a593Smuzhiyun #define acct_exit_ns(ns)	do { } while (0)
32*4882a593Smuzhiyun #endif
33*4882a593Smuzhiyun 
34*4882a593Smuzhiyun /*
35*4882a593Smuzhiyun  * ACCT_VERSION numbers as yet defined:
36*4882a593Smuzhiyun  * 0: old format (until 2.6.7) with 16 bit uid/gid
37*4882a593Smuzhiyun  * 1: extended variant (binary compatible on M68K)
38*4882a593Smuzhiyun  * 2: extended variant (binary compatible on everything except M68K)
39*4882a593Smuzhiyun  * 3: new binary incompatible format (64 bytes)
40*4882a593Smuzhiyun  * 4: new binary incompatible format (128 bytes)
41*4882a593Smuzhiyun  * 5: new binary incompatible format (128 bytes, second half)
42*4882a593Smuzhiyun  *
43*4882a593Smuzhiyun  */
44*4882a593Smuzhiyun 
45*4882a593Smuzhiyun #undef ACCT_VERSION
46*4882a593Smuzhiyun #undef AHZ
47*4882a593Smuzhiyun 
48*4882a593Smuzhiyun #ifdef CONFIG_BSD_PROCESS_ACCT_V3
49*4882a593Smuzhiyun #define ACCT_VERSION	3
50*4882a593Smuzhiyun #define AHZ		100
51*4882a593Smuzhiyun typedef struct acct_v3 acct_t;
52*4882a593Smuzhiyun #else
53*4882a593Smuzhiyun #ifdef CONFIG_M68K
54*4882a593Smuzhiyun #define ACCT_VERSION	1
55*4882a593Smuzhiyun #else
56*4882a593Smuzhiyun #define ACCT_VERSION	2
57*4882a593Smuzhiyun #endif
58*4882a593Smuzhiyun #define AHZ		(USER_HZ)
59*4882a593Smuzhiyun typedef struct acct acct_t;
60*4882a593Smuzhiyun #endif
61*4882a593Smuzhiyun 
62*4882a593Smuzhiyun #include <linux/jiffies.h>
63*4882a593Smuzhiyun /*
64*4882a593Smuzhiyun  * Yet another set of HZ to *HZ helper functions.
65*4882a593Smuzhiyun  * See <linux/jiffies.h> for the original.
66*4882a593Smuzhiyun  */
67*4882a593Smuzhiyun 
jiffies_to_AHZ(unsigned long x)68*4882a593Smuzhiyun static inline u32 jiffies_to_AHZ(unsigned long x)
69*4882a593Smuzhiyun {
70*4882a593Smuzhiyun #if (TICK_NSEC % (NSEC_PER_SEC / AHZ)) == 0
71*4882a593Smuzhiyun # if HZ < AHZ
72*4882a593Smuzhiyun 	return x * (AHZ / HZ);
73*4882a593Smuzhiyun # else
74*4882a593Smuzhiyun 	return x / (HZ / AHZ);
75*4882a593Smuzhiyun # endif
76*4882a593Smuzhiyun #else
77*4882a593Smuzhiyun         u64 tmp = (u64)x * TICK_NSEC;
78*4882a593Smuzhiyun         do_div(tmp, (NSEC_PER_SEC / AHZ));
79*4882a593Smuzhiyun         return (long)tmp;
80*4882a593Smuzhiyun #endif
81*4882a593Smuzhiyun }
82*4882a593Smuzhiyun 
nsec_to_AHZ(u64 x)83*4882a593Smuzhiyun static inline u64 nsec_to_AHZ(u64 x)
84*4882a593Smuzhiyun {
85*4882a593Smuzhiyun #if (NSEC_PER_SEC % AHZ) == 0
86*4882a593Smuzhiyun 	do_div(x, (NSEC_PER_SEC / AHZ));
87*4882a593Smuzhiyun #elif (AHZ % 512) == 0
88*4882a593Smuzhiyun 	x *= AHZ/512;
89*4882a593Smuzhiyun 	do_div(x, (NSEC_PER_SEC / 512));
90*4882a593Smuzhiyun #else
91*4882a593Smuzhiyun 	/*
92*4882a593Smuzhiyun          * max relative error 5.7e-8 (1.8s per year) for AHZ <= 1024,
93*4882a593Smuzhiyun          * overflow after 64.99 years.
94*4882a593Smuzhiyun          * exact for AHZ=60, 72, 90, 120, 144, 180, 300, 600, 900, ...
95*4882a593Smuzhiyun          */
96*4882a593Smuzhiyun 	x *= 9;
97*4882a593Smuzhiyun 	do_div(x, (unsigned long)((9ull * NSEC_PER_SEC + (AHZ/2))
98*4882a593Smuzhiyun 	                          / AHZ));
99*4882a593Smuzhiyun #endif
100*4882a593Smuzhiyun 	return x;
101*4882a593Smuzhiyun }
102*4882a593Smuzhiyun 
103*4882a593Smuzhiyun #endif	/* _LINUX_ACCT_H */
104