From owner-svn-src-all@freebsd.org Fri Jan 3 02:39:23 2020 Return-Path: Delivered-To: svn-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id CF7CD1E3566 for ; Fri, 3 Jan 2020 02:39:23 +0000 (UTC) (envelope-from jroberson@jroberson.net) Received: from mail-pg1-x544.google.com (mail-pg1-x544.google.com [IPv6:2607:f8b0:4864:20::544]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "smtp.gmail.com", Issuer "GTS CA 1O1" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 47ppyM0k8Mz4Jjl for ; Fri, 3 Jan 2020 02:39:22 +0000 (UTC) (envelope-from jroberson@jroberson.net) Received: by mail-pg1-x544.google.com with SMTP id b137so22775512pga.6 for ; Thu, 02 Jan 2020 18:39:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jroberson-net.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:in-reply-to:message-id:references :user-agent:mime-version; bh=pxUVZkl/lLnQnaIfsoM5GUj+0CtVho0erFlLc4mpfDM=; b=T4K3Pqepd5E7R7k0GXIFY8czUrKe8dkdJgxkYCeoAGd3AOQ/85wEPIc0GsXI47ofQp WP57xkhNTtkAiWcCF0o5qQsVBg63mC4QqN1kI5N4KE7YLfHjwBl7XGXW40e8bPwinCbB XpBYbQ5byx84jYS0AH4Y4ptV/pwbvlU4TiPVUt+I1odSwdLPhlHHKynF+26RYPcFxywR TopDA1lFt0j2cZ+tNecoV1d5SEszqjNXL2h8kUS40NTmgFDbaHzR0NkYdGxHWvKNpoOL 5vXcRa1MfsK7XQzkcds+am3BlpDbEDkp6I6CbbcLAoQnuaSRKxqPVqbqmC1f+NNeS3HU Vexg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:in-reply-to:message-id :references:user-agent:mime-version; bh=pxUVZkl/lLnQnaIfsoM5GUj+0CtVho0erFlLc4mpfDM=; b=O89colaOMnJTzsL3jP7Bb2g3HCUNJEGTp9gNcPlbGxx0fp1T1//4g4fU+/Ehi5LX5Y 9kov0H8UuKFJyZArMhvoGun/kfYtj/odgBpQ6N8CDJZtdsZ0f2fYsZrE2kMNuc89ZBaG eAOySjFaFrIZrvo1UAM6fB4qTMvHKrLd8p3+lAyC2JUpHF4PdldhGMf/rnlVz8NDHKGN g+FGGDhvl++S5Z0GPjO9fkgG7ONdSewTwVyu5UwUxhizAqpKiShPT/halCq51aXMkGig +5kJUxLzSlLdJ5L06OOLFs8BuVzVNsLLxlAwxoE7NTksb9+b912pwahGTyM2yHCeGc63 M01Q== X-Gm-Message-State: APjAAAVAbep4L2hyW2nw0wYEcIetYExA1uL8oMD8cMsMUdumeaXaSaTv OklN+L5tuoOW1ADRFdpxBwZ+7Q== X-Google-Smtp-Source: APXvYqzDBEeatPWUVTBgIhXswPmE49b5v8yiWu5pF+a15GF1y+T5fkM74NjxHqGfKAiQ/Cysd0mLFQ== X-Received: by 2002:a65:66d7:: with SMTP id c23mr95530270pgw.40.1578019161252; Thu, 02 Jan 2020 18:39:21 -0800 (PST) Received: from rrcs-76-81-105-82.west.biz.rr.com (rrcs-76-81-105-82.west.biz.rr.com. [76.81.105.82]) by smtp.gmail.com with ESMTPSA id u10sm61007414pgg.41.2020.01.02.18.39.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 02 Jan 2020 18:39:20 -0800 (PST) Date: Thu, 2 Jan 2020 16:39:18 -1000 (HST) From: Jeff Roberson X-X-Sender: jroberson@desktop To: Brandon Bergren cc: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: Re: svn commit: r356308 - in head/sys: cddl/compat/opensolaris/kern cddl/compat/opensolaris/sys conf kern mips/include powerpc/include sys In-Reply-To: <202001022320.002NKcio041437@repo.freebsd.org> Message-ID: References: <202001022320.002NKcio041437@repo.freebsd.org> User-Agent: Alpine 2.21.9999 (BSF 287 2018-06-16) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed X-Rspamd-Queue-Id: 47ppyM0k8Mz4Jjl X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org; dkim=pass header.d=jroberson-net.20150623.gappssmtp.com header.s=20150623 header.b=T4K3Pqep; dmarc=none; spf=none (mx1.freebsd.org: domain of jroberson@jroberson.net has no SPF policy when checking 2607:f8b0:4864:20::544) smtp.mailfrom=jroberson@jroberson.net X-Spamd-Result: default: False [-2.72 / 15.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; R_DKIM_ALLOW(-0.20)[jroberson-net.20150623.gappssmtp.com:s=20150623]; NEURAL_HAM_MEDIUM(-1.00)[-1.000,0]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_THREE(0.00)[4]; TO_DN_SOME(0.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000,0]; MIME_GOOD(-0.10)[text/plain]; PREVIOUSLY_DELIVERED(0.00)[svn-src-all@freebsd.org]; DMARC_NA(0.00)[jroberson.net]; RCVD_COUNT_THREE(0.00)[3]; TO_MATCH_ENVRCPT_SOME(0.00)[]; DKIM_TRACE(0.00)[jroberson-net.20150623.gappssmtp.com:+]; RCVD_IN_DNSWL_NONE(0.00)[4.4.5.0.0.0.0.0.0.0.0.0.0.0.0.0.0.2.0.0.4.6.8.4.0.b.8.f.7.0.6.2.list.dnswl.org : 127.0.5.0]; R_SPF_NA(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; MID_RHS_NOT_FQDN(0.50)[]; MIME_TRACE(0.00)[0:+]; ASN(0.00)[asn:15169, ipnet:2607:f8b0::/32, country:US]; RCVD_TLS_ALL(0.00)[]; IP_SCORE(-0.92)[ip: (-0.54), ipnet: 2607:f8b0::/32(-2.14), asn: 15169(-1.87), country: US(-0.05)] X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 03 Jan 2020 02:39:23 -0000 Thank you to everyone involved. This will make a lot of MI code much simpler. Jeff On Thu, 2 Jan 2020, Brandon Bergren wrote: > Author: bdragon > Date: Thu Jan 2 23:20:37 2020 > New Revision: 356308 > URL: https://svnweb.freebsd.org/changeset/base/356308 > > Log: > [PowerPC] [MIPS] Implement 32-bit kernel emulation of atomic64 operations > > This is a lock-based emulation of 64-bit atomics for kernel use, split off > from an earlier patch by jhibbits. > > This is needed to unblock future improvements that reduce the need for > locking on 64-bit platforms by using atomic updates. > > The implementation allows for future integration with userland atomic64, > but as that implies going through sysarch for every use, the current > status quo of userland doing its own locking may be for the best. > > Submitted by: jhibbits (original patch), kevans (mips bits) > Reviewed by: jhibbits, jeff, kevans > Differential Revision: https://reviews.freebsd.org/D22976 > > Added: > head/sys/kern/subr_atomic64.c (contents, props changed) > head/sys/sys/_atomic64e.h (contents, props changed) > Modified: > head/sys/cddl/compat/opensolaris/kern/opensolaris_atomic.c > head/sys/cddl/compat/opensolaris/sys/atomic.h > head/sys/conf/files.mips > head/sys/conf/files.powerpc > head/sys/mips/include/atomic.h > head/sys/powerpc/include/atomic.h > > Modified: head/sys/cddl/compat/opensolaris/kern/opensolaris_atomic.c > ============================================================================== > --- head/sys/cddl/compat/opensolaris/kern/opensolaris_atomic.c Thu Jan 2 23:18:43 2020 (r356307) > +++ head/sys/cddl/compat/opensolaris/kern/opensolaris_atomic.c Thu Jan 2 23:20:37 2020 (r356308) > @@ -33,7 +33,8 @@ __FBSDID("$FreeBSD$"); > #include > > #if !defined(__LP64__) && !defined(__mips_n32) && \ > - !defined(ARM_HAVE_ATOMIC64) && !defined(I386_HAVE_ATOMIC64) > + !defined(ARM_HAVE_ATOMIC64) && !defined(I386_HAVE_ATOMIC64) && \ > + !defined(HAS_EMULATED_ATOMIC64) > > #ifdef _KERNEL > #include > > Modified: head/sys/cddl/compat/opensolaris/sys/atomic.h > ============================================================================== > --- head/sys/cddl/compat/opensolaris/sys/atomic.h Thu Jan 2 23:18:43 2020 (r356307) > +++ head/sys/cddl/compat/opensolaris/sys/atomic.h Thu Jan 2 23:20:37 2020 (r356308) > @@ -42,7 +42,8 @@ > #endif > > #if !defined(__LP64__) && !defined(__mips_n32) && \ > - !defined(ARM_HAVE_ATOMIC64) && !defined(I386_HAVE_ATOMIC64) > + !defined(ARM_HAVE_ATOMIC64) && !defined(I386_HAVE_ATOMIC64) && \ > + !defined(HAS_EMULATED_ATOMIC64) > extern void atomic_add_64(volatile uint64_t *target, int64_t delta); > extern void atomic_dec_64(volatile uint64_t *target); > extern uint64_t atomic_swap_64(volatile uint64_t *a, uint64_t value); > @@ -109,7 +110,8 @@ atomic_cas_32(volatile uint32_t *target, uint32_t cmp, > #endif > > #if defined(__LP64__) || defined(__mips_n32) || \ > - defined(ARM_HAVE_ATOMIC64) || defined(I386_HAVE_ATOMIC64) > + defined(ARM_HAVE_ATOMIC64) || defined(I386_HAVE_ATOMIC64) || \ > + defined(HAS_EMULATED_ATOMIC64) > static __inline void > atomic_dec_64(volatile uint64_t *target) > { > > Modified: head/sys/conf/files.mips > ============================================================================== > --- head/sys/conf/files.mips Thu Jan 2 23:18:43 2020 (r356307) > +++ head/sys/conf/files.mips Thu Jan 2 23:20:37 2020 (r356308) > @@ -50,6 +50,7 @@ mips/mips/vm_machdep.c standard > # misc opt-in bits > kern/kern_clocksource.c standard > kern/link_elf_obj.c standard > +kern/subr_atomic64.c optional mips | mipsel | mipshf | mipselhf > kern/subr_busdma_bufalloc.c standard > kern/subr_dummy_vdso_tc.c standard > kern/subr_sfbuf.c optional mips | mipsel | mipsn32 > > Modified: head/sys/conf/files.powerpc > ============================================================================== > --- head/sys/conf/files.powerpc Thu Jan 2 23:18:43 2020 (r356307) > +++ head/sys/conf/files.powerpc Thu Jan 2 23:20:37 2020 (r356308) > @@ -76,6 +76,7 @@ dev/uart/uart_cpu_powerpc.c optional uart > dev/usb/controller/ehci_fsl.c optional ehci mpc85xx > dev/vt/hw/ofwfb/ofwfb.c optional vt aim > kern/kern_clocksource.c standard > +kern/subr_atomic64.c optional powerpc | powerpcspe > kern/subr_dummy_vdso_tc.c standard > kern/syscalls.c optional ktr > kern/subr_sfbuf.c standard > > Added: head/sys/kern/subr_atomic64.c > ============================================================================== > --- /dev/null 00:00:00 1970 (empty, because file is newly added) > +++ head/sys/kern/subr_atomic64.c Thu Jan 2 23:20:37 2020 (r356308) > @@ -0,0 +1,140 @@ > +/*- > + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD > + * > + * Copyright (c) 2019 Justin Hibbits > + * > + * 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. > + * > + * $FreeBSD$ > + */ > + > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +#include > +#include > + > +#include > +#include > + > +enum { > + ATOMIC64_ADD, > + ATOMIC64_CLEAR, > + ATOMIC64_CMPSET, > + ATOMIC64_FCMPSET, > + ATOMIC64_FETCHADD, > + ATOMIC64_LOAD, > + ATOMIC64_SET, > + ATOMIC64_SUBTRACT, > + ATOMIC64_STORE, > + ATOMIC64_SWAP > +}; > + > +#ifdef _KERNEL > +#define A64_POOL_SIZE MAXCPU > +/* Estimated size of a cacheline */ > +#define CACHE_ALIGN CACHE_LINE_SIZE > + > +#define GET_MUTEX(p) \ > + (&a64_mtx_pool[(pmap_kextract((vm_offset_t)p) / CACHE_ALIGN) % (A64_POOL_SIZE)]) > + > +#define LOCK_A64() \ > + struct mtx *_amtx = GET_MUTEX(p); \ > + if (smp_started) mtx_lock(_amtx) > + > +#define UNLOCK_A64() if (smp_started) mtx_unlock(_amtx) > + > +#define ATOMIC64_EMU_UN(op, rt, block, ret) \ > + rt \ > + atomic_##op##_64(volatile u_int64_t *p) { \ > + u_int64_t tmp __unused; \ > + LOCK_A64(); \ > + block; \ > + UNLOCK_A64(); \ > + ret; } struct hack > + > +#define ATOMIC64_EMU_BIN(op, rt, block, ret) \ > + rt \ > + atomic_##op##_64(volatile u_int64_t *p, u_int64_t v) { \ > + u_int64_t tmp __unused; \ > + LOCK_A64(); \ > + block; \ > + UNLOCK_A64(); \ > + ret; } struct hack > + > +static struct mtx a64_mtx_pool[A64_POOL_SIZE]; > + > +ATOMIC64_EMU_BIN(add, void, (*p = *p + v), return); > +ATOMIC64_EMU_BIN(clear, void, *p &= ~v, return); > +ATOMIC64_EMU_BIN(fetchadd, u_int64_t, (*p = *p + v, v = *p - v), return (v)); > +ATOMIC64_EMU_UN(load, u_int64_t, (tmp = *p), return (tmp)); > +ATOMIC64_EMU_BIN(set, void, *p |= v, return); > +ATOMIC64_EMU_BIN(subtract, void, (*p = *p - v), return); > +ATOMIC64_EMU_BIN(store, void, *p = v, return); > +ATOMIC64_EMU_BIN(swap, u_int64_t, tmp = *p; *p = v; v = tmp, return(v)); > + > +int atomic_cmpset_64(volatile u_int64_t *p, u_int64_t old, u_int64_t new) > +{ > + u_int64_t tmp; > + > + LOCK_A64(); > + tmp = *p; > + if (tmp == old) > + *p = new; > + UNLOCK_A64(); > + > + return (tmp == old); > +} > + > +int atomic_fcmpset_64(volatile u_int64_t *p, u_int64_t *old, u_int64_t new) > +{ > + u_int64_t tmp, tmp_old; > + > + LOCK_A64(); > + tmp = *p; > + tmp_old = *old; > + if (tmp == tmp_old) > + *p = new; > + else > + *old = tmp; > + UNLOCK_A64(); > + > + return (tmp == tmp_old); > +} > + > +static void > +atomic64_mtxinit(void *x __unused) > +{ > + int i; > + > + for (i = 0; i < A64_POOL_SIZE; i++) > + mtx_init(&a64_mtx_pool[i], "atomic64 mutex", NULL, MTX_DEF); > +} > + > +SYSINIT(atomic64_mtxinit, SI_SUB_LOCK, SI_ORDER_MIDDLE, atomic64_mtxinit, NULL); > + > +#endif /* _KERNEL */ > > Modified: head/sys/mips/include/atomic.h > ============================================================================== > --- head/sys/mips/include/atomic.h Thu Jan 2 23:18:43 2020 (r356307) > +++ head/sys/mips/include/atomic.h Thu Jan 2 23:20:37 2020 (r356308) > @@ -38,6 +38,10 @@ > > #include > > +#if !defined(__mips_n64) && !defined(__mips_n32) > +#include > +#endif > + > /* > * Note: All the 64-bit atomic operations are only atomic when running > * in 64-bit mode. It is assumed that code compiled for n32 and n64 > > Modified: head/sys/powerpc/include/atomic.h > ============================================================================== > --- head/sys/powerpc/include/atomic.h Thu Jan 2 23:18:43 2020 (r356307) > +++ head/sys/powerpc/include/atomic.h Thu Jan 2 23:20:37 2020 (r356308) > @@ -40,6 +40,10 @@ > > #include > > +#ifndef __powerpc64__ > +#include > +#endif > + > /* > * The __ATOMIC_REL/ACQ() macros provide memory barriers only in conjunction > * with the atomic lXarx/stXcx. sequences below. They are not exposed outside > > Added: head/sys/sys/_atomic64e.h > ============================================================================== > --- /dev/null 00:00:00 1970 (empty, because file is newly added) > +++ head/sys/sys/_atomic64e.h Thu Jan 2 23:20:37 2020 (r356308) > @@ -0,0 +1,80 @@ > +/*- > + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD > + * > + * Copyright (c) 2019 Justin Hibbits > + * > + * 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. > + * > + * $FreeBSD$ > + */ > + > + > +#ifndef _SYS_ATOMIC64E_H_ > +#define _SYS_ATOMIC64E_H_ > + > +#ifndef _MACHINE_ATOMIC_H_ > +#error "This should not be included directly. Include " > +#endif > + > +#ifdef _KERNEL > +#define HAS_EMULATED_ATOMIC64 > + > +/* Emulated versions of 64-bit atomic operations. */ > + > +void atomic_add_64(volatile u_int64_t *, u_int64_t); > +#define atomic_add_acq_64 atomic_add_64 > +#define atomic_add_rel_64 atomic_add_64 > + > +int atomic_cmpset_64(volatile u_int64_t *, u_int64_t, u_int64_t); > +#define atomic_cmpset_acq_64 atomic_cmpset_64 > +#define atomic_cmpset_rel_64 atomic_cmpset_64 > + > +void atomic_clear_64(volatile u_int64_t *, u_int64_t); > +#define atomic_clear_acq_64 atomic_clear_64 > +#define atomic_clear_rel_64 atomic_clear_64 > + > +int atomic_fcmpset_64(volatile u_int64_t *, u_int64_t *, u_int64_t); > +#define atomic_fcmpset_acq_64 atomic_fcmpset_64 > +#define atomic_fcmpset_rel_64 atomic_fcmpset_64 > + > +u_int64_t atomic_fetchadd_64(volatile u_int64_t *, u_int64_t); > + > +u_int64_t atomic_load_64(volatile u_int64_t *); > +#define atomic_load_acq_64 atomic_load_64 > + > +void atomic_readandclear_64(volatile u_int64_t *); > + > +void atomic_set_64(volatile u_int64_t *, u_int64_t); > +#define atomic_set_acq_64 atomic_set_64 > +#define atomic_set_rel_64 atomic_set_64 > + > +void atomic_subtract_64(volatile u_int64_t *, u_int64_t); > +#define atomic_subtract_acq_64 atomic_subtract_64 > +#define atomic_subtract_rel_64 atomic_subtract_64 > + > +void atomic_store_64(volatile u_int64_t *, u_int64_t); > +#define atomic_store_rel_64 atomic_store_64 > + > +u_int64_t atomic_swap_64(volatile u_int64_t *, u_int64_t); > + > +#endif /* _KERNEL */ > +#endif /* _SYS_ATOMIC64E_H_ */ >