Go to file
riastradh 53ecfc3aad Restore xcall(9) fast path using atomic_load/store_*.
While here, fix a bug that was formerly in xcall(9): a missing
acquire operation in the xc_wait fast path so that all memory
operations in the xcall on remote CPUs will happen before any memory
operations on the issuing CPU after xc_wait returns.

All stores of xc->xc_donep are done with atomic_store_release so that
we can safely use atomic_load_acquire to read it outside the lock.
However, this fast path only works on platforms with cheap 64-bit
atomic load/store, so conditionalize it on __HAVE_ATOMIC64_LOADSTORE.
(Under the lock, no need for atomic loads since nobody else will be
issuing stores.)

For review, here's the relevant diff from the old version of the fast
path, from before it was removed and some other things changed in the
file:

diff --git a/sys/kern/subr_xcall.c b/sys/kern/subr_xcall.c
index 45a877aa90e0..b6bfb6455291 100644
--- a/sys/kern/subr_xcall.c
+++ b/sys/kern/subr_xcall.c
@@ -84,6 +84,7 @@ __KERNEL_RCSID(0, "$NetBSD: subr_xcall.c,v 1.27 2019/10/06 15:11:17 uwe Exp $");
 #include <sys/evcnt.h>
 #include <sys/kthread.h>
 #include <sys/cpu.h>
+#include <sys/atomic.h>

 #ifdef _RUMPKERNEL
 #include "rump_private.h"
@@ -334,10 +353,12 @@ xc_wait(uint64_t where)
 		xc = &xc_low_pri;
 	}

+#ifdef __HAVE_ATOMIC64_LOADSTORE
 	/* Fast path, if already done. */
-	if (xc->xc_donep >= where) {
+	if (atomic_load_acquire(&xc->xc_donep) >= where) {
 		return;
 	}
+#endif

 	/* Slow path: block until awoken. */
 	mutex_enter(&xc->xc_lock);
@@ -422,7 +443,11 @@ xc_thread(void *cookie)
 		(*func)(arg1, arg2);

 		mutex_enter(&xc->xc_lock);
+#ifdef __HAVE_ATOMIC64_LOADSTORE
+		atomic_store_release(&xc->xc_donep, xc->xc_donep + 1);
+#else
 		xc->xc_donep++;
+#endif
 	}
 	/* NOTREACHED */
 }
@@ -462,7 +487,6 @@ xc__highpri_intr(void *dummy)
 	 * Lock-less fetch of function and its arguments.
 	 * Safe since it cannot change at this point.
 	 */
-	KASSERT(xc->xc_donep < xc->xc_headp);
 	func = xc->xc_func;
 	arg1 = xc->xc_arg1;
 	arg2 = xc->xc_arg2;
@@ -475,7 +499,13 @@ xc__highpri_intr(void *dummy)
 	 * cross-call has been processed - notify waiters, if any.
 	 */
 	mutex_enter(&xc->xc_lock);
-	if (++xc->xc_donep == xc->xc_headp) {
+	KASSERT(xc->xc_donep < xc->xc_headp);
+#ifdef __HAVE_ATOMIC64_LOADSTORE
+	atomic_store_release(&xc->xc_donep, xc->xc_donep + 1);
+#else
+	xc->xc_donep++;
+#endif
+	if (xc->xc_donep == xc->xc_headp) {
 		cv_broadcast(&xc->xc_busy);
 	}
 	mutex_exit(&xc->xc_lock);
2019-12-01 20:56:39 +00:00
bin Avoid arithmetics on strings. 2019-10-29 16:19:59 +00:00
common Make it easier to use strtoi and strtou in downsteam applications 2019-11-28 12:33:23 +00:00
compat 1. All Makefiles that use ARM_APCS_FLAGS add -marm unconditionally and 2019-10-24 18:46:20 +00:00
crypto Update LLVM to 10.0.0git (01f3a59fb3e2542fce74c768718f594d0debd0da) 2019-11-11 22:44:56 +00:00
dist/pf grammar 2019-09-21 19:48:15 +00:00
distrib Remove the pretty much useless 128MB swap partition from the arm images. 2019-12-01 15:07:04 +00:00
doc new terminfo 2019-11-27 19:04:45 +00:00
etc Document NETBSD_OFFICIAL_RELEASE and add it to /etc/release - it is 2019-11-22 13:30:19 +00:00
external Need sys/atomic.h on NetBSD 2019-12-01 20:26:31 +00:00
extsrc
games https://twitter.com/sei6r/status/1182433546331279360 2019-11-10 22:42:21 +00:00
include Switch the iconv(3) prototype to the POSIX conformant variation 2019-10-24 18:17:14 +00:00
lib Fix PR/54074 and PR/54093 completely. 2019-11-21 23:06:15 +00:00
libexec Use alignof and not size_t for platforms with non-natural base 2019-11-05 22:22:42 +00:00
regress Redo previous differently. 2019-11-23 20:37:49 +00:00
rescue Remove ldconfig from /rescue, and mark it MI obsolete. 2019-10-02 09:45:10 +00:00
sbin Sort options and SEE ALSO. Improve a sentence. 2019-11-20 21:56:19 +00:00
share Enable ZFS support on aarch64 2019-12-01 20:28:25 +00:00
sys Restore xcall(9) fast path using atomic_load/store_*. 2019-12-01 20:56:39 +00:00
tests Adapt <sys/pslist.h> to use atomic_load/store_*. 2019-12-01 15:28:19 +00:00
tools Update LLVM to 10.0.0git (01f3a59fb3e2542fce74c768718f594d0debd0da) 2019-11-11 22:44:56 +00:00
usr.bin Sort 2019-11-30 12:04:13 +00:00
usr.sbin Update to match change in layout of vnode LRU lists. 2019-12-01 14:04:52 +00:00
build.sh
BUILDING
Makefile
Makefile.inc
README.md
UPDATING catch-up with more ports switched to gcc-8 2019-11-18 15:42:26 +00:00

NetBSD

NetBSD is a free, fast, secure, and highly portable Unix-like Open Source operating system. It is available for a wide range of platforms, from large-scale servers and powerful desktop systems to handheld and embedded devices.

Building

You can cross-build NetBSD from most UNIX-like operating systems. To build for amd64 (x86_64), in the src directory:

./build.sh -U -u -j4 -m amd64 -O ~/obj release

Additional build information available in the BUILDING file.

Binaries

Testing

On a running NetBSD system:

cd /usr/tests; atf-run | atf-report

Troubleshooting

Latest sources

To fetch the main CVS repository:

cvs -d anoncvs@anoncvs.NetBSD.org:/cvsroot checkout -P src

To work in the Git mirror, which is updated every few hours from CVS:

git clone https://github.com/NetBSD/src.git