Received: by 2002:a05:7412:b795:b0:e2:908c:2ebd with SMTP id iv21csp558935rdb; Thu, 2 Nov 2023 11:06:09 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG67UvHjtvg6uUKpbn00qMqCHtbNESfeNgwka29HVXRX78fkdyczhLHwO7ej5DffXKw+5sF X-Received: by 2002:a17:902:ecc6:b0:1cc:4a66:7d83 with SMTP id a6-20020a170902ecc600b001cc4a667d83mr14024147plh.2.1698948369424; Thu, 02 Nov 2023 11:06:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698948369; cv=none; d=google.com; s=arc-20160816; b=jLKwTlnKax9Iov1x2YaRq3hTTb6Du7V8PT2ULCE8g9lO1i+OTXj2tyPFO8vFVaDCGr y3Is+VPPdAEQZLKLnI/ar7q4zsQGXcYbW3tv5ArbKh1kPPkg/BNc8L0TPkGOUrtwfK8V Qh2jBdr16LTxaYe5bUYE10O7WvwwouE+rqfL9CnOhpuwCtWQjw+7X/cT1X4eEw5MPl/d +JUV5kJPdgvShVbnV4orQKHtCrofJEIYvdAJw7KYubBYfR9HKi+KBL/U1TSI/LGBCFGl SdmcOfVZSIbIMikkdVo6TvdZhDvGxeJmPFerstE80GClRF+zZBb5JrjPO0ewbefYtnsR 6hsA== 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=G3nDplTrebdm5iQF8GpuK9pqqqSsnd2vVKAMSYAi6/U=; fh=z1KcSqUpYQ9oC4uLSeIkhAYTnJ2bvP0QbNW2xqV5NqA=; b=YW4PSOpu98JKpIdre+TYanL1pHyHHXUpm3RUE8gSJ8yPQfqus+Uf18xKhB3j1IyboV SaXKs1R0/T7T7g6mbgBq8xE0WtMycBJ+DBYnGN+W9nq8PDg0NwnnGcGat6kaPyYKx9Gm uAdadi5jTBi1brkU02493XK7Y2Yja/u08EB4dRXPmSwT1O6qLba/dab2jbV8vqygvJhL 3M5RHVCKKNRxy6yjOJKsoEAeUn5iH91pccowHzgY0xNs/NrJLVoolDPjHnI56/keLSAy +wgp3X96S9wEzf1RBIMsAhnFMMtmoPx9IhvOvBSYCclHUJuzdHFFVYxWUXPfJgOlIZRF aubg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=uwakhFd4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 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. [23.128.96.35]) by mx.google.com with ESMTPS id t9-20020a17090340c900b001c9c3f327e1si71589pld.191.2023.11.02.11.06.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Nov 2023 11:06:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=uwakhFd4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 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 3AEE580295F3; Thu, 2 Nov 2023 11:05:25 -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 S1347205AbjKBSEI (ORCPT + 99 others); Thu, 2 Nov 2023 14:04:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55890 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377143AbjKBSD4 (ORCPT ); Thu, 2 Nov 2023 14:03:56 -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 5424A170A for ; Thu, 2 Nov 2023 10:59:13 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-da1aa98ec19so1505643276.2 for ; Thu, 02 Nov 2023 10:59:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1698947952; x=1699552752; 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=G3nDplTrebdm5iQF8GpuK9pqqqSsnd2vVKAMSYAi6/U=; b=uwakhFd4QZmdg6AUzmNOHUhtPDlYF2XavCxQsLHHVCpo/X669UtoDC2oa6r7w14DSv 5/AZ2vtRTtM+et6w6t22VNGjTn7Z0K1xeRcp2HzItFejpfI8z0M90ARq+lVRaH7NX3At qftuKs0hhmuANKgZrVvJQwte91o7nkTYA0BQS/Dp9Pvk4C3cevz6/LysYJrMjARXB191 LlaVXVU3XGfODmGel1gjlBUq9st8ZjcwgAR92TmF/kl9eyG7CLg7wQmRcAATNRxelcT8 +gH28+RNt+GP7OAkmeRyqDEXWwwAsPvs7KNaSJfQ/Tm6XSKZJ/Wk7+5Qtadr/YvcccMg Mt5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698947952; x=1699552752; 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=G3nDplTrebdm5iQF8GpuK9pqqqSsnd2vVKAMSYAi6/U=; b=vTyxIZmV5Hm2S+A6iAc32iBCUmC7HtHrMb7wQeZh8CPBpE3Iwc1q1TRJ0r00Z3Y6oq M/uClLIZj09wi7/An1rVRIILuv/ZhnN9uzbnR+obXcvipDdvyY+XoHVc7S/trelBdLli A0r5feexdTudgxC4Mv2bnyVF3QBmijur7/Ksg4kcF6+KM+lnT3AbyAM+wcicSv4do5oq jpZhReSDlzxgwanw6xdwO7XwM0Qo2o+mZ3aOu4aS+6L6EucDGVARj2Z58PW0edADK8QY 2s5oz6BlL8xWbyzyV2/UesDw7TTtRKKyqBpyRx4pi3sl6vrcKHphfFM28MD76quBFSEV ZNDw== X-Gm-Message-State: AOJu0YyRM/0Si0X2UVm7WcbScd0NKTimCAjNcQz9ZlvGXgPQmuoMPgJs 63ITN3xeNUl8J5O51ejHK5Vtna6JRyRl X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:bb34:df9c:836c:afca]) (user=irogers job=sendgmr) by 2002:a25:68cc:0:b0:da0:622b:553b with SMTP id d195-20020a2568cc000000b00da0622b553bmr342818ybc.12.1698947952141; Thu, 02 Nov 2023 10:59:12 -0700 (PDT) Date: Thu, 2 Nov 2023 10:57:15 -0700 In-Reply-To: <20231102175735.2272696-1-irogers@google.com> Message-Id: <20231102175735.2272696-34-irogers@google.com> Mime-Version: 1.0 References: <20231102175735.2272696-1-irogers@google.com> X-Mailer: git-send-email 2.42.0.869.gea05f2083d-goog Subject: [PATCH v4 33/53] 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 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 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]); Thu, 02 Nov 2023 11:05:25 -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.869.gea05f2083d-goog