Module Name: src Committed By: christos Date: Sat Oct 29 15:58:38 UTC 2011
Modified Files: src/sys/kern: kern_clock.c Log Message: PR/45539: Greg A. Woods: add support for getrusage(2) memory size statistics To generate a diff of this commit: cvs rdiff -u -r1.128 -r1.129 src/sys/kern/kern_clock.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/kern/kern_clock.c diff -u src/sys/kern/kern_clock.c:1.128 src/sys/kern/kern_clock.c:1.129 --- src/sys/kern/kern_clock.c:1.128 Wed Jul 27 10:35:33 2011 +++ src/sys/kern/kern_clock.c Sat Oct 29 11:58:38 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: kern_clock.c,v 1.128 2011/07/27 14:35:33 uebayasi Exp $ */ +/* $NetBSD: kern_clock.c,v 1.129 2011/10/29 15:58:38 christos Exp $ */ /*- * Copyright (c) 2000, 2004, 2006, 2007, 2008 The NetBSD Foundation, Inc. @@ -69,7 +69,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: kern_clock.c,v 1.128 2011/07/27 14:35:33 uebayasi Exp $"); +__KERNEL_RCSID(0, "$NetBSD: kern_clock.c,v 1.129 2011/10/29 15:58:38 christos Exp $"); #include "opt_ntp.h" #include "opt_perfctrs.h" @@ -429,7 +429,32 @@ statclock(struct clockframe *frame) } spc->spc_pscnt = psdiv; + /* + * If the CPU is currently scheduled to a non-idle process, then charge + * that process with the appropriate VM resource utilization for a tick. + * + * Assume that the current process has been running the entire last + * tick, and account for VM use regardless of whether in user mode or + * system mode (XXX or interrupt mode?). + * + * rusage VM stats are expressed in kilobytes * ticks-of-execution. + */ + /* based on code from 4.3BSD kern_clock.c and from FreeBSD */ + if (p != NULL) { + struct vmspace *vm = p->p_vmspace; + struct rusage *ru = &p->p_stats->p_ru; + long rss; + +#define pg2kb(n) (((n) * PAGE_SIZE) / 1024) + ru->ru_idrss += pg2kb(vm->vm_dsize); /* unshared data */ + ru->ru_isrss += pg2kb(vm->vm_ssize); /* unshared stack */ + ru->ru_ixrss += pg2kb(vm->vm_tsize); /* "shared" text? */ + + rss = pg2kb(vm_resident_count(vm)); + if (rss > ru->ru_maxrss) + ru->ru_maxrss = rss; + atomic_inc_uint(&l->l_cpticks); mutex_spin_exit(&p->p_stmutex); }