From 6ad39cae663c271410864cfa6784f4ae3091d910 Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Fri, 11 Jul 2003 23:26:20 +0000 Subject: [PATCH] Cleanup hardclock() and statclock(), making them work properly even though we do not replicate the clock interrupts across all cpus. --- sys/i386/i386/trap.c | 6 ++-- sys/kern/kern_clock.c | 52 +++++++++++++++++++++-------------- sys/platform/pc32/i386/trap.c | 6 ++-- sys/sys/globaldata.h | 4 ++- sys/vm/vm_glue.c | 3 +- 5 files changed, 42 insertions(+), 29 deletions(-) diff --git a/sys/i386/i386/trap.c b/sys/i386/i386/trap.c index 11c2866d98..c3b6680fe5 100644 --- a/sys/i386/i386/trap.c +++ b/sys/i386/i386/trap.c @@ -36,7 +36,7 @@ * * from: @(#)trap.c 7.4 (Berkeley) 5/13/91 * $FreeBSD: src/sys/i386/i386/trap.c,v 1.147.2.11 2003/02/27 19:09:59 luoqi Exp $ - * $DragonFly: src/sys/i386/i386/Attic/trap.c,v 1.22 2003/07/11 17:42:08 dillon Exp $ + * $DragonFly: src/sys/i386/i386/Attic/trap.c,v 1.23 2003/07/11 23:26:15 dillon Exp $ */ /* @@ -262,11 +262,11 @@ userret(struct proc *p, struct trapframe *frame, u_quad_t oticks) } /* - * Charge system time if profiling. + * Charge system time if profiling. Note: times are in microseconds. */ if (p->p_flag & P_PROFIL) { addupc_task(p, frame->tf_eip, - (u_int)(curthread->td_sticks - oticks) * psratio); + (u_int)(curthread->td_sticks - oticks)); } /* diff --git a/sys/kern/kern_clock.c b/sys/kern/kern_clock.c index faa3d5531d..db2065d016 100644 --- a/sys/kern/kern_clock.c +++ b/sys/kern/kern_clock.c @@ -38,7 +38,7 @@ * * @(#)kern_clock.c 8.5 (Berkeley) 1/21/94 * $FreeBSD: src/sys/kern/kern_clock.c,v 1.105.2.10 2002/10/17 13:19:40 maxim Exp $ - * $DragonFly: src/sys/kern/kern_clock.c,v 1.7 2003/07/10 04:47:54 dillon Exp $ + * $DragonFly: src/sys/kern/kern_clock.c,v 1.8 2003/07/11 23:26:16 dillon Exp $ */ #include "opt_ntp.h" @@ -90,7 +90,11 @@ static void tco_forward __P((int force)); static void tco_setscales __P((struct timecounter *tc)); static __inline unsigned tco_delta __P((struct timecounter *tc)); -/* Some of these don't belong here, but it's easiest to concentrate them. */ +/* + * Some of these don't belong here, but it's easiest to concentrate them. + * Note that cp_time[] counts in microseconds, but most userland programs + * just compare relative times against the total by delta. + */ long cp_time[CPUSTATES]; SYSCTL_OPAQUE(_kern, OID_AUTO, cp_time, CTLFLAG_RD, &cp_time, sizeof(cp_time), @@ -173,8 +177,9 @@ int stathz; int profhz; static int profprocs; int ticks; -static int psdiv, pscnt; /* prof => stat divider */ -int psratio; /* ratio: prof / stat */ +static int psticks; /* profiler ticks */ +static int psdiv; /* prof / stat divider */ +int psratio; /* ratio: prof * 100 / stat */ /* * Initialize clock frequencies and start both clocks running. @@ -190,7 +195,7 @@ initclocks(dummy) * Set divisors to 1 (normal case) and let the machine-specific * code do its bit. */ - psdiv = pscnt = 1; + psdiv = 1; cpu_initclocks(); #ifdef DEVICE_POLLING @@ -234,7 +239,7 @@ hardclock(frame) psignal(p, SIGPROF); } -#if defined(SMP) && defined(BETTER_CLOCK) +#if 0 /* SMP and BETTER_CLOCK */ forward_hardclock(pscnt); #endif @@ -337,7 +342,7 @@ startprofclock(p) p->p_flag |= P_PROFIL; if (++profprocs == 1 && stathz != 0) { s = splstatclock(); - psdiv = pscnt = psratio; + psdiv = psratio; setstatclockrate(profhz); splx(s); } @@ -357,7 +362,7 @@ stopprofclock(p) p->p_flag &= ~P_PROFIL; if (--profprocs == 0 && stathz != 0) { s = splstatclock(); - psdiv = pscnt = 1; + psdiv = 1; setstatclockrate(stathz); splx(s); } @@ -419,21 +424,19 @@ statclock(frame) */ if (p && (p->p_flag & P_PROFIL)) addupc_intr(p, CLKF_PC(frame), 1); -#if defined(SMP) && defined(BETTER_CLOCK) +#if 0 /* SMP and BETTER_CLOCK */ if (stathz != 0) forward_statclock(pscnt); #endif td->td_uticks += bump; - if (--pscnt > 0) - return; /* * Charge the time as appropriate */ if (p && p->p_nice > NZERO) - ++cp_time[CP_NICE]; + cp_time[CP_NICE] += bump; else - ++cp_time[CP_USER]; + cp_time[CP_USER] += bump; } else { #ifdef GPROF /* @@ -448,7 +451,7 @@ statclock(frame) } } #endif -#if defined(SMP) && defined(BETTER_CLOCK) +#if 0 /* SMP and BETTER_CLOCK */ if (stathz != 0) forward_statclock(pscnt); #endif @@ -469,19 +472,26 @@ statclock(frame) else td->td_sticks += bump; - if (--pscnt > 0) - return; - if (CLKF_INTR(frame)) { - cp_time[CP_INTR]++; + cp_time[CP_INTR] += bump; } else { if (td == &mycpu->gd_idlethread) - ++cp_time[CP_IDLE]; + cp_time[CP_IDLE] += bump; else - ++cp_time[CP_SYS]; + cp_time[CP_SYS] += bump; } } - pscnt = psdiv; + + /* + * bump psticks and check against gd_psticks. When we hit the + * 1*hz mark (psdiv ticks) we do the more expensive stuff. + */ + ++psticks; + if (psticks < mycpu->gd_psticks || psdiv == mycpu->gd_psdiv) + return; + + mycpu->gd_psdiv = psdiv; + mycpu->gd_psticks = psticks + psdiv; if (p != NULL) { schedclock(p); diff --git a/sys/platform/pc32/i386/trap.c b/sys/platform/pc32/i386/trap.c index 51fea80877..9ada4e7487 100644 --- a/sys/platform/pc32/i386/trap.c +++ b/sys/platform/pc32/i386/trap.c @@ -36,7 +36,7 @@ * * from: @(#)trap.c 7.4 (Berkeley) 5/13/91 * $FreeBSD: src/sys/i386/i386/trap.c,v 1.147.2.11 2003/02/27 19:09:59 luoqi Exp $ - * $DragonFly: src/sys/platform/pc32/i386/trap.c,v 1.22 2003/07/11 17:42:08 dillon Exp $ + * $DragonFly: src/sys/platform/pc32/i386/trap.c,v 1.23 2003/07/11 23:26:15 dillon Exp $ */ /* @@ -262,11 +262,11 @@ userret(struct proc *p, struct trapframe *frame, u_quad_t oticks) } /* - * Charge system time if profiling. + * Charge system time if profiling. Note: times are in microseconds. */ if (p->p_flag & P_PROFIL) { addupc_task(p, frame->tf_eip, - (u_int)(curthread->td_sticks - oticks) * psratio); + (u_int)(curthread->td_sticks - oticks)); } /* diff --git a/sys/sys/globaldata.h b/sys/sys/globaldata.h index 26c4c79bab..050e53d1e7 100644 --- a/sys/sys/globaldata.h +++ b/sys/sys/globaldata.h @@ -24,7 +24,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/i386/include/globaldata.h,v 1.11.2.1 2000/05/16 06:58:10 dillon Exp $ - * $DragonFly: src/sys/sys/globaldata.h,v 1.9 2003/07/10 04:47:55 dillon Exp $ + * $DragonFly: src/sys/sys/globaldata.h,v 1.10 2003/07/11 23:26:18 dillon Exp $ */ #ifndef _SYS_GLOBALDATA_H_ @@ -78,6 +78,8 @@ struct globaldata { struct timeval gd_stattv; int gd_intr_nesting_level; /* (for fast interrupts) */ int gd_astpending; /* sorta MD but easier here */ + int gd_psticks; /* profile kern/kern_clock.c */ + int gd_psdiv; /* profile kern/kern_clock.c */ struct vmmeter gd_cnt; struct lwkt_ipiq *gd_ipiq; struct thread gd_schedthread; diff --git a/sys/vm/vm_glue.c b/sys/vm/vm_glue.c index 29037c20ae..a730668964 100644 --- a/sys/vm/vm_glue.c +++ b/sys/vm/vm_glue.c @@ -60,7 +60,7 @@ * rights to redistribute these changes. * * $FreeBSD: src/sys/vm/vm_glue.c,v 1.94.2.4 2003/01/13 22:51:17 dillon Exp $ - * $DragonFly: src/sys/vm/vm_glue.c,v 1.11 2003/07/10 04:47:55 dillon Exp $ + * $DragonFly: src/sys/vm/vm_glue.c,v 1.12 2003/07/11 23:26:20 dillon Exp $ */ #include "opt_vm.h" @@ -243,6 +243,7 @@ vm_fork(p1, p2, flags) td2 = lwkt_alloc_thread(NULL); pmap_init_proc(p2, td2); lwkt_setpri(td2, TDPRI_KERN_USER); + lwkt_set_comm(td2, "%s", p1->p_comm); up = p2->p_addr; -- 2.41.0