diff options
Diffstat (limited to 'sys/kern')
-rw-r--r-- | sys/kern/init_main.c | 12 | ||||
-rw-r--r-- | sys/kern/kern_clock.c | 27 | ||||
-rw-r--r-- | sys/kern/kern_resource.c | 25 | ||||
-rw-r--r-- | sys/kern/kern_synch.c | 44 | ||||
-rw-r--r-- | sys/kern/kern_tc.c | 27 | ||||
-rw-r--r-- | sys/kern/subr_log.c | 5 | ||||
-rw-r--r-- | sys/kern/subr_prf.c | 49 |
7 files changed, 115 insertions, 74 deletions
diff --git a/sys/kern/init_main.c b/sys/kern/init_main.c index ba263aa..ea599a7 100644 --- a/sys/kern/init_main.c +++ b/sys/kern/init_main.c @@ -39,7 +39,7 @@ * SUCH DAMAGE. * * @(#)init_main.c 8.9 (Berkeley) 1/21/94 - * $Id: init_main.c,v 1.91 1998/04/19 23:31:54 julian Exp $ + * $Id: init_main.c,v 1.92 1998/05/17 11:52:35 phk Exp $ */ #include "opt_devfs.h" @@ -377,8 +377,10 @@ proc0_init(dummy) limit0.pl_rlimit[RLIMIT_RSS].rlim_max = i; limit0.pl_rlimit[RLIMIT_MEMLOCK].rlim_max = i; limit0.pl_rlimit[RLIMIT_MEMLOCK].rlim_cur = i / 3; + limit0.p_cpulimit = RLIM_INFINITY; limit0.p_refcnt = 1; + /* Allocate a prototype map so we have something to fork. */ pmap_pinit0(&vmspace0.vm_pmap); p->p_vmspace = &vmspace0; @@ -426,13 +428,13 @@ proc0_post(dummy) /* * Now can look at time, having had a chance to verify the time - * from the file system. Reset p->p_rtime as it may have been + * from the file system. Reset p->p_runtime as it may have been * munched in mi_switch() after the time got set. Set - * p->p_runtime to be consistent with this unmunching. + * p->p_switchtime to be consistent with this unmunching. */ microtime(&proc0.p_stats->p_start); - timevalclear(&proc0.p_rtime); - microuptime(&proc0.p_runtime); + proc0.p_runtime = 0; + microuptime(&proc0.p_switchtime); /* * Give the ``random'' number generator a thump. diff --git a/sys/kern/kern_clock.c b/sys/kern/kern_clock.c index 1cb2233..5334bf0 100644 --- a/sys/kern/kern_clock.c +++ b/sys/kern/kern_clock.c @@ -39,7 +39,7 @@ static volatile int print_tci = 1; * SUCH DAMAGE. * * @(#)kern_clock.c 8.5 (Berkeley) 1/21/94 - * $Id: kern_clock.c,v 1.68 1998/05/17 11:52:39 phk Exp $ + * $Id: kern_clock.c,v 1.69 1998/05/19 18:54:38 phk Exp $ */ #include <sys/param.h> @@ -73,6 +73,7 @@ SYSINIT(clocks, SI_SUB_CLOCKS, SI_ORDER_FIRST, initclocks, NULL) static void tco_forward __P((void)); static void tco_setscales __P((struct timecounter *tc)); +static __inline unsigned tco_getdelta __P((struct timecounter *tc)); /* Some of these don't belong here, but it's easiest to concentrate them. */ #if defined(SMP) && defined(BETTER_CLOCK) @@ -493,8 +494,12 @@ sysctl_kern_clockrate SYSCTL_HANDLER_ARGS SYSCTL_PROC(_kern, KERN_CLOCKRATE, clockrate, CTLTYPE_STRUCT|CTLFLAG_RD, 0, 0, sysctl_kern_clockrate, "S,clockinfo",""); -#define TC_DELTA(tc) \ - (((tc)->get_timecount() - (tc)->offset_count) & (tc)->counter_mask) +static __inline unsigned +tco_getdelta(struct timecounter *tc) +{ + + return ((tc->get_timecount() - tc->offset_count) & tc->counter_mask); +} /* * We have four functions for looking at the clock, two for microseconds @@ -530,7 +535,7 @@ microtime(struct timeval *tv) tc = (struct timecounter *)timecounter; tv->tv_sec = tc->offset_sec; tv->tv_usec = tc->offset_micro; - tv->tv_usec += ((u_int64_t)TC_DELTA(tc) * tc->scale_micro) >> 32; + tv->tv_usec += ((u_int64_t)tco_getdelta(tc) * tc->scale_micro) >> 32; tv->tv_usec += boottime.tv_usec; tv->tv_sec += boottime.tv_sec; while (tv->tv_usec >= 1000000) { @@ -548,7 +553,7 @@ nanotime(struct timespec *tv) tc = (struct timecounter *)timecounter; tv->tv_sec = tc->offset_sec; - count = TC_DELTA(tc); + count = tco_getdelta(tc); delta = tc->offset_nano; delta += ((u_int64_t)count * tc->scale_nano_f); delta >>= 32; @@ -590,7 +595,7 @@ microuptime(struct timeval *tv) tc = (struct timecounter *)timecounter; tv->tv_sec = tc->offset_sec; tv->tv_usec = tc->offset_micro; - tv->tv_usec += ((u_int64_t)TC_DELTA(tc) * tc->scale_micro) >> 32; + tv->tv_usec += ((u_int64_t)tco_getdelta(tc) * tc->scale_micro) >> 32; if (tv->tv_usec >= 1000000) { tv->tv_usec -= 1000000; tv->tv_sec++; @@ -600,13 +605,13 @@ microuptime(struct timeval *tv) void nanouptime(struct timespec *tv) { - u_int count; + unsigned count; u_int64_t delta; struct timecounter *tc; tc = (struct timecounter *)timecounter; tv->tv_sec = tc->offset_sec; - count = TC_DELTA(tc); + count = tco_getdelta(tc); delta = tc->offset_nano; delta += ((u_int64_t)count * tc->scale_nano_f); delta >>= 32; @@ -725,7 +730,7 @@ sync_other_counter(void) tco = tc->other; *tc = *timecounter; tc->other = tco; - delta = TC_DELTA(tc); + delta = tco_getdelta(tc); tc->offset_count += delta; tc->offset_count &= tc->counter_mask; tc->offset_nano += (u_int64_t)delta * tc->scale_nano_f; @@ -799,10 +804,10 @@ SYSCTL_PROC(_kern_timecounter, OID_AUTO, adjustment, CTLTYPE_INT | CTLFLAG_RW, * timeservices. */ -static u_int +static unsigned dummy_get_timecount(void) { - static u_int now; + static unsigned now; return (++now); } diff --git a/sys/kern/kern_resource.c b/sys/kern/kern_resource.c index 82ff088..a19f489 100644 --- a/sys/kern/kern_resource.c +++ b/sys/kern/kern_resource.c @@ -36,7 +36,7 @@ * SUCH DAMAGE. * * @(#)kern_resource.c 8.5 (Berkeley) 1/21/94 - * $Id: kern_resource.c,v 1.35 1998/04/05 02:59:10 peter Exp $ + * $Id: kern_resource.c,v 1.36 1998/05/17 11:52:43 phk Exp $ */ #include "opt_compat.h" @@ -399,6 +399,13 @@ dosetrlimit(p, which, limp) switch (which) { + case RLIMIT_CPU: + if (limp->rlim_cur > RLIM_INFINITY / (rlim_t)1000000) + p->p_limit->p_cpulimit = RLIM_INFINITY; + else + p->p_limit->p_cpulimit = + (rlim_t)1000000 * limp->rlim_cur; + break; case RLIMIT_DATA: if (limp->rlim_cur > MAXDSIZ) limp->rlim_cur = MAXDSIZ; @@ -485,9 +492,8 @@ calcru(p, up, sp, ip) struct timeval *sp; struct timeval *ip; { - quad_t totusec; - u_quad_t u, st, ut, it, tot; - long sec, usec; + int64_t totusec; + u_int64_t u, st, ut, it, tot; int s; struct timeval tv; @@ -504,8 +510,7 @@ calcru(p, up, sp, ip) tot = 1; } - sec = p->p_rtime.tv_sec; - usec = p->p_rtime.tv_usec; + totusec = p->p_runtime; #ifdef SMP if (p->p_oncpu != (char)0xff) { #else @@ -517,10 +522,9 @@ calcru(p, up, sp, ip) * quantum, which is much greater than the sampling error. */ microuptime(&tv); - sec += tv.tv_sec - p->p_runtime.tv_sec; - usec += tv.tv_usec - p->p_runtime.tv_usec; + totusec += (tv.tv_usec - p->p_switchtime.tv_usec) + + (tv.tv_sec - p->p_switchtime.tv_sec) * (int64_t)1000000; } - totusec = (quad_t)sec * 1000000 + usec; if (totusec < 0) { /* XXX no %qd in kernel. Truncate. */ printf("calcru: negative time of %ld usec for pid %d (%s)\n", @@ -602,8 +606,7 @@ limcopy(lim) MALLOC(copy, struct plimit *, sizeof(struct plimit), M_SUBPROC, M_WAITOK); - bcopy(lim->pl_rlimit, copy->pl_rlimit, - sizeof(struct rlimit) * RLIM_NLIMITS); + bcopy(lim->pl_rlimit, copy->pl_rlimit, sizeof(struct plimit)); copy->p_lflags = 0; copy->p_refcnt = 1; return (copy); 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); } diff --git a/sys/kern/kern_tc.c b/sys/kern/kern_tc.c index 1cb2233..5334bf0 100644 --- a/sys/kern/kern_tc.c +++ b/sys/kern/kern_tc.c @@ -39,7 +39,7 @@ static volatile int print_tci = 1; * SUCH DAMAGE. * * @(#)kern_clock.c 8.5 (Berkeley) 1/21/94 - * $Id: kern_clock.c,v 1.68 1998/05/17 11:52:39 phk Exp $ + * $Id: kern_clock.c,v 1.69 1998/05/19 18:54:38 phk Exp $ */ #include <sys/param.h> @@ -73,6 +73,7 @@ SYSINIT(clocks, SI_SUB_CLOCKS, SI_ORDER_FIRST, initclocks, NULL) static void tco_forward __P((void)); static void tco_setscales __P((struct timecounter *tc)); +static __inline unsigned tco_getdelta __P((struct timecounter *tc)); /* Some of these don't belong here, but it's easiest to concentrate them. */ #if defined(SMP) && defined(BETTER_CLOCK) @@ -493,8 +494,12 @@ sysctl_kern_clockrate SYSCTL_HANDLER_ARGS SYSCTL_PROC(_kern, KERN_CLOCKRATE, clockrate, CTLTYPE_STRUCT|CTLFLAG_RD, 0, 0, sysctl_kern_clockrate, "S,clockinfo",""); -#define TC_DELTA(tc) \ - (((tc)->get_timecount() - (tc)->offset_count) & (tc)->counter_mask) +static __inline unsigned +tco_getdelta(struct timecounter *tc) +{ + + return ((tc->get_timecount() - tc->offset_count) & tc->counter_mask); +} /* * We have four functions for looking at the clock, two for microseconds @@ -530,7 +535,7 @@ microtime(struct timeval *tv) tc = (struct timecounter *)timecounter; tv->tv_sec = tc->offset_sec; tv->tv_usec = tc->offset_micro; - tv->tv_usec += ((u_int64_t)TC_DELTA(tc) * tc->scale_micro) >> 32; + tv->tv_usec += ((u_int64_t)tco_getdelta(tc) * tc->scale_micro) >> 32; tv->tv_usec += boottime.tv_usec; tv->tv_sec += boottime.tv_sec; while (tv->tv_usec >= 1000000) { @@ -548,7 +553,7 @@ nanotime(struct timespec *tv) tc = (struct timecounter *)timecounter; tv->tv_sec = tc->offset_sec; - count = TC_DELTA(tc); + count = tco_getdelta(tc); delta = tc->offset_nano; delta += ((u_int64_t)count * tc->scale_nano_f); delta >>= 32; @@ -590,7 +595,7 @@ microuptime(struct timeval *tv) tc = (struct timecounter *)timecounter; tv->tv_sec = tc->offset_sec; tv->tv_usec = tc->offset_micro; - tv->tv_usec += ((u_int64_t)TC_DELTA(tc) * tc->scale_micro) >> 32; + tv->tv_usec += ((u_int64_t)tco_getdelta(tc) * tc->scale_micro) >> 32; if (tv->tv_usec >= 1000000) { tv->tv_usec -= 1000000; tv->tv_sec++; @@ -600,13 +605,13 @@ microuptime(struct timeval *tv) void nanouptime(struct timespec *tv) { - u_int count; + unsigned count; u_int64_t delta; struct timecounter *tc; tc = (struct timecounter *)timecounter; tv->tv_sec = tc->offset_sec; - count = TC_DELTA(tc); + count = tco_getdelta(tc); delta = tc->offset_nano; delta += ((u_int64_t)count * tc->scale_nano_f); delta >>= 32; @@ -725,7 +730,7 @@ sync_other_counter(void) tco = tc->other; *tc = *timecounter; tc->other = tco; - delta = TC_DELTA(tc); + delta = tco_getdelta(tc); tc->offset_count += delta; tc->offset_count &= tc->counter_mask; tc->offset_nano += (u_int64_t)delta * tc->scale_nano_f; @@ -799,10 +804,10 @@ SYSCTL_PROC(_kern_timecounter, OID_AUTO, adjustment, CTLTYPE_INT | CTLFLAG_RW, * timeservices. */ -static u_int +static unsigned dummy_get_timecount(void) { - static u_int now; + static unsigned now; return (++now); } diff --git a/sys/kern/subr_log.c b/sys/kern/subr_log.c index 60b1c3e..d35f83b 100644 --- a/sys/kern/subr_log.c +++ b/sys/kern/subr_log.c @@ -31,7 +31,7 @@ * SUCH DAMAGE. * * @(#)subr_log.c 8.1 (Berkeley) 6/10/93 - * $Id: subr_log.c,v 1.27 1998/02/20 13:46:56 bde Exp $ + * $Id: subr_log.c,v 1.28 1998/05/19 08:58:51 phk Exp $ */ /* @@ -39,7 +39,6 @@ */ #include "opt_devfs.h" -#include "opt_msgbuf.h" #include <sys/param.h> #include <sys/systm.h> @@ -269,5 +268,3 @@ log_drvinit(unused) } SYSINIT(logdev,SI_SUB_DRIVERS,SI_ORDER_MIDDLE+CDEV_MAJOR,log_drvinit,NULL) - - diff --git a/sys/kern/subr_prf.c b/sys/kern/subr_prf.c index 9124f67..c30e45b 100644 --- a/sys/kern/subr_prf.c +++ b/sys/kern/subr_prf.c @@ -36,13 +36,12 @@ * SUCH DAMAGE. * * @(#)subr_prf.c 8.3 (Berkeley) 1/21/94 - * $Id: subr_prf.c,v 1.44 1997/12/28 05:03:33 bde Exp $ + * $Id: subr_prf.c,v 1.45 1998/05/19 08:58:51 phk Exp $ */ -#include "opt_msgbuf.h" - #include <sys/param.h> #include <sys/systm.h> +#include <sys/kernel.h> #include <sys/msgbuf.h> #include <sys/malloc.h> #include <sys/proc.h> @@ -71,6 +70,7 @@ static void putchar __P((int ch, void *arg)); static char *ksprintn __P((u_long num, int base, int *len)); static int consintr = 1; /* Ok to handle console interrupts? */ +static int msgbufmapped; /* Set when safe to use msgbuf */ /* * Warn that a system table is full. @@ -275,7 +275,7 @@ vprintf(const char *fmt, va_list ap) /* * Print a character on console or users terminal. If destination is - * the console then the last MSGBUFS characters are saved in msgbuf for + * the console then the last bunch of characters are saved in msgbuf for * inspection later. */ static void @@ -598,3 +598,44 @@ msglogchar(int c, void *dummyarg) } } } + +void +msgbufinit(void *ptr, size_t size) +{ + char *cp; + + cp = (char *)ptr; + msgbufp = (struct msgbuf *) (cp + size - sizeof(*msgbufp)); + if (msgbufp->msg_magic != MSG_MAGIC || msgbufp->msg_ptr != cp) { + bzero(cp, size); + msgbufp->msg_magic = MSG_MAGIC; + msgbufp->msg_size = (char *)msgbufp - cp; + msgbufp->msg_ptr = cp; + } + msgbufmapped = 1; +} + +#include "opt_ddb.h" +#ifdef DDB +#include <ddb/ddb.h> + +DB_SHOW_COMMAND(msgbuf, db_show_msgbuf) +{ + int i, j; + + if (!msgbufmapped) { + db_printf("msgbuf not mapped yet\n"); + return; + } + db_printf("msgbufp = %p\n", msgbufp); + db_printf("magic = %x, size = %d, r= %d, w = %d, ptr = %p\n", + msgbufp->msg_magic, msgbufp->msg_size, msgbufp->msg_bufr, + msgbufp->msg_bufx, msgbufp->msg_ptr); + for (i = 0; i < msgbufp->msg_size; i++) { + j = (i + msgbufp->msg_bufr) % msgbufp->msg_size; + db_printf("%c", msgbufp->msg_ptr[j]); + } + db_printf("\n"); +} + +#endif /* DDB */ |