Received: by 10.223.185.116 with SMTP id b49csp71335wrg; Thu, 8 Mar 2018 13:04:31 -0800 (PST) X-Google-Smtp-Source: AG47ELvgXVZY0jlHQKOyFpbr3ZT9YZF7PCTs3bQ/UCj1GjkUIpXwwYvpcNX3bdkTDXPA/xI7uPMb X-Received: by 10.99.149.87 with SMTP id t23mr22114211pgn.411.1520543071208; Thu, 08 Mar 2018 13:04:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520543071; cv=none; d=google.com; s=arc-20160816; b=TAqSAljbdiDtUh9xZEqGb47O6VGgC1/YYYRA4WEEZvrpHYwiw0oEVN8Q/kKm2FrhYs xRCfRt9jQRc3DIGR5+qryIx2c5NkggPvxD/jhBQdqa+n3IxXiYPv0MiJQ7GpWHSxJZg7 PAE55m9XyP0EpfXKwpnuicGAA8JRc1XbI5DsgEEnSeL/6iz9+RKqdvK+pSoEjZ0DHE/j FZWPCy+5m+wUUtlghK3l1ydr40ch4EMDD2jssZ7BLD3YPyPRsFSYx6lEkYgoI9hsskTI 1erPw8XIp+ALpg2JMzi53QiBDiiknY76dlUkhyCpUBniIaGieJKHCu7X+wMH2ThVwEMG DbBg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=47beejbh/tMimYqIvNqbcNh5hTekGByLq/Ba2V7uFe4=; b=kZUPjzZmuTgxzKY/EjW/zJ0Pc+LSsNRgr6cc8Sa6Y8i+a1a5FY13iIMLq82k2p3Eqo fsxn5lHdDV7iK5Xqbretw/G5aFZEkqhxTwAAGRDa4omXpTj+E8yDFfelI7/zmtrZKIuz EYI/syxCRme9ICNe/f77E+G55Nk8TuoHgEerI2WhrVk9F++BnbCe0FG5T8BDQz4juIez ysdAxJrVv/cUkhjY5Wwhf7SWbkbzS4bWenMxabsPrDweAc1UV9D3VZV/2dHuk9uaLAnz XHrm2uTDT2V2Q8qzM1WYY0ySN92MZe9Gf7ZmO2hVZOxGh2OHJuH0Qz0XyBcpepY34ti0 mbDw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=GVWjn2xo; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r1si13507420pgq.305.2018.03.08.13.04.16; Thu, 08 Mar 2018 13:04:31 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=GVWjn2xo; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751166AbeCHVDN (ORCPT + 99 others); Thu, 8 Mar 2018 16:03:13 -0500 Received: from mail-wm0-f66.google.com ([74.125.82.66]:33960 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750939AbeCHVDL (ORCPT ); Thu, 8 Mar 2018 16:03:11 -0500 Received: by mail-wm0-f66.google.com with SMTP id a20so783329wmd.1 for ; Thu, 08 Mar 2018 13:03:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=47beejbh/tMimYqIvNqbcNh5hTekGByLq/Ba2V7uFe4=; b=GVWjn2xowl3AvJoA6HvwHpy5FTqmL20CE0YgC4e/cJtdTo6u4pP4YCmFAgrC1ExB9N xtB/LsgeS+44sTnTb+UMoVXzQrbY0bFb5e9gs5fUx2KJbUOPYMzHOsDg7ARJGuu6PR8h A+q2QLcZoGWwgXXar85/4FZq9/YPB1CPmqdJ07DsvCnnvgilF0MuDfEeqE5oGhbITNEH UBBb8hUkdEAeJB8wihdsWqOXex2EtRI/8+gdl3a5iXZy3gdP51FNS/9vPIDy9y6h5zn6 ojW1WThCBOldZs2qZ8HMDKr/JRiFunsCVf3efxTggw6qvyTAhBYta4OnQIU9Xjq0BMx6 emEA== 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:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=47beejbh/tMimYqIvNqbcNh5hTekGByLq/Ba2V7uFe4=; b=FbSsDA6M7nt/AXtPuMBLZh4C1QdsP54s9qitcbzZigm8sKmjy6shqrbxTpHs1Sh9Jt d4foSQp897rhtihnZT0H/gIlJIjvjpC9QgRXd6+mQQ+8ZLpYHuEv0wqeKLiXOTRTSzPU 1blycrisqWXuMbIdB+QlNhT4pR/bDkZPsSBCxS1X92pgAbzsMD2KQWIMHOICXV3vbqXJ pzRJ8mT2W7YKdlHmzcZL4676RZe042j6Q4ZWinnX4oUYSQrLhKRw+W+2OIczTxR87y1F ioc0MRxCxd7FKsTzAnU9IOatVJuOuIrdb1zCCbooF6wciba4lWwXCE4Vxj/mEe7aFEZW N3ag== X-Gm-Message-State: AElRT7G04oBxpJfLJ/XB1RNiveJQKUvAbJfOSYVe4bPzDbcYW9rXSBP7 1WedWNn6sT32C8a03oepUTA= X-Received: by 10.28.202.26 with SMTP id a26mr141124wmg.45.1520542990267; Thu, 08 Mar 2018 13:03:10 -0800 (PST) Received: from andrea ([94.230.152.15]) by smtp.gmail.com with ESMTPSA id n49sm23653526wrn.90.2018.03.08.13.03.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 08 Mar 2018 13:03:09 -0800 (PST) Date: Thu, 8 Mar 2018 22:03:03 +0100 From: Andrea Parri To: Palmer Dabbelt Cc: albert@sifive.com, Daniel Lustig , stern@rowland.harvard.edu, Will Deacon , peterz@infradead.org, boqun.feng@gmail.com, npiggin@gmail.com, dhowells@redhat.com, j.alglave@ucl.ac.uk, luc.maranget@inria.fr, paulmck@linux.vnet.ibm.com, akiyks@gmail.com, mingo@kernel.org, Linus Torvalds , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [RFC PATCH 1/2] riscv/spinlock: Strengthen implementations with fences Message-ID: <20180308210303.GA2897@andrea> References: <20180307105242.GA6133@andrea> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Mar 07, 2018 at 10:33:49AM -0800, Palmer Dabbelt wrote: [...] > I'm going to go produce a new set of spinlocks, I think it'll be a bit more > coherent then. > > I'm keeping your other patch in my queue for now, it generally looks good > but I haven't looked closely yet. Patches 1 and 2 address a same issue ("release-to-acquire"); this is also expressed, more or less explicitly, in the corresponding commit messages: it might make sense to "queue" them together, and to build the new locks on top of these (even if this meant "rewrite all of/a large portion of spinlock.h"...). Andrea > > Thanks! > > > > > Andrea > > > > > >> > >> Signed-off-by: Palmer Dabbelt > >> > >>diff --git a/arch/riscv/include/asm/spinlock.h b/arch/riscv/include/asm/spinlock.h > >>index 2fd27e8ef1fd..9b166ea81fe5 100644 > >>--- a/arch/riscv/include/asm/spinlock.h > >>+++ b/arch/riscv/include/asm/spinlock.h > >>@@ -15,128 +15,7 @@ > >>#ifndef _ASM_RISCV_SPINLOCK_H > >>#define _ASM_RISCV_SPINLOCK_H > >> > >>-#include > >>-#include > >>- > >>-/* > >>- * Simple spin lock operations. These provide no fairness guarantees. > >>- */ > >>- > >>-/* FIXME: Replace this with a ticket lock, like MIPS. */ > >>- > >>-#define arch_spin_is_locked(x) (READ_ONCE((x)->lock) != 0) > >>- > >>-static inline void arch_spin_unlock(arch_spinlock_t *lock) > >>-{ > >>- __asm__ __volatile__ ( > >>- "amoswap.w.rl x0, x0, %0" > >>- : "=A" (lock->lock) > >>- :: "memory"); > >>-} > >>- > >>-static inline int arch_spin_trylock(arch_spinlock_t *lock) > >>-{ > >>- int tmp = 1, busy; > >>- > >>- __asm__ __volatile__ ( > >>- "amoswap.w.aq %0, %2, %1" > >>- : "=r" (busy), "+A" (lock->lock) > >>- : "r" (tmp) > >>- : "memory"); > >>- > >>- return !busy; > >>-} > >>- > >>-static inline void arch_spin_lock(arch_spinlock_t *lock) > >>-{ > >>- while (1) { > >>- if (arch_spin_is_locked(lock)) > >>- continue; > >>- > >>- if (arch_spin_trylock(lock)) > >>- break; > >>- } > >>-} > >>- > >>-/***********************************************************/ > >>- > >>-static inline void arch_read_lock(arch_rwlock_t *lock) > >>-{ > >>- int tmp; > >>- > >>- __asm__ __volatile__( > >>- "1: lr.w %1, %0\n" > >>- " bltz %1, 1b\n" > >>- " addi %1, %1, 1\n" > >>- " sc.w.aq %1, %1, %0\n" > >>- " bnez %1, 1b\n" > >>- : "+A" (lock->lock), "=&r" (tmp) > >>- :: "memory"); > >>-} > >>- > >>-static inline void arch_write_lock(arch_rwlock_t *lock) > >>-{ > >>- int tmp; > >>- > >>- __asm__ __volatile__( > >>- "1: lr.w %1, %0\n" > >>- " bnez %1, 1b\n" > >>- " li %1, -1\n" > >>- " sc.w.aq %1, %1, %0\n" > >>- " bnez %1, 1b\n" > >>- : "+A" (lock->lock), "=&r" (tmp) > >>- :: "memory"); > >>-} > >>- > >>-static inline int arch_read_trylock(arch_rwlock_t *lock) > >>-{ > >>- int busy; > >>- > >>- __asm__ __volatile__( > >>- "1: lr.w %1, %0\n" > >>- " bltz %1, 1f\n" > >>- " addi %1, %1, 1\n" > >>- " sc.w.aq %1, %1, %0\n" > >>- " bnez %1, 1b\n" > >>- "1:\n" > >>- : "+A" (lock->lock), "=&r" (busy) > >>- :: "memory"); > >>- > >>- return !busy; > >>-} > >>- > >>-static inline int arch_write_trylock(arch_rwlock_t *lock) > >>-{ > >>- int busy; > >>- > >>- __asm__ __volatile__( > >>- "1: lr.w %1, %0\n" > >>- " bnez %1, 1f\n" > >>- " li %1, -1\n" > >>- " sc.w.aq %1, %1, %0\n" > >>- " bnez %1, 1b\n" > >>- "1:\n" > >>- : "+A" (lock->lock), "=&r" (busy) > >>- :: "memory"); > >>- > >>- return !busy; > >>-} > >>- > >>-static inline void arch_read_unlock(arch_rwlock_t *lock) > >>-{ > >>- __asm__ __volatile__( > >>- "amoadd.w.rl x0, %1, %0" > >>- : "+A" (lock->lock) > >>- : "r" (-1) > >>- : "memory"); > >>-} > >>- > >>-static inline void arch_write_unlock(arch_rwlock_t *lock) > >>-{ > >>- __asm__ __volatile__ ( > >>- "amoswap.w.rl x0, x0, %0" > >>- : "=A" (lock->lock) > >>- :: "memory"); > >>-} > >>+#include > >>+#include > >> > >>#endif /* _ASM_RISCV_SPINLOCK_H */ > >>