
From: Jay Lan <jlan@engr.sgi.com>

This patch is to offer common accounting data collection method at I/O for
various accounting packages including BSD accounting, ELSA, CSA and any
other acct packages that use a common layer of data collection.

Patch is made to fs/read_write.c to collect per process data on character
read/written in bytes and number of read/write syscalls made.

New struct fields are added to task_struct to store the data.

These data are collected on per process basis.

Signed-off-by: Jay Lan <jlan@sgi.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
---

 25-akpm/fs/read_write.c       |   23 +++++++++++++++++++++--
 25-akpm/include/linux/sched.h |    2 ++
 25-akpm/kernel/fork.c         |   15 ++++++++++++---
 3 files changed, 35 insertions(+), 5 deletions(-)

diff -puN fs/read_write.c~enhanced-i-o-accounting-data-patch fs/read_write.c
--- 25/fs/read_write.c~enhanced-i-o-accounting-data-patch	2004-12-03 20:55:51.870995984 -0800
+++ 25-akpm/fs/read_write.c	2004-12-03 20:55:51.876995072 -0800
@@ -216,8 +216,11 @@ ssize_t vfs_read(struct file *file, char
 				ret = file->f_op->read(file, buf, count, pos);
 			else
 				ret = do_sync_read(file, buf, count, pos);
-			if (ret > 0)
+			if (ret > 0) {
 				dnotify_parent(file->f_dentry, DN_ACCESS);
+				current->rchar += ret;
+			}
+			current->syscr++;
 		}
 	}
 
@@ -260,8 +263,11 @@ ssize_t vfs_write(struct file *file, con
 				ret = file->f_op->write(file, buf, count, pos);
 			else
 				ret = do_sync_write(file, buf, count, pos);
-			if (ret > 0)
+			if (ret > 0) {
 				dnotify_parent(file->f_dentry, DN_MODIFY);
+				current->wchar += ret;
+			}
+			current->syscw++;
 		}
 	}
 
@@ -540,6 +546,9 @@ sys_readv(unsigned long fd, const struct
 		fput_light(file, fput_needed);
 	}
 
+	if (ret > 0)
+		current->rchar += ret;
+	current->syscr++;
 	return ret;
 }
 
@@ -558,6 +567,9 @@ sys_writev(unsigned long fd, const struc
 		fput_light(file, fput_needed);
 	}
 
+	if (ret > 0)
+		current->wchar += ret;
+	current->syscw++;
 	return ret;
 }
 
@@ -636,6 +648,13 @@ static ssize_t do_sendfile(int out_fd, i
 
 	retval = in_file->f_op->sendfile(in_file, ppos, count, file_send_actor, out_file);
 
+	if (retval > 0) {
+		current->rchar += retval;
+		current->wchar += retval;
+	}
+	current->syscr++;
+	current->syscw++;
+
 	if (*ppos > max)
 		retval = -EOVERFLOW;
 
diff -puN include/linux/sched.h~enhanced-i-o-accounting-data-patch include/linux/sched.h
--- 25/include/linux/sched.h~enhanced-i-o-accounting-data-patch	2004-12-03 20:55:51.871995832 -0800
+++ 25-akpm/include/linux/sched.h	2004-12-03 20:55:51.877994920 -0800
@@ -661,6 +661,8 @@ struct task_struct {
  * to a stack based synchronous wait) if its doing sync IO.
  */
 	wait_queue_t *io_wait;
+/* i/o counters(bytes read/written, #syscalls */
+	u64 rchar, wchar, syscr, syscw;
 #ifdef CONFIG_NUMA
   	struct mempolicy *mempolicy;
   	short il_next;		/* could be shared with used_math */
diff -puN kernel/fork.c~enhanced-i-o-accounting-data-patch kernel/fork.c
--- 25/kernel/fork.c~enhanced-i-o-accounting-data-patch	2004-12-03 20:55:51.872995680 -0800
+++ 25-akpm/kernel/fork.c	2004-12-03 20:55:51.878994768 -0800
@@ -865,12 +865,21 @@ static task_t *copy_process(unsigned lon
 	clear_tsk_thread_flag(p, TIF_SIGPENDING);
 	init_sigpending(&p->pending);
 
-	p->it_real_value = p->it_virt_value = p->it_prof_value = 0;
-	p->it_real_incr = p->it_virt_incr = p->it_prof_incr = 0;
+	p->it_real_value = 0;
+	p->it_real_incr = 0;
+	p->it_virt_value = 0;
+	p->it_virt_incr = 0;
+	p->it_prof_value = 0;
+	p->it_prof_incr = 0;
 	init_timer(&p->real_timer);
 	p->real_timer.data = (unsigned long) p;
 
-	p->utime = p->stime = 0;
+	p->utime = 0;
+	p->stime = 0;
+	p->rchar = 0;		/* I/O counter: bytes read */
+	p->wchar = 0;		/* I/O counter: bytes written */
+	p->syscr = 0;		/* I/O counter: read syscalls */
+	p->syscw = 0;		/* I/O counter: write syscalls */
 	p->lock_depth = -1;		/* -1 = no lock */
 	do_posix_clock_monotonic_gettime(&p->start_time);
 	p->security = NULL;
_
