Received: by 2002:a05:7412:251c:b0:e2:908c:2ebd with SMTP id w28csp2186117rda; Tue, 24 Oct 2023 15:27:39 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFynty/l2X8KpaFt7ztggRTrNaICarvSMbZ6RBsEKmA2fIjrB9wOsv15J5JJs21EG/4g3zs X-Received: by 2002:a17:903:4095:b0:1ca:a8d8:4056 with SMTP id z21-20020a170903409500b001caa8d84056mr9487897plc.10.1698186458786; Tue, 24 Oct 2023 15:27:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698186458; cv=none; d=google.com; s=arc-20160816; b=IuKYj5BWt1Bg1VIhDF9FFcpQvZxXxUsE2Z3t4+Mn3wKdHfy4TkvcJfdF8rFW7vpo0A eoSB50ZNLWxtay4UMo9OS42CifLtcKJ4ZpneGNYAs3tgTIL/Cs7gIz4rDrQ5HJky5Tob wbbIzm1B7FHQYEEuIRLyvRak23DzUaXhfaXaSeo4n7MULE71KkswYFg24W0JBNAT2/14 gX913lcpUBbgB3nuK1dCxsYRsz7bPUOR7SRhEEm+52aqglq/0SbNewxN4QTsL+YsD6bz +2/bm9e/cGOc8FKsTXQ+hZEYqXvJVsQPgE5x8UFCgEMsq1FwUKjVhHkuXiIdw0VRf4fU ImdA== 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=KF5V0xK2Lq20qZdw/Kvq8/AiFWZ8gPx81P4SISP1cMg=; fh=NAro5oTsDEB2Or99ABwb774QJkwQSkr6EoLVqn/Yde0=; b=iM9FGQPLnS4taGvaLxeBuY3V72nqR4vF6x0it61XFLxce3nMaLwe3EAkluMwEsC3kL 0xQaM6gZTzme4qZP/SCOL9Rztyi5mVGwmYDyr8mpKMtXPKLGM8HhkWiz9Vjr3E2L4GHn 12GcSlBXHQk+ShC1i5kuTVSE2KzuUo6eikxN77GrmgIsphNh37w7LBFUj/o3pCHi6yvz 2Q0n20udBv+QrEIRrzI7qGmrysNnrlySrm4RS9qpQAKgWXjQG2gIHLoldbDNseWrVpFc NU8lDmUQ+vjKbPAO+ndov6bEgAbBY8eWS4bUJw+sq2QDWH2OiDlbZ1zMdsH1LFEpM9JY xp+A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=PDoKSkai; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 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 pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id x8-20020a170902ec8800b001ca176b7974si9279269plg.103.2023.10.24.15.27.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Oct 2023 15:27:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=PDoKSkai; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 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 pete.vger.email (Postfix) with ESMTP id 005A1802A9DF; Tue, 24 Oct 2023 15:27:32 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344500AbjJXW1S (ORCPT + 99 others); Tue, 24 Oct 2023 18:27:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57906 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344531AbjJXW0f (ORCPT ); Tue, 24 Oct 2023 18:26:35 -0400 Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9F75519B0 for ; Tue, 24 Oct 2023 15:25:50 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-5a92864859bso45302977b3.0 for ; Tue, 24 Oct 2023 15:25:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1698186350; x=1698791150; 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=KF5V0xK2Lq20qZdw/Kvq8/AiFWZ8gPx81P4SISP1cMg=; b=PDoKSkaivxThTnIPOnsPmCIN2WrnTiC/G1oFvPQZnObsne4v8Fnkt11X9zR1X3SxKx NcnqThhriSs99HGL1Go4iZJplH4vxD2Yomiv49I2/Ppkl3GNjT1wNLA7Gx/GoRl2dApp 7a+57Ix5QPU8PxvwEj020HjRPXuMw99Sk/XxfdHTs8aeLjkZF11TWkyADAzdyY4T0lit tRyJ+A+OLLZaHmyRR5IR/sthOvNQv4YCoIN+7pXhHGxOf8dMEN2iJouit+8otPCCAt4m QNVK3RJNjiers2FuKcaKXBReaSZHz+igmitIHkp1yyF/bvgfhHnBxiQmvsUUoMlYglmE ry6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698186350; x=1698791150; 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=KF5V0xK2Lq20qZdw/Kvq8/AiFWZ8gPx81P4SISP1cMg=; b=AV09mhNAq21UNzNUu3F62oaZ7cvRGEfL2BVuRJD9U/55JZOYYY7l7tBqgl/KG7ecYS WmBqYp13VJTiiUj7vD8gk2Wsz1yo7e8dROXLlW3o9j9t3mSVC1hCE1b+yfOwzt0HSiIi oiScJglW/XmGmg1mBf1iu7t7WU0JZ84FcR4ZJ5f1PYPpiwefgnYPLE3S92DhW85o2yIH Mh9Tl/GrW39mcE6p2us/WpaKfb8v2mgFKH9lqUGZFVHyd7uhb70CdFbyRAPE2o//dCq0 cjtvNV+agRAdtX5qL39onLiZRFj2QBrsa9NB9pqD9QMraZx/FYxoq70ffJRzhnGntnvx nzWA== X-Gm-Message-State: AOJu0YxzaOBayV4u9n7Pgj1L2zuXrJKXA9oEYwcrkzYAu4QeQfGuN27a lBs7a5FVOBpCbXyEqlwP6DFYVzKf1/mU X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:93d2:18cc:4d63:45ba]) (user=irogers job=sendgmr) by 2002:a81:4e84:0:b0:5a8:2fb9:aeab with SMTP id c126-20020a814e84000000b005a82fb9aeabmr277735ywb.3.1698186349788; Tue, 24 Oct 2023 15:25:49 -0700 (PDT) Date: Tue, 24 Oct 2023 15:23:46 -0700 In-Reply-To: <20231024222353.3024098-1-irogers@google.com> Message-Id: <20231024222353.3024098-44-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 43/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 , 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 pete.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 (pete.vger.email [0.0.0.0]); Tue, 24 Oct 2023 15:27:33 -0700 (PDT) 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.42.0.758.gaed0368e0e-goog