Source-Changes-HG archive

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

[src/trunk]: src/sys/rump/librump/rumpkern Add a lockless uniprocessor versio...



details:   https://anonhg.NetBSD.org/src/rev/ff8e66e46dbc
branches:  trunk
changeset: 758938:ff8e66e46dbc
user:      pooka <pooka%NetBSD.org@localhost>
date:      Sun Nov 21 21:46:43 2010 +0000

description:
Add a lockless uniprocessor version of atomic_cas_generic.c, which
is currently used by all the archs that previously used cas_generic.

diffstat:

 sys/rump/librump/rumpkern/Makefile.rumpkern |   8 ++-
 sys/rump/librump/rumpkern/atomic_cas_up.c   |  60 +++++++++++++++++++++++++++++
 2 files changed, 65 insertions(+), 3 deletions(-)

diffs (91 lines):

diff -r 54dcbf4d2a9b -r ff8e66e46dbc sys/rump/librump/rumpkern/Makefile.rumpkern
--- a/sys/rump/librump/rumpkern/Makefile.rumpkern       Sun Nov 21 21:07:46 2010 +0000
+++ b/sys/rump/librump/rumpkern/Makefile.rumpkern       Sun Nov 21 21:46:43 2010 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile.rumpkern,v 1.99 2010/11/21 17:34:11 pooka Exp $
+#      $NetBSD: Makefile.rumpkern,v 1.100 2010/11/21 21:46:43 pooka Exp $
 #
 
 .include "${RUMPTOP}/Makefile.rump"
@@ -167,13 +167,15 @@
 # Some architectures require a little special massage with atomic
 # compare-and-swap.  This is because the kernel version is using
 # instructions or routines unavailable to us in userspace.  We
-# use effectively the multiprocessor version of the userspace ops.
+# use a very simple CAS routine which (correctly) assumes non-SMP
+# and no preemption.  If some of these archs later develop MP
+# support, switch them to use atomic_cas_generic.c
 #
 .if ${MACHINE_CPU} == "arm" || ${MACHINE_CPU} == "hppa" \
     || ${MACHINE_CPU} == "mips" || ${MACHINE_CPU} == "sh3" \
     || ${MACHINE_CPU} == "vax" || ${MACHINE_ARCH} == "m68000"
 CPPFLAGS+=     -I${RUMPTOP}/../../common/lib/libc/atomic
-SRCS+=         atomic_cas_generic.c
+SRCS+=         atomic_cas_up.c
 .endif
 
 .include <bsd.lib.mk>
diff -r 54dcbf4d2a9b -r ff8e66e46dbc sys/rump/librump/rumpkern/atomic_cas_up.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/rump/librump/rumpkern/atomic_cas_up.c Sun Nov 21 21:46:43 2010 +0000
@@ -0,0 +1,60 @@
+/*     $NetBSD: atomic_cas_up.c,v 1.1 2010/11/21 21:46:43 pooka Exp $  */
+
+/*-
+ * Copyright (c) 2010 Antti Kantee.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: atomic_cas_up.c,v 1.1 2010/11/21 21:46:43 pooka Exp $");
+
+/*
+ * Uniprocessor version of atomic CAS.  Since there is no preemption
+ * in rump, this is a piece of cake.
+ */
+
+#include <sys/types.h>
+
+uint32_t rumpup_cas_32_up(volatile uint32_t *ptr, uint32_t, uint32_t);
+
+uint32_t
+rumpup_cas_32_up(volatile uint32_t *ptr, uint32_t old, uint32_t new)
+{
+       uint32_t ret;
+
+       ret = *ptr;
+       if (__predict_true(ret == old)) {
+               *ptr = new;
+       }
+
+       return ret;
+}
+
+__strong_alias(atomic_cas_32,rumpup_cas_32_up)
+__strong_alias(atomic_cas_uint,rumpup_cas_32_up)
+__strong_alias(atomic_cas_ulong,rumpup_cas_32_up)
+__strong_alias(atomic_cas_ptr,rumpup_cas_32_up)
+__strong_alias(atomic_cas_32_ni,rumpup_cas_32_up)
+__strong_alias(atomic_cas_uint_ni,rumpup_cas_32_up)
+__strong_alias(atomic_cas_ulong_ni,rumpup_cas_32_up)
+__strong_alias(atomic_cas_ptr_ni,rumpup_cas_32_up)



Home | Main Index | Thread Index | Old Index