acct.h 5.8 KB

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