Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp31893pxf; Wed, 24 Mar 2021 20:00:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwRPTmPLkuz1l+01htPiNeZVA8UwOtWjhAe8Nq7pnWUkeNmDTqI+PJB2smIAffV7ULG2jp2 X-Received: by 2002:a05:6402:30a5:: with SMTP id df5mr6771247edb.24.1616641233285; Wed, 24 Mar 2021 20:00:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616641233; cv=none; d=google.com; s=arc-20160816; b=O8AuCvWYISM+4WH21y8ti28RHdDrDvFNcdOUWDSdHRmrU7dXNJJJ+KJOpBMGYbJ4he TQxUMjwHvyCt1XQT/isTGlhCCbQ4v7fIe2fUZKl/E5WO3OxUIPvpnAUL61PF273UASEE Ods0B88MAPe1ms4U+sxoiUbr7m749vyF4+2oxIv8vfN9tyueEp91ZEFBhPlWjGOXlEec Z94S03ZOp/gCk/9f0nRpOlxhkyjRuV477gpOv8fMrk/RZJug7g0VOKjPkU7FCXQyw0T0 s4QgaLou84vvPbf6bH04NfX3s0S0d42wJwWxe+ulPgoBidslAk/ysgY8KVP50uNCBdDF 5RAQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=nCih8e8FvAJ1QLsZQAmhVFWCEzjKxO+nRAZK+8WxU8s=; b=uLV/LBMbiBDCGX3prAWZUtuRNSGjg5Va8IIxbXOi4jnW31Mcoh90S5ugTikIYxxu6l nbxmbo9HdPtlJxoV0pEKJ4yLzP3V8yrV68WHzZ/wz+6RfCTqV2T/O78sBYfX6VSdsK5m m1IaOCnyE+wLuCkn1NMOwkNsodGcycg76ZXmJm/LKkr+9YFhTFUYMDq4NMy9ogGKYDRJ QoqG861FkEhcXyY40YxTKWOEcVBEDaQ3QcV5gTzA73iUu0RPhHbLDUXmyQw3znxz2NJh GVFENE6gAhnI2X1lMrSbcyfIVBP9r7e1xFihICaVQd4dY2VMsretnvKosMejXB/FPnZa lqZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=AnSjMG9U; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y15si3498237edv.49.2021.03.24.20.00.09; Wed, 24 Mar 2021 20:00:33 -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=@kernel.org header.s=k20201202 header.b=AnSjMG9U; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233132AbhCXMLS (ORCPT + 99 others); Wed, 24 Mar 2021 08:11:18 -0400 Received: from mail.kernel.org ([198.145.29.99]:59610 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233100AbhCXMLL (ORCPT ); Wed, 24 Mar 2021 08:11:11 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id E044261A0A for ; Wed, 24 Mar 2021 12:11:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1616587863; bh=kEx0TIsJHajLeIyFUwPJAU5kpomMAoLZGOL83edNDYM=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=AnSjMG9UhEB4+85PdfpildgQIi/Yq58nviKe6bZkBkVeXl/4OMOhzilxaoK5MqKhJ kvzWlpvlIhUG8JNvkVzUlU3g5UiUl4btFKKJiYg/bu6cbuwUKghX7vwudnOj6P8Gk7 rvlXPJy761kqBC76BhZ1+wLV/y750e8e5CBV0edSKzqi95C9xNv1PQ5QD4jbr9z3gy TMa7jNLIC+mqs+qlQ4BmkdO8+W5ngc5X80y9f3G18/1FLsnF5BEn2ErmUjU+A9G9Ka N7GHZZATIKFxcGEE8QhEoZBYr2Nyt3w8Dpo/xdR7Unksp79H7KYOMxtiOvvxdoSdRV Tr1FshV3f1I4g== Received: by mail-lj1-f175.google.com with SMTP id z8so29847257ljm.12 for ; Wed, 24 Mar 2021 05:11:02 -0700 (PDT) X-Gm-Message-State: AOAM530/vydhLGAGd/SqXRSSD7GUV3IZS6XXJAyYlmipXUdEO1Eg2deu onBizf4SWkOqr76kOQrWO8M1qUm002SHSoPQqO8= X-Received: by 2002:a2e:994e:: with SMTP id r14mr1940414ljj.115.1616587861091; Wed, 24 Mar 2021 05:11:01 -0700 (PDT) MIME-Version: 1.0 References: <1616580892-80815-1-git-send-email-guoren@kernel.org> In-Reply-To: From: Guo Ren Date: Wed, 24 Mar 2021 20:10:49 +0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] riscv: locks: introduce ticket-based spinlock implementation To: Peter Zijlstra Cc: linux-riscv , Linux Kernel Mailing List , Guo Ren , Catalin Marinas , Will Deacon , Palmer Dabbelt , Anup Patel , Arnd Bergmann Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Thx Peter, On Wed, Mar 24, 2021 at 7:09 PM Peter Zijlstra wrote: > > 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 Yes, I'm considering that kind of code. > ARM64 model is far superious IMO, and then you can use > smp_cond_load_acquire() in arch_spin_lock() and call it a day. Great tip, thx. I'll follow that. -- Best Regards Guo Ren ML: https://lore.kernel.org/linux-csky/