Received: by 2002:a05:7412:251c:b0:e2:908c:2ebd with SMTP id w28csp2184885rda; Tue, 24 Oct 2023 15:24:36 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF6Jcf037NJDWsiKMg+Ro+DaHVa/3iFE5NdicGs7bqqrqWPQsm8rfcI4Epeun68I37X6ZWf X-Received: by 2002:a05:6a21:788a:b0:17b:c254:a6a9 with SMTP id bf10-20020a056a21788a00b0017bc254a6a9mr4219789pzc.50.1698186276226; Tue, 24 Oct 2023 15:24:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698186276; cv=none; d=google.com; s=arc-20160816; b=u2FyatmtbiTnBQOOvdU1abG7qQ/LQ3rS/iW2e4Ouk7+OeKk1csMYCLQV9aDUklW7zE 1myHThcEZnHrNXsngV5Z9lws6ImZrb9TvXqNadujTzzhOYu6EX+erspYjCujgdxgXS29 mrp5E09PxVo6AFP4lfbvTBCjEIkCBsEa7n6HST4QoognPyxUa232SthOV9zuMHYeU4fT hTjm7WeQdVwndW3YQJpfWKBstrzrFhNsEi6zLI57O1VMQ/EkNGRYDLBptcE57s8e2eN5 vv/eVdJBb9yuJPiylHVqjMP0W1VpFTWVDBEwF+hzKyMvxQa0vgkVAAW0A7FU9Bbo/fwi m5xQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:from:subject:references:mime-version :message-id:in-reply-to:date:dkim-signature; bh=NM9dcQFM3UJZ90iyVMmsCAaNS1wz3u9iN52BCuG9Qew=; fh=NAro5oTsDEB2Or99ABwb774QJkwQSkr6EoLVqn/Yde0=; b=vyRNRv11+OwjVDl06oVY73SaRI8fzZaUvGWis/v0f+Hlo7TwfVGDkUtWazPDlHllMK UZreL0geWIe4evNt97kyWjrt1MePZGm8WYEBBqyY+LUyQE+ufSOsnc9l3fyLDUWpn5ru 7kOGHppGuT+2KKE4QCsZsxV1AVVG0l0UALQkA6f+lu0r8bZp+NRrCj29DQ6UrTgQGueH lzl1yA0EhjdpxMthy8V6DZBawa/B1sNv4B/Uqup7CWmQXcXyqOl+tAvjAMtJDSLTaBeZ cbFGKPTa074fVzNJdUZOBzXuWey/oQ3rbHeK860+tnpWPQbMO81Zof6OkOQJ3FYRrkUb kvRw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=meDc3XHp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id 6-20020a170902ee4600b001c9e890f42fsi8964627plo.110.2023.10.24.15.24.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Oct 2023 15:24:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=meDc3XHp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 789E88050600; Tue, 24 Oct 2023 15:24:32 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344435AbjJXWYV (ORCPT + 99 others); Tue, 24 Oct 2023 18:24:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59392 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234958AbjJXWYS (ORCPT ); Tue, 24 Oct 2023 18:24:18 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2FD5B10D1 for ; Tue, 24 Oct 2023 15:24:16 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-d9cafa90160so5745255276.2 for ; Tue, 24 Oct 2023 15:24:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1698186255; x=1698791055; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=NM9dcQFM3UJZ90iyVMmsCAaNS1wz3u9iN52BCuG9Qew=; b=meDc3XHpY9ExaB280nqOJ6K12OSUwce6tf+IECrl3phpC11mlm2lK0RtXg1hlcetqQ IARFzopmnj2l0M1LYYdylBWVYy8/qq2za77E8GuduEiFUQJyM9cjX9GO45Fiil3YMs6Y GY3R2xmNPk5JnsdAhz+XU2mGcSN++OBrYzAvjbRZU5i9w7OSu5mV/7UmwQRYvderROeH qFtLHtmi3fAE89TaP/eI9TrrMZosgnEr2XPChozMnTtw2Q2rXVkY0eIs5kE5k/VjROEs M4j+fFEFoz23hcJILF8zpJj/P9hNWAXbMOqtnsHCx7dDkufNWU8GmNTqVk1gMtn7S+Q1 LfIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698186255; x=1698791055; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=NM9dcQFM3UJZ90iyVMmsCAaNS1wz3u9iN52BCuG9Qew=; b=nqnVu+0weadMj83l6jmG+VzU0F3NLIF+un41zNGbA4a78a/6pnh1c5DBA0D7lIJpnY fVJswvGlfXaQUPMwwmc8wvXC1ObSffGttzXXhRfoltekHb0k3HsXAEjbQjyS88T9+/Zr GcLNUVuvIb9MlSiT3oAsA+6sgBCyyoyWfZiubjmwA+E4PazPXYMhYm6S7SBf8Wel+PjG rZZWYhqxkGUIO0Q+m0JmoFR3DOCsRW4pApBUFHnJR8smhcVSf7a6+0gqjGvw9Egb2JMP QVu4oqRqT0uVHvEtnKoWDXejNdvUplPEQg/4NS9boJbKSs9CfFjlIvPoa+yLcdpbPh74 A6YA== X-Gm-Message-State: AOJu0Yw+m51ZQmHMjVI5+zkXw93cKuzH1j1ydOYjiQh7Kef27QpD5p/1 DteBeSVoEfds8KM8iuYvfS5rewQZ9qtw X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:93d2:18cc:4d63:45ba]) (user=irogers job=sendgmr) by 2002:a25:d107:0:b0:d9a:50d2:a8ba with SMTP id i7-20020a25d107000000b00d9a50d2a8bamr250692ybg.2.1698186255187; Tue, 24 Oct 2023 15:24:15 -0700 (PDT) Date: Tue, 24 Oct 2023 15:23:04 -0700 In-Reply-To: <20231024222353.3024098-1-irogers@google.com> Message-Id: <20231024222353.3024098-2-irogers@google.com> Mime-Version: 1.0 References: <20231024222353.3024098-1-irogers@google.com> X-Mailer: git-send-email 2.42.0.758.gaed0368e0e-goog Subject: [PATCH v3 01/50] perf rwsem: Add debug mode that uses a mutex From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , Nick Terrell , Kan Liang , Andi Kleen , Leo Yan , Song Liu , Sandipan Das , James Clark , Anshuman Khandual , Miguel Ojeda , Liam Howlett , Yang Jihong , Athira Rajeev , Kajol Jain , K Prateek Nayak , Sean Christopherson , Yanteng Si , Ravi Bangoria , German Gomez , Changbin Du , Paolo Bonzini , Masami Hiramatsu , liuwenyu , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Tue, 24 Oct 2023 15:24:32 -0700 (PDT) Mutex error check will capture trying to take the lock recursively and other problems that rwlock won't. At the expense of concurrency, adda debug mode that uses a mutex in place of a rwsem. Signed-off-by: Ian Rogers --- tools/perf/util/rwsem.c | 34 ++++++++++++++++++++++++++++++++++ tools/perf/util/rwsem.h | 11 +++++++++++ 2 files changed, 45 insertions(+) diff --git a/tools/perf/util/rwsem.c b/tools/perf/util/rwsem.c index f3d29d8ddc99..5109167f27f7 100644 --- a/tools/perf/util/rwsem.c +++ b/tools/perf/util/rwsem.c @@ -2,32 +2,66 @@ #include "util.h" #include "rwsem.h" +#if RWS_ERRORCHECK +#include "mutex.h" +#endif + int init_rwsem(struct rw_semaphore *sem) { +#if RWS_ERRORCHECK + mutex_init(&sem->mtx); + return 0; +#else return pthread_rwlock_init(&sem->lock, NULL); +#endif } int exit_rwsem(struct rw_semaphore *sem) { +#if RWS_ERRORCHECK + mutex_destroy(&sem->mtx); + return 0; +#else return pthread_rwlock_destroy(&sem->lock); +#endif } int down_read(struct rw_semaphore *sem) { +#if RWS_ERRORCHECK + mutex_lock(&sem->mtx); + return 0; +#else return perf_singlethreaded ? 0 : pthread_rwlock_rdlock(&sem->lock); +#endif } int up_read(struct rw_semaphore *sem) { +#if RWS_ERRORCHECK + mutex_unlock(&sem->mtx); + return 0; +#else return perf_singlethreaded ? 0 : pthread_rwlock_unlock(&sem->lock); +#endif } int down_write(struct rw_semaphore *sem) { +#if RWS_ERRORCHECK + mutex_lock(&sem->mtx); + return 0; +#else return perf_singlethreaded ? 0 : pthread_rwlock_wrlock(&sem->lock); +#endif } int up_write(struct rw_semaphore *sem) { +#if RWS_ERRORCHECK + mutex_unlock(&sem->mtx); + return 0; +#else return perf_singlethreaded ? 0 : pthread_rwlock_unlock(&sem->lock); +#endif } diff --git a/tools/perf/util/rwsem.h b/tools/perf/util/rwsem.h index 94565ad4d494..ef5cbc31d967 100644 --- a/tools/perf/util/rwsem.h +++ b/tools/perf/util/rwsem.h @@ -2,9 +2,20 @@ #define _PERF_RWSEM_H #include +#include "mutex.h" + +/* + * Mutexes have additional error checking. Enable to use a mutex rather than a + * rwlock for debugging. + */ +#define RWS_ERRORCHECK 0 struct rw_semaphore { +#if RWS_ERRORCHECK + struct mutex mtx; +#else pthread_rwlock_t lock; +#endif }; int init_rwsem(struct rw_semaphore *sem); -- 2.42.0.758.gaed0368e0e-goog