From owner-dev-commits-src-all@freebsd.org Thu Jul 29 09:46:10 2021 Return-Path: Delivered-To: dev-commits-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 1F6A066FED5; Thu, 29 Jul 2021 09:46:10 +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 4Gb5JK73WFz3sK7; Thu, 29 Jul 2021 09:46:09 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 D7274726A; Thu, 29 Jul 2021 09:46:09 +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 16T9k9bC056797; Thu, 29 Jul 2021 09:46:09 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 16T9k9d6056796; Thu, 29 Jul 2021 09:46:09 GMT (envelope-from git) Date: Thu, 29 Jul 2021 09:46:09 GMT Message-Id: <202107290946.16T9k9d6056796@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Dmitry Chagin Subject: git: 7caa29115b4a - main - umtx: Add bitset conditional wakeup functionality. MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: dchagin X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 7caa29115b4a2023128ed07942b71074507a44a1 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-all@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for all branches of the src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 29 Jul 2021 09:46:10 -0000 The branch main has been updated by dchagin: URL: https://cgit.FreeBSD.org/src/commit/?id=7caa29115b4a2023128ed07942b71074507a44a1 commit 7caa29115b4a2023128ed07942b71074507a44a1 Author: Dmitry Chagin AuthorDate: 2021-07-29 09:42:49 +0000 Commit: Dmitry Chagin CommitDate: 2021-07-29 09:42:49 +0000 umtx: Add bitset conditional wakeup functionality. The bitset is a Linux emulation layer extension. This 32-bit mask, in which at least one bit must be set, is used to select which threads should be woken up. The bitset is stored in the umtx_q structure, which is used to enqueue the waiter into the umtx waitqueue. Put the bitset into the hole, that appeared on LP64 due to data alignment, to prevent the growth of the struct umtx_q. Reviewed by: kib Differential Revision: https://reviews.freebsd.org/D31234 MFC after: 2 weeks --- sys/kern/kern_umtx.c | 26 ++++++++++++++++++++++++++ sys/sys/umtxvar.h | 4 ++++ 2 files changed, 30 insertions(+) diff --git a/sys/kern/kern_umtx.c b/sys/kern/kern_umtx.c index ae80554cbbb8..d869d5870000 100644 --- a/sys/kern/kern_umtx.c +++ b/sys/kern/kern_umtx.c @@ -558,6 +558,32 @@ umtxq_count_pi(struct umtx_key *key, struct umtx_q **first) return (0); } +/* + * Wake up threads waiting on an userland object by a bit mask. + */ +int +umtxq_signal_mask(struct umtx_key *key, int n_wake, u_int bitset) +{ + struct umtxq_queue *uh; + struct umtx_q *uq, *uq_temp; + int ret; + + ret = 0; + UMTXQ_LOCKED_ASSERT(umtxq_getchain(key)); + uh = umtxq_queue_lookup(key, UMTX_SHARED_QUEUE); + if (uh == NULL) + return (0); + TAILQ_FOREACH_SAFE(uq, &uh->head, uq_link, uq_temp) { + if ((uq->uq_bitset & bitset) == 0) + continue; + umtxq_remove_queue(uq, UMTX_SHARED_QUEUE); + wakeup_one(uq); + if (++ret >= n_wake) + break; + } + return (ret); +} + /* * Wake up threads waiting on an userland object. */ diff --git a/sys/sys/umtxvar.h b/sys/sys/umtxvar.h index 68f261fe6abf..de1b649ed8d7 100644 --- a/sys/sys/umtxvar.h +++ b/sys/sys/umtxvar.h @@ -120,6 +120,9 @@ struct umtx_q { int uq_flags; #define UQF_UMTXQ 0x0001 + /* Futex bitset mask */ + u_int uq_bitset; + /* The thread waits on. */ struct thread *uq_thread; @@ -207,6 +210,7 @@ void umtxq_free(struct umtx_q *); struct umtxq_chain *umtxq_getchain(struct umtx_key *); void umtxq_insert_queue(struct umtx_q *, int); void umtxq_remove_queue(struct umtx_q *, int); +int umtxq_signal_mask(struct umtx_key *, int, u_int); int umtxq_sleep(struct umtx_q *, const char *, struct umtx_abs_timeout *); void umtxq_unbusy(struct umtx_key *);