summaryrefslogtreecommitdiffstats
path: root/sys/kern/kern_synch.c
diff options
context:
space:
mode:
authorphk <phk@FreeBSD.org>1998-05-28 09:30:28 +0000
committerphk <phk@FreeBSD.org>1998-05-28 09:30:28 +0000
commitd3d65c6b2e376ac074f3ca386b6f5b70ea37636f (patch)
tree6beef0d8c93f6063bf0b9870b87a8c1ef8267cd4 /sys/kern/kern_synch.c
parent3654f28d394a609d42e7000c62963c45e3bba3db (diff)
downloadFreeBSD-src-d3d65c6b2e376ac074f3ca386b6f5b70ea37636f.zip
FreeBSD-src-d3d65c6b2e376ac074f3ca386b6f5b70ea37636f.tar.gz
Some cleanups related to timecounters and weird ifdefs in <sys/time.h>.
Clean up (or if antipodic: down) some of the msgbuf stuff. Use an inline function rather than a macro for timecounter delta. Maintain process "on-cpu" time as 64 bits of microseconds to avoid needless second rollover overhead. Avoid calling microuptime the second time in mi_switch() if we do not pass through _idle in cpu_switch() This should reduce our context-switch overhead a bit, in particular on pre-P5 and SMP systems. WARNING: Programs which muck about with struct proc in userland will have to be fixed. Reviewed, but found imperfect by: bde
Diffstat (limited to 'sys/kern/kern_synch.c')
-rw-r--r--sys/kern/kern_synch.c44
1 files changed, 16 insertions, 28 deletions
diff --git a/sys/kern/kern_synch.c b/sys/kern/kern_synch.c
index 342cb3a..8e429e2 100644
--- a/sys/kern/kern_synch.c
+++ b/sys/kern/kern_synch.c
@@ -36,7 +36,7 @@
* SUCH DAMAGE.
*
* @(#)kern_synch.c 8.9 (Berkeley) 5/19/95
- * $Id: kern_synch.c,v 1.55 1998/05/17 11:52:45 phk Exp $
+ * $Id: kern_synch.c,v 1.56 1998/05/17 22:12:14 tegge Exp $
*/
#include "opt_ktrace.h"
@@ -599,9 +599,7 @@ mi_switch()
{
register struct proc *p = curproc; /* XXX */
register struct rlimit *rlim;
- register long s, u;
int x;
- struct timeval tv;
/*
* XXX this spl is almost unnecessary. It is partly to allow for
@@ -630,36 +628,23 @@ mi_switch()
* Compute the amount of time during which the current
* process was running, and add that to its total so far.
*/
- microuptime(&tv);
- u = p->p_rtime.tv_usec + (tv.tv_usec - p->p_runtime.tv_usec);
- s = p->p_rtime.tv_sec + (tv.tv_sec - p->p_runtime.tv_sec);
- if (u < 0) {
- u += 1000000;
- s--;
- } else if (u >= 1000000) {
- u -= 1000000;
- s++;
- }
-#ifdef SMP
- if (s < 0)
- s = u = 0;
-#endif
- p->p_rtime.tv_usec = u;
- p->p_rtime.tv_sec = s;
+ microuptime(&switchtime);
+ p->p_runtime += (switchtime.tv_usec - p->p_switchtime.tv_usec) +
+ (switchtime.tv_sec - p->p_switchtime.tv_sec) * (int64_t)1000000;
/*
* Check if the process exceeds its cpu resource allocation.
* If over max, kill it.
*/
- if (p->p_stat != SZOMB) {
+ if (p->p_stat != SZOMB && p->p_runtime > p->p_limit->p_cpulimit) {
rlim = &p->p_rlimit[RLIMIT_CPU];
- if (s >= rlim->rlim_cur) {
- if (s >= rlim->rlim_max)
- killproc(p, "exceeded maximum CPU limit");
- else {
- psignal(p, SIGXCPU);
- if (rlim->rlim_cur < rlim->rlim_max)
- rlim->rlim_cur += 5;
+ if (p->p_runtime / (rlim_t)1000000 >= rlim->rlim_max) {
+ killproc(p, "exceeded maximum CPU limit");
+ } else {
+ psignal(p, SIGXCPU);
+ if (rlim->rlim_cur < rlim->rlim_max) {
+ /* XXX: we should make a private copy */
+ rlim->rlim_cur += 5;
}
}
}
@@ -669,7 +654,10 @@ mi_switch()
*/
cnt.v_swtch++;
cpu_switch(p);
- microuptime(&p->p_runtime);
+ if (switchtime.tv_sec)
+ p->p_switchtime = switchtime;
+ else
+ microuptime(&p->p_switchtime);
splx(x);
}
OpenPOWER on IntegriCloud