Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /*
0003  *  BSD Process Accounting for Linux - Definitions
0004  *
0005  *  Author: Marco van Wieringen (mvw@planets.elm.net)
0006  *
0007  *  This header file contains the definitions needed to implement
0008  *  BSD-style process accounting. The kernel accounting code and all
0009  *  user-level programs that try to do something useful with the
0010  *  process accounting log must include this file.
0011  *
0012  *  Copyright (C) 1995 - 1997 Marco van Wieringen - ELM Consultancy B.V.
0013  *
0014  */
0015 #ifndef _LINUX_ACCT_H
0016 #define _LINUX_ACCT_H
0017 
0018 #include <uapi/linux/acct.h>
0019 
0020 
0021 
0022 #ifdef CONFIG_BSD_PROCESS_ACCT
0023 struct pid_namespace;
0024 extern void acct_collect(long exitcode, int group_dead);
0025 extern void acct_process(void);
0026 extern void acct_exit_ns(struct pid_namespace *);
0027 #else
0028 #define acct_collect(x,y)   do { } while (0)
0029 #define acct_process()      do { } while (0)
0030 #define acct_exit_ns(ns)    do { } while (0)
0031 #endif
0032 
0033 /*
0034  * ACCT_VERSION numbers as yet defined:
0035  * 0: old format (until 2.6.7) with 16 bit uid/gid
0036  * 1: extended variant (binary compatible on M68K)
0037  * 2: extended variant (binary compatible on everything except M68K)
0038  * 3: new binary incompatible format (64 bytes)
0039  * 4: new binary incompatible format (128 bytes)
0040  * 5: new binary incompatible format (128 bytes, second half)
0041  *
0042  */
0043 
0044 #undef ACCT_VERSION
0045 #undef AHZ
0046 
0047 #ifdef CONFIG_BSD_PROCESS_ACCT_V3
0048 #define ACCT_VERSION    3
0049 #define AHZ     100
0050 typedef struct acct_v3 acct_t;
0051 #else
0052 #ifdef CONFIG_M68K
0053 #define ACCT_VERSION    1
0054 #else
0055 #define ACCT_VERSION    2
0056 #endif
0057 #define AHZ     (USER_HZ)
0058 typedef struct acct acct_t;
0059 #endif
0060 
0061 #include <linux/jiffies.h>
0062 /*
0063  * Yet another set of HZ to *HZ helper functions.
0064  * See <linux/jiffies.h> for the original.
0065  */
0066 
0067 static inline u32 jiffies_to_AHZ(unsigned long x)
0068 {
0069 #if (TICK_NSEC % (NSEC_PER_SEC / AHZ)) == 0
0070 # if HZ < AHZ
0071     return x * (AHZ / HZ);
0072 # else
0073     return x / (HZ / AHZ);
0074 # endif
0075 #else
0076         u64 tmp = (u64)x * TICK_NSEC;
0077         do_div(tmp, (NSEC_PER_SEC / AHZ));
0078         return (long)tmp;
0079 #endif
0080 }
0081 
0082 static inline u64 nsec_to_AHZ(u64 x)
0083 {
0084 #if (NSEC_PER_SEC % AHZ) == 0
0085     do_div(x, (NSEC_PER_SEC / AHZ));
0086 #elif (AHZ % 512) == 0
0087     x *= AHZ/512;
0088     do_div(x, (NSEC_PER_SEC / 512));
0089 #else
0090     /*
0091          * max relative error 5.7e-8 (1.8s per year) for AHZ <= 1024,
0092          * overflow after 64.99 years.
0093          * exact for AHZ=60, 72, 90, 120, 144, 180, 300, 600, 900, ...
0094          */
0095     x *= 9;
0096     do_div(x, (unsigned long)((9ull * NSEC_PER_SEC + (AHZ/2))
0097                               / AHZ));
0098 #endif
0099     return x;
0100 }
0101 
0102 #endif  /* _LINUX_ACCT_H */