Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp3429003rdh; Mon, 27 Nov 2023 14:13:16 -0800 (PST) X-Google-Smtp-Source: AGHT+IFHEzFWC8N4NmrhMnPeixbX0RZXnA12kJk04RpTWDYVdYPtJbmz5y7SaMxpL32c4qPn4dNJ X-Received: by 2002:a05:6a20:a123:b0:187:6cc4:5aea with SMTP id q35-20020a056a20a12300b001876cc45aeamr14227135pzk.59.1701123195647; Mon, 27 Nov 2023 14:13:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701123195; cv=none; d=google.com; s=arc-20160816; b=sSuRG0LzC/Ali3qQpX2yphlpGTI2Thvx0IwpX7v5FplQgzXX+HkGRBXwg94tEznMPV 1vN0Rr35d7M/WCZIVzdObKZh3SREajyVKp22BdGHL0KyYslgQr8358043JDBTh/lGUUW 6iS0zd4oRDnSUm22TqWnYPka9OYiHZyLZO1cSL2THs/GVbUCOPe77v62i06ckIMRSKab I6ruN4OFLoRNR6KAjUGICps58mHgDvIzqrtL+YTTFgtL2zmpRKvwXoE5sJNxFiyWXA/g AQf45c10PPGFuh/khtC+1zZvVxu3UWgwGb4ufgD3IAwxI/gum23oUmCY0iLzcV53nUZH UXBA== 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=YZfEEyCJPKtNkyz47mAJgILH81a+f20AhnpCUE58jks=; fh=Io7x3OacpefNRRNKoYAzVE0aWTDwD7FRzyCdD1e3AN4=; b=b/VQozO7OxYtIkz4EoEjKNptee3/M5cF48Pcf20byUS5ND25K90HxotrLDjk18Uxmu Wsia1onYMlv5BqFXkp8WR8vQH3ewHoWpVAOdxL6/XGyM7htU2Exl1D2+7VJ+utCPpAqo kLZAj2inr9P+x7+hJ273EpKj0JtKgOBdUbHZpPmDSoFHBsDkWR+lrtIXUv0Vl1phAfUs br+jk7YpOqF2VvKYR13CJ1egAjMXV7/U3m/SnJoWiJPCDLgQz6Y4NTM+YccVSWc/k3ze gGzRUArXHeZWRT6fM+F71rllSOOtsyg62C5Rrgsxw6B55pqSuNF63+992chiSF+rwvXv 8Lpg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=lOOgu7Dp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 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 morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id go17-20020a17090b03d100b00276571c0d34si10248782pjb.6.2023.11.27.14.13.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Nov 2023 14:13:15 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=lOOgu7Dp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 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 morse.vger.email (Postfix) with ESMTP id 55023810DEC2; Mon, 27 Nov 2023 14:13:12 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234060AbjK0WMq (ORCPT + 99 others); Mon, 27 Nov 2023 17:12:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39350 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233747AbjK0WLw (ORCPT ); Mon, 27 Nov 2023 17:11:52 -0500 Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 95E0F273B for ; Mon, 27 Nov 2023 14:10:33 -0800 (PST) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-5cdde93973aso57464587b3.1 for ; Mon, 27 Nov 2023 14:10:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1701123032; x=1701727832; 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=YZfEEyCJPKtNkyz47mAJgILH81a+f20AhnpCUE58jks=; b=lOOgu7DpFF5e/5fBy4hzKmtp9Lhidfv2FMQzXONNxPyKIusQBoniXCvavpIVz7skqD 3Gf8PT7TnxR5n4k/nDb28s+mvOzX5OGasLTfB5/2i3kkqLl4/V8AgXP+AEL/Oo5qyzFf ymSOkFJPvgq1itMhvvS6bY9X2EampnnBN2GKLDPOU8N7O5z79CpL+2Zzv9HaEBxwBFFB 75ah3pTCsut1T9Ar/YNdjEhDINNfgfOG3RFob93Nysy6lwWt84ENxyMzTiV8k3wJv0Ve uzOM6C5H5oEOFFaCMYxRs5AD5WfZPhEcImbpDoliuM2Z/4PsjUn4W7smXBE5EoCNfBHf HjBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701123032; x=1701727832; 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=YZfEEyCJPKtNkyz47mAJgILH81a+f20AhnpCUE58jks=; b=vgjZwIbgRFEA+XvDKnOZKYDkqD2a1XLcs9AKY0umCLb8rFDMCQYE0mg0FuaQ2ENQcF NiDoLRZYiERc+c25niuz1uZPtt2S8AZjJdZ3E68muHhHZvC8gpjhicQDiynY9v+Fz2YC cBl7uyuiVddZfbxCPWt6DKcrU0yLzAhsB25C0ttWCrtVOK9zZ2Mrc25uHfLKEJXD8Am2 x3g77byaPv1+FnJj7SN/T5xMh+Sr7BckhD5ASuaxJUV9lIpDyYxRJaKpwQgighkQoqKB PaCWWpUjMpkHWFUIjoGKSoKjA8haZqPNOzYFH6og85hzOlaC4ebMRlwxBmQ/j3TEmAYn GriQ== X-Gm-Message-State: AOJu0YxJHxmUPehOZTjPuoDcgKcXpeV+ie71W541w4k6I7ZfrOgIDzDy U+EiQmiDjYtAGWDVWv1wQoPpvGEy1tL4 X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:829:6e77:9093:f39b]) (user=irogers job=sendgmr) by 2002:a05:690c:270e:b0:5ca:fa88:f4b6 with SMTP id dy14-20020a05690c270e00b005cafa88f4b6mr443123ywb.3.1701123032722; Mon, 27 Nov 2023 14:10:32 -0800 (PST) Date: Mon, 27 Nov 2023 14:08:42 -0800 In-Reply-To: <20231127220902.1315692-1-irogers@google.com> Message-Id: <20231127220902.1315692-31-irogers@google.com> Mime-Version: 1.0 References: <20231127220902.1315692-1-irogers@google.com> X-Mailer: git-send-email 2.43.0.rc1.413.gea7ed67945-goog Subject: [PATCH v5 30/50] perf maps: Locking tidy up of nr_maps 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 , Kajol Jain , Athira Rajeev , Huacai Chen , Masami Hiramatsu , Vincent Whitchurch , "Steinar H. Gunderson" , Liam Howlett , Miguel Ojeda , Colin Ian King , Dmitrii Dolgov <9erthalion6@gmail.com>, Yang Jihong , Ming Wang , James Clark , K Prateek Nayak , Sean Christopherson , Leo Yan , Ravi Bangoria , German Gomez , Changbin Du , Paolo Bonzini , Li Dong , Sandipan Das , liuwenyu , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Guilherme Amadio 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,T_SCC_BODY_TEXT_LINE, 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 morse.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 (morse.vger.email [0.0.0.0]); Mon, 27 Nov 2023 14:13:12 -0800 (PST) After this change maps__nr_maps is only used by tests, existing users are migrated to maps__empty. Compute maps__empty under the read lock. Signed-off-by: Ian Rogers --- tools/perf/util/machine.c | 2 +- tools/perf/util/maps.c | 10 ++++++++-- tools/perf/util/maps.h | 4 ++-- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c index 42d73f00f9c1..f9c77119af22 100644 --- a/tools/perf/util/machine.c +++ b/tools/perf/util/machine.c @@ -441,7 +441,7 @@ static struct thread *findnew_guest_code(struct machine *machine, return NULL; /* Assume maps are set up if there are any */ - if (maps__nr_maps(thread__maps(thread))) + if (!maps__empty(thread__maps(thread))) return thread; host_thread = machine__find_thread(host_machine, -1, pid); diff --git a/tools/perf/util/maps.c b/tools/perf/util/maps.c index 41e9e39b1b4c..725f5d73e93a 100644 --- a/tools/perf/util/maps.c +++ b/tools/perf/util/maps.c @@ -528,7 +528,13 @@ void maps__remove(struct maps *maps, struct map *map) bool maps__empty(struct maps *maps) { - return maps__nr_maps(maps) == 0; + bool res; + + down_read(maps__lock(maps)); + res = maps__nr_maps(maps) == 0; + up_read(maps__lock(maps)); + + return res; } bool maps__equal(struct maps *a, struct maps *b) @@ -851,7 +857,7 @@ int maps__copy_from(struct maps *dest, struct maps *parent) parent_maps_by_address = maps__maps_by_address(parent); n = maps__nr_maps(parent); - if (maps__empty(dest)) { + if (maps__nr_maps(dest) == 0) { /* No existing mappings so just copy from parent to avoid reallocs in insert. */ unsigned int nr_maps_allocated = RC_CHK_ACCESS(parent)->nr_maps_allocated; struct map **dest_maps_by_address = diff --git a/tools/perf/util/maps.h b/tools/perf/util/maps.h index 4bcba136ffe5..d9aa62ed968a 100644 --- a/tools/perf/util/maps.h +++ b/tools/perf/util/maps.h @@ -43,8 +43,8 @@ int maps__for_each_map(struct maps *maps, int (*cb)(struct map *map, void *data) void maps__remove_maps(struct maps *maps, bool (*cb)(struct map *map, void *data), void *data); struct machine *maps__machine(const struct maps *maps); -unsigned int maps__nr_maps(const struct maps *maps); -refcount_t *maps__refcnt(struct maps *maps); +unsigned int maps__nr_maps(const struct maps *maps); /* Test only. */ +refcount_t *maps__refcnt(struct maps *maps); /* Test only. */ #ifdef HAVE_LIBUNWIND_SUPPORT void *maps__addr_space(const struct maps *maps); -- 2.43.0.rc1.413.gea7ed67945-goog