diff options
author | Claudio Jeker <claudio@cvs.openbsd.org> | 2024-07-08 13:17:13 +0000 |
---|---|---|
committer | Claudio Jeker <claudio@cvs.openbsd.org> | 2024-07-08 13:17:13 +0000 |
commit | 75518fa8eaa6911ea53a350c2d3e090ce8e963e3 (patch) | |
tree | 20ec444be8a846f99fdbb0816f5c2c758662a116 /sys/kern/sched_bsd.c | |
parent | 544021728069ca351e05502774eabb3c0fed1d4f (diff) |
Rework per proc and per process time usage accounting
For procs (threads) the accounting happens now lockless by curproc using
a generation counter. Callers need to use tu_enter() and tu_leave() for this.
To read the proc p_tu struct tuagg_get_proc() should be used. It ensures
that the values read is consistent.
For processes only the time of exited threads is accumulated in ps_tu and
to get the proper process time usage tuagg_get_process() needs to be called.
tuagg_get_process() will sum up all procs p_tu plus the ps_tu.
This removes another SCHED_LOCK() dependency. Adjust the code in
exit1() and exit2() to correctly account for the full run time.
For this adjust sched_exit() to do the runtime accounting like it is done
in mi_switch().
OK jca@ dlg@
Diffstat (limited to 'sys/kern/sched_bsd.c')
-rw-r--r-- | sys/kern/sched_bsd.c | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/sys/kern/sched_bsd.c b/sys/kern/sched_bsd.c index 54ce3173e4e..d6b18d30bc4 100644 --- a/sys/kern/sched_bsd.c +++ b/sys/kern/sched_bsd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sched_bsd.c,v 1.93 2024/06/03 12:48:25 claudio Exp $ */ +/* $OpenBSD: sched_bsd.c,v 1.94 2024/07/08 13:17:12 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 process *pr = p->p_p; struct timespec ts; int oldipl; #ifdef MULTIPROCESSOR @@ -382,9 +381,9 @@ mi_switch(void) } else { timespecsub(&ts, &spc->spc_runtime, &ts); } - - /* add the time counts for this thread to the process's total */ - tuagg_locked(pr, p, &ts); + tu_enter(&p->p_tu); + timespecadd(&p->p_tu.tu_runtime, &ts, &p->p_tu.tu_runtime); + tu_leave(&p->p_tu); /* Stop any optional clock interrupts. */ if (ISSET(spc->spc_schedflags, SPCF_ITIMER)) { |