Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 18 Jun 2025 02:13:12 GMT
From:      Olivier Certner <olce@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: 57540a0666f6 - main - runq: Clarity and style pass
Message-ID:  <202506180213.55I2DCXa024070@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by olce:

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

commit 57540a0666f6bfebf55c905dceac36230c0743c5
Author:     Olivier Certner <olce@FreeBSD.org>
AuthorDate: 2024-03-01 09:47:13 +0000
Commit:     Olivier Certner <olce@FreeBSD.org>
CommitDate: 2025-06-18 02:07:58 +0000

    runq: Clarity and style pass
    
    In runq_choose() and runq_choose_fuzz(), replace an unnecessary 'while'
    with an 'if', and separate assignment and test of 'idx' into two lines.
    
    Add missing parentheses to one 'sizeof' operator.
    
    Remove superfluous brackets for one-line "then" and "else" branches (to
    match style elsewhere in the file).
    
    Declare loop indices in their 'for'.
    
    Test for non-empty bit sets with an explicit '!= 0'.
    
    Move TABs in some prototypes of <sys/runq.h> (should not split the
    return type specifier, but instead separate the type specifier with the
    function declarator).
    
    No functional change intended.
    
    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 | 24 ++++++++++++------------
 sys/sys/runq.h         |  6 +++---
 2 files changed, 15 insertions(+), 15 deletions(-)

diff --git a/sys/kern/kern_switch.c b/sys/kern/kern_switch.c
index 5c529862bc53..906efca4bb51 100644
--- a/sys/kern/kern_switch.c
+++ b/sys/kern/kern_switch.c
@@ -269,7 +269,7 @@ runq_init(struct runq *rq)
 {
 	int i;
 
-	bzero(rq, sizeof *rq);
+	bzero(rq, sizeof(*rq));
 	for (i = 0; i < RQ_NQS; i++)
 		TAILQ_INIT(&rq->rq_queues[i]);
 }
@@ -300,11 +300,11 @@ static __inline int
 runq_findbit(struct runq *rq)
 {
 	struct rqbits *rqb;
-	int idx, i;
+	int idx;
 
 	rqb = &rq->rq_status;
-	for (i = 0; i < RQB_LEN; i++)
-		if (rqb->rqb_bits[i]) {
+	for (int i = 0; i < RQB_LEN; i++)
+		if (rqb->rqb_bits[i] != 0) {
 			idx = RQB_FFS(rqb->rqb_bits[i]) + i * RQB_BPW;
 			CHECK_IDX(idx);
 			CTR3(KTR_RUNQ, "runq_findbit: bits=%#x i=%d idx=%d",
@@ -390,11 +390,10 @@ runq_add_idx(struct runq *rq, struct thread *td, int idx, int flags)
 	rqh = &rq->rq_queues[idx];
 	CTR4(KTR_RUNQ, "runq_add_idx: td=%p pri=%d idx=%d rqh=%p",
 	    td, td->td_priority, idx, rqh);
-	if (flags & SRQ_PREEMPTED) {
+	if (flags & SRQ_PREEMPTED)
 		TAILQ_INSERT_HEAD(rqh, td, td_runq);
-	} else {
+	else
 		TAILQ_INSERT_TAIL(rqh, td, td_runq);
-	}
 }
 
 /*
@@ -405,11 +404,10 @@ bool
 runq_not_empty(struct runq *rq)
 {
 	struct rqbits *rqb;
-	int i;
 
 	rqb = &rq->rq_status;
-	for (i = 0; i < RQB_LEN; i++)
-		if (rqb->rqb_bits[i]) {
+	for (int i = 0; i < RQB_LEN; i++)
+		if (rqb->rqb_bits[i] != 0) {
 			CTR2(KTR_RUNQ, "runq_not_empty: bits=%#x i=%d",
 			    rqb->rqb_bits[i], i);
 			return (true);
@@ -429,7 +427,8 @@ runq_choose_fuzz(struct runq *rq, int fuzz)
 	struct thread *td;
 	int idx;
 
-	while ((idx = runq_findbit(rq)) != -1) {
+	idx = runq_findbit(rq);
+	if (idx != -1) {
 		rqh = &rq->rq_queues[idx];
 		/* fuzz == 1 is normal.. 0 or less are ignored */
 		if (fuzz > 1) {
@@ -471,7 +470,8 @@ runq_choose(struct runq *rq)
 	struct thread *td;
 	int idx;
 
-	while ((idx = runq_findbit(rq)) != -1) {
+	idx = runq_findbit(rq);
+	if (idx != -1) {
 		rqh = &rq->rq_queues[idx];
 		td = TAILQ_FIRST(rqh);
 		KASSERT(td != NULL, ("runq_choose: no thread on busy queue"));
diff --git a/sys/sys/runq.h b/sys/sys/runq.h
index 693a3666d7a8..030b4bb370a8 100644
--- a/sys/sys/runq.h
+++ b/sys/sys/runq.h
@@ -90,9 +90,9 @@ struct runq {
 void	runq_add(struct runq *, struct thread *, int _flags);
 void	runq_add_idx(struct runq *, struct thread *, int _idx, int _flags);
 bool	runq_not_empty(struct runq *);
-struct	thread *runq_choose(struct runq *);
-struct	thread *runq_choose_from(struct runq *, int _idx);
-struct	thread *runq_choose_fuzz(struct runq *, int _fuzz);
+struct thread	*runq_choose(struct runq *);
+struct thread	*runq_choose_from(struct runq *, int _idx);
+struct thread	*runq_choose_fuzz(struct runq *, int _fuzz);
 void	runq_init(struct runq *);
 bool	runq_remove(struct runq *, struct thread *);
 #endif /* _KERNEL */



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202506180213.55I2DCXa024070>