Module Name: src
Committed By: ad
Date: Sun Oct 8 11:12:47 UTC 2023
Modified Files:
src/sys/kern: kern_sleepq.c
Log Message:
sleepq_block(): slightly reduce number of test+branch in the common case.
To generate a diff of this commit:
cvs rdiff -u -r1.80 -r1.81 src/sys/kern/kern_sleepq.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/kern/kern_sleepq.c
diff -u src/sys/kern/kern_sleepq.c:1.80 src/sys/kern/kern_sleepq.c:1.81
--- src/sys/kern/kern_sleepq.c:1.80 Sat Oct 7 20:48:50 2023
+++ src/sys/kern/kern_sleepq.c Sun Oct 8 11:12:47 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: kern_sleepq.c,v 1.80 2023/10/07 20:48:50 ad Exp $ */
+/* $NetBSD: kern_sleepq.c,v 1.81 2023/10/08 11:12:47 ad Exp $ */
/*-
* Copyright (c) 2006, 2007, 2008, 2009, 2019, 2020, 2023
@@ -36,7 +36,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_sleepq.c,v 1.80 2023/10/07 20:48:50 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_sleepq.c,v 1.81 2023/10/08 11:12:47 ad Exp $");
#include <sys/param.h>
#include <sys/kernel.h>
@@ -334,7 +334,8 @@ sleepq_uncatch(lwp_t *l)
int
sleepq_block(int timo, bool catch_p, syncobj_t *syncobj, int nlocks)
{
- int error = 0, sig;
+ const int mask = LW_CANCELLED|LW_WEXIT|LW_WCORE|LW_PENDSIG;
+ int error = 0, sig, flag;
struct proc *p;
lwp_t *l = curlwp;
bool early = false;
@@ -406,11 +407,14 @@ sleepq_block(int timo, bool catch_p, syn
* considering it is only meaningful here inside this function,
* and is set to reflect intent upon entry.
*/
- if ((l->l_flag & LW_CATCHINTR) != 0 && error == 0) {
+ flag = atomic_load_relaxed(&l->l_flag);
+ if (__predict_false((flag & mask) != 0)) {
p = l->l_proc;
- if ((l->l_flag & (LW_CANCELLED | LW_WEXIT | LW_WCORE)) != 0)
+ if ((flag & LW_CATCHINTR) == 0 && error != 0)
+ /* nothing */;
+ else if ((flag & (LW_CANCELLED | LW_WEXIT | LW_WCORE)) != 0)
error = EINTR;
- else if ((l->l_flag & LW_PENDSIG) != 0) {
+ else if ((flag & LW_PENDSIG) != 0) {
/*
* Acquiring p_lock may cause us to recurse
* through the sleep path and back into this