as argument to the tuagg_locked function.
- Remove incorrect use of p_rtime in other parts of the tree. p_rtime was
almost always 0 so including it in any sum did not alter the result.
- In main() the update of time can be further simplified since at that time
only the primary cpu is running.
- Add missing nanouptime() call in cpu_hatch() for hppa
- Rename tuagg_unlocked to tuagg_locked like it is done in the rest of
the tree.
OK cheloha@ dlg@
-/* $OpenBSD: cpu.c,v 1.45 2023/06/15 22:18:07 cheloha Exp $ */
+/* $OpenBSD: cpu.c,v 1.46 2023/08/29 16:19:34 claudio Exp $ */
/*
* Copyright (c) 1998-2003 Michael Shalayeff
while (!start_secondary_cpu)
;
+ s = splhigh();
+ nanouptime(&ci->ci_schedstate.spc_runtime);
+ splx(s);
+
SCHED_LOCK(s);
cpu_switchto(NULL, sched_chooseproc());
}
-/* $OpenBSD: init_main.c,v 1.321 2023/06/15 22:18:06 cheloha Exp $ */
+/* $OpenBSD: init_main.c,v 1.322 2023/08/29 16:19:34 claudio Exp $ */
/* $NetBSD: init_main.c,v 1.84.4.1 1996/06/02 09:08:06 mrg Exp $ */
/*
/*
* 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
- * munched in mi_switch() after the time got set.
+ * from the file system.
*/
LIST_FOREACH(pr, &allprocess, ps_list) {
nanouptime(&pr->ps_start);
- TAILQ_FOREACH(p, &pr->ps_threads, p_thr_link) {
- nanouptime(&p->p_cpu->ci_schedstate.spc_runtime);
- timespecclear(&p->p_rtime);
- }
}
+ nanouptime(&curcpu()->ci_schedstate.spc_runtime);
uvm_swap_init();
-/* $OpenBSD: kern_exit.c,v 1.211 2023/04/25 18:14:06 claudio Exp $ */
+/* $OpenBSD: kern_exit.c,v 1.212 2023/08/29 16:19:34 claudio Exp $ */
/* $NetBSD: kern_exit.c,v 1.39 1996/04/22 01:38:25 christos Exp $ */
/*
{
struct process *pr, *qr, *nqr;
struct rusage *rup;
+ struct timespec ts;
int s;
atomic_setbits_int(&p->p_flag, P_WEXIT);
/* add thread's accumulated rusage into the process's total */
ruadd(rup, &p->p_ru);
- tuagg(pr, p);
+ nanouptime(&ts);
+ if (timespeccmp(&ts, &curcpu()->ci_schedstate.spc_runtime, <))
+ timespecclear(&ts);
+ else
+ timespecsub(&ts, &curcpu()->ci_schedstate.spc_runtime, &ts);
+ SCHED_LOCK(s);
+ tuagg_locked(pr, p, &ts);
+ SCHED_UNLOCK(s);
/*
* clear %cpu usage during swap
-/* $OpenBSD: kern_resource.c,v 1.77 2023/02/04 19:33:03 cheloha Exp $ */
+/* $OpenBSD: kern_resource.c,v 1.78 2023/08/29 16:19:34 claudio Exp $ */
/* $NetBSD: kern_resource.c,v 1.38 1996/10/23 07:19:38 matthias Exp $ */
/*-
struct plimit *lim_write_begin(void);
void lim_write_commit(struct plimit *);
-void tuagg_sub(struct tusage *, struct proc *);
+void tuagg_sub(struct tusage *, struct proc *, const struct timespec *);
/*
* Patchable maximum data and stack limits.
}
void
-tuagg_sub(struct tusage *tup, struct proc *p)
+tuagg_sub(struct tusage *tup, struct proc *p, const struct timespec *ts)
{
- timespecadd(&tup->tu_runtime, &p->p_rtime, &tup->tu_runtime);
+ if (ts != NULL)
+ timespecadd(&tup->tu_runtime, ts, &tup->tu_runtime);
tup->tu_uticks += p->p_uticks;
tup->tu_sticks += p->p_sticks;
tup->tu_iticks += p->p_iticks;
* totals for the thread and process
*/
void
-tuagg_unlocked(struct process *pr, struct proc *p)
+tuagg_locked(struct process *pr, struct proc *p, const struct timespec *ts)
{
- tuagg_sub(&pr->ps_tu, p);
- tuagg_sub(&p->p_tu, p);
- timespecclear(&p->p_rtime);
+ tuagg_sub(&pr->ps_tu, p, ts);
+ tuagg_sub(&p->p_tu, p, ts);
p->p_uticks = 0;
p->p_sticks = 0;
p->p_iticks = 0;
int s;
SCHED_LOCK(s);
- tuagg_unlocked(pr, p);
+ tuagg_locked(pr, p, NULL);
SCHED_UNLOCK(s);
}
-/* $OpenBSD: kern_sched.c,v 1.86 2023/08/14 08:33:24 mpi Exp $ */
+/* $OpenBSD: kern_sched.c,v 1.87 2023/08/29 16:19:34 claudio Exp $ */
/*
* Copyright (c) 2007, 2008 Artur Grabowski <art@openbsd.org>
*
sched_exit(struct proc *p)
{
struct schedstate_percpu *spc = &curcpu()->ci_schedstate;
- struct timespec ts;
struct proc *idle;
int s;
- nanouptime(&ts);
- timespecsub(&ts, &spc->spc_runtime, &ts);
- timespecadd(&p->p_rtime, &ts, &p->p_rtime);
-
if (ISSET(spc->spc_schedflags, SPCF_ITIMER)) {
atomic_clearbits_int(&spc->spc_schedflags, SPCF_ITIMER);
clockintr_cancel(spc->spc_itimer);
-/* $OpenBSD: kern_time.c,v 1.164 2023/08/05 20:07:55 cheloha Exp $ */
+/* $OpenBSD: kern_time.c,v 1.165 2023/08/29 16:19:34 claudio Exp $ */
/* $NetBSD: kern_time.c,v 1.20 1996/02/18 11:57:06 fvdl Exp $ */
/*
nanouptime(tp);
timespecsub(tp, &curcpu()->ci_schedstate.spc_runtime, tp);
timespecadd(tp, &p->p_p->ps_tu.tu_runtime, tp);
- timespecadd(tp, &p->p_rtime, tp);
break;
case CLOCK_THREAD_CPUTIME_ID:
nanouptime(tp);
timespecsub(tp, &curcpu()->ci_schedstate.spc_runtime, tp);
timespecadd(tp, &p->p_tu.tu_runtime, tp);
- timespecadd(tp, &p->p_rtime, tp);
break;
default:
/* check for clock from pthread_getcpuclockid() */
-/* $OpenBSD: sched_bsd.c,v 1.83 2023/08/19 11:14:11 claudio Exp $ */
+/* $OpenBSD: sched_bsd.c,v 1.84 2023/08/29 16:19:34 claudio Exp $ */
/* $NetBSD: kern_synch.c,v 1.37 1996/04/22 01:38:37 christos Exp $ */
/*-
(long long)spc->spc_runtime.tv_sec,
spc->spc_runtime.tv_nsec);
#endif
+ timespecclear(&ts);
} else {
timespecsub(&ts, &spc->spc_runtime, &ts);
- timespecadd(&p->p_rtime, &ts, &p->p_rtime);
}
/* add the time counts for this thread to the process's total */
- tuagg_unlocked(pr, p);
+ tuagg_locked(pr, p, &ts);
/* Stop any optional clock interrupts. */
if (ISSET(spc->spc_schedflags, SPCF_ITIMER)) {
-/* $OpenBSD: proc.h,v 1.347 2023/08/05 20:07:56 cheloha Exp $ */
+/* $OpenBSD: proc.h,v 1.348 2023/08/29 16:19:34 claudio Exp $ */
/* $NetBSD: proc.h,v 1.44 1996/04/22 01:23:21 christos Exp $ */
/*-
struct rusage p_ru; /* Statistics */
struct tusage p_tu; /* accumulated times. */
- struct timespec p_rtime; /* Real time. */
struct plimit *p_limit; /* [l] read ref. of p_p->ps_limit */
struct kcov_dev *p_kd; /* kcov device handle */
-/* $OpenBSD: resourcevar.h,v 1.27 2023/07/25 18:16:19 cheloha Exp $ */
+/* $OpenBSD: resourcevar.h,v 1.28 2023/08/29 16:19:34 claudio Exp $ */
/* $NetBSD: resourcevar.h,v 1.12 1995/11/22 23:01:53 cgd Exp $ */
/*
void addupc_intr(struct proc *, u_long, u_long);
void addupc_task(struct proc *, u_long, u_int);
void profclock(struct clockintr *, void *);
-void tuagg_unlocked(struct process *, struct proc *);
+void tuagg_locked(struct process *, struct proc *, const struct timespec *);
void tuagg(struct process *, struct proc *);
struct tusage;
void calctsru(struct tusage *, struct timespec *, struct timespec *,