Received: by 2002:ab2:7b86:0:b0:1f7:5705:b850 with SMTP id q6csp1451303lqh; Mon, 6 May 2024 08:07:07 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXw9lv8em2cQihrbYsFsJs2tSFDFcGIAgQFNx+logig4rah6XgrLYKwbJs2EDkK5aPSTsYiH05BnhYVrbeinG/SqGkM3xEdfdR0iSAiJQ== X-Google-Smtp-Source: AGHT+IG5kbHtL7j4+S4P9X17LeeGtLgWhRONhJmE2ZRIQerOqoKzol8jCvVWHmPBgFlWYJJZ8MlJ X-Received: by 2002:a17:902:d884:b0:1dd:135e:2604 with SMTP id b4-20020a170902d88400b001dd135e2604mr8747490plz.40.1715008027024; Mon, 06 May 2024 08:07:07 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715008027; cv=pass; d=google.com; s=arc-20160816; b=0D+yIm7SJJTndjpNgIPYFsY+8HCJJKnLu2x5Iu23rYiD3EdIMBMb2nqTmslyz2ZAb/ 2kKRa3tk5FFJlQ9qMW7NHP93sytIQie8OcPI3Uz6R3EvCNWvBBfv8Jzczr8aF82ksj9D oXG/re82Vn8vJ10Y9bKoqqCNzSEQttudsB7/V3rXevMoZPmSzJCnz+a/uAy5x6ehTsWi xLJl5JfzF6IS/+4trYx7kSVCG4Zebe6CrgaZzTVPPT01T2yntiRnosLOb3FVVYQZdBV1 VYkp8jFEOwf7ors11SEDbfxoX4tkzEK1EZPZXKz4KtNPGTiYtHGr/9HxiWGibRPvYrUG ROAg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=Y43xCC2ORJwXxDBQyZMiQf+AzAg+xaw7pKNsy092Gws=; fh=0vre0JEFRr0dCE64iJN91CQC+t8aHv9Dg3eHQtgoeoY=; b=lqn9lLm05UL6tMOIRntVxKURp2R4+r6mzdyl5ZUnM9nkUL7bvmQ49iEcdjlBaneWZL pQ5Jss9na/AgXTrq0AlCrVVccbIdz8qmSXW1BTxrvsash82pw0uvCyC0sGInLqS2l08g ck5RLPqemzFbasnHn2VUUnoELkaA98L2Picz5I/ZJpmQQu7KBeYVIkrL86bBnKChzAQh FLZ1hFW8gm9UZq6/+4bmAWhVvUeDV148fNHd1xtuA6rStOByQGM7pxxG3YikE5gcDYTL Zq0mzda2fPtLvZdcxdVTHEq1MW6vqxO9tWXAEvH0v4MmTmAO5K472bAyMKjzqRmf7+Yx BHhA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=U2DfIxbf; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-170041-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-170041-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id i3-20020a170902cf0300b001e2571f0babsi8412085plg.625.2024.05.06.08.07.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 May 2024 08:07:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-170041-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=U2DfIxbf; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-170041-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-170041-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 47347283B54 for ; Mon, 6 May 2024 15:05:44 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2EF4015445D; Mon, 6 May 2024 15:05:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="U2DfIxbf" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E85D815359F for ; Mon, 6 May 2024 15:05:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715007939; cv=none; b=ULfojMqdt6T76hsGUJt7lNQZ3lHtOsgRpXGfL9vzd7AkREAQm0inoi+3upo7hoifLxsizcf5s4i3k9S+Xfzouj0VWF90kBJwPZfUTrRMDJiGqZbjqwXr02r977W1d9nDsOBbKuu4HKmDDN3am1TIUUrLGcFS2ZGkXLbPZgtoyM4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715007939; c=relaxed/simple; bh=pwUPJqSGaVxRG3VA0JRT0gFWsqDaBMCCyALOjtCGlJg=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=ikPbaGOJquAPIEqCair4O7k/R5WmFfS52M/wDexZAn5uk/2Di6+6QcjXj35oVGYeuc6akd0WlG0D3oV5+LN/i8wBiyKi8G/68T/DoTGPkDpYJhG4z+8NxpAUCIES2M/ABOWZRq5OJjmJtMCskPuJsjdtnV/6eKq1f3z02l31WPw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=U2DfIxbf; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1715007936; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Y43xCC2ORJwXxDBQyZMiQf+AzAg+xaw7pKNsy092Gws=; b=U2DfIxbfmHTjKQJyevOF+4mDvBZVXQ0+AeuY+mvlcVEZLpAB8+NJ8UtjrrFQhZcSkJzXk1 3x6YENWmm3SWVbnPxaFnspJdiszcOBJT+zmkoaYjLgClFIxNeOptc3Dcg4CozsWfw0Tp0+ PxKs7+ELcOKPgNzZQnTuUKLasjfAajo= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-368-EralcbDbMqOGvUgRqeAwxA-1; Mon, 06 May 2024 11:05:32 -0400 X-MC-Unique: EralcbDbMqOGvUgRqeAwxA-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9392388CE81; Mon, 6 May 2024 15:05:32 +0000 (UTC) Received: from [10.22.17.85] (unknown [10.22.17.85]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4293F1C060D0; Mon, 6 May 2024 15:05:32 +0000 (UTC) Message-ID: <7628453e-c418-49bb-be0a-50bc4248b7b9@redhat.com> Date: Mon, 6 May 2024 11:05:32 -0400 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2] locking/qspinlock: Save previous node & owner CPU into mcs_spinlock To: Peter Zijlstra Cc: Ingo Molnar , Will Deacon , Boqun Feng , linux-kernel@vger.kernel.org, Vernon Lovejoy References: <20240504024106.654319-1-longman@redhat.com> <20240506103637.GM40213@noisy.programming.kicks-ass.net> Content-Language: en-US From: Waiman Long In-Reply-To: <20240506103637.GM40213@noisy.programming.kicks-ass.net> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.7 On 5/6/24 06:36, Peter Zijlstra wrote: > On Fri, May 03, 2024 at 10:41:06PM -0400, Waiman Long wrote: > > Not much of a fan of this thing, but I suppose it won't hurt too much ... I purposely doesn't touch the fast path and add code only to slow path to make sure there shouldn't be any noticeable performance impact. >> diff --git a/kernel/locking/mcs_spinlock.h b/kernel/locking/mcs_spinlock.h >> index 85251d8771d9..cbe6f07dff2e 100644 >> --- a/kernel/locking/mcs_spinlock.h >> +++ b/kernel/locking/mcs_spinlock.h >> @@ -13,12 +13,19 @@ >> #ifndef __LINUX_MCS_SPINLOCK_H >> #define __LINUX_MCS_SPINLOCK_H >> >> +/* >> + * Save an encoded version of the current MCS lock owner CPU to the >> + * mcs_spinlock structure of the next lock owner. >> + */ >> +#define MCS_LOCKED (smp_processor_id() + 1) >> + >> #include >> >> struct mcs_spinlock { >> struct mcs_spinlock *next; >> - int locked; /* 1 if lock acquired */ >> - int count; /* nesting count, see qspinlock.c */ >> + int locked; /* non-zero if lock acquired */ >> + short count; /* nesting count, see qspinlock.c */ >> + short prev_node; /* encoded previous node value */ > Strictly speaking, count shouldn't ever go much higher than 4, so I > suppose a byte should be sufficient. That would then leave 24bit for the > prev thing, but you'll get to use bitfields or some other horrible > thing. Using bit field will be more expensive. So I am deferring that until the time it becomes necessary. >> }; >> >> #ifndef arch_mcs_spin_lock_contended >> @@ -42,7 +49,7 @@ do { \ >> * unlocking. >> */ >> #define arch_mcs_spin_unlock_contended(l) \ >> - smp_store_release((l), 1) >> + smp_store_release((l), MCS_LOCKED) > This leaves ARM up a creek I suppose... Also, there's but a single > MCS_LOCKED user. I am aware that ARM has its ownarch_mcs_spin_unlock_contended() macro defined. That is why I define the MCS_LOCKED macro before including asm/mcs_spinlock.h. I am planning to send an arm patch to change 1 to MCS_LOCKED if this patch is merged to close the gap. None other arches have arch_mcs_spin_unlock_contended() macro defined. Cheers, Longman