acct.h 2.5 KB

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