From: cheloha Date: Sat, 4 Feb 2023 19:33:03 +0000 (+0000) Subject: kernel: stathz is always non-zero after cpu_initclocks() X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=9bcfcad5a8f89fd60010f3485ee44bf251abde23;p=openbsd kernel: stathz is always non-zero after cpu_initclocks() Now that the clockintr switch is complete, cpu_initclocks() always initializes stathz to a non-zero value. We don't call statclock() from hardclock(9) anymore and, more broadly, we don't need to test whether stathz is non-zero before using it. With input from kettenis@. Link: https://marc.info/?l=openbsd-tech&m=167434223309668&w=2 ok kettenis@ miod@ --- diff --git a/sys/kern/kern_clock.c b/sys/kern/kern_clock.c index c3942987b4f..fc6d90486c3 100644 --- a/sys/kern/kern_clock.c +++ b/sys/kern/kern_clock.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_clock.c,v 1.105 2022/08/14 01:58:27 jsg Exp $ */ +/* $OpenBSD: kern_clock.c,v 1.106 2023/02/04 19:33:03 cheloha Exp $ */ /* $NetBSD: kern_clock.c,v 1.34 1996/06/09 04:51:03 briggs Exp $ */ /*- @@ -98,8 +98,6 @@ volatile unsigned long jiffies; /* XXX Linux API for drm(4) */ void initclocks(void) { - int i; - ticks = INT_MAX - (15 * 60 * hz); jiffies = ULONG_MAX - (10 * 60 * hz); @@ -111,12 +109,9 @@ initclocks(void) cpu_initclocks(); /* - * Compute profhz/stathz, and fix profhz if needed. + * Compute profhz/stathz. */ - i = stathz ? stathz : hz; - if (profhz == 0) - profhz = i; - psratio = profhz / i; + psratio = profhz / stathz; inittimecounter(); } @@ -158,12 +153,6 @@ hardclock(struct clockframe *frame) } } - /* - * If no separate statistics clock is available, run it from here. - */ - if (stathz == 0) - statclock(frame); - if (--ci->ci_schedstate.spc_rrticks <= 0) roundrobin(ci); @@ -268,7 +257,7 @@ startprofclock(struct process *pr) if ((pr->ps_flags & PS_PROFIL) == 0) { atomic_setbits_int(&pr->ps_flags, PS_PROFIL); - if (++profprocs == 1 && stathz != 0) { + if (++profprocs == 1) { s = splstatclock(); psdiv = pscnt = psratio; setstatclockrate(profhz); @@ -287,7 +276,7 @@ stopprofclock(struct process *pr) if (pr->ps_flags & PS_PROFIL) { atomic_clearbits_int(&pr->ps_flags, PS_PROFIL); - if (--profprocs == 0 && stathz != 0) { + if (--profprocs == 0) { s = splstatclock(); psdiv = pscnt = 1; setstatclockrate(stathz); @@ -415,6 +404,6 @@ sysctl_clockrate(char *where, size_t *sizep, void *newp) clkinfo.tick = tick; clkinfo.hz = hz; clkinfo.profhz = profhz; - clkinfo.stathz = stathz ? stathz : hz; + clkinfo.stathz = stathz; return (sysctl_rdstruct(where, sizep, newp, &clkinfo, sizeof(clkinfo))); } diff --git a/sys/kern/kern_resource.c b/sys/kern/kern_resource.c index 456dc080196..98bcd6ba436 100644 --- a/sys/kern/kern_resource.c +++ b/sys/kern/kern_resource.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_resource.c,v 1.76 2022/11/17 18:53:13 deraadt Exp $ */ +/* $OpenBSD: kern_resource.c,v 1.77 2023/02/04 19:33:03 cheloha Exp $ */ /* $NetBSD: kern_resource.c,v 1.38 1996/10/23 07:19:38 matthias Exp $ */ /*- @@ -410,7 +410,6 @@ calctsru(struct tusage *tup, struct timespec *up, struct timespec *sp, struct timespec *ip) { u_quad_t st, ut, it; - int freq; st = tup->tu_sticks; ut = tup->tu_uticks; @@ -424,16 +423,14 @@ calctsru(struct tusage *tup, struct timespec *up, struct timespec *sp, return; } - freq = stathz ? stathz : hz; - - st = st * 1000000000 / freq; + st = st * 1000000000 / stathz; sp->tv_sec = st / 1000000000; sp->tv_nsec = st % 1000000000; - ut = ut * 1000000000 / freq; + ut = ut * 1000000000 / stathz; up->tv_sec = ut / 1000000000; up->tv_nsec = ut % 1000000000; if (ip != NULL) { - it = it * 1000000000 / freq; + it = it * 1000000000 / stathz; ip->tv_sec = it / 1000000000; ip->tv_nsec = it % 1000000000; } diff --git a/sys/kern/kern_time.c b/sys/kern/kern_time.c index 1dd0f3aef7f..9072595194f 100644 --- a/sys/kern/kern_time.c +++ b/sys/kern/kern_time.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_time.c,v 1.161 2023/01/02 23:09:48 guenther Exp $ */ +/* $OpenBSD: kern_time.c,v 1.162 2023/02/04 19:33:03 cheloha Exp $ */ /* $NetBSD: kern_time.c,v 1.20 1996/02/18 11:57:06 fvdl Exp $ */ /* @@ -218,10 +218,9 @@ sys_clock_getres(struct proc *p, void *v, register_t *retval) struct timespec ts; struct proc *q; u_int64_t scale; - int error = 0, realstathz; + int error = 0; memset(&ts, 0, sizeof(ts)); - realstathz = (stathz == 0) ? hz : stathz; clock_id = SCARG(uap, clock_id); switch (clock_id) { @@ -238,7 +237,7 @@ sys_clock_getres(struct proc *p, void *v, register_t *retval) break; case CLOCK_PROCESS_CPUTIME_ID: case CLOCK_THREAD_CPUTIME_ID: - ts.tv_nsec = 1000000000 / realstathz; + ts.tv_nsec = 1000000000 / stathz; break; default: /* check for clock from pthread_getcpuclockid() */ @@ -248,7 +247,7 @@ sys_clock_getres(struct proc *p, void *v, register_t *retval) if (q == NULL) error = ESRCH; else - ts.tv_nsec = 1000000000 / realstathz; + ts.tv_nsec = 1000000000 / stathz; KERNEL_UNLOCK(); } else error = EINVAL; diff --git a/sys/kern/sched_bsd.c b/sys/kern/sched_bsd.c index a02a529b866..94d0950b5a8 100644 --- a/sys/kern/sched_bsd.c +++ b/sys/kern/sched_bsd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sched_bsd.c,v 1.73 2022/12/05 23:18:37 deraadt Exp $ */ +/* $OpenBSD: sched_bsd.c,v 1.74 2023/02/04 19:33:03 cheloha Exp $ */ /* $NetBSD: kern_synch.c,v 1.37 1996/04/22 01:38:37 christos Exp $ */ /*- @@ -189,16 +189,6 @@ schedcpu(void *arg) struct proc *p; int s; unsigned int newcpu; - int phz; - - /* - * If we have a statistics clock, use that to calculate CPU - * time, otherwise revert to using the profiling clock (which, - * in turn, defaults to hz if there is no separate profiling - * clock available) - */ - phz = stathz ? stathz : profhz; - KASSERT(phz); LIST_FOREACH(p, &allproc, p_list) { /* @@ -225,13 +215,13 @@ schedcpu(void *arg) * p_pctcpu is only for diagnostic tools such as ps. */ #if (FSHIFT >= CCPU_SHIFT) - p->p_pctcpu += (phz == 100)? + p->p_pctcpu += (stathz == 100)? ((fixpt_t) p->p_cpticks) << (FSHIFT - CCPU_SHIFT): 100 * (((fixpt_t) p->p_cpticks) - << (FSHIFT - CCPU_SHIFT)) / phz; + << (FSHIFT - CCPU_SHIFT)) / stathz; #else p->p_pctcpu += ((FSCALE - ccpu) * - (p->p_cpticks * FSCALE / phz)) >> FSHIFT; + (p->p_cpticks * FSCALE / stathz)) >> FSHIFT; #endif p->p_cpticks = 0; newcpu = (u_int) decay_cpu(loadfac, p->p_estcpu);