1: /*
   2:  * Copyright (c) 1986 Regents of the University of California.
   3:  * All rights reserved.  The Berkeley software License Agreement
   4:  * specifies the terms and conditions for redistribution.
   5:  *
   6:  *	@(#)kern_acct.c	3.1 (2.11BSD) 1999/4/29
   7:  *
   8:  * This module is a shadow of its former self.  This comment:
   9:  *
  10:  * 	SHOULD REPLACE THIS WITH A DRIVER THAT CAN BE READ TO SIMPLIFY.
  11:  *
  12:  * is all that is left of the original kern_acct.c module.
  13:  */
  14: 
  15: #include "param.h"
  16: #include "systm.h"
  17: #include "user.h"
  18: #include "msgbuf.h"
  19: #include "kernel.h"
  20: #include "acct.h"
  21: 
  22:     comp_t  compress();
  23:     int Acctthresh = 10;
  24: 
  25: /*
  26:  * On exit, write a record on the accounting file.
  27:  */
  28: acct()
  29:     {
  30:     struct  acct acctbuf;
  31:     register struct acct *ap = &acctbuf;
  32:     static  short acctcnt = 0;
  33: 
  34:     bcopy(u.u_comm, ap->ac_comm, sizeof(acctbuf.ac_comm));
  35: /*
  36:  * The 'user' and 'system' times need to be converted from 'hz' (linefrequency)
  37:  * clockticks to the AHZ pseudo-tick unit of measure.  The elapsed time is
  38:  * converted from seconds to AHZ ticks.
  39: */
  40:     ap->ac_utime = compress(((u_long)u.u_ru.ru_utime * AHZ) / hz);
  41:     ap->ac_stime = compress(((u_long)u.u_ru.ru_stime * AHZ) / hz);
  42:     ap->ac_etime = compress((u_long)(time.tv_sec - u.u_start) * AHZ);
  43:     ap->ac_btime = u.u_start;
  44:     ap->ac_uid = u.u_ruid;
  45:     ap->ac_gid = u.u_rgid;
  46:     ap->ac_mem = (u.u_dsize+u.u_ssize) / 16; /* fast ctok() */
  47: /*
  48:  * Section 3.9 of the 4.3BSD book says that I/O is measured in 1/AHZ units too.
  49: */
  50:     ap->ac_io = compress((u_long)(u.u_ru.ru_inblock+u.u_ru.ru_oublock)*AHZ);
  51:     if  (u.u_ttyp)
  52:         ap->ac_tty = u.u_ttyd;
  53:     else
  54:         ap->ac_tty = NODEV;
  55:     ap->ac_flag = u.u_acflag;
  56: /*
  57:  * Not a lot that can be done if logwrt fails so ignore any errors.  Every
  58:  * few (10 by default) commands call the wakeup routine.  This isn't perfect
  59:  * but does cut down the overhead of issuing a wakeup to the accounting daemon
  60:  * every single accounting record.  The threshold is settable via sysctl(8)
  61: */
  62:     logwrt(ap, sizeof (*ap), logACCT);
  63:     if  (++acctcnt >= Acctthresh)
  64:         {
  65:         logwakeup(logACCT);
  66:         acctcnt = 0;
  67:         }
  68:     }
  69: 
  70: /*
  71:  * Raise exponent and drop bits off the right of the mantissa until the
  72:  * mantissa fits.  If we run out of exponent space, return max value (all
  73:  * one bits).  With AHZ set to 64 this is good for close to 8.5 years:
  74:  * (8191 * (1 << (3*7)) / 64 / 60 / 60 / 24 / 365 ~= 8.5)
  75:  */
  76: 
  77: #define MANTSIZE    13          /* 13 bit mantissa. */
  78: #define EXPSIZE     3           /* Base 8 (3 bit) exponent. */
  79: 
  80: comp_t
  81: compress(mant)
  82:     u_long mant;
  83:     {
  84:     register int exp;
  85: 
  86:     for (exp = 0; exp < (1 << EXPSIZE); exp++, mant >>= EXPSIZE)
  87:         if  (mant < (1L << MANTSIZE))
  88:             return(mant | (exp << MANTSIZE));
  89:     return(~0);
  90:     }

Defined functions

acct defined in line 28; used 1 times
compress defined in line 80; used 5 times

Defined variables

Acctthresh defined in line 23; used 1 times
  • in line 63

Defined macros

EXPSIZE defined in line 78; used 2 times
  • in line 86(2)
MANTSIZE defined in line 77; used 2 times
Last modified: 1999-04-30
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 2384
Valid CSS Valid XHTML 1.0 Strict