-/* $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 $ */
/*
{
struct process *pr, *qr, *nqr;
struct rusage *rup;
- struct timespec ts, pts;
atomic_setbits_int(&p->p_flag, P_WEXIT);
}
/* 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) {
-/* $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 $ */
/*-
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.
-/* $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 <art@openbsd.org>
*
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();
-/* $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 $ */
/*-
struct schedstate_percpu *spc = &curcpu()->ci_schedstate;
struct proc *p = curproc;
struct proc *nextproc;
- struct timespec ts;
int oldipl;
#ifdef MULTIPROCESSOR
int hold_count;
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)) {
-/* $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 $ */
/*
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 *);