Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/kern pserialize(9): Fix bug in recent micro-optimization.



details:   https://anonhg.NetBSD.org/src/rev/78585bf86d7d
branches:  trunk
changeset: 374251:78585bf86d7d
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Fri Apr 14 16:51:46 2023 +0000

description:
pserialize(9): Fix bug in recent micro-optimization.

curcpu() is always a valid struct cpu_info pointer, but curlwp->l_cpu
is not necessarily -- early at boot on some architectures (like x86,
apparently) it may be null.

Not clear that l->l_cpu is always a cost win over curcpu(): on some
architectures curcpu() is basically a macro for curlwp->l_cpu, while
on others it is a fixed VA.  So let's use the one that always works
instead of the one that's sometimes cheaper and sometimes crashier.

diffstat:

 sys/kern/subr_pserialize.c |  6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diffs (27 lines):

diff -r 6c7006f3cc2e -r 78585bf86d7d sys/kern/subr_pserialize.c
--- a/sys/kern/subr_pserialize.c        Thu Apr 13 13:07:48 2023 +0000
+++ b/sys/kern/subr_pserialize.c        Fri Apr 14 16:51:46 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: subr_pserialize.c,v 1.21 2023/04/09 08:28:24 riastradh Exp $   */
+/*     $NetBSD: subr_pserialize.c,v 1.22 2023/04/14 16:51:46 riastradh Exp $   */
 
 /*-
  * Copyright (c) 2010, 2011 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: subr_pserialize.c,v 1.21 2023/04/09 08:28:24 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_pserialize.c,v 1.22 2023/04/14 16:51:46 riastradh Exp $");
 
 #include <sys/param.h>
 
@@ -180,7 +180,7 @@ pserialize_not_in_read_section(void)
 
        ncsw = l->l_ncsw;
        __insn_barrier();
-       notin = __predict_true(l->l_cpu->ci_psz_read_depth == 0);
+       notin = __predict_true(curcpu()->ci_psz_read_depth == 0);
        __insn_barrier();
 
        /*



Home | Main Index | Thread Index | Old Index