From: claudio Date: Tue, 8 Oct 2024 11:57:59 +0000 (+0000) Subject: Move common code to update the proc runtime into tuagg_add_runtime(). X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=7b3f8d1d68d965ba90edeb8b95711a130dd8d612;p=openbsd Move common code to update the proc runtime into tuagg_add_runtime(). OK mpi@ kn@ --- diff --git a/sys/kern/kern_exit.c b/sys/kern/kern_exit.c index 47b3ea68468..874e197389b 100644 --- a/sys/kern/kern_exit.c +++ b/sys/kern/kern_exit.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_exit.c,v 1.235 2024/10/08 09:05:40 claudio Exp $ */ +/* $OpenBSD: kern_exit.c,v 1.236 2024/10/08 11:57:59 claudio Exp $ */ /* $NetBSD: kern_exit.c,v 1.39 1996/04/22 01:38:25 christos Exp $ */ /* @@ -118,7 +118,6 @@ exit1(struct proc *p, int xexit, int xsig, int flags) { struct process *pr, *qr, *nqr; struct rusage *rup; - struct timespec ts, pts; atomic_setbits_int(&p->p_flag, P_WEXIT); @@ -172,16 +171,7 @@ exit1(struct proc *p, int xexit, int xsig, int flags) } /* proc is off ps_threads list so update accounting of process now */ - nanouptime(&ts); - if (timespeccmp(&ts, &curcpu()->ci_schedstate.spc_runtime, <)) - timespecclear(&pts); - else - timespecsub(&ts, &curcpu()->ci_schedstate.spc_runtime, &pts); - tu_enter(&p->p_tu); - timespecadd(&p->p_tu.tu_runtime, &pts, &p->p_tu.tu_runtime); - tu_leave(&p->p_tu); - /* adjust spc_runtime to not double account the runtime from above */ - curcpu()->ci_schedstate.spc_runtime = ts; + tuagg_add_runtime(); tuagg_add_process(p->p_p, p); if ((p->p_flag & P_THREAD) == 0) { diff --git a/sys/kern/kern_resource.c b/sys/kern/kern_resource.c index 8796b4833d3..bd2c5468fba 100644 --- a/sys/kern/kern_resource.c +++ b/sys/kern/kern_resource.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_resource.c,v 1.90 2024/10/03 10:20:05 claudio Exp $ */ +/* $OpenBSD: kern_resource.c,v 1.91 2024/10/08 11:57:59 claudio Exp $ */ /* $NetBSD: kern_resource.c,v 1.38 1996/10/23 07:19:38 matthias Exp $ */ /*- @@ -443,6 +443,37 @@ tuagg_add_process(struct process *pr, struct proc *p) p->p_tu.tu_uticks = p->p_tu.tu_sticks = p->p_tu.tu_iticks = 0; } +void +tuagg_add_runtime(void) +{ + struct schedstate_percpu *spc = &curcpu()->ci_schedstate; + struct proc *p = curproc; + struct timespec ts; + + /* + * Compute the amount of time during which the current + * process was running, and add that to its total so far. + */ + nanouptime(&ts); + if (timespeccmp(&ts, &spc->spc_runtime, <)) { +#if 0 + printf("uptime is not monotonic! " + "ts=%lld.%09lu, runtime=%lld.%09lu\n", + (long long)tv.tv_sec, tv.tv_nsec, + (long long)spc->spc_runtime.tv_sec, + spc->spc_runtime.tv_nsec); +#endif + timespecclear(&ts); + } else { + timespecsub(&ts, &spc->spc_runtime, &ts); + } + /* update spc_runtime */ + spc->spc_runtime = ts; + tu_enter(&p->p_tu); + timespecadd(&p->p_tu.tu_runtime, &ts, &p->p_tu.tu_runtime); + tu_leave(&p->p_tu); +} + /* * Transform the running time and tick information in a struct tusage * into user, system, and interrupt time usage. diff --git a/sys/kern/kern_sched.c b/sys/kern/kern_sched.c index 9aca302233b..27784d35baf 100644 --- a/sys/kern/kern_sched.c +++ b/sys/kern/kern_sched.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_sched.c,v 1.101 2024/10/06 01:50:56 jsg Exp $ */ +/* $OpenBSD: kern_sched.c,v 1.102 2024/10/08 11:57:59 claudio Exp $ */ /* * Copyright (c) 2007, 2008 Artur Grabowski * @@ -213,21 +213,10 @@ void sched_exit(struct proc *p) { struct schedstate_percpu *spc = &curcpu()->ci_schedstate; - struct timespec ts; LIST_INSERT_HEAD(&spc->spc_deadproc, p, p_hash); - /* update the tu_runtime one last time */ - nanouptime(&ts); - if (timespeccmp(&ts, &spc->spc_runtime, <)) - timespecclear(&ts); - else - timespecsub(&ts, &spc->spc_runtime, &ts); - - /* add the time counts for this thread */ - tu_enter(&p->p_tu); - timespecadd(&p->p_tu.tu_runtime, &ts, &p->p_tu.tu_runtime); - tu_leave(&p->p_tu); + tuagg_add_runtime(); KERNEL_ASSERT_LOCKED(); sched_toidle(); diff --git a/sys/kern/sched_bsd.c b/sys/kern/sched_bsd.c index d6b18d30bc4..21c1ee8280a 100644 --- a/sys/kern/sched_bsd.c +++ b/sys/kern/sched_bsd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sched_bsd.c,v 1.94 2024/07/08 13:17:12 claudio Exp $ */ +/* $OpenBSD: sched_bsd.c,v 1.95 2024/10/08 11:57:59 claudio Exp $ */ /* $NetBSD: kern_synch.c,v 1.37 1996/04/22 01:38:37 christos Exp $ */ /*- @@ -344,7 +344,6 @@ mi_switch(void) struct schedstate_percpu *spc = &curcpu()->ci_schedstate; struct proc *p = curproc; struct proc *nextproc; - struct timespec ts; int oldipl; #ifdef MULTIPROCESSOR int hold_count; @@ -364,26 +363,8 @@ mi_switch(void) hold_count = 0; #endif - /* - * Compute the amount of time during which the current - * process was running, and add that to its total so far. - */ - nanouptime(&ts); - if (timespeccmp(&ts, &spc->spc_runtime, <)) { -#if 0 - printf("uptime is not monotonic! " - "ts=%lld.%09lu, runtime=%lld.%09lu\n", - (long long)tv.tv_sec, tv.tv_nsec, - (long long)spc->spc_runtime.tv_sec, - spc->spc_runtime.tv_nsec); -#endif - timespecclear(&ts); - } else { - timespecsub(&ts, &spc->spc_runtime, &ts); - } - tu_enter(&p->p_tu); - timespecadd(&p->p_tu.tu_runtime, &ts, &p->p_tu.tu_runtime); - tu_leave(&p->p_tu); + /* Update thread runtime */ + tuagg_add_runtime(); /* Stop any optional clock interrupts. */ if (ISSET(spc->spc_schedflags, SPCF_ITIMER)) { diff --git a/sys/sys/resourcevar.h b/sys/sys/resourcevar.h index 06a00b27f27..36b0303568a 100644 --- a/sys/sys/resourcevar.h +++ b/sys/sys/resourcevar.h @@ -1,4 +1,4 @@ -/* $OpenBSD: resourcevar.h,v 1.33 2024/10/01 09:22:25 claudio Exp $ */ +/* $OpenBSD: resourcevar.h,v 1.34 2024/10/08 11:57:59 claudio Exp $ */ /* $NetBSD: resourcevar.h,v 1.12 1995/11/22 23:01:53 cgd Exp $ */ /* @@ -67,6 +67,7 @@ void addupc_task(struct proc *, u_long, u_int); struct clockrequest; void profclock(struct clockrequest *, void *, void *); void tuagg_add_process(struct process *, struct proc *); +void tuagg_add_runtime(void); struct tusage; void tuagg_get_proc(struct tusage *, struct proc *); void tuagg_get_process(struct tusage *, struct process *);