From 566f7922d9d8f117335833d5f480f557c5dd27d1 Mon Sep 17 00:00:00 2001 From: pooka Date: Sun, 21 Nov 2010 21:46:43 +0000 Subject: [PATCH] Add a lockless uniprocessor version of atomic_cas_generic.c, which is currently used by all the archs that previously used cas_generic. --- sys/rump/librump/rumpkern/Makefile.rumpkern | 8 +-- sys/rump/librump/rumpkern/atomic_cas_up.c | 60 +++++++++++++++++++++ 2 files changed, 65 insertions(+), 3 deletions(-) create mode 100644 sys/rump/librump/rumpkern/atomic_cas_up.c diff --git a/sys/rump/librump/rumpkern/Makefile.rumpkern b/sys/rump/librump/rumpkern/Makefile.rumpkern index 82529122e66a..9e55a17de8e9 100644 --- a/sys/rump/librump/rumpkern/Makefile.rumpkern +++ b/sys/rump/librump/rumpkern/Makefile.rumpkern @@ -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 @@ KERNMISCCPPFLAGS+= -D_RUMPKERNEL # 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 diff --git a/sys/rump/librump/rumpkern/atomic_cas_up.c b/sys/rump/librump/rumpkern/atomic_cas_up.c new file mode 100644 index 000000000000..9ea7f2cc1a00 --- /dev/null +++ b/sys/rump/librump/rumpkern/atomic_cas_up.c @@ -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 +__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 + +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)