From owner-dev-commits-src-main@freebsd.org Mon May 3 16:20:40 2021 Return-Path: Delivered-To: dev-commits-src-main@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 6FE486366EE; Mon, 3 May 2021 16:20:40 +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 4FYp9g6ZMbz3DNY; Mon, 3 May 2021 16:20:39 +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 CB6AF21316; Mon, 3 May 2021 16:20:39 +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 143GKdTw022237; Mon, 3 May 2021 16:20:39 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 143GKdDt022236; Mon, 3 May 2021 16:20:39 GMT (envelope-from git) Date: Mon, 3 May 2021 16:20:39 GMT Message-Id: <202105031620.143GKdDt022236@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Konstantin Belousov Subject: git: 15465a2c25cc - main - Add sleepq_remove_nested() 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/main X-Git-Reftype: branch X-Git-Commit: 15465a2c25cc2915e8c7c65178805b10e339dde3 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-main@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for the main branch of the src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 03 May 2021 16:20:40 -0000 The branch main has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=15465a2c25cc2915e8c7c65178805b10e339dde3 commit 15465a2c25cc2915e8c7c65178805b10e339dde3 Author: Konstantin Belousov AuthorDate: 2021-04-25 00:01:32 +0000 Commit: Konstantin Belousov CommitDate: 2021-05-03 16:13:47 +0000 Add sleepq_remove_nested() The helper removes the thread from a sleep queue, assuming that it would need to sleep. The sleepq_remove_nested() function is intended for quite special case, where suspended thread from traced stopped process is temporary unsuspended to do some work on behalf of the debugger in the target context, and this work might require sleep. Reviewed by: markj Tested by: pho Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D29955 --- sys/kern/subr_sleepqueue.c | 20 ++++++++++++++++++++ sys/sys/sleepqueue.h | 1 + 2 files changed, 21 insertions(+) diff --git a/sys/kern/subr_sleepqueue.c b/sys/kern/subr_sleepqueue.c index 20ca455480b5..0718f01fa48a 100644 --- a/sys/kern/subr_sleepqueue.c +++ b/sys/kern/subr_sleepqueue.c @@ -854,6 +854,26 @@ sleepq_remove_thread(struct sleepqueue *sq, struct thread *td) (void *)td, (long)td->td_proc->p_pid, td->td_name); } +void +sleepq_remove_nested(struct thread *td) +{ + struct sleepqueue_chain *sc; + struct sleepqueue *sq; + const void *wchan; + + MPASS(TD_ON_SLEEPQ(td)); + + wchan = td->td_wchan; + sc = SC_LOOKUP(wchan); + mtx_lock_spin(&sc->sc_lock); + sq = sleepq_lookup(wchan); + MPASS(sq != NULL); + thread_lock(td); + sleepq_remove_thread(sq, td); + mtx_unlock_spin(&sc->sc_lock); + /* Returns with the thread lock owned. */ +} + #ifdef INVARIANTS /* * UMA zone item deallocator. diff --git a/sys/sys/sleepqueue.h b/sys/sys/sleepqueue.h index ba2f85f2c8a1..18c7568777b6 100644 --- a/sys/sys/sleepqueue.h +++ b/sys/sys/sleepqueue.h @@ -100,6 +100,7 @@ void sleepq_release(const void *wchan); void sleepq_remove(struct thread *td, const void *wchan); int sleepq_remove_matching(struct sleepqueue *sq, int queue, bool (*matches)(struct thread *), int pri); +void sleepq_remove_nested(struct thread *td); int sleepq_signal(const void *wchan, int flags, int pri, int queue); void sleepq_set_timeout_sbt(const void *wchan, sbintime_t sbt, sbintime_t pr, int flags);