The branch main has been updated by olce:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=a31193172cb98bd1fb242555ca8e122efff74258

commit a31193172cb98bd1fb242555ca8e122efff74258
Author:     Olivier Certner <o...@freebsd.org>
AuthorDate: 2024-05-23 15:31:06 +0000
Commit:     Olivier Certner <o...@freebsd.org>
CommitDate: 2025-06-18 02:08:00 +0000

    runq: New function runq_is_queue_empty(); Use it in ULE
    
    Indicates if some particular queue of the runqueue is empty.
    
    Reviewed by:    kib
    MFC after:      1 month
    Event:          Kitchener-Waterloo Hackathon 202506
    Sponsored by:   The FreeBSD Foundation
    Differential Revision:  https://reviews.freebsd.org/D45387
---
 sys/kern/kern_switch.c | 28 ++++++++++++++++++++++++++++
 sys/kern/sched_ule.c   |  2 +-
 sys/sys/runq.h         |  1 +
 3 files changed, 30 insertions(+), 1 deletion(-)

diff --git a/sys/kern/kern_switch.c b/sys/kern/kern_switch.c
index eb39ca88992c..b23dfa162c4f 100644
--- a/sys/kern/kern_switch.c
+++ b/sys/kern/kern_switch.c
@@ -271,10 +271,13 @@ static inline uintptr_t   runq_sw_set_not_empty_op(int 
idx, int sw_idx,
                            rqsw_t sw_bit, rqsw_t *swp);
 static inline uintptr_t        runq_sw_set_empty_op(int idx, int sw_idx,
                            rqsw_t sw_bit, rqsw_t *swp);
+static inline uintptr_t        runq_sw_is_empty_op(int idx, int sw_idx,
+                           rqsw_t sw_bit, rqsw_t *swp);
 
 /* Status words' individual bit manipulators. */
 static inline void     runq_sw_set_not_empty(struct runq *rq, int idx);
 static inline void     runq_sw_set_empty(struct runq *rq, int idx);
+static inline bool     runq_sw_is_empty(struct runq *rq, int idx);
 
 /*
  * Initialize a run structure.
@@ -358,6 +361,31 @@ runq_sw_set_empty(struct runq *rq, int idx)
        (void)runq_sw_apply(rq, idx, &runq_sw_set_empty_op);
 }
 
+static inline uintptr_t
+runq_sw_is_empty_op(int idx, int sw_idx, rqsw_t sw_bit, rqsw_t *swp)
+{
+       return ((*swp & sw_bit) == 0);
+}
+
+/*
+ * Returns whether the status words indicate that some queue is empty.
+ */
+static inline bool
+runq_sw_is_empty(struct runq *rq, int idx)
+{
+       return (runq_sw_apply(rq, idx, &runq_sw_is_empty_op));
+}
+
+/*
+ * Returns whether a particular queue is empty.
+ */
+bool
+runq_is_queue_empty(struct runq *rq, int idx)
+{
+
+       return (runq_sw_is_empty(rq, idx));
+}
+
 /*
  * Add the thread to the queue specified by its priority, and set the
  * corresponding status bit.
diff --git a/sys/kern/sched_ule.c b/sys/kern/sched_ule.c
index 1cec38597952..c23d00fd6049 100644
--- a/sys/kern/sched_ule.c
+++ b/sys/kern/sched_ule.c
@@ -2602,7 +2602,7 @@ sched_clock(struct thread *td, int cnt)
         */
        if (tdq->tdq_idx == tdq->tdq_ridx) {
                tdq->tdq_idx = (tdq->tdq_idx + 1) % RQ_NQS;
-               if (TAILQ_EMPTY(&tdq->tdq_timeshare.rq_queues[tdq->tdq_ridx]))
+               if (runq_is_queue_empty(&tdq->tdq_timeshare, tdq->tdq_ridx))
                        tdq->tdq_ridx = tdq->tdq_idx;
        }
        ts = td_get_sched(td);
diff --git a/sys/sys/runq.h b/sys/sys/runq.h
index c570dd25503b..5156a7d8c307 100644
--- a/sys/sys/runq.h
+++ b/sys/sys/runq.h
@@ -98,6 +98,7 @@ struct runq {
 };
 
 void   runq_init(struct runq *);
+bool   runq_is_queue_empty(struct runq *, int _idx);
 void   runq_add(struct runq *, struct thread *, int _flags);
 void   runq_add_idx(struct runq *, struct thread *, int _idx, int _flags);
 bool   runq_remove(struct runq *, struct thread *);

Reply via email to