From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 70DA4C4332F for ; Thu, 2 Nov 2023 18:04:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377120AbjKBSEJ (ORCPT ); Thu, 2 Nov 2023 14:04:09 -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-Google-Smtp-Source: AGHT+IFAjztiAvvNiMf3iWUGJQNMicnApvTgiv+yrKYYwovvblpvEwEBD601Ligi0c2e4b4huzVaSLsngqct 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" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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