From nobody Wed May 4 22:33:25 2022 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 857341AAAFB2; Wed, 4 May 2022 22:33:26 +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 "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Kts6s5zxBz4gVS; Wed, 4 May 2022 22:33:25 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1651703605; 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=bDbgNJRw9TWz7/bcYB8habgZ9diiZvQAgtkmpZY0jKI=; b=Zd6U6x6nuLiTUMAwEQBXm6DSbTlxgruYR3lKMjEOg+ASfq4zRdhVIYdJWi0EYo+kEaykUC LLJz12Sg+TbFWoV+GI/nsURjqrWUgbtTAYcBqsLESmHRCTVoNmnZLqr2dB/TppQMuwf1jd f91oJAue5wDxkLO3oaV+QTr5bRL9EMSSxBDjSNVV4ZFp85G34wosChLLQ1DRtTlYmURzF+ hcebxzh81mK6Kfn9gAvwmzbvuzfTKoCjRl7JLQdOc7EHkedoNgQ36tP1U4RoRN79mkolj1 MqhtHujkt0N0rWvUWmnOrC18wonKbycZl/p8kkuB280iA4ny6zCLUAWBbzsfFw== 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 ABA8A1B5CE; Wed, 4 May 2022 22:33:25 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 244MXP9R015091; Wed, 4 May 2022 22:33:25 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 244MXPhn015090; Wed, 4 May 2022 22:33:25 GMT (envelope-from git) Date: Wed, 4 May 2022 22:33:25 GMT Message-Id: <202205042233.244MXPhn015090@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Konstantin Belousov Subject: git: 3bf38618ee3f - stable/13 - unr(9): allow to avoid internal locking 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: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kib X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 3bf38618ee3ff8068d983f249311f473c864e421 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1651703605; 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=bDbgNJRw9TWz7/bcYB8habgZ9diiZvQAgtkmpZY0jKI=; b=fjh+pshf3jphnodg5O6wx53aO1FeND0bm3wMCnVgJIJYArKzwhHNRWiX9q3qHKZk8WPque lCd4nOjXvbb9AT/Jqtx+Za+M7s9h2OAwE8W8xe058fy6lzJIx/WayLH5RPh0Prff8kpTgw qQ3jBdDv3gnaJzVwn+icxHCRUOSMyTULa+KJZLfkSoFGifDJWYI1oMRGsct3D4kp5Y9HDM n/g4hC6gZdyFmbbYz9vthnDFZOWF1eGYmNQBozS0geWDcRQPneQcXpWwIi7cxVmtUssjZW bh/Yga+lTUYh0R9V+VZEI5mTUM+UYTlUwbJ2iZSU8jgsEU31JcEUZJ182+6Pug== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1651703605; a=rsa-sha256; cv=none; b=vo6nyCh3ZUgXpwm59g8Ia5PCWE6ezd/LzspmG2kJctscvJFRq9nFz7WxfAms2jWs9tavhr In9qBNgAfkuEz2kghzZvSbZdcTQAwa69v+sE+S03CM6pRssYZsU1V/ZSmkkvJXHk4Ufh6D zqT6pakHmunUgGeAN4/eQcw00iD1bPONnMlrzF/UnYecS9dq7YTZU1UeKZ18QgEI6ddv0o qCa5dsc7mDurNhqwTL3wvkLxI3kTdvgX/SnS+j34CJWqDevdsSb9laLreJpNUE/ZqfQMEf piD72xauXGFwYjKb3uomPx5A3GQ0B8sDgR6hJtazWeCIi7PLRV3zpXYsdjdttA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=3bf38618ee3ff8068d983f249311f473c864e421 commit 3bf38618ee3ff8068d983f249311f473c864e421 Author: Konstantin Belousov AuthorDate: 2022-04-20 22:14:37 +0000 Commit: Konstantin Belousov CommitDate: 2022-05-04 22:33:05 +0000 unr(9): allow to avoid internal locking (cherry picked from commit e59b940dcb45b887974aeae8d8f86665aed2c913) --- share/man/man9/unr.9 | 5 ++++- sys/kern/subr_unit.c | 43 +++++++++++++++++++++++++++++-------------- sys/sys/systm.h | 1 + 3 files changed, 34 insertions(+), 15 deletions(-) diff --git a/share/man/man9/unr.9 b/share/man/man9/unr.9 index fe1299d40e5d..c2e9b3943829 100644 --- a/share/man/man9/unr.9 +++ b/share/man/man9/unr.9 @@ -24,7 +24,7 @@ .\" .\" $FreeBSD$ .\" -.Dd October 4, 2017 +.Dd April 21, 2022 .Dt UNR 9 .Os .Sh NAME @@ -72,6 +72,9 @@ If is not .Dv NULL , it is used for locking when allocating and freeing units. +If the passed value is the token +.Va UNR_NO_MTX , +then no locking is applied internally. Otherwise, internal mutex is used. .It Fn clear_unrhdr uh Clear all units from the specified unit number allocator entity. diff --git a/sys/kern/subr_unit.c b/sys/kern/subr_unit.c index 9ca67bcfe7a2..66314887ac39 100644 --- a/sys/kern/subr_unit.c +++ b/sys/kern/subr_unit.c @@ -312,12 +312,15 @@ clean_unrhdrl(struct unrhdr *uh) { struct unr *up; - mtx_assert(uh->mtx, MA_OWNED); + if (uh->mtx != NULL) + mtx_assert(uh->mtx, MA_OWNED); while ((up = TAILQ_FIRST(&uh->ppfree)) != NULL) { TAILQ_REMOVE(&uh->ppfree, up, list); - mtx_unlock(uh->mtx); + if (uh->mtx != NULL) + mtx_unlock(uh->mtx); Free(up); - mtx_lock(uh->mtx); + if (uh->mtx != NULL) + mtx_lock(uh->mtx); } } @@ -326,9 +329,11 @@ void clean_unrhdr(struct unrhdr *uh) { - mtx_lock(uh->mtx); + if (uh->mtx != NULL) + mtx_lock(uh->mtx); clean_unrhdrl(uh); - mtx_unlock(uh->mtx); + if (uh->mtx != NULL) + mtx_unlock(uh->mtx); } void @@ -337,7 +342,9 @@ init_unrhdr(struct unrhdr *uh, int low, int high, struct mtx *mutex) KASSERT(low >= 0 && low <= high, ("UNR: use error: new_unrhdr(%d, %d)", low, high)); - if (mutex != NULL) + if (mutex == UNR_NO_MTX) + uh->mtx = NULL; + else if (mutex != NULL) uh->mtx = mutex; else uh->mtx = &unitmtx; @@ -608,7 +615,8 @@ alloc_unrl(struct unrhdr *uh) u_int x; int y; - mtx_assert(uh->mtx, MA_OWNED); + if (uh->mtx != NULL) + mtx_assert(uh->mtx, MA_OWNED); check_unrhdr(uh, __LINE__); x = uh->low + uh->first; @@ -653,10 +661,12 @@ alloc_unr(struct unrhdr *uh) { int i; - mtx_lock(uh->mtx); + if (uh->mtx != NULL) + mtx_lock(uh->mtx); i = alloc_unrl(uh); clean_unrhdrl(uh); - mtx_unlock(uh->mtx); + if (uh->mtx != NULL) + mtx_unlock(uh->mtx); return (i); } @@ -667,7 +677,8 @@ alloc_unr_specificl(struct unrhdr *uh, u_int item, void **p1, void **p2) struct unrb *ub; u_int i, last, tl; - mtx_assert(uh->mtx, MA_OWNED); + if (uh->mtx != NULL) + mtx_assert(uh->mtx, MA_OWNED); if (item < uh->low + uh->first || item > uh->high) return (-1); @@ -773,9 +784,11 @@ alloc_unr_specific(struct unrhdr *uh, u_int item) p1 = Malloc(sizeof(struct unr)); p2 = Malloc(sizeof(struct unr)); - mtx_lock(uh->mtx); + if (uh->mtx != NULL) + mtx_lock(uh->mtx); i = alloc_unr_specificl(uh, item, &p1, &p2); - mtx_unlock(uh->mtx); + if (uh->mtx != NULL) + mtx_unlock(uh->mtx); if (p1 != NULL) Free(p1); @@ -906,10 +919,12 @@ free_unr(struct unrhdr *uh, u_int item) WITNESS_WARN(WARN_GIANTOK | WARN_SLEEPOK, NULL, "free_unr"); p1 = Malloc(sizeof(struct unr)); p2 = Malloc(sizeof(struct unr)); - mtx_lock(uh->mtx); + if (uh->mtx != NULL) + mtx_lock(uh->mtx); free_unrl(uh, item, &p1, &p2); clean_unrhdrl(uh); - mtx_unlock(uh->mtx); + if (uh->mtx != NULL) + mtx_unlock(uh->mtx); if (p1 != NULL) Free(p1); if (p2 != NULL) diff --git a/sys/sys/systm.h b/sys/sys/systm.h index cf13c16f8b4a..e2e4a30275e9 100644 --- a/sys/sys/systm.h +++ b/sys/sys/systm.h @@ -477,6 +477,7 @@ int root_mounted(void); * Unit number allocation API. (kern/subr_unit.c) */ struct unrhdr; +#define UNR_NO_MTX ((void *)(uintptr_t)-1) struct unrhdr *new_unrhdr(int low, int high, struct mtx *mutex); void init_unrhdr(struct unrhdr *uh, int low, int high, struct mtx *mutex); void delete_unrhdr(struct unrhdr *uh);