--- kern_synch.c 2012-04-22 00:38:25.000000000 +0200 +++ ../../../src.old/sys/kern/kern_synch.c 2012-06-23 19:43:25.000000000 +0200 @@ -1143,6 +1143,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(r->r_rtime.sec < 0)) { + memset(r->r_rtime, 0, sizeof(r->r_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 +1161,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); @@ -1195,25 +1216,19 @@ if (__predict_false(runtm >= rlim->rlim_cur)) { if (runtm >= rlim->rlim_max) { sig = SIGKILL; - log(LOG_NOTICE, "pid %d is killed: %s\n", - 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; + log(LOG_NOTICE, "pid %d is killed: %s\n", + p->p_pid, "exceeded RLIMIT_CPU"); + uprintf("pid %d, command %s, is killed: %s\n", + p->p_pid, p->p_comm, + "exceeded RLIMIT_CPU"); if (rlim->rlim_cur < rlim->rlim_max) rlim->rlim_cur += 5; } } 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); }