All of lore.kernel.org
 help / color / mirror / Atom feed
* + getrusage-fill-ru_inblock-and-ru_oublock-fields-if-possible.patch added to -mm tree
@ 2007-03-19 21:47 akpm
  0 siblings, 0 replies; 7+ messages in thread
From: akpm @ 2007-03-19 21:47 UTC (permalink / raw)
  To: mm-commits; +Cc: dada1, oleg


The patch titled
     getrusage(): fill ru_inblock and ru_oublock fields if possible
has been added to the -mm tree.  Its filename is
     getrusage-fill-ru_inblock-and-ru_oublock-fields-if-possible.patch

*** Remember to use Documentation/SubmitChecklist when testing your code ***

See http://www.zip.com.au/~akpm/linux/patches/stuff/added-to-mm.txt to find
out what to do about this

------------------------------------------------------
Subject: getrusage(): fill ru_inblock and ru_oublock fields if possible
From: Eric Dumazet <dada1@cosmosbay.com>

If CONFIG_TASK_IO_ACCOUNTING is defined, we update io accounting counters for
each task.

This patch permits reporting of values using the well known getrusage() 
syscall, filling ru_inblock and ru_oublock instead of null values.

As TASK_IO_ACCOUNTING currently counts bytes counts, we approximate blocks
count doing : nr_blocks = nr_bytes / 512

Example of use :
----------------------
After patch is applied, /usr/bin/time command can now give a good 
approximation of IO that the process had to do.

$ /usr/bin/time grep tototo /usr/include/*
Command exited with non-zero status 1
0.00user 0.02system 0:02.11elapsed 1%CPU (0avgtext+0avgdata 0maxresident)k
24288inputs+0outputs (0major+259minor)pagefaults 0swaps

$ /usr/bin/time dd if=/dev/zero of=/tmp/testfile count=1000
1000+0 enregistrements lus
1000+0 enregistrements écrits
512000 octets (512 kB) copiés, 0,00326601 seconde, 157 MB/s
0.00user 0.00system 0:00.00elapsed 80%CPU (0avgtext+0avgdata 0maxresident)k
0inputs+3000outputs (0major+299minor)pagefaults 0swaps

Signed-off-by: Eric Dumazet <dada1@cosmosbay.com>
Cc: Oleg Nesterov <oleg@tv-sign.ru>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---

 include/linux/sched.h                  |    1 
 include/linux/task_io_accounting_ops.h |   28 +++++++++++++++++++++++
 kernel/exit.c                          |    9 +++++++
 kernel/fork.c                          |    1 
 kernel/sys.c                           |    7 +++++
 5 files changed, 46 insertions(+)

diff -puN include/linux/sched.h~getrusage-fill-ru_inblock-and-ru_oublock-fields-if-possible include/linux/sched.h
--- a/include/linux/sched.h~getrusage-fill-ru_inblock-and-ru_oublock-fields-if-possible
+++ a/include/linux/sched.h
@@ -457,6 +457,7 @@ struct signal_struct {
 	cputime_t utime, stime, cutime, cstime;
 	unsigned long nvcsw, nivcsw, cnvcsw, cnivcsw;
 	unsigned long min_flt, maj_flt, cmin_flt, cmaj_flt;
+	unsigned long inblock, oublock, cinblock, coublock;
 
 	/*
 	 * Cumulative ns of scheduled CPU time for dead threads in the
diff -puN include/linux/task_io_accounting_ops.h~getrusage-fill-ru_inblock-and-ru_oublock-fields-if-possible include/linux/task_io_accounting_ops.h
--- a/include/linux/task_io_accounting_ops.h~getrusage-fill-ru_inblock-and-ru_oublock-fields-if-possible
+++ a/include/linux/task_io_accounting_ops.h
@@ -10,11 +10,29 @@ static inline void task_io_account_read(
 	current->ioac.read_bytes += bytes;
 }
 
+/*
+ * We approximate number of blocks, because we account bytes only.
+ * A 'block' is 512 bytes
+ */
+static inline unsigned long task_io_get_inblock(const struct task_struct *p)
+{
+	return p->ioac.read_bytes >> 9;
+}
+
 static inline void task_io_account_write(size_t bytes)
 {
 	current->ioac.write_bytes += bytes;
 }
 
