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