From: Tim Schmielau <tim@physik3.uni-rostock.de>

Hi Andrew,

I rolled up a new (final?) version of the BSD accounting patch to replace
the two patches currently in -mm.

It fixes the outstanding issue with USER_HZ -> AHZ inaccuracy, a problem
with including <linux/acct.h> in userland, and updates some URLs.
I believe it's appropriate for mainline sometime after 2.6.7 is out, if no
other issues come up until then.

Apparently the new functionality didn't yet get much outside testing,
since there was only a single download of the userspace tools, so testers
are still welcome.

Thanks,
Tim

==========================================================================
BSD accounting format rework:

Use all explicit and implicit padding in struct acct to

 - correctly report 32 bit uid/gid,
 - correctly report jobs (e.g., daemons) running longer than 497 days,
 - increase the precision of ac_etime from 2^-13 to 2^-20
   (i.e., from ~6 hours to ~1 min. after a year)
 - store the current AHZ value.
 - allow cross-platform processing of the accounting file
   (limited for m68k which has a different size struct acct).
 - introduce versioning for smooth transition to incompatible formats in 
   the future. Currently the following version numbers are defined:
     0: old format (until 2.6.7) with 16 bit uid/gid
     1: extended variant (binary compatible to v0 on M68K)
     2: extended variant (binary compatible to v0 on everything except M68K)
     3: a new binary incompatible format (64 bytes)
     4: new binary incompatible format (128 bytes).
        layout of its first 64 bytes is the same as for v3.
     5: marks second half of new binary incompatible format (128 bytes)
        (layout is not yet defined)

All this is accomplished without breaking binary compatibility.  32 bit
uid/gid support is compatible with the patch previously floating around and
used e.g. by Red Hat.

This patch also introduces a config option for a new, binary incompatible
"version 3" format that

 - is uniform across and properly aligned on all platforms
 - stores pid and ppid
 - uses AHZ==100 on all platforms (allows to report longer times)

Much of the compatibility glue goes away when v1/v2 support is removed from
the kernel.  Such a patch is at
  <http://www.physik3.uni-rostock.de/tim/kernel/2.7/acct-cleanup-04.patch>
and might be applied in the 2.7 timeframe.

The new v3 format is source compatible with current GNU acct tools (6.3.5). 
However, current GNU acct tools can be compiled for only one format.  As
there is no way to pass the kernel configuration to userspace, with my
patch it will still only support the old v2 format.  Only if v1/v2 support
is removed from the kernel, recompiling GNU acct tools will yield v3
support.

A preliminary take at the corresponding work on cross-platform userspace
tools (GNU acct package) is at
  <http://www.physik3.uni-rostock.de/tim/kernel/utils/acct/>
This version of the package is able to read any of the v0/v2/v3 formats,
regardless of byte-order (untested), even within the same file.
Cross-platform compatibility with m68k (v1 format) is not yet implemented,
but native use on m68k should work (untested).
pid and ppid are currently only shown by the dump-acct utility.

Thanks to Arthur Corliss, Albert Cahalan and Ragnar Kj�rstad for their
comments, and to Albert Cahalan for the u64->IEEE float conversion code.

Signed-off-by: Tim Schmielau <tim@physik3.uni-rostock.de>
Signed-off-by: Andrew Morton <akpm@osdl.org>
---

 25-akpm/include/linux/acct.h |   28 +++++++++++++++++-----------
 25-akpm/init/Kconfig         |    2 +-
 kernel/acct.c                |    0 
 3 files changed, 18 insertions(+), 12 deletions(-)

diff -puN include/linux/acct.h~bsd-accounting-format-rework-update include/linux/acct.h
--- 25/include/linux/acct.h~bsd-accounting-format-rework-update	2004-06-13 21:02:43.434525904 -0700
+++ 25-akpm/include/linux/acct.h	2004-06-13 21:03:31.922154664 -0700
@@ -146,33 +146,39 @@ typedef struct acct acct_t;
 
 #else
 #define ACCT_VERSION	2
-#define AHZ		(USER_HZ)
+#define AHZ		(HZ)
 #endif	/* __KERNEL */
 
 #ifdef __KERNEL__
 /*
- * Yet another HZ to *HZ helper function.
+ * Yet another set of HZ to *HZ helper functions.
  * See <linux/times.h> for the original.
- * TODO: Not exactly precise on i386.
  */
-#if (HZ % AHZ)==0
-# define jiffies_to_AHZ(x) ((x) / (HZ / AHZ))
+
+static inline u32 jiffies_to_AHZ(unsigned long x)
+{
+#if (TICK_NSEC % (NSEC_PER_SEC / AHZ)) == 0
+	return x / (HZ / USER_HZ);
 #else
-# define jiffies_to_AHZ(x) ((clock_t) jiffies_64_to_AHZ((u64) x))
+        u64 tmp = (u64)x * TICK_NSEC;
+        do_div(tmp, (NSEC_PER_SEC / AHZ));
+        return (long)tmp;
 #endif
+}
 
 static inline u64 jiffies_64_to_AHZ(u64 x)
 {
-#if HZ == AHZ
-	/* do nothing */
-#elif (HZ % AHZ) == 0
+#if (TICK_NSEC % (NSEC_PER_SEC / AHZ)) == 0
+#if HZ != AHZ
 	do_div(x, HZ / AHZ);
+#endif
 #else
-	x *= AHZ;
-	do_div(x, HZ);
+	x *= TICK_NSEC;
+	do_div(x, (NSEC_PER_SEC / AHZ));
 #endif
        return x;
 }
+
 #endif  /* __KERNEL */
 
 #endif	/* _LINUX_ACCT_H */
diff -puN init/Kconfig~bsd-accounting-format-rework-update init/Kconfig
--- 25/init/Kconfig~bsd-accounting-format-rework-update	2004-06-13 21:02:43.436525600 -0700
+++ 25-akpm/init/Kconfig	2004-06-13 21:03:31.923154512 -0700
@@ -131,7 +131,7 @@ config BSD_PROCESS_ACCT_V3
 	  process and it's parent. Note that this file format is incompatible
 	  with previous v0/v1/v2 file formats, so you will need updated tools
 	  for processing it. A preliminary version of these tools is available
-	  at <http://http://www.de.kernel.org/pub/linux/utils/>.
+	  at <http://http://www.de.kernel.org/pub/linux/utils/acct/>.
 
 config SYSCTL
 	bool "Sysctl support"
diff -puN kernel/acct.c~bsd-accounting-format-rework-update kernel/acct.c
_