Received: by 2002:ab2:7b86:0:b0:1f7:5705:b850 with SMTP id q6csp102916lqh; Fri, 3 May 2024 15:01:27 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWPzQsOS42+xtXxFMXx99krUCEI1Exj4X7ieD3+BeJdWIfGkCPafCsM5cPpCGConCisK5gmak3agg9DNL4z1dyNHjBzW0wZmKis6hE9Vw== X-Google-Smtp-Source: AGHT+IHAZBXZoxygXudAchKJ8BeXBpcBCiWnPd0MM9o5m0miiuiVe6bGMf06b4siCjzrMOaTcZbV X-Received: by 2002:a05:6122:4710:b0:4d3:39c3:717c with SMTP id ed16-20020a056122471000b004d339c3717cmr4348628vkb.1.1714773687025; Fri, 03 May 2024 15:01:27 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714773687; cv=pass; d=google.com; s=arc-20160816; b=qG/ASgQYFraaCeUho8O1PdWFEOEckaqUCWcja84UNF4EVQlobHc1O8uLW6hCpLs3NE Wsi0970TsfNHIIYsjqmpfh1iGAHhKZLGuWqXMYpOViNMr5+AqfhPOtomLh7Lo7eOhsJS DwGNOdNyi24fDUPFpMgpBl3vty0yzAD2LrqeFi4tLnsId6cCUZq9zALLUK+LuAfgDOKM 5K7oYp/hC/qsS40nmem8codweNsPSIrDcU3heYcLWF1aDsipozrHP83+h0MgpzPsKMKf 7w5NCUK5QArjBAASSFLIcNhXsrs6AWb1LBEjfi/rPkl3zbci6DJdVH9+aKDf5GCyJzm3 87Fw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=0sjv9T+egk2i7mbNVwnFuef2h+PLNLCnFrs/sJ5ral0=; fh=/uHqH7TnX3zwDDRlfN9Dw61nbo8ySQWwH8ehiK/tP8s=; b=FqdpB6xnYP1DYViSoP+ow7Tn0wYviud8+4RrvJayjbxiNuD+JiWfAteHHab5jlrXFY 2FvuvRZaLzU9gyHDvDuScMWb8F6Ol3bFkwjeoR9tRg5VGukz9B5+gxX7dB5g+Cx3zcFT Xb7Zx373dDgCpleiBQ+T9gZkqTN5YBWIfpJM6/nbNYYBIbBwFoi5FQ2IEmjpRU+qBxGi LDlupjwg0dQ44WdDG+av1mF0PjevQzelt3C8Wj2VhoXpFbGYbgTFFOpjs2LLndyBIZAS U39ZEfZY4KeLG2w7zPXdWhNw4K6Q05/XrSXWGSDaxuvXkr0KEd2OUeKcvu9Ed2kzF6HX GXyA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=HAzJeiXl; 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-168330-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-168330-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id m62-20020a1fee41000000b004df29aab8b9si388586vkh.276.2024.05.03.15.01.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 May 2024 15:01:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-168330-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=HAzJeiXl; 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-168330-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-168330-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id B6D561C23AA8 for ; Fri, 3 May 2024 22:01:26 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D7A4358AA5; Fri, 3 May 2024 22:01:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="HAzJeiXl" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.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 9724C57333 for ; Fri, 3 May 2024 22:01:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714773683; cv=none; b=LKW8X/Md4/JZ9ZcfokOwWR/6qfubntKxcnD5r//BNsXdXf4h9vS8fPApQzBSf57eC4lkm2fWGxcro/UMZ9A1Z0yX4kDzDQygLhzaxfmtEAe7wtZ3/YaCjB71qvnjm3DO5UGpIiK0Po7MTK8S8Q28tSprmU9zDRuwiSrQsSRbP6I= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714773683; c=relaxed/simple; bh=pUxq7jUksP4Q+cMJXZOkqnA/K+QpYMgfwqOUdO4C2e0=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=D91a+pogRDj+qf+P1OzDMJHhq6N4elx5ELhDYA2v0X9cm2lF450oazHGc1ePDYwgIyisWkz7e2PbA2wgBnDvghv+0rNlCPCr88bigbqXCsrPysU/Q6S4/FjiZEjVmhb/CldQs46LXjC8JFmobzKRDPofbbf+56yUrxQOq3MtR6g= 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=HAzJeiXl; arc=none smtp.client-ip=170.10.129.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=1714773680; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=0sjv9T+egk2i7mbNVwnFuef2h+PLNLCnFrs/sJ5ral0=; b=HAzJeiXlLy2R/Clb4B2WvYd2TcvYdl/reDnVPcmDDNknteMF3Bo7oa63Ili4m8EfGHc4Oq 807ZK25bce04BiPt6OBSLtAX1XVROanc6fA6wGia1u7xlIb7jddxcp3aZOptzVZzu+I9sJ ktmX7kax8q9guN73GI7HM5IOpx5y9xQ= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-451-48_ZKH75MNSAPskrKHvgoA-1; Fri, 03 May 2024 18:01:17 -0400 X-MC-Unique: 48_ZKH75MNSAPskrKHvgoA-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (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 14C713C000B5; Fri, 3 May 2024 22:01:17 +0000 (UTC) Received: from llong.com (unknown [10.22.34.156]) by smtp.corp.redhat.com (Postfix) with ESMTP id 757C340C6CC0; Fri, 3 May 2024 22:01:16 +0000 (UTC) From: Waiman Long To: Peter Zijlstra , Ingo Molnar , Will Deacon , Boqun Feng Cc: linux-kernel@vger.kernel.org, Vernon Lovejoy , Waiman Long Subject: [PATCH] locking/qspinlock: Save qspinlock owner CPU into mcs_spinlock Date: Fri, 3 May 2024 17:59:18 -0400 Message-Id: <20240503215918.639519-1-longman@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 When examining a contended spinlock in a crash dump, we can trace out the list of lock waiter CPUs waiting for the lock by following the linked list of mcs_spinlock structures. However, the actual owner of the lock is not there making it hard to figure out who the current lock owner is. Make it easier to figure out this information by saving the lock owner CPU into the mcs_spinlock structure of new MCS lock owner, if available, when acquiring the lock in the qspinlock slowpath. We can then follow the linked list of mcs_spinlock structures to the end to get an encoded CPU number of the lock owner, if set. This owner information is still not available when the lock is acquired directly in the fast path or in the pending code path. There is no easy way around that. The additional cost to get the current CPU number in the slowpath should be minimal as it should be in a hot cacheline. Signed-off-by: Waiman Long --- kernel/locking/mcs_spinlock.h | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/kernel/locking/mcs_spinlock.h b/kernel/locking/mcs_spinlock.h index 85251d8771d9..ac0ed0a8f028 100644 --- a/kernel/locking/mcs_spinlock.h +++ b/kernel/locking/mcs_spinlock.h @@ -13,11 +13,17 @@ #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 locked; /* non-zero if lock acquired */ int count; /* nesting count, see qspinlock.c */ }; @@ -42,7 +48,7 @@ do { \ * unlocking. */ #define arch_mcs_spin_unlock_contended(l) \ - smp_store_release((l), 1) + smp_store_release((l), MCS_LOCKED) #endif /* -- 2.39.3