From nobody Mon Jul 28 13:31:18 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 4brKBG6Zhkz634sS; Mon, 28 Jul 2025 13:31: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 "R10" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4brKBG2jXgz3tTS; Mon, 28 Jul 2025 13:31:18 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1753709478; 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=GfMA9t5m0OBzdrShjxP/rT6fh674H5mLq7q9S0r7Py4=; b=Udc/bbvjPXCcpGT4g1Gos7sK5jkTXHT5oKpzneshotY6piwyDvxdpXQfpK5OJM7ydlguY5 Re4H975Vyj6FKEpvojZzE7HQl9nf5KlpWnehLxLCfzXMpM4uRSTZnsgICqA3+tG3oze0an FurJies2CFrNezmBajBneXwG0PTBhLSLCj/5NvFfQXiP5Wh1Fc+2cyHJSCnErSLJHaN90n nL+2ZqaZGIlJ0p1L/Xf3J/qpsjJR9L0O+2b6850GcGUoSTJo6PUyCfUKgcdWUvb6I1Cq/m zpOYtiQ7ckLaqgBZEuV8O+sZffc4aQ3y9QHwl0T4n+onvRs0dBJae4F137Ce8A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1753709478; 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=GfMA9t5m0OBzdrShjxP/rT6fh674H5mLq7q9S0r7Py4=; b=fRd2CotlYabmm2O+pAjeRcVf6ZG1u0Q/3nU95/Fkbw3mY53n41u8d5dEHUsQNKRoSGKcCS TGSVeAO9+o6WHOnY7mC+CRaNdshJLeuVUkW20d1kgCuaZdH3HMSyejQVfZuKKBOJFGENoa Hy99bSd4ZLwjQaXA+JZg2xu2G+EDcxC2YMM2DdQqHE2EizFyY30waohbWe20IzlbwFvVFO ST4ocdm9vc/e/8059Qi0L1ixPOedChKn3NwJZpsrSV6u8uMQ2KDN8SC9wEt19GGwNMkWJz XhNynm+ogLOwKJQ2dPS5UAjivVb1WXtdxQMEuC7gv0MT4+M47WKA8+A/yiK3yg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1753709478; a=rsa-sha256; cv=none; b=RDtuuKnRYBFKvTD72Vl3oVbQ7sF4XlT7/5xpHnpnIjmiLxUXQGz+aPT7wsEqFqtqpO20if DW1XqJVbZ03Nk7T7z+hMUbmF8VzM4yjwsOull1hWxp0xm0EXopV7+zKE5t4Lf9gORuaGgz 9ztMB7TkZc0DF8SIKE+oqNxT58JVm14ywaNcdaF5Pd3jTjczsXOCQhStgMId6GtTfiiM7c OzkEGbrYBemPd85Z7CTcMzqRUngC0uxe4j8CAfd/EAvXiiDsRugSO683YSDHcb4RVUn6R2 j8BjnDmZTs5wTM0F/1x+Ju7L6w7NLNjpj3KDMfYiSM6aVR/V6MbbPExyvEzYaw== 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 4brKBG1wXlznRH; Mon, 28 Jul 2025 13:31: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 56SDVIuO080195; Mon, 28 Jul 2025 13:31:18 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 56SDVIJB080192; Mon, 28 Jul 2025 13:31:18 GMT (envelope-from git) Date: Mon, 28 Jul 2025 13:31:18 GMT Message-Id: <202507281331.56SDVIJB080192@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Olivier Certner Subject: git: bd97078d704b - stable/14 - 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/stable/14 X-Git-Reftype: branch X-Git-Commit: bd97078d704b59341bc05674e89e4d0c9eb2351e Auto-Submitted: auto-generated The branch stable/14 has been updated by olce: URL: https://cgit.FreeBSD.org/src/commit/?id=bd97078d704b59341bc05674e89e4d0c9eb2351e commit bd97078d704b59341bc05674e89e4d0c9eb2351e Author: Olivier Certner AuthorDate: 2024-03-01 20:41:23 +0000 Commit: Olivier Certner CommitDate: 2025-07-28 13:28:12 +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 (cherry picked from commit 757bab06fb59abca8b7fda38e8f546ff7c2d3280) --- 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); }