From nobody Thu Jan 1 09:12:23 2026 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 9BEECC07545 for ; Tue, 24 Oct 2023 22:26:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344568AbjJXW0u (ORCPT ); Tue, 24 Oct 2023 18:26:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47554 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344585AbjJXW0L (ORCPT ); Tue, 24 Oct 2023 18:26:11 -0400 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 9F7002D76 for ; Tue, 24 Oct 2023 15:25:35 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-5a7cf717bacso67706637b3.1 for ; Tue, 24 Oct 2023 15:25:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1698186334; x=1698791134; 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=nzIlX+P2Xnb51CqannJImstzqGSg/CO4GFxV9EhldOc=; b=XtlLXBykJVKWfk5yCU+rQn2Ll3gCSIsu1hHyuLDQqWdexiEcx0cDqPhM0Z1y+cxDP8 FCTxk5T2UFFxH52Wv8sLC5OtK45tol1MiXEuh4hecOSn95JZ1b/wpyGgr2hSBg+6t6/a e1Rt7+mLp+K7PMssJ8Aczt3mAMc6qWvofhfNCpjdXmb6WxHdsd6nhaTDZ+vgmB6dSMyn v3sLqdx7GtzSUtYarXbyZnXzkOBcdM8la3spVgZqMSNMd8U5mPz9F6iM40I33lw6c/AR X9nYb0oNOr+D5GIxoYY4NXtY/y96qK75aXcLWf/rArqs7r8cNUAYbzmJIl8c82kNCYyv LlDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698186334; x=1698791134; 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=nzIlX+P2Xnb51CqannJImstzqGSg/CO4GFxV9EhldOc=; b=ZK07sLGO7o95JJxVoIIeZhIjV9/x6TIah4EofUTnBKfzfcF2Shg7QsqZlYj5Zjo0gO zaAdkL49vPKfY6mu1r+1aiLyaIXk/DfjZQmvqilpAlJfLyETXGPLXreA2dAmHaW7j2sB VnSmRGOuIZP8Sl0jojxPmjJAsWT3BKITpcspHW5AoDK9wG+3u6OnZI0NeV6bP91IUY00 1PyUdcXP4a+S0KvVcR2i/5b7RuWYAGu/GyFUmhlAhTFpeB68f9i6XOi/vUNtA6/+mkM8 VdADaZ8YbXNjjcKjC8Tgs0xyGYmYFG7i1a1WRZO+pdBQCozj91wYzYcCbu7gCfckKYKI xM5g== X-Gm-Message-State: AOJu0YztGFwYLbW8Mo9J582A+pC68rsHnzxra1N+LxwGE/HxLxxV7Pds mIJ5dG5qh40S9GPakfhkrnVBvjeonOFL X-Google-Smtp-Source: AGHT+IG8FPY+Ogk4FsuhljaKZCeaOvPfVDckGfcLgfkV20JexqX0pZ9Dav8nr0jJMm9f0W29T3x30fmqQh9i X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:93d2:18cc:4d63:45ba]) (user=irogers job=sendgmr) by 2002:a0d:ca8b:0:b0:589:a855:7af with SMTP id m133-20020a0dca8b000000b00589a85507afmr268615ywd.7.1698186333865; Tue, 24 Oct 2023 15:25:33 -0700 (PDT) Date: Tue, 24 Oct 2023 15:23:39 -0700 In-Reply-To: <20231024222353.3024098-1-irogers@google.com> Message-Id: <20231024222353.3024098-37-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 36/50] perf maps: Reduce scope of map_rb_node and maps internals 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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Avoid exposing the implementation of maps so that the internals can be refactored. Signed-off-by: Ian Rogers --- tools/perf/util/maps.c | 90 ++++++++++++++++++++++++++---------------- tools/perf/util/maps.h | 23 ----------- 2 files changed, 55 insertions(+), 58 deletions(-) diff --git a/tools/perf/util/maps.c b/tools/perf/util/maps.c index 38d56709bd5e..01c15d0b300a 100644 --- a/tools/perf/util/maps.c +++ b/tools/perf/util/maps.c @@ -10,6 +10,11 @@ #include "ui/ui.h" #include "unwind.h" =20 +struct map_rb_node { + struct rb_node rb_node; + struct map *map; +}; + #define maps__for_each_entry(maps, map) \ for (map =3D maps__first(maps); map; map =3D map_rb_node__next(map)) =20 @@ -17,6 +22,56 @@ for (map =3D maps__first(maps), next =3D map_rb_node__next(map); map; \ map =3D next, next =3D map_rb_node__next(map)) =20 +static struct rb_root *maps__entries(struct maps *maps) +{ + return &RC_CHK_ACCESS(maps)->entries; +} + +static struct rw_semaphore *maps__lock(struct maps *maps) +{ + return &RC_CHK_ACCESS(maps)->lock; +} + +static struct map **maps__maps_by_name(struct maps *maps) +{ + return RC_CHK_ACCESS(maps)->maps_by_name; +} + +static struct map_rb_node *maps__first(struct maps *maps) +{ + struct rb_node *first =3D rb_first(maps__entries(maps)); + + if (first) + return rb_entry(first, struct map_rb_node, rb_node); + return NULL; +} + +static struct map_rb_node *map_rb_node__next(struct map_rb_node *node) +{ + struct rb_node *next; + + if (!node) + return NULL; + + next =3D rb_next(&node->rb_node); + + if (!next) + return NULL; + + return rb_entry(next, struct map_rb_node, rb_node); +} + +static struct map_rb_node *maps__find_node(struct maps *maps, struct map *= map) +{ + struct map_rb_node *rb_node; + + maps__for_each_entry(maps, rb_node) { + if (rb_node->RC_CHK_ACCESS(map) =3D=3D RC_CHK_ACCESS(map)) + return rb_node; + } + return NULL; +} + static void maps__init(struct maps *maps, struct machine *machine) { refcount_set(maps__refcnt(maps), 1); @@ -484,17 +539,6 @@ int maps__copy_from(struct maps *maps, struct maps *pa= rent) return err; } =20 -struct map_rb_node *maps__find_node(struct maps *maps, struct map *map) -{ - struct map_rb_node *rb_node; - - maps__for_each_entry(maps, rb_node) { - if (rb_node->RC_CHK_ACCESS(map) =3D=3D RC_CHK_ACCESS(map)) - return rb_node; - } - return NULL; -} - struct map *maps__find(struct maps *maps, u64 ip) { struct rb_node *p; @@ -520,30 +564,6 @@ struct map *maps__find(struct maps *maps, u64 ip) return m ? m->map : NULL; } =20 -struct map_rb_node *maps__first(struct maps *maps) -{ - struct rb_node *first =3D rb_first(maps__entries(maps)); - - if (first) - return rb_entry(first, struct map_rb_node, rb_node); - return NULL; -} - -struct map_rb_node *map_rb_node__next(struct map_rb_node *node) -{ - struct rb_node *next; - - if (!node) - return NULL; - - next =3D rb_next(&node->rb_node); - - if (!next) - return NULL; - - return rb_entry(next, struct map_rb_node, rb_node); -} - static int map__strcmp(const void *a, const void *b) { const struct map *map_a =3D *(const struct map **)a; diff --git a/tools/perf/util/maps.h b/tools/perf/util/maps.h index 84b42c8456e8..d836d04c9402 100644 --- a/tools/perf/util/maps.h +++ b/tools/perf/util/maps.h @@ -15,11 +15,6 @@ struct machine; struct map; struct maps; =20 -struct map_rb_node { - struct rb_node rb_node; - struct map *map; -}; - struct map_list_node { struct list_head node; struct map *map; @@ -30,9 +25,6 @@ static inline struct map_list_node *map_list_node__new(vo= id) return malloc(sizeof(struct map_list_node)); } =20 -struct map_rb_node *maps__first(struct maps *maps); -struct map_rb_node *map_rb_node__next(struct map_rb_node *node); -struct map_rb_node *maps__find_node(struct maps *maps, struct map *map); struct map *maps__find(struct maps *maps, u64 addr); =20 DECLARE_RC_STRUCT(maps) { @@ -78,26 +70,11 @@ int maps__for_each_map(struct maps *maps, int (*cb)(str= uct map *map, void *data) /* Iterate over map removing an entry if cb returns true. */ void maps__remove_maps(struct maps *maps, bool (*cb)(struct map *map, void= *data), void *data); =20 -static inline struct rb_root *maps__entries(struct maps *maps) -{ - return &RC_CHK_ACCESS(maps)->entries; -} - static inline struct machine *maps__machine(struct maps *maps) { return RC_CHK_ACCESS(maps)->machine; } =20 -static inline struct rw_semaphore *maps__lock(struct maps *maps) -{ - return &RC_CHK_ACCESS(maps)->lock; -} - -static inline struct map **maps__maps_by_name(struct maps *maps) -{ - return RC_CHK_ACCESS(maps)->maps_by_name; -} - static inline unsigned int maps__nr_maps(const struct maps *maps) { return RC_CHK_ACCESS(maps)->nr_maps; --=20 2.42.0.758.gaed0368e0e-goog