Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 5 Aug 2021 22:51:57 GMT
From:      Andrew Gallatin <gallatin@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: 1b97a054f3ac - main - tsleep: Add a PNOLOCK flag
Message-ID:  <202108052251.175MpvX7090849@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by gallatin:

URL: https://cgit.FreeBSD.org/src/commit/?id=1b97a054f3acaf13a5c8361b7b80e10ad16257b9

commit 1b97a054f3acaf13a5c8361b7b80e10ad16257b9
Author:     Andrew Gallatin <gallatin@FreeBSD.org>
AuthorDate: 2021-08-05 21:16:30 +0000
Commit:     Andrew Gallatin <gallatin@FreeBSD.org>
CommitDate: 2021-08-05 21:16:30 +0000

    tsleep: Add a PNOLOCK flag
    
    Add a PNOLOCK flag so that, in the race circumstance where
    wakeup races are externally mitigated, tsleep() can be
    called with a sleep time of 0 without triggering an
    an assertion.
    
    Reviewed by: jhb
    Sponsored by: Netflix
---
 sys/kern/kern_synch.c | 3 ++-
 sys/sys/param.h       | 3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/sys/kern/kern_synch.c b/sys/kern/kern_synch.c
index 793c5309a30b..7bf5193fb7b1 100644
--- a/sys/kern/kern_synch.c
+++ b/sys/kern/kern_synch.c
@@ -148,7 +148,8 @@ _sleep(const void *ident, struct lock_object *lock, int priority,
 #endif
 	WITNESS_WARN(WARN_GIANTOK | WARN_SLEEPOK, lock,
 	    "Sleeping on \"%s\"", wmesg);
-	KASSERT(sbt != 0 || mtx_owned(&Giant) || lock != NULL,
+	KASSERT(sbt != 0 || mtx_owned(&Giant) || lock != NULL ||
+	    (priority & PNOLOCK) != 0,
 	    ("sleeping without a lock"));
 	KASSERT(ident != NULL, ("_sleep: NULL ident"));
 	KASSERT(TD_IS_RUNNING(td), ("_sleep: curthread not running"));
diff --git a/sys/sys/param.h b/sys/sys/param.h
index f842b344e9f9..8864063e3d9b 100644
--- a/sys/sys/param.h
+++ b/sys/sys/param.h
@@ -246,7 +246,8 @@
 #define	PRIMASK		0x0ff
 #define	PCATCH		0x100	/* OR'd with pri for tsleep to check signals */
 #define	PDROP		0x200	/* OR'd with pri to stop re-entry of interlock mutex */
-#define	PRILASTFLAG	0x200	/* Last flag defined above */
+#define	PNOLOCK		0x400	/* OR'd with pri to allow sleeping w/o a lock */
+#define	PRILASTFLAG	0x400	/* Last flag defined above */
 
 #define	NZERO	0		/* default "nice" */
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202108052251.175MpvX7090849>