acct.h 2.7 KB

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