/*1* BSD Process Accounting for Linux - Definitions2*3* Author: Marco van Wieringen ([email protected])4*5* This header file contains the definitions needed to implement6* BSD-style process accounting. The kernel accounting code and all7* user-level programs that try to do something useful with the8* process accounting log must include this file.9*10* Copyright (C) 1995 - 1997 Marco van Wieringen - ELM Consultancy B.V.11*12*/1314#ifndef _LINUX_ACCT_H15#define _LINUX_ACCT_H1617#include <linux/types.h>1819#include <asm/param.h>20#include <asm/byteorder.h>2122/*23* comp_t is a 16-bit "floating" point number with a 3-bit base 824* exponent and a 13-bit fraction.25* comp2_t is 24-bit with 5-bit base 2 exponent and 20 bit fraction26* (leading 1 not stored).27* See linux/kernel/acct.c for the specific encoding systems used.28*/2930typedef __u16 comp_t;31typedef __u32 comp2_t;3233/*34* accounting file record35*36* This structure contains all of the information written out to the37* process accounting file whenever a process exits.38*/3940#define ACCT_COMM 164142struct acct43{44char ac_flag; /* Flags */45char 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 */51comp_t ac_utime; /* User Time */52comp_t ac_stime; /* System Time */53comp_t ac_etime; /* Elapsed Time */54comp_t ac_mem; /* Average Memory Usage */55comp_t ac_io; /* Chars Transferred */56comp_t ac_rw; /* Blocks Read or Written */57comp_t ac_minflt; /* Minor Pagefaults */58comp_t ac_majflt; /* Major Pagefaults */59comp_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#endif64__u32 ac_exitcode; /* Exitcode */65char 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};7172struct acct_v373{74char ac_flag; /* Flags */75char 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#else86float ac_etime; /* Elapsed Time */87#endif88comp_t ac_utime; /* User Time */89comp_t ac_stime; /* System Time */90comp_t ac_mem; /* Average Memory Usage */91comp_t ac_io; /* Chars Transferred */92comp_t ac_rw; /* Blocks Read or Written */93comp_t ac_minflt; /* Minor Pagefaults */94comp_t ac_majflt; /* Major Pagefaults */95comp_t ac_swaps; /* Number of Swaps */96char ac_comm[ACCT_COMM]; /* Command Name */97};9899/*100* accounting flags101*/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 */108109#ifdef __BIG_ENDIAN110#define ACCT_BYTEORDER 0x80 /* accounting file is big endian */111#else112#define ACCT_BYTEORDER 0x00 /* accounting file is little endian */113#endif114115#ifdef __KERNEL__116117118#ifdef CONFIG_BSD_PROCESS_ACCT119struct vfsmount;120struct super_block;121struct pacct_struct;122struct pid_namespace;123extern int acct_parm[]; /* for sysctl */124extern void acct_auto_close_mnt(struct vfsmount *m);125extern void acct_auto_close(struct super_block *sb);126extern void acct_collect(long exitcode, int group_dead);127extern void acct_process(void);128extern void acct_exit_ns(struct pid_namespace *);129#else130#define acct_auto_close_mnt(x) do { } while (0)131#define acct_auto_close(x) do { } while (0)132#define acct_collect(x,y) do { } while (0)133#define acct_process() do { } while (0)134#define acct_exit_ns(ns) do { } while (0)135#endif136137/*138* ACCT_VERSION numbers as yet defined:139* 0: old format (until 2.6.7) with 16 bit uid/gid140* 1: extended variant (binary compatible on M68K)141* 2: extended variant (binary compatible on everything except M68K)142* 3: new binary incompatible format (64 bytes)143* 4: new binary incompatible format (128 bytes)144* 5: new binary incompatible format (128 bytes, second half)145*146*/147148#ifdef CONFIG_BSD_PROCESS_ACCT_V3149#define ACCT_VERSION 3150#define AHZ 100151typedef struct acct_v3 acct_t;152#else153#ifdef CONFIG_M68K154#define ACCT_VERSION 1155#else156#define ACCT_VERSION 2157#endif158#define AHZ (USER_HZ)159typedef struct acct acct_t;160#endif161162#else163#define ACCT_VERSION 2164#define AHZ (HZ)165#endif /* __KERNEL */166167#ifdef __KERNEL__168#include <linux/jiffies.h>169/*170* Yet another set of HZ to *HZ helper functions.171* See <linux/jiffies.h> for the original.172*/173174static inline u32 jiffies_to_AHZ(unsigned long x)175{176#if (TICK_NSEC % (NSEC_PER_SEC / AHZ)) == 0177# if HZ < AHZ178return x * (AHZ / HZ);179# else180return x / (HZ / AHZ);181# endif182#else183u64 tmp = (u64)x * TICK_NSEC;184do_div(tmp, (NSEC_PER_SEC / AHZ));185return (long)tmp;186#endif187}188189static inline u64 nsec_to_AHZ(u64 x)190{191#if (NSEC_PER_SEC % AHZ) == 0192do_div(x, (NSEC_PER_SEC / AHZ));193#elif (AHZ % 512) == 0194x *= AHZ/512;195do_div(x, (NSEC_PER_SEC / 512));196#else197/*198* max relative error 5.7e-8 (1.8s per year) for AHZ <= 1024,199* overflow after 64.99 years.200* exact for AHZ=60, 72, 90, 120, 144, 180, 300, 600, 900, ...201*/202x *= 9;203do_div(x, (unsigned long)((9ull * NSEC_PER_SEC + (AHZ/2))204/ AHZ));205#endif206return x;207}208209#endif /* __KERNEL */210211#endif /* _LINUX_ACCT_H */212213214