Index: linux/include/linux/taskstats.h =================================================================== --- linux.orig/include/linux/taskstats.h 2006-06-19 18:27:38.881105605 -0700 +++ linux/include/linux/taskstats.h 2006-06-20 11:37:51.278901513 -0700 @@ -15,6 +15,11 @@ #ifndef _LINUX_TASKSTATS_H #define _LINUX_TASKSTATS_H +#ifdef __KERNEL__ +#include +#include +#endif + /* Format for per-task data returned to userland when * - a task exits * - listener requests stats for a task @@ -84,6 +89,40 @@ struct taskstats { /* version of taskstats */ __u64 version; + + /* Common Accounting Fields start */ + __u32 ac_uid; /* User ID */ + __u32 ac_gid; /* Group ID */ + __u32 ac_pid; /* Process ID */ + __u32 ac_ppid; /* Parent process ID */ + struct timespec start_time; /* Start time */ + struct timespec exit_time; /* Exit time */ + __u64 ac_utime; /* User CPU time [usec] */ + __u64 ac_stime; /* SYstem CPU time [usec] */ + char ac_comm[TASK_COMM_LEN]; /* Command name */ + /* Common Accounting Fields end */ + + /* CSA accounting fields start */ + __u64 ac_sbu; /* System billing units */ + __u16 csa_revision; /* CSA Revision */ + __u8 csa_type; /* Record types */ + __u8 csa_flag; /* Record flags */ + __u8 ac_stat; /* Exit status */ + __u8 ac_nice; /* Nice value */ + __u8 ac_sched; /* Scheduling discipline */ + __u8 pad0; /* Unused */ + __u64 acct_rss_mem1; /* accumulated rss usage */ + __u64 acct_vm_mem1; /* accumulated virtual memory usage */ + __u64 hiwater_rss; /* High-watermark of RSS usage */ + __u64 hiwater_vm; /* High-water virtual memory usage */ + __u64 ac_minflt; /* Minor Page Fault */ + __u64 ac_majflt; /* Major Page Fault */ + __u64 ac_chr; /* bytes read */ + __u64 ac_chw; /* bytes written */ + __u64 ac_scr; /* read syscalls */ + __u64 ac_scw; /* write syscalls */ + __u64 ac_jid; /* Job ID */ + /* CSA accounting fields end */ }; Index: linux/init/Kconfig =================================================================== --- linux.orig/init/Kconfig 2006-06-19 18:27:38.913105990 -0700 +++ linux/init/Kconfig 2006-06-20 11:37:51.290901649 -0700 @@ -173,6 +173,31 @@ config TASK_DELAY_ACCT Say N if unsure. +config CSA_ACCT + bool "Enable CSA Job Accounting (EXPERIMENTAL)" + depends on TASKSTATS + help + Comprehensive System Accounting (CSA) provides job level + accounting of resource usage. The accounting records are + written by the kernel into a file. CSA user level scripts + and commands process the binary accounting records and + combine them by job identifier within system boot uptime + periods. These accounting records are then used to produce + reports and charge fees to users. + + Say Y here if you want job level accounting to be compiled + into the kernel. Say M here if you want the writing of + accounting records portion of this feature to be a loadable + module. Say N here if you do not want job level accounting + (the default). + + The CSA commands and scripts package needs to be installed + to process the CSA accounting records. See + http://oss.sgi.com/projects/csa for further information + about CSA and download instructions for the CSA commands + package and documentation. + + config SYSCTL bool "Sysctl support" ---help--- Index: linux/kernel/Makefile =================================================================== --- linux.orig/kernel/Makefile 2006-06-19 18:27:38.929106183 -0700 +++ linux/kernel/Makefile 2006-06-20 11:37:51.290901649 -0700 @@ -40,6 +40,7 @@ obj-$(CONFIG_RCU_TORTURE_TEST) += rcutor obj-$(CONFIG_RELAY) += relay.o obj-$(CONFIG_TASK_DELAY_ACCT) += delayacct.o obj-$(CONFIG_TASKSTATS) += taskstats.o +obj-$(CONFIG_CSA_ACCT) += csa.o ifneq ($(CONFIG_SCHED_NO_NO_OMIT_FRAME_POINTER),y) # According to Alan Modra , the -fno-omit-frame-pointer is Index: linux/kernel/csa.c =================================================================== --- /dev/null 1970-01-01 00:00:00.000000000 +0000 +++ linux/kernel/csa.c 2006-06-20 11:37:51.294901694 -0700 @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2006 Silicon Graphics, Inc All Rights Reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it would be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA. + * + * Contact information: Silicon Graphics, Inc., 1500 Crittenden Lane, + * Mountain View, CA 94043, or: + * + * http://www.sgi.com + */ + +#include +#include + +int csa_add_tsk(struct taskstats *stats, struct task_struct *p) +{ + stats->version = 0x3132333435363738; + stats->ac_uid = 0x39393939; /* p->uid; */ + stats->ac_gid = 0x38383838; /* p->gid; */ + stats->ac_pid = p->pid; + stats->ac_ppid = (p->parent) ? p->parent->pid : 0; + stats->ac_utime = p->utime * USEC_PER_TICK; + stats->ac_stime = p->stime * USEC_PER_TICK; + /* Each process gets a minimum of a half tick cpu time */ + if ((stats->ac_utime == 0) && (stats->ac_stime == 0)) { + stats->ac_stime = USEC_PER_TICK/2; + } + + stats->start_time = p->start_time; + do_posix_clock_monotonic_gettime(&stats->exit_time); + strncpy(stats->ac_comm, p->comm, sizeof(stats->ac_comm)); + + stats->ac_sbu = 0; + stats->csa_revision = REV_CSA; + stats->csa_type = 0; + stats->csa_flag = 0; + stats->ac_stat = p->exit_code; + stats->ac_nice = task_nice(p); + stats->ac_sched = p->policy; + stats->acct_rss_mem1 = p->acct_rss_mem1; + stats->acct_vm_mem1 = p->acct_vm_mem1; + if (p->mm) { + stats->hiwater_rss = p->mm->hiwater_rss; + stats->hiwater_vm = p->mm->hiwater_vm; + } + stats->ac_minflt = p->min_flt; + stats->ac_majflt = p->maj_flt; + stats->ac_chr = p->rchar; + stats->ac_chw = p->wchar; + stats->ac_scr = p->syscr; + stats->ac_scw = p->syscw; + stats->ac_jid = 0xffffffffffffffff; + return 0; +} Index: linux/kernel/taskstats.c =================================================================== --- linux.orig/kernel/taskstats.c 2006-06-20 11:34:51.652867983 -0700 +++ linux/kernel/taskstats.c 2006-06-20 11:37:51.298901739 -0700 @@ -19,6 +19,7 @@ #include #include #include +#include #include #include @@ -123,8 +124,16 @@ static int fill_pid(pid_t pid, struct ta */ rc = delayacct_add_tsk(stats, tsk); +/* + if (rc) + goto err; + */ + rc = csa_add_tsk(stats, tsk); + if (rc) { + goto err; + } - /* Define err: label here if needed */ +err: /* Define err: label here if needed */ put_task_struct(tsk); return rc; @@ -269,12 +278,14 @@ void taskstats_exit_send(struct task_str size = 2 * size; /* PID + STATS + TGID + STATS */ rc = prepare_reply(NULL, TASKSTATS_CMD_NEW, &rep_skb, &reply, size); - if (rc < 0) + if (rc < 0) { goto ret; + } rc = fill_pid(tsk->pid, tsk, tidstats); - if (rc < 0) + if (rc < 0) { goto err_skb; + } tidstats->version = TASKSTATS_VERSION; Index: linux/include/linux/csa_kern.h =================================================================== --- /dev/null 1970-01-01 00:00:00.000000000 +0000 +++ linux/include/linux/csa_kern.h 2006-06-20 11:37:51.314901921 -0700 @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2006 Silicon Graphics, Inc All Rights Reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it would be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA. + * + * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy, + * Mountain View, CA 94043, or: + * + * http://www.sgi.com + */ +/* + * CSA (Comprehensive System Accounting) + * Job Accounting for Linux + * + * This header file contains the definitions needed for job + * accounting. The kernel CSA accounting module code and all + * user-level programs that try to write or process the binary job + * accounting data must include this file. + * + * This kernel header file and the csa.h in the csa userland source + * rpm share same data struct declaration and #define's. Do not modify + * one without modify the other one as well. The compatibility between + * userland and the kernel is ensured by using the 'ah_revision' field + * of struct achead. + * + */ + +#ifndef _CSA_KERN_H +#define _CSA_KERN_H + +#include + +extern int csa_add_tsk(struct taskstats *, struct task_struct *); + +/* + * Record revision levels. + * + * These are incremented to indicate that a record's format has changed since + * a previous release. + * + * History: 05000 The first rev in Linux + * 06000 Major rework to clean up unused fields and features. + * No binary compatibility with earlier rev. + * 07000 Convert to taskstats interface + * + * NOTE: The header revision number was defined as 02400 in earlier version. + * However, since ah_revision was defined as 15-bit field (ah_magic + * takes up 17 bits), the revision number is read as twice the value in + * new code. So, define it to be 05000 accordingly. + */ +#define REV_CSA 07000 /* Kernel: CSA base record */ + + +/* this defines can be removed once they're available in kernel header files */ +/* #define USEC_PER_SEC 1000000L */ /* number of usecs for 1 second */ +#define USEC_PER_TICK (USEC_PER_SEC/HZ) + + +#endif /* _CSA_KERN_H */