Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp4053601pxf; Mon, 29 Mar 2021 20:16:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwaKb0Wk5zQ62SqVIcGH2Yhxh877KF5n9Uzr28KUZlmMyfezHZCEdlAXoXcAR5aOvmT8AZ6 X-Received: by 2002:a05:6402:699:: with SMTP id f25mr31731384edy.47.1617074160725; Mon, 29 Mar 2021 20:16:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617074160; cv=none; d=google.com; s=arc-20160816; b=yxDizRbGYeBWjD4SsAh2CwfyBdeNroBTKkagfouMhWkA1sTlX192AzONmq4BIO46cy mHm59o8TZ8/XSvVvJ21LYz1L1wyF3F5WugTveEyeU6IsQVLdzJ+kt5qF9SsRQEI+/8jF Ak0j2myXvdImOcEcEc8qXbfzjYpaFZ+R+ZoWvQJkRqPrjdlw7zLpnz30JlKPrVgDmr0x d21XUc2+BFmMgZCKFaEkW1K1msgwuni7gj7Oi+J5MbcgCK3bPlSEOy9YsZBSkRi/3NIf 8K8T1x7JOvPoCTHJQo8qHR/O0Sr9Uk3UVjszE1y6JZscvowJPDckAAOo0Gi+uVFqK3zf Ab6Q== 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=KG4IpTNXBNEsfENHU/HXKYU2ptleNXLAlIKcY7nyb2A=; b=uQugrk7aHvvm40Typ8jLXRmC5hD+ruWJz7viuHP3B2CYTfy1YbW6YdAdcdcsKRTBhV FBTMpFSQ0rAiCZF5XSP2BlKguobo5Q3HacskwyFYp5B5rzOFQNhjT7FD7rUZkgD5cflc QqMxKYvT2ZVdixeRvMoHSa8xTZluPJbDvXw9QURwFdGUMpkD01GMXqPtiwgXqcVhKGo0 JnmTd9hFp1qzHY/RJbnGXmSHIp9yFc8weiQFXiO7hzxPZ57UQh52Jtb9sGtAPUr0vqzk G9z9mmuqdAWDS5YWw3fYey+Ob2VsBf+0DLraClR3GJKHMtlXD5ZAnisdyyzf4Xu9os5X +aJQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=KdMi5KiM; 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 hr14si14922771ejc.394.2021.03.29.20.15.36; Mon, 29 Mar 2021 20:16: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=@kernel.org header.s=k20201202 header.b=KdMi5KiM; 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 S229842AbhC3DOl (ORCPT + 99 others); Mon, 29 Mar 2021 23:14:41 -0400 Received: from mail.kernel.org ([198.145.29.99]:37708 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229689AbhC3DO0 (ORCPT ); Mon, 29 Mar 2021 23:14:26 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id EC07D61864; Tue, 30 Mar 2021 03:14:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1617074049; bh=6eSMLRiak11IODOB+CePI7a65DX9N8EkAy9ZzrCIP+E=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=KdMi5KiMduBWy6xItpcEY9isb6e1nAEdmm9B7NVKTZqjF7+XWdljKvaUejdZRj94U qX67Y1c/XOgi9ZKIGLXXCN4VvmqEwFf8du1gXCAXZD3bTU4HmKJ0MLlEWg/JIAwinH WXgA5tPnnDNdUb2WG2acEptutFjaiM2ZY08Tl7DYFPvkKg2VJ1N4OCgFtiCsoGXX7k WEF9v+hEtplZ766rLquAVZYq5UOENcf9DfrgULGkGDm8uLzhLQkFGtDGkJjmlALSGK aMMzRqLK9GmKpYm5j27NOW0PIxO+ssEnNA45LMd+ldPrTaoq7fPTZATXycZfHSAbc6 UkH9hUYA93fGQ== Received: by mail-lj1-f178.google.com with SMTP id u9so18196746ljd.11; Mon, 29 Mar 2021 20:14:08 -0700 (PDT) X-Gm-Message-State: AOAM533xojLaMbVQuvvFH3mkmvGx3B2EVx5uSVuhMeA4INfHaQmx6mS5 4sPhQIQFMgvUYOKnrNO7zXlqEbDThzhjTcj0ePU= X-Received: by 2002:a05:651c:211e:: with SMTP id a30mr13812844ljq.18.1617074047272; Mon, 29 Mar 2021 20:14:07 -0700 (PDT) MIME-Version: 1.0 References: <1616868399-82848-1-git-send-email-guoren@kernel.org> <1616868399-82848-4-git-send-email-guoren@kernel.org> In-Reply-To: From: Guo Ren Date: Tue, 30 Mar 2021 11:13:55 +0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v4 3/4] locking/qspinlock: Add ARCH_USE_QUEUED_SPINLOCKS_XCHG32 To: Peter Zijlstra Cc: linux-riscv , Linux Kernel Mailing List , linux-csky@vger.kernel.org, linux-arch , Guo Ren , Will Deacon , Ingo Molnar , Waiman Long , Arnd Bergmann , Anup Patel Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Mar 29, 2021 at 8:50 PM Peter Zijlstra wrote: > > On Mon, Mar 29, 2021 at 08:01:41PM +0800, Guo Ren wrote: > > u32 a = 0x55aa66bb; > > u16 *ptr = &a; > > > > CPU0 CPU1 > > ========= ========= > > xchg16(ptr, new) while(1) > > WRITE_ONCE(*(ptr + 1), x); > > > > When we use lr.w/sc.w implement xchg16, it'll cause CPU0 deadlock. > > Then I think your LL/SC is broken. > > That also means you really don't want to build super complex locking > primitives on top, because that live-lock will percolate through. Do you mean the below implementation has live-lock risk? +static __always_inline u32 xchg_tail(struct qspinlock *lock, u32 tail) +{ + u32 old, new, val = atomic_read(&lock->val); + + for (;;) { + new = (val & _Q_LOCKED_PENDING_MASK) | tail; + old = atomic_cmpxchg(&lock->val, val, new); + if (old == val) + break; + + val = old; + } + return old; +} > > Step 1 would be to get your architecute fixed such that it can provide > fwd progress guarantees for LL/SC. Otherwise there's absolutely no point > in building complex systems with it. Quote Waiman's comment [1] on xchg16 optimization: "This optimization is needed to make the qspinlock achieve performance parity with ticket spinlock at light load." [1] https://lore.kernel.org/kvm/1429901803-29771-6-git-send-email-Waiman.Long@hp.com/ So for a non-xhg16 machine: - ticket-lock for small numbers of CPUs - qspinlock for large numbers of CPUs Okay, I'll put all of them into the next patch :P -- Best Regards Guo Ren ML: https://lore.kernel.org/linux-csky/