Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp267465pxf; Wed, 24 Mar 2021 04:52:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwJ67XhUKy0uKUbTnKKoYedxNwRjo9qqMbAL1dGxvaWhw90CvMbopfp89gzdTnAb1K/CjOi X-Received: by 2002:a17:906:3b84:: with SMTP id u4mr3184769ejf.431.1616586720825; Wed, 24 Mar 2021 04:52:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616586720; cv=none; d=google.com; s=arc-20160816; b=IIITYrPhfIGk0d2X9CW7KPaadMk/U7havHh8oYVvexZlNGUlQvBiF6FMjgwXwJUjjK z60WiPjHvg8UkGNhNL+VVrDDqNhmSBH82RJq3XOVhB8EFTy68d8XUdVxXsqKA4FpHZA/ 3odIJCBhHCwyY6CAWHNX9RGTceNSJoffn77mTtw0P3vYnqbovIJ3iM1dpGODiUQkmyyq YvQ92zgyK9Tkaq0R0jZgs0fJzMB5APHwXklalNWPzui9NBk8x5kLr3p495tK71q4YCzJ 20sykxiLBNMFMc+7RSiuJ6dy1b7FRiy1nl7lnUSgCN2og5jPeeAppl55ciKUzWY21x8C M9kw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=3T8iu/qdOkx2N3h+JT3OPgD2ctqodSwNmXaB7wutWzA=; b=PHDKy70wDxXtwzqCI98jBkmh8UUMsqbmAN5RxExKF+RkZWvqbANMe06OXX36OOajed KJMon7NlRtqJiMZRXJpCIarfZ7zDcSUIrYyZ/jsbZOx4g7HzZaZT9lS9m8LYEfCz+jj+ nZoLf9Kf9fw+AheiBfGBM6GoJ1IRdgZDF7ZgGfFmFbgiRaZV706dHloGBSAexcqOiS3A 29RZ4irw4RwEokqz+kcpC33c7jeOT7tHgXG1WhJWU6WH59ZN0DNOX4jK7jv7iudhOSYN O4rPqEMqxHdSLGIWLXl5cSSAvdMxAAUrNw/Bx1+AgjZP0aIVQPHHumVzxiw8yDbjJnmw Y6jA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=lnQQHrIn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dc3si1718858edb.57.2021.03.24.04.51.38; Wed, 24 Mar 2021 04:52:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=lnQQHrIn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231872AbhCXLKO (ORCPT + 99 others); Wed, 24 Mar 2021 07:10:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34682 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231455AbhCXLKJ (ORCPT ); Wed, 24 Mar 2021 07:10:09 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CA6DDC061763 for ; Wed, 24 Mar 2021 04:10:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=3T8iu/qdOkx2N3h+JT3OPgD2ctqodSwNmXaB7wutWzA=; b=lnQQHrIn6MADzhda+f8n/XYl6e ZR3Cyl1TtYeVGMyTw9gmG3b6Z4zz4MQI+pIdHuPq85cl/9zzqG6+Z0MGRDdEMagII+txSiRO7PeWA r0F/HEOkTcnToQ1quMwVezUsvRZyu0yO8FuWUwJKHo2IgZUGZ6wlW5mi9bP7X8f+yRwF9V5ITBY/K levcbfd3jRvy5iItCXZq87VNBi7jbIkbqBeg+h4f/ro1SrF5NQUuNhLGvn88cdNzMAYy0UeZ5zGpS Zeoa6fJ3RamzmkB09WJrJ5WJHK/8XutRPGgSZKfBdmC1VAde5w/v+6/ObAKO09+406yUAN6zyKVm5 q8xCtr5A==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.94 #2 (Red Hat Linux)) id 1lP1OH-00BGwS-AS; Wed, 24 Mar 2021 11:09:37 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 8F6413010C8; Wed, 24 Mar 2021 12:09:32 +0100 (CET) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 6C17A28B290D3; Wed, 24 Mar 2021 12:09:32 +0100 (CET) Date: Wed, 24 Mar 2021 12:09:32 +0100 From: Peter Zijlstra To: guoren@kernel.org Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Guo Ren , Catalin Marinas , Will Deacon , Palmer Dabbelt , Anup Patel , Arnd Bergmann Subject: Re: [PATCH] riscv: locks: introduce ticket-based spinlock implementation Message-ID: References: <1616580892-80815-1-git-send-email-guoren@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1616580892-80815-1-git-send-email-guoren@kernel.org> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Mar 24, 2021 at 10:14:52AM +0000, guoren@kernel.org wrote: > +static inline void arch_spin_lock(arch_spinlock_t *lock) > +{ > + arch_spinlock_t lockval; > + u32 tmp; > + > + asm volatile ( > + "1: lr.w %0, %2 \n" > + " mv %1, %0 \n" > + " addw %0, %0, %3 \n" > + " sc.w %0, %0, %2 \n" > + " bnez %0, 1b \n" > + : "=&r" (tmp), "=&r" (lockval), "+A" (lock->lock) > + : "r" (1 << TICKET_NEXT) > + : "memory"); > > + while (lockval.tickets.next != lockval.tickets.owner) { > + /* > + * FIXME - we need wfi/wfe here to prevent: > + * - cache line bouncing > + * - saving cpu pipeline in multi-harts-per-core > + * processor > + */ > + lockval.tickets.owner = READ_ONCE(lock->tickets.owner); > + } > > + __atomic_acquire_fence(); > } > +static inline void arch_spin_unlock(arch_spinlock_t *lock) > { > + smp_store_release(&lock->tickets.owner, lock->tickets.owner + 1); > + /* FIXME - we need ipi/sev here to notify above */ > } Urgh, are you saying your WFE requires an explicit SEV like on ARM ? The ARM64 model is far superious IMO, and then you can use smp_cond_load_acquire() in arch_spin_lock() and call it a day.