Module Name:    src
Committed By:   ad
Date:           Sat Nov 30 17:49:03 UTC 2019

Modified Files:
        src/sys/sys: userret.h

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


To generate a diff of this commit:
cvs rdiff -u -r1.30 -r1.31 src/sys/sys/userret.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/sys/userret.h
diff -u src/sys/sys/userret.h:1.30 src/sys/sys/userret.h:1.31
--- src/sys/sys/userret.h:1.30	Fri Nov 22 23:38:15 2019
+++ src/sys/sys/userret.h	Sat Nov 30 17:49:03 2019
@@ -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 @@ mi_userret(struct lwp *l)
 		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);

Reply via email to