diff --git a/sys/kern/kern_switch.c b/sys/kern/kern_switch.c index 917f7368256..42fee61a99a 100644 --- a/sys/kern/kern_switch.c +++ b/sys/kern/kern_switch.c @@ -493,7 +493,7 @@ int runq_findq(struct runq *const rq, const int lvl_min, const int lvl_max, runq_pred_t *const pred, void *const pred_data) { - rqsw_t const (*const rqsw)[RQSW_NB] = &rq->rq_status.rq_sw; + const rqsw_t (*const rqsw)[RQSW_NB] = &rq->rq_status.rq_sw; rqsw_t w; int i, last, idx; @@ -568,20 +568,27 @@ runq_first_thread(struct runq *const rq) /* * Return true if there are some processes of any priority on the run queue, - * false otherwise. Has no side effects. + * false otherwise. Has no side effects. Supports racy lookups (required by + * 4BSD). */ bool runq_not_empty(struct runq *rq) { - struct thread *const td = runq_first_thread(rq); + const rqsw_t (*const rqsw)[RQSW_NB] = &rq->rq_status.rq_sw; + int sw_idx; - if (td != NULL) { - CTR2(KTR_RUNQ, "runq_not_empty: idx=%d, td=%p", - td->td_rqindex, td); - return (true); + for (sw_idx = 0; sw_idx < RQSW_NB; ++sw_idx) { + const rqsw_t w = (*rqsw)[sw_idx]; + + if (w != 0) { + CTR3(KTR_RUNQ, "runq_not_empty: not empty; " + "rq=%p, sw_idx=%d, bits=" RQSW_PRI, + rq, sw_idx, w); + return (true); + } } - CTR0(KTR_RUNQ, "runq_not_empty: empty"); + CTR1(KTR_RUNQ, "runq_not_empty: empty; rq=%p", rq); return (false); }