Module Name: src
Committed By: ozaki-r
Date: Thu Jun 16 02:34:33 UTC 2016
Modified Files:
src/sys/sys: lwp.h
Log Message:
Introduce curlwp_bind and curlwp_bindx
The API prevents the current LWP from migrating between CPUs during
the critical section (between curlwp_bind and curlwp_bindx). One use
case of it is psref(9) that has a contract that forbids such migrations.
Proposed at http://mail-index.netbsd.org/tech-kern/2016/06/13/msg020710.html
(check it out if you want to know why the function names are chosen)
To generate a diff of this commit:
cvs rdiff -u -r1.170 -r1.171 src/sys/sys/lwp.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/lwp.h
diff -u src/sys/sys/lwp.h:1.170 src/sys/sys/lwp.h:1.171
--- src/sys/sys/lwp.h:1.170 Tue Mar 31 01:10:02 2015
+++ src/sys/sys/lwp.h Thu Jun 16 02:34:33 2016
@@ -1,4 +1,4 @@
-/* $NetBSD: lwp.h,v 1.170 2015/03/31 01:10:02 matt Exp $ */
+/* $NetBSD: lwp.h,v 1.171 2016/06/16 02:34:33 ozaki-r Exp $ */
/*-
* Copyright (c) 2001, 2006, 2007, 2008, 2009, 2010
@@ -521,6 +521,28 @@ KPREEMPT_ENABLE(lwp_t *l)
#define DOPREEMPT_ACTIVE 0x01
#define DOPREEMPT_COUNTED 0x02
+/*
+ * Prevent curlwp from migrating between CPUs beteen curlwp_bind and
+ * curlwp_bindx. One use case is psref(9) that has a contract that
+ * forbids migrations.
+ */
+static inline int
+curlwp_bind(void)
+{
+ int bound;
+
+ bound = curlwp->l_pflag & LP_BOUND;
+ curlwp->l_pflag |= LP_BOUND;
+
+ return bound;
+}
+
+static inline void
+curlwp_bindx(int bound)
+{
+ curlwp->l_pflag ^= bound ^ LP_BOUND;
+}
+
#endif /* _KERNEL */
/* Flags for _lwp_create(), as per Solaris. */