+/*
+ * We approximate number of blocks, because we account bytes only.
+ * A 'block' is 512 bytes
+ */
+static inline unsigned long task_io_get_oublock(const struct task_struct *p)
+{
+	return p->ioac.write_bytes >> 9;
+}
+
 static inline void task_io_account_cancelled_write(size_t bytes)
 {
 	current->ioac.cancelled_write_bytes += bytes;
@@ -31,10 +49,20 @@ static inline void task_io_account_read(
 {
 }
 
+static inline unsigned long task_io_get_inblock(const struct task_struct *p)
+{
+	return 0;
+}
+
 static inline void task_io_account_write(size_t bytes)
 {
 }
 
+static inline unsigned long task_io_get_oublock(const struct task_struct *p)
+{
+	return 0;
+}
+
 static inline void task_io_account_cancelled_write(size_t bytes)
 {
 }
diff -puN kernel/exit.c~getrusage-fill-ru_inblock-and-ru_oublock-fields-if-possible kernel/exit.c
--- a/kernel/exit.c~getrusage-fill-ru_inblock-and-ru_oublock-fields-if-possible
+++ a/kernel/exit.c
@@ -42,6 +42,7 @@
 #include <linux/audit.h> /* for audit_free() */
 #include <linux/resource.h>
 #include <linux/blkdev.h>
+#include <linux/task_io_accounting_ops.h>
 
 #include <asm/uaccess.h>
 #include <asm/unistd.h>
@@ -113,6 +114,8 @@ static void __exit_signal(struct task_st
 		sig->nvcsw += tsk->nvcsw;
 		sig->nivcsw += tsk->nivcsw;
 		sig->sched_time += tsk->sched_time;
+		sig->inblock += task_io_get_inblock(tsk);
+		sig->oublock += task_io_get_oublock(tsk);
 		sig = NULL; /* Marker for below. */
 	}
 
@@ -1191,6 +1194,12 @@ static int wait_task_zombie(struct task_
 			p->nvcsw + sig->nvcsw + sig->cnvcsw;
 		psig->cnivcsw +=
 			p->nivcsw + sig->nivcsw + sig->cnivcsw;
+		psig->cinblock +=
+			task_io_get_inblock(p) +
+			sig->inblock + sig->cinblock;
+		psig->coublock +=
+			task_io_get_oublock(p) +
+			sig->oublock + sig->coublock;
 		spin_unlock_irq(&p->parent->sighand->siglock);
 	}
 
diff -puN kernel/fork.c~getrusage-fill-ru_inblock-and-ru_oublock-fields-if-possible kernel/fork.c
--- a/kernel/fork.c~getrusage-fill-ru_inblock-and-ru_oublock-fields-if-possible
+++ a/kernel/fork.c
@@ -875,6 +875,7 @@ static inline int copy_signal(unsigned l
 	sig->utime = sig->stime = sig->cutime = sig->cstime = cputime_zero;
 	sig->nvcsw = sig->nivcsw = sig->cnvcsw = sig->cnivcsw = 0;
 	sig->min_flt = sig->maj_flt = sig->cmin_flt = sig->cmaj_flt = 0;
+	sig->inblock = sig->oublock = sig->cinblock = sig->coublock = 0;
 	sig->sched_time = 0;
 	INIT_LIST_HEAD(&sig->cpu_timers[0]);
 	INIT_LIST_HEAD(&sig->cpu_timers[1]);
diff -puN kernel/sys.c~getrusage-fill-ru_inblock-and-ru_oublock-fields-if-possible kernel/sys.c
--- a/kernel/sys.c~getrusage-fill-ru_inblock-and-ru_oublock-fields-if-possible
+++ a/kernel/sys.c
@@ -29,6 +29,7 @@
 #include <linux/signal.h>
 #include <linux/cn_proc.h>
 #include <linux/getcpu.h>
+#include <linux/task_io_accounting_ops.h>
 
 #include <linux/compat.h>
 #include <linux/syscalls.h>
@@ -2021,6 +2022,8 @@ static void k_getrusage(struct task_stru
 			r->ru_nivcsw = p->signal->cnivcsw;
 			r->ru_minflt = p->signal->cmin_flt;
 			r->ru_majflt = p->signal->cmaj_flt;
+			r->ru_inblock = p->signal->cinblock;
+			r->ru_oublock = p->signal->coublock;
 
 			if (who == RUSAGE_CHILDREN)
 				break;
@@ -2032,6 +2035,8 @@ static void k_getrusage(struct task_stru
 			r->ru_nivcsw += p->signal->nivcsw;
 			r->ru_minflt += p->signal->min_flt;
 			r->ru_majflt += p->signal->maj_flt;
+			r->ru_inblock += p->signal->inblock;
+			r->ru_oublock += p->signal->oublock;
 			t = p;
 			do {
 				utime = cputime_add(utime, t->utime);
@@ -2040,6 +2045,8 @@ static void k_getrusage(struct task_stru
 				r->ru_nivcsw += t->nivcsw;
 				r->ru_minflt += t->min_flt;
 				r->ru_majflt += t->maj_flt;
+				r->ru_inblock += task_io_get_inblock(t);
+				r->ru_oublock += task_io_get_oublock(t);
 				t = next_thread(t);
 			} while (t != p);
 			break;
_

Patches currently in -mm which might be from dada1@cosmosbay.com are

optimize-timespec_trunc.patch
procfs-reorder-struct-pid_dentry-to-save-space-on-64bit-archs-and-constify-them.patch
vfs-delay-the-dentry-name-generation-on-sockets-and.patch
getrusage-fill-ru_inblock-and-ru_oublock-fields-if-possible.patch
make-static-counters-in-new_inode-and-iunique-be-32-bits.patch
speedup-divides-by-cpu_power-in-scheduler.patch

^ permalink raw reply	[flat|nested] 7+ messages in thread

* + getrusage-fill-ru_inblock-and-ru_oublock-fields-if-possible.patch added to -mm tree
@ 2007-03-19 21:26 akpm
  0 siblings, 0 replies; 7+ messages in thread
From: akpm @ 2007-03-19 21:26 UTC (permalink / raw)
  To: mm-commits; +Cc: dada1, oleg


The patch titled
     getrusage(): fill ru_inblock and ru_oublock fields if possible
has been added to the -mm tree.  Its filename is
     getrusage-fill-ru_inblock-and-ru_oublock-fields-if-possible.patch

*** Remember to use Documentation/SubmitChecklist when testing your code ***

See http://www.zip.com.au/~akpm/linux/patches/stuff/added-to-mm.txt to find
out what to do about this

------------------------------------------------------
Subject: getrusage(): fill ru_inblock and ru_oublock fields if possible
From: Eric Dumazet <dada1@cosmosbay.com>

If CONFIG_TASK_IO_ACCOUNTING is defined, we update io accounting counters for
each task.

This patch permits reporting of values using the well known getrusage() 
syscall, filling ru_inblock and ru_oublock instead of null values.

As TASK_IO_ACCOUNTING currently counts bytes counts, we approximate blocks
count doing : nr_blocks = nr_bytes / 512

Example of use :
----------------------
After patch is applied, /usr/bin/time command can now give a good 
approximation of IO that the process had to do.

$ /usr/bin/time grep tototo /usr/include/*
Command exited with non-zero status 1
0.00user 0.02system 0:02.11elapsed 1%CPU (0avgtext+0avgdata 0maxresident)k
24288inputs+0outputs (0major+259minor)pagefaults 0swaps

$ /usr/bin/time dd if=/dev/zero of=/tmp/testfile count=1000
1000+0 enregistrements lus
1000+0 enregistrements écrits
512000 octets (512 kB) copiés, 0,00326601 seconde, 157 MB/s
0.00user 0.00system 0:00.00elapsed 80%CPU (0avgtext+0avgdata 0maxresident)k
0inputs+3000outputs (0major+299minor)pagefaults 0swaps

Signed-off-by: Eric Dumazet <dada1@cosmosbay.com>
Cc: Oleg Nesterov <oleg@tv-sign.ru>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---

 include/linux/task_io_accounting_ops.h |   28 +++++++++++++++++++++++
 kernel/sys.c                           |    7 +++++
 2 files changed, 35 insertions(+)

diff -puN include/linux/task_io_accounting_ops.h~getrusage-fill-ru_inblock-and-ru_oublock-fields-if-possible include/linux/task_io_accounting_ops.h
--- a/include/linux/task_io_accounting_ops.h~getrusage-fill-ru_inblock-and-ru_oublock-fields-if-possible
+++ a/include/linux/task_io_accounting_ops.h
@@ -10,11 +10,29 @@ static inline void task_io_account_read(
 	current->ioac.read_bytes += bytes;
 }
 
+/*
+ * We approximate number of blocks, because we account bytes only.
+ * A 'block' is 512 bytes
+ */
+static inline unsigned long task_io_get_inblock(const struct task_struct *p)
+{
+	return p->ioac.read_bytes >> 9;
+}
+
 static inline void task_io_account_write(size_t bytes)
 {
 	current->ioac.write_bytes += bytes;
 }
 
+/*
+ * We approximate number of blocks, because we account bytes only.
+ * A 'block' is 512 bytes
+ */
+static inline unsigned long task_io_get_oublock(const struct task_struct *p)
+{
+	return p->ioac.write_bytes >> 9;
+}
+
 static inline void task_io_account_cancelled_write(size_t bytes)
 {
 	current->ioac.cancelled_write_bytes += bytes;
@@ -31,10 +49,20 @@ static inline void task_io_account_read(
 {
 }
 
+static inline unsigned long task_io_get_inblock(const struct task_struct *p)
+{
+	return 0;
+}
+
 static inline void task_io_account_write(size_t bytes)
 {
 }
 
+static inline unsigned long task_io_get_oublock(const struct task_struct *p)
+{
+	return 0;
+}
+
 static inline void task_io_account_cancelled_write(size_t bytes)
 {
 }
diff -puN kernel/sys.c~getrusage-fill-ru_inblock-and-ru_oublock-fields-if-possible kernel/sys.c
--- a/kernel/sys.c~getrusage-fill-ru_inblock-and-ru_oublock-fields-if-possible
+++ a/kernel/sys.c
@@ -29,6 +29,7 @@
 #include <linux/signal.h>
 #include <linux/cn_proc.h>
 #include <linux/getcpu.h>
+#include <linux/task_io_accounting_ops.h>
 
 #include <linux/compat.h>
 #include <linux/syscalls.h>
@@ -2021,6 +2022,8 @@ static void k_getrusage(struct task_stru
 			r->ru_nivcsw = p->signal->cnivcsw;
 			r->ru_minflt = p->signal->cmin_flt;
 			r->ru_majflt = p->signal->cmaj_flt;
+			r->ru_inblock = task_io_get_inblock(p);
+			r->ru_oublock = task_io_get_oublock(p);
 
 			if (who == RUSAGE_CHILDREN)
 				break;
@@ -2032,6 +2035,8 @@ static void k_getrusage(struct task_stru
 			r->ru_nivcsw += p->signal->nivcsw;
 			r->ru_minflt += p->signal->min_flt;
 			r->ru_majflt += p->signal->maj_flt;
+			r->ru_inblock += task_io_get_inblock(p);
+			r->ru_oublock += task_io_get_oublock(p);
 			t = p;
 			do {
 				utime = cputime_add(utime, t->utime);
@@ -2040,6 +2045,8 @@ static void k_getrusage(struct task_stru
 				r->ru_nivcsw += t->nivcsw;
 				r->ru_minflt += t->min_flt;
 				r->ru_majflt += t->maj_flt;
+				r->ru_inblock += task_io_get_inblock(t);
+				r->ru_oublock += task_io_get_oublock(t);
 				t = next_thread(t);
 			} while (t != p);
 			break;
_

Patches currently in -mm which might be from dada1@cosmosbay.com are

optimize-timespec_trunc.patch
procfs-reorder-struct-pid_dentry-to-save-space-on-64bit-archs-and-constify-them.patch
vfs-delay-the-dentry-name-generation-on-sockets-and.patch
getrusage-fill-ru_inblock-and-ru_oublock-fields-if-possible.patch
make-static-counters-in-new_inode-and-iunique-be-32-bits.patch
speedup-divides-by-cpu_power-in-scheduler.patch

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: + getrusage-fill-ru_inblock-and-ru_oublock-fields-if-possible.patch added to -mm tree
  2007-03-16 17:23 ` Eric Dumazet
  2007-03-16 17:34   ` Eric Dumazet
@ 2007-03-16 17:40   ` Oleg Nesterov
  1 sibling, 0 replies; 7+ messages in thread
From: Oleg Nesterov @ 2007-03-16 17:40 UTC (permalink / raw)
  To: Eric Dumazet; +Cc: Andrew Morton, linux-kernel

On 03/16, Eric Dumazet wrote:
>
> On Friday 16 March 2007 18:10, Oleg Nesterov wrote:
> > Eric Dumazet wrote:
> > > @@ -2021,6 +2022,8 @@ static void k_getrusage(struct task_stru
> > >  			r->ru_nivcsw = p->signal->cnivcsw;
> > >  			r->ru_minflt = p->signal->cmin_flt;
> > >  			r->ru_majflt = p->signal->cmaj_flt;
> > > +			r->ru_inblock = task_io_get_inblock(p);
> > > +			r->ru_oublock = task_io_get_oublock(p);
> > >
> > >  			if (who == RUSAGE_CHILDREN)
> > >  				break;
> > > @@ -2032,6 +2035,8 @@ static void k_getrusage(struct task_stru
> > >  			r->ru_nivcsw += p->signal->nivcsw;
> > >  			r->ru_minflt += p->signal->min_flt;
> > >  			r->ru_majflt += p->signal->maj_flt;
> > > +			r->ru_inblock += task_io_get_inblock(p);
> > > +			r->ru_oublock += task_io_get_oublock(p);
> > >  			t = p;
> > >  			do {
> > >  				utime = cputime_add(utime, t->utime);
> > > @@ -2040,6 +2045,8 @@ static void k_getrusage(struct task_stru
> > >  				r->ru_nivcsw += t->nivcsw;
> > >  				r->ru_minflt += t->min_flt;
> > >  				r->ru_majflt += t->maj_flt;
> > > +				r->ru_inblock += task_io_get_inblock(t);
> > > +				r->ru_oublock += task_io_get_oublock(t);
> >
> > I can't understand this. Consider k_getrusage(RUSAGE_BOTH). The end result
> > is that r->ru_inblock == 3 * task_io_get_inblock(p).
> >
> > No?
> 
> Yes :)
> 
> Very good point, you found a bug in k_getrusage().

No, no, please check the code.

> So not only ru_inblock/ru_oublock are multiplied by 3 : others fields as well 
> are wrong.
> 
> Also the definition of RUSAGE_CHILDREN is not conformant to standard
> 
> http://www.opengroup.org/onlinepubs/009695399/functions/getrusage.html
> 
> 	"If the value of the who argument is RUSAGE_CHILDREN, information shall be 
> 	"returned about resources used by the terminated and waited-for children of 
> 	"the current process

This exactly happens. We are reading ->signal->*, see wait_task_zombie().

> We currently do a sum of rusage stats of still alive children.. thats totally 
> wrong...

I hope not :)

Oleg.


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: + getrusage-fill-ru_inblock-and-ru_oublock-fields-if-possible.patch added to -mm tree
  2007-03-16 17:23 ` Eric Dumazet
@ 2007-03-16 17:34   ` Eric Dumazet
  2007-03-16 17:40   ` Oleg Nesterov
  1 sibling, 0 replies; 7+ messages in thread
From: Eric Dumazet @ 2007-03-16 17:34 UTC (permalink / raw)
  To: Oleg Nesterov; +Cc: Andrew Morton, linux-kernel

On Friday 16 March 2007 18:23, Eric Dumazet wrote:

>
> Very good point, you found a bug in k_getrusage().
>
> I just followed the existing logic, but it seems this logic is bad.
>
> So not only ru_inblock/ru_oublock are multiplied by 3 : others fields as
> well are wrong.
>
> Also the definition of RUSAGE_CHILDREN is not conformant to standard
>
> http://www.opengroup.org/onlinepubs/009695399/functions/getrusage.html
>
> 	"If the value of the who argument is RUSAGE_CHILDREN, information shall be
> 	"returned about resources used by the terminated and waited-for children
> of "the current process
>
> We currently do a sum of rusage stats of still alive children.. thats
> totally wrong...

Please ignore this mail, I was very wrong.

I shall rethink a proper patch.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: + getrusage-fill-ru_inblock-and-ru_oublock-fields-if-possible.patch added to -mm tree
  2007-03-16 17:10 Oleg Nesterov
@ 2007-03-16 17:23 ` Eric Dumazet
  2007-03-16 17:34   ` Eric Dumazet
  2007-03-16 17:40   ` Oleg Nesterov
  0 siblings, 2 replies; 7+ messages in thread
From: Eric Dumazet @ 2007-03-16 17:23 UTC (permalink / raw)
  To: Oleg Nesterov; +Cc: Andrew Morton, linux-kernel

On Friday 16 March 2007 18:10, Oleg Nesterov wrote:
> Eric Dumazet wrote:
> > @@ -2021,6 +2022,8 @@ static void k_getrusage(struct task_stru
> >  			r->ru_nivcsw = p->signal->cnivcsw;
> >  			r->ru_minflt = p->signal->cmin_flt;
> >  			r->ru_majflt = p->signal->cmaj_flt;
> > +			r->ru_inblock = task_io_get_inblock(p);
> > +			r->ru_oublock = task_io_get_oublock(p);
> >
> >  			if (who == RUSAGE_CHILDREN)
> >  				break;
> > @@ -2032,6 +2035,8 @@ static void k_getrusage(struct task_stru
> >  			r->ru_nivcsw += p->signal->nivcsw;
> >  			r->ru_minflt += p->signal->min_flt;
> >  			r->ru_majflt += p->signal->maj_flt;
> > +			r->ru_inblock += task_io_get_inblock(p);
> > +			r->ru_oublock += task_io_get_oublock(p);
> >  			t = p;
> >  			do {
> >  				utime = cputime_add(utime, t->utime);
> > @@ -2040,6 +2045,8 @@ static void k_getrusage(struct task_stru
> >  				r->ru_nivcsw += t->nivcsw;
> >  				r->ru_minflt += t->min_flt;
> >  				r->ru_majflt += t->maj_flt;
> > +				r->ru_inblock += task_io_get_inblock(t);
> > +				r->ru_oublock += task_io_get_oublock(t);
>
> I can't understand this. Consider k_getrusage(RUSAGE_BOTH). The end result
> is that r->ru_inblock == 3 * task_io_get_inblock(p).
>
> No?

Yes :)

Very good point, you found a bug in k_getrusage().

I just followed the existing logic, but it seems this logic is bad.

So not only ru_inblock/ru_oublock are multiplied by 3 : others fields as well 
are wrong.

Also the definition of RUSAGE_CHILDREN is not conformant to standard

http://www.opengroup.org/onlinepubs/009695399/functions/getrusage.html

	"If the value of the who argument is RUSAGE_CHILDREN, information shall be 
	"returned about resources used by the terminated and waited-for children of 
	"the current process

We currently do a sum of rusage stats of still alive children.. thats totally 
wrong...

Eric

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: + getrusage-fill-ru_inblock-and-ru_oublock-fields-if-possible.patch added to -mm tree
@ 2007-03-16 17:10 Oleg Nesterov
  2007-03-16 17:23 ` Eric Dumazet
  0 siblings, 1 reply; 7+ messages in thread
From: Oleg Nesterov @ 2007-03-16 17:10 UTC (permalink / raw)
  To: Eric Dumazet; +Cc: Andrew Morton, linux-kernel

Eric Dumazet wrote:
>
> @@ -2021,6 +2022,8 @@ static void k_getrusage(struct task_stru
>  			r->ru_nivcsw = p->signal->cnivcsw;
>  			r->ru_minflt = p->signal->cmin_flt;
>  			r->ru_majflt = p->signal->cmaj_flt;
> +			r->ru_inblock = task_io_get_inblock(p);
> +			r->ru_oublock = task_io_get_oublock(p);
>
>  			if (who == RUSAGE_CHILDREN)
>  				break;
> @@ -2032,6 +2035,8 @@ static void k_getrusage(struct task_stru
>  			r->ru_nivcsw += p->signal->nivcsw;
>  			r->ru_minflt += p->signal->min_flt;
>  			r->ru_majflt += p->signal->maj_flt;
> +			r->ru_inblock += task_io_get_inblock(p);
> +			r->ru_oublock += task_io_get_oublock(p);
>  			t = p;
>  			do {
>  				utime = cputime_add(utime, t->utime);
> @@ -2040,6 +2045,8 @@ static void k_getrusage(struct task_stru
>  				r->ru_nivcsw += t->nivcsw;
>  				r->ru_minflt += t->min_flt;
>  				r->ru_majflt += t->maj_flt;
> +				r->ru_inblock += task_io_get_inblock(t);
> +				r->ru_oublock += task_io_get_oublock(t);

I can't understand this. Consider k_getrusage(RUSAGE_BOTH). The end result
is that r->ru_inblock == 3 * task_io_get_inblock(p).

No?

Oleg.


^ permalink raw reply	[flat|nested] 7+ messages in thread

* + getrusage-fill-ru_inblock-and-ru_oublock-fields-if-possible.patch added to -mm tree
@ 2007-03-16  3:08 akpm
  0 siblings, 0 replies; 7+ messages in thread
From: akpm @ 2007-03-16  3:08 UTC (permalink / raw)
  To: mm-commits; +Cc: dada1


The patch titled
     getrusage(): fill ru_inblock and ru_oublock fields if possible
has been added to the -mm tree.  Its filename is
     getrusage-fill-ru_inblock-and-ru_oublock-fields-if-possible.patch

*** Remember to use Documentation/SubmitChecklist when testing your code ***

See http://www.zip.com.au/~akpm/linux/patches/stuff/added-to-mm.txt to find
out what to do about this

------------------------------------------------------
Subject: getrusage(): fill ru_inblock and ru_oublock fields if possible
From: Eric Dumazet <dada1@cosmosbay.com>

If CONFIG_TASK_IO_ACCOUNTING is defined, we update io accounting counters for
each task.

This patch permits reporting of values using the well known getrusage() 
syscall, filling ru_inblock and ru_oublock instead of null values.

As TASK_IO_ACCOUNTING currently counts bytes counts, we approximate blocks
count doing : nr_blocks = nr_bytes / 512

Example of use :
----------------------
After patch is applied, /usr/bin/time command can now give a good 
approximation of IO that the process had to do.

$ /usr/bin/time grep tototo /usr/include/*
Command exited with non-zero status 1
0.00user 0.02system 0:02.11elapsed 1%CPU (0avgtext+0avgdata 0maxresident)k
24288inputs+0outputs (0major+259minor)pagefaults 0swaps

$ /usr/bin/time dd if=/dev/zero of=/tmp/testfile count=1000
1000+0 enregistrements lus
1000+0 enregistrements écrits
512000 octets (512 kB) copiés, 0,00326601 seconde, 157 MB/s
0.00user 0.00system 0:00.00elapsed 80%CPU (0avgtext+0avgdata 0maxresident)k
0inputs+3000outputs (0major+299minor)pagefaults 0swaps

Signed-off-by: Eric Dumazet <dada1@cosmosbay.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---

 include/linux/task_io_accounting_ops.h |   28 +++++++++++++++++++++++
 kernel/sys.c                           |    7 +++++
 2 files changed, 35 insertions(+)

diff -puN include/linux/task_io_accounting_ops.h~getrusage-fill-ru_inblock-and-ru_oublock-fields-if-possible include/linux/task_io_accounting_ops.h
--- a/include/linux/task_io_accounting_ops.h~getrusage-fill-ru_inblock-and-ru_oublock-fields-if-possible
+++ a/include/linux/task_io_accounting_ops.h
@@ -10,11 +10,29 @@ static inline void task_io_account_read(
 	current->ioac.read_bytes += bytes;
 }
 
+/*
+ * We approximate number of blocks, because we account bytes only.
+ * A 'block' is 512 bytes
+ */
+static inline unsigned long task_io_get_inblock(const struct task_struct *p)
+{
+	return p->ioac.read_bytes >> 9;
+}
+
 static inline void task_io_account_write(size_t bytes)
 {
 	current->ioac.write_bytes += bytes;
 }
 
+/*
+ * We approximate number of blocks, because we account bytes only.
+ * A 'block' is 512 bytes
+ */
+static inline unsigned long task_io_get_oublock(const struct task_struct *p)
+{
+	return p->ioac.write_bytes >> 9;
+}
+
 static inline void task_io_account_cancelled_write(size_t bytes)
 {
 	current->ioac.cancelled_write_bytes += bytes;
@@ -31,10 +49,20 @@ static inline void task_io_account_read(
 {
 }
 
+static inline unsigned long task_io_get_inblock(const struct task_struct *p)
+{
+	return 0;
+}
+
 static inline void task_io_account_write(size_t bytes)
 {
 }
 
+static inline unsigned long task_io_get_oublock(const struct task_struct *p)
+{
+	return 0;
+}
+
 static inline void task_io_account_cancelled_write(size_t bytes)
 {
 }
diff -puN kernel/sys.c~getrusage-fill-ru_inblock-and-ru_oublock-fields-if-possible kernel/sys.c
--- a/kernel/sys.c~getrusage-fill-ru_inblock-and-ru_oublock-fields-if-possible
+++ a/kernel/sys.c
@@ -29,6 +29,7 @@
 #include <linux/signal.h>
 #include <linux/cn_proc.h>
 #include <linux/getcpu.h>
+#include <linux/task_io_accounting_ops.h>
 
 #include <linux/compat.h>
 #include <linux/syscalls.h>
@@ -2021,6 +2022,8 @@ static void k_getrusage(struct task_stru
 			r->ru_nivcsw = p->signal->cnivcsw;
 			r->ru_minflt = p->signal->cmin_flt;
 			r->ru_majflt = p->signal->cmaj_flt;
+			r->ru_inblock = task_io_get_inblock(p);
+			r->ru_oublock = task_io_get_oublock(p);
 
 			if (who == RUSAGE_CHILDREN)
 				break;
@@ -2032,6 +2035,8 @@ static void k_getrusage(struct task_stru
 			r->ru_nivcsw += p->signal->nivcsw;
 			r->ru_minflt += p->signal->min_flt;
 			r->ru_majflt += p->signal->maj_flt;
+			r->ru_inblock += task_io_get_inblock(p);
+			r->ru_oublock += task_io_get_oublock(p);
 			t = p;
 			do {
 				utime = cputime_add(utime, t->utime);
@@ -2040,6 +2045,8 @@ static void k_getrusage(struct task_stru
 				r->ru_nivcsw += t->nivcsw;
 				r->ru_minflt += t->min_flt;
 				r->ru_majflt += t->maj_flt;
+				r->ru_inblock += task_io_get_inblock(t);
+				r->ru_oublock += task_io_get_oublock(t);
 				t = next_thread(t);
 			} while (t != p);
 			break;
_

Patches currently in -mm which might be from dada1@cosmosbay.com are

optimize-timespec_trunc.patch
procfs-reorder-struct-pid_dentry-to-save-space-on-64bit-archs-and-constify-them.patch
vfs-delay-the-dentry-name-generation-on-sockets-and.patch
getrusage-fill-ru_inblock-and-ru_oublock-fields-if-possible.patch
make-static-counters-in-new_inode-and-iunique-be-32-bits.patch
speedup-divides-by-cpu_power-in-scheduler.patch

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2007-03-19 21:48 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-03-19 21:47 + getrusage-fill-ru_inblock-and-ru_oublock-fields-if-possible.patch added to -mm tree akpm
  -- strict thread matches above, loose matches on Subject: below --
2007-03-19 21:26 akpm
2007-03-16 17:10 Oleg Nesterov
2007-03-16 17:23 ` Eric Dumazet
2007-03-16 17:34   ` Eric Dumazet
2007-03-16 17:40   ` Oleg Nesterov
2007-03-16  3:08 akpm

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.