From nobody Wed Jun 18 02:13:17 2025 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4bMS2Q6Fwzz5q6W2; Wed, 18 Jun 2025 02:13:18 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4bMS2Q11B0z41Qw; Wed, 18 Jun 2025 02:13:18 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1750212798; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=mTrBy99k8rNFpZK4enLS7YvCeCN7R86zzQesekF5UnM=; b=TgexplIUYHBRCoQuMjt+4ELlzgbWEyDIpchP1zcXEHu8pgHjYCaUFRQ5tt2kbu1zaMpv+1 RWpRSVuMEJKmdlaLikObdznWqV9y2lSxaUfCJ1casJ1IyIXF86w/YxE0UUvqHGJ1RXcoDN dTR6vKfh8lQWn2eLoZStgqCoYbf0sXPAhUlGC8Yp1GeQWCscMmjqERY6fbATQiKBXtIIuk oXrYNTKuYrWFVO3EUSQa9WrWoimmds0KoOv5dhsNGIEa7FVseBbgN6vW8l1AHBaC1aduYC 3VwvJevbzXbSDX5Q6S9M6+SUER7gddiKCIA9EtJIZooOArBEp1LibtBDmU6xjg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1750212798; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=mTrBy99k8rNFpZK4enLS7YvCeCN7R86zzQesekF5UnM=; b=gyAN8qQu7jl+JMgIXrsB+zEinuS+xFF3vYculpSVVezkyqXImLmfmsVcVZtoicfH3z64Wb fwHO7gVpPknYsHf1SUAz9JRY3ukR5SP7ffnOwVDFxtQo3jfK8TR6obi6f9ctyMFq6IRlws JmATNv5QWe4Qq/JEdAMG5RsIz2y7he5ZbloqtMpK378EBeQwfUFUp50IWqbflC2/DlMsbN cyjaR7KsW66SucYI150kUh8DQePMOGkQkNDMkrm3OrgWc/YqzLGAlC6qlESZA6PwVEQZ2v SGJQqqW/JsnOGbDg+CLbIsgUGqY/ugVLq7RZ2AAZCW7kxCT/6FQxENFeVvcllw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1750212798; a=rsa-sha256; cv=none; b=Y60ML8glfDxxXqtSjT8y3ML4wkOV1jlSUNDwwBrvYcu7Ic7OQZEYM3FeO/AgBLaXgW8O+C waFdNZBxD7Wk/gkkagCsPtzSdY5Kiab+rXL496aRKRF7JPNoM7w9wNDjHp59xjR8JSeG9g uTg6p0MJ+2nsvmmDAyrl/ouo/Va5LwcvdYH4vN+sHDgKxfyJdxsiIZkS9y2yFStfzMsDU/ EQpVbRla9sLUFnSXvOWgzaAJNKYXxT50OmAqaoTc2MnTrLiJIrIa4oz7fUWBReV0KgFNTQ hWff8W2gGumhjPpEAvsYTnAaJ5wFuZtw23p4h3vRGyglLAh+8a531evqN+VBlg== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4bMS2Q0C8Sz18gX; Wed, 18 Jun 2025 02:13:18 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 55I2DHZg024236; Wed, 18 Jun 2025 02:13:17 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 55I2DH8Y024233; Wed, 18 Jun 2025 02:13:17 GMT (envelope-from git) Date: Wed, 18 Jun 2025 02:13:17 GMT Message-Id: <202506180213.55I2DH8Y024233@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Olivier Certner Subject: git: 757bab06fb59 - main - runq: Tidy up and rename runq_setbit() and runq_clrbit() List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: olce X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 757bab06fb59abca8b7fda38e8f546ff7c2d3280 Auto-Submitted: auto-generated The branch main has been updated by olce: URL: https://cgit.FreeBSD.org/src/commit/?id=757bab06fb59abca8b7fda38e8f546ff7c2d3280 commit 757bab06fb59abca8b7fda38e8f546ff7c2d3280 Author: Olivier Certner AuthorDate: 2024-03-01 20:41:23 +0000 Commit: Olivier Certner CommitDate: 2025-06-18 02:08:00 +0000 runq: Tidy up and rename runq_setbit() and runq_clrbit() Factorize common sub-expressions in a separate helper (runq_sw_apply()) for better readability. Rename these functions so that the names refer to the use cases rather than the implementations. 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 | 104 ++++++++++++++++++++++++++++++++++++------------- 1 file changed, 76 insertions(+), 28 deletions(-) diff --git a/sys/kern/kern_switch.c b/sys/kern/kern_switch.c index 59925c10c30d..eb39ca88992c 100644 --- a/sys/kern/kern_switch.c +++ b/sys/kern/kern_switch.c @@ -261,6 +261,21 @@ _Static_assert(RQ_NQS <= 256, ("%s: %s out of range: %d", __func__, __STRING(idx), _idx)); \ }) +/* Status words' individual bit manipulators' internals. */ +typedef uintptr_t runq_sw_op(int idx, int sw_idx, rqsw_t sw_bit, + rqsw_t *swp); +static inline uintptr_t runq_sw_apply(struct runq *rq, int idx, + runq_sw_op *op); + +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); + +/* 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); + /* * Initialize a run structure. */ @@ -275,39 +290,72 @@ runq_init(struct runq *rq) } /* - * Set the status bit of the queue at index 'idx', indicating that it is - * non-empty. + * Helper to implement functions operating on a particular status word bit. + * + * The operator is passed the initial 'idx', the corresponding status word index + * in 'rq_status' in 'sw_idx', a status word with only that bit set in 'sw_bit' + * and a pointer to the corresponding status word in 'swp'. */ -static __inline void -runq_setbit(struct runq *rq, int idx) +static inline uintptr_t +runq_sw_apply(struct runq *rq, int idx, runq_sw_op *op) { - struct rq_status *rqs; + rqsw_t *swp; + rqsw_t sw_bit; + int sw_idx; CHECK_IDX(idx); - rqs = &rq->rq_status; - CTR4(KTR_RUNQ, "runq_setbit: bits=%#x %#x bit=%#x word=%d", - rqs->rq_sw[RQSW_IDX(idx)], - rqs->rq_sw[RQSW_IDX(idx)] | RQSW_BIT(idx), - RQSW_BIT(idx), RQSW_IDX(idx)); - rqs->rq_sw[RQSW_IDX(idx)] |= RQSW_BIT(idx); + + sw_idx = RQSW_IDX(idx); + sw_bit = RQSW_BIT(idx); + swp = &rq->rq_status.rq_sw[sw_idx]; + + return (op(idx, sw_idx, sw_bit, swp)); +} + +static inline uintptr_t +runq_sw_set_not_empty_op(int idx, int sw_idx, rqsw_t sw_bit, rqsw_t *swp) +{ + rqsw_t old_sw __unused = *swp; + + *swp |= sw_bit; + CTR4(KTR_RUNQ, "runq_sw_set_not_empty: idx=%d sw_idx=%d bits=%#x->%#x", + idx, sw_idx, old_sw, *swp); + return (0); } /* - * Clear the status bit of the queue at index 'idx', indicating that it is - * empty. + * Modify the status words to indicate that some queue is not empty. + * + * Sets the status bit corresponding to the queue at index 'idx'. */ -static __inline void -runq_clrbit(struct runq *rq, int idx) +static inline void +runq_sw_set_not_empty(struct runq *rq, int idx) { - struct rq_status *rqs; - CHECK_IDX(idx); - rqs = &rq->rq_status; - CTR4(KTR_RUNQ, "runq_clrbit: bits=%#x %#x bit=%#x word=%d", - rqs->rq_sw[RQSW_IDX(idx)], - rqs->rq_sw[RQSW_IDX(idx)] & ~RQSW_BIT(idx), - RQSW_BIT(idx), RQSW_IDX(idx)); - rqs->rq_sw[RQSW_IDX(idx)] &= ~RQSW_BIT(idx); + (void)runq_sw_apply(rq, idx, &runq_sw_set_not_empty_op); +} + +static inline uintptr_t +runq_sw_set_empty_op(int idx, int sw_idx, rqsw_t sw_bit, rqsw_t *swp) +{ + rqsw_t old_sw __unused = *swp; + + *swp &= ~sw_bit; + CTR4(KTR_RUNQ, "runq_sw_set_empty: idx=%d sw_idx=%d bits=%#x->%#x", + idx, sw_idx, old_sw, *swp); + return (0); +} + +/* + * Modify the status words to indicate that some queue is empty. + * + * Clears the status bit corresponding to the queue at index 'idx'. + */ +static inline void +runq_sw_set_empty(struct runq *rq, int idx) +{ + + (void)runq_sw_apply(rq, idx, &runq_sw_set_empty_op); } /* @@ -327,12 +375,12 @@ runq_add_idx(struct runq *rq, struct thread *td, int idx, int flags) struct rq_queue *rqq; /* - * runq_setbit() asserts 'idx' is non-negative and below 'RQ_NQS', and - * a static assert earlier in this file ensures that 'RQ_NQS' is no more - * than 256. + * runq_sw_*() functions assert that 'idx' is non-negative and below + * 'RQ_NQS', and a static assert earlier in this file ensures that + * 'RQ_NQS' is no more than 256. */ td->td_rqindex = idx; - runq_setbit(rq, idx); + runq_sw_set_not_empty(rq, idx); rqq = &rq->rq_queues[idx]; CTR4(KTR_RUNQ, "runq_add_idx: td=%p pri=%d idx=%d rqq=%p", td, td->td_priority, idx, rqq); @@ -362,7 +410,7 @@ runq_remove(struct runq *rq, struct thread *td) td, td->td_priority, idx, rqq); TAILQ_REMOVE(rqq, td, td_runq); if (TAILQ_EMPTY(rqq)) { - runq_clrbit(rq, idx); + runq_sw_set_empty(rq, idx); CTR1(KTR_RUNQ, "runq_remove: queue at idx=%d now empty", idx); return (true); }