In rucheck() sum up the tusage from all threads to get the real current
authorclaudio <claudio@openbsd.org>
Thu, 3 Oct 2024 10:20:05 +0000 (10:20 +0000)
committerclaudio <claudio@openbsd.org>
Thu, 3 Oct 2024 10:20:05 +0000 (10:20 +0000)
runtime of the process. Also this no longer needs the SCHED_LOCK().
OK mpi@

sys/kern/kern_resource.c

index 403f4ad..8796b48 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: kern_resource.c,v 1.89 2024/10/01 09:22:25 claudio Exp $      */
+/*     $OpenBSD: kern_resource.c,v 1.90 2024/10/03 10:20:05 claudio Exp $      */
 /*     $NetBSD: kern_resource.c,v 1.38 1996/10/23 07:19:38 matthias Exp $      */
 
 /*-
@@ -578,19 +578,22 @@ void
 rucheck(void *arg)
 {
        struct rlimit rlim;
+       struct tusage tu = { 0 };
        struct process *pr = arg;
+       struct proc *q;
        time_t runtime;
 
        KERNEL_ASSERT_LOCKED();
 
-       SCHED_LOCK();
-       runtime = pr->ps_tu.tu_runtime.tv_sec;
-       SCHED_UNLOCK();
-
        mtx_enter(&pr->ps_mtx);
        rlim = pr->ps_limit->pl_rlimit[RLIMIT_CPU];
+       tuagg_sumup(&tu, &pr->ps_tu);
+       TAILQ_FOREACH(q, &pr->ps_threads, p_thr_link)
+               tuagg_sumup(&tu, &q->p_tu);
        mtx_leave(&pr->ps_mtx);
 
+       runtime = tu.tu_runtime.tv_sec;
+
        if ((rlim_t)runtime >= rlim.rlim_cur) {
                if ((rlim_t)runtime >= rlim.rlim_max) {
                        prsignal(pr, SIGKILL);