Fix runtime calculation. Assiging ts to spc_runtime does not work if ts
authorclaudio <claudio@openbsd.org>
Tue, 15 Oct 2024 12:26:53 +0000 (12:26 +0000)
committerclaudio <claudio@openbsd.org>
Tue, 15 Oct 2024 12:26:53 +0000 (12:26 +0000)
is modified.
OK tb@ jca@

sys/kern/kern_resource.c

index bd2c546..56dc366 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: kern_resource.c,v 1.91 2024/10/08 11:57:59 claudio Exp $      */
+/*     $OpenBSD: kern_resource.c,v 1.92 2024/10/15 12:26:53 claudio Exp $      */
 /*     $NetBSD: kern_resource.c,v 1.38 1996/10/23 07:19:38 matthias Exp $      */
 
 /*-
@@ -448,7 +448,7 @@ tuagg_add_runtime(void)
 {
        struct schedstate_percpu *spc = &curcpu()->ci_schedstate;
        struct proc *p = curproc;
-       struct timespec ts;
+       struct timespec ts, delta;
 
        /*
         * Compute the amount of time during which the current
@@ -463,14 +463,14 @@ tuagg_add_runtime(void)
                    (long long)spc->spc_runtime.tv_sec,
                    spc->spc_runtime.tv_nsec);
 #endif
-               timespecclear(&ts);
+               timespecclear(&delta);
        } else {
-               timespecsub(&ts, &spc->spc_runtime, &ts);
+               timespecsub(&ts, &spc->spc_runtime, &delta);
        }
        /* update spc_runtime */
        spc->spc_runtime = ts;
        tu_enter(&p->p_tu);
-       timespecadd(&p->p_tu.tu_runtime, &ts, &p->p_tu.tu_runtime);
+       timespecadd(&p->p_tu.tu_runtime, &delta, &p->p_tu.tu_runtime);
        tu_leave(&p->p_tu);
 }