From owner-freebsd-arch@FreeBSD.ORG Mon Oct 27 22:49:07 2014 Return-Path: Delivered-To: freebsd-arch@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 2C8FC45C; Mon, 27 Oct 2014 22:49:07 +0000 (UTC) Received: from mail-wi0-x233.google.com (mail-wi0-x233.google.com [IPv6:2a00:1450:400c:c05::233]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 9586DFA2; Mon, 27 Oct 2014 22:49:06 +0000 (UTC) Received: by mail-wi0-f179.google.com with SMTP id h11so5822112wiw.12 for ; Mon, 27 Oct 2014 15:49:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=date:from:to:cc:subject:message-id:mime-version:content-type :content-disposition:user-agent; bh=c8u/AtI7w58RsWcr9Oj+CGdSjTpVcz3VkhOWG2wJlt0=; b=jKDs6FvPZ9kRQDcBXDlNu2pjR6jMX2uyvPzJsUy/DRI1w0OdgxrzG56wKwU11GLriz LkfbkqkzND6BjAZIh96eVgDzUGNlQqnzVnqNm3PdHAIxljIaLnwQ/63W/8pEjKvXJNti DNwPNGng/qOP41zHHXlgVIIUnXgCpWpkOolIyRdwd8YuGKCDEXbv5Kl+08J74kw5FCYl uuIt1OUeA8oWguFAmz62uJTLB8IBvqoeRzcQyxUQg1rH/hZ9URU09kRpUCN8+BGHzMH6 Jq9w7oa13fxp4cZoTz6FgKLLjpR2UipN2zW/XaMRRqDw+9p2vda3SovnhHJtO2F56jqt Y8Lg== X-Received: by 10.180.212.48 with SMTP id nh16mr354104wic.50.1414450144706; Mon, 27 Oct 2014 15:49:04 -0700 (PDT) Received: from dft-labs.eu (n1x0n-1-pt.tunnel.tserv5.lon1.ipv6.he.net. [2001:470:1f08:1f7::2]) by mx.google.com with ESMTPSA id u4sm13361327wiy.9.2014.10.27.15.49.03 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Mon, 27 Oct 2014 15:49:04 -0700 (PDT) Date: Mon, 27 Oct 2014 23:49:01 +0100 From: Mateusz Guzik To: freebsd-arch@freebsd.org Subject: amd64 modules still use atomics as callable functions Message-ID: <20141027224901.GC28049@dft-labs.eu> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) Cc: Konstantin Belousov , Alan Cox X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 27 Oct 2014 22:49:07 -0000 Turns out several years ago the kernel was modified to provide actual functions for atomic operations and modules are always using them. I propose plugging it on amd64 in head. For stable/10 we can always provide them, but inline in modules by default (testing a KLD_WANT_ATOMIC_FUNC knob?). diff --git a/sys/amd64/amd64/atomic.c b/sys/amd64/amd64/atomic.c deleted file mode 100644 index 1b4ff7e..0000000 --- a/sys/amd64/amd64/atomic.c +++ /dev/null @@ -1,49 +0,0 @@ -/*- - * Copyright (c) 1999 Peter Jeremy - * 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 THE 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 -__FBSDID("$FreeBSD$"); - -/* This file creates publically callable functions to perform various - * simple arithmetic on memory which is atomic in the presence of - * interrupts and multiple processors. - */ -#include - -/* Firstly make atomic.h generate prototypes as it will for kernel modules */ -#define KLD_MODULE -#include -#undef _MACHINE_ATOMIC_H_ /* forget we included it */ -#undef KLD_MODULE -#undef ATOMIC_ASM - -/* Make atomic.h generate public functions */ -#define WANT_FUNCTIONS -#define static -#undef __inline -#define __inline - -#include diff --git a/sys/amd64/include/atomic.h b/sys/amd64/include/atomic.h index 9110dc5..e7e1735 100644 --- a/sys/amd64/include/atomic.h +++ b/sys/amd64/include/atomic.h @@ -69,28 +69,7 @@ * The above functions are expanded inline in the statically-linked * kernel. Lock prefixes are generated if an SMP kernel is being * built. - * - * Kernel modules call real functions which are built into the kernel. - * This allows kernel modules to be portable between UP and SMP systems. */ -#if defined(KLD_MODULE) || !defined(__GNUCLIKE_ASM) -#define ATOMIC_ASM(NAME, TYPE, OP, CONS, V) \ -void atomic_##NAME##_##TYPE(volatile u_##TYPE *p, u_##TYPE v); \ -void atomic_##NAME##_barr_##TYPE(volatile u_##TYPE *p, u_##TYPE v) - -int atomic_cmpset_int(volatile u_int *dst, u_int expect, u_int src); -int atomic_cmpset_long(volatile u_long *dst, u_long expect, u_long src); -u_int atomic_fetchadd_int(volatile u_int *p, u_int v); -u_long atomic_fetchadd_long(volatile u_long *p, u_long v); -int atomic_testandset_int(volatile u_int *p, u_int v); -int atomic_testandset_long(volatile u_long *p, u_int v); - -#define ATOMIC_LOAD(TYPE, LOP) \ -u_##TYPE atomic_load_acq_##TYPE(volatile u_##TYPE *p) -#define ATOMIC_STORE(TYPE) \ -void atomic_store_rel_##TYPE(volatile u_##TYPE *p, u_##TYPE v) - -#else /* !KLD_MODULE && __GNUCLIKE_ASM */ /* * For userland, always use lock prefixes so that the binaries will run @@ -293,8 +272,6 @@ struct __hack #endif /* _KERNEL && !SMP */ -#endif /* KLD_MODULE || !__GNUCLIKE_ASM */ - ATOMIC_ASM(set, char, "orb %b1,%0", "iq", v); ATOMIC_ASM(clear, char, "andb %b1,%0", "iq", ~v); ATOMIC_ASM(add, char, "addb %b1,%0", "iq", v); diff --git a/sys/conf/files.amd64 b/sys/conf/files.amd64 index 9e5a2ed..0749b05 100644 --- a/sys/conf/files.amd64 +++ b/sys/conf/files.amd64 @@ -91,7 +91,6 @@ acpi_wakedata.h optional acpi \ # amd64/amd64/amd64_mem.c optional mem #amd64/amd64/apic_vector.S standard -amd64/amd64/atomic.c standard amd64/amd64/autoconf.c standard amd64/amd64/bios.c standard amd64/amd64/bpf_jit_machdep.c optional bpf_jitter -- Mateusz Guzik