@@ -1143,6 +1144,16 @@ /* Increment sleep time (if sleeping), ignore overflow. */ mutex_enter(p->p_lock); + /* Check if we have a negative process runtime because of + timecounter anomaly, fix it if yes. */ + if (__predict_false(p->p_rtime.sec < 0)) { + memset(&p->p_rtime, 0, sizeof(p->p_rtime)); + if (!backwards) { + backwards = true; + printf("WARNING: negative runtime; " + "monotonic clock has gone backwards\n"); + } + } runtm = p->p_rtime.sec; LIST_FOREACH(l, &p->p_lwps, l_sibling) { fixpt_t lpctcpu; @@ -1151,6 +1162,17 @@ if (__predict_false((l->l_flag & LW_IDLE) != 0)) continue; lwp_lock(l); + /* Check if we have a negative lwp runtime because of + timecounter anomaly, fix it if yes. */ + if (__predict_false(l->l_rtime.sec < 0)) { + memset(&l->l_rtime, 0, sizeof(l->l_rtime)); + if (!backwards) { + backwards = true; + printf("WARNING: negative runtime; " + "monotonic clock has " + "gone backwards\n"); + } + } runtm += l->l_rtime.sec; l->l_swtime++; sched_lwp_stats(l); @@ -1196,24 +1218,18 @@ if (runtm >= rlim->rlim_max) { sig = SIGKILL; log(LOG_NOTICE, "pid %d is killed: %s\n", - p->p_pid, "exceeded RLIMIT_CPU"); + p->p_pid, "exceeded RLIMIT_CPU"); uprintf("pid %d, command %s, is killed: %s\n", - p->p_pid, p->p_comm, - "exceeded RLIMIT_CPU"); - } else { - sig = SIGXCPU; + p->p_pid, p->p_comm, + "exceeded RLIMIT_CPU"); if (rlim->rlim_cur < rlim->rlim_max) rlim->rlim_cur += 5; + } else { + sig = SIGXCPU; } } mutex_exit(p->p_lock); - if (__predict_false(runtm < 0)) { - if (!backwards) { - backwards = true; - printf("WARNING: negative runtime; " - "monotonic clock has gone backwards\n"); - } - } else if (__predict_false(sig)) { + if (__predict_false(sig)) { KASSERT((p->p_flag & PK_SYSTEM) == 0); psignal(p, sig); }