Source-Changes-HG archive

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

[src/trunk]: src/sys/sys Avoid false sharing: only update spc_curpriority if ...



details:   https://anonhg.NetBSD.org/src/rev/950d9ae14959
branches:  trunk
changeset: 465630:950d9ae14959
user:      ad <ad%NetBSD.org@localhost>
date:      Sat Nov 30 17:49:03 2019 +0000

description:
Avoid false sharing: only update spc_curpriority if value has changed.

diffstat:

 sys/sys/userret.h |  12 +++++++++---
 1 files changed, 9 insertions(+), 3 deletions(-)

diffs (32 lines):

diff -r d829019bf03a -r 950d9ae14959 sys/sys/userret.h
--- a/sys/sys/userret.h Sat Nov 30 17:46:27 2019 +0000
+++ b/sys/sys/userret.h Sat Nov 30 17:49:03 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: userret.h,v 1.30 2019/11/22 23:38:15 ad Exp $  */
+/*     $NetBSD: userret.h,v 1.31 2019/11/30 17:49:03 ad Exp $  */
 
 /*-
  * Copyright (c) 1998, 2000, 2003, 2006, 2008, 2019 The NetBSD Foundation, Inc.
@@ -100,14 +100,20 @@
                KPREEMPT_DISABLE(l);
                ci = l->l_cpu;
        }
-       l->l_kpriority = false;
        /*
         * lwp_eprio() is too involved to use here unlocked.  At this point
         * it only matters for PTHREAD_PRIO_PROTECT; setting a too low value
         * is OK because the scheduler will find out the true value if we
         * end up in mi_switch().
+        *
+        * This is being called on every syscall and trap, and remote CPUs
+        * regularly look at ci_schedstate.  Keep the cache line in the
+        * SHARED state by only updating spc_curpriority if it has changed.
         */
-       ci->ci_schedstate.spc_curpriority = l->l_priority;
+       l->l_kpriority = false;
+       if (ci->ci_schedstate.spc_curpriority != l->l_priority) {
+               ci->ci_schedstate.spc_curpriority = l->l_priority;
+       }
        KPREEMPT_ENABLE(l);
 
        LOCKDEBUG_BARRIER(NULL, 0);



Home | Main Index | Thread Index | Old Index