From nobody Wed Dec 17 12:44:26 2025 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 0B265C4167B for ; Mon, 27 Nov 2023 22:11:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234165AbjK0WLk (ORCPT ); Mon, 27 Nov 2023 17:11:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39198 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233816AbjK0WKu (ORCPT ); Mon, 27 Nov 2023 17:10:50 -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 B5E2A2698 for ; Mon, 27 Nov 2023 14:10:17 -0800 (PST) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-5cdc42ce40fso47466297b3.2 for ; Mon, 27 Nov 2023 14:10:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1701123017; x=1701727817; 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=jKzr4H8qcCWkzlhhc5mjc/fFOHye0m+UsUUrI2SedSA=; b=HtMZ9Zvgj5ZtK5nQb4syb6X+0JZdUGOwgIzsY+sCZ1WxNSPpPwsApBt9NqmLb1e/aO CEiqc8oDdKctNCYZ77cT9ofL4vl7cMntVok3wrFX0Ak1UJbZFqGqJLP2FF+7mDXw8yqX CYP+yThPsFQeE6L5/BRZyDgrKoM2bC+6hKrQYsmSvo05WcRw5ko70cVV/FFIsjOU6svv k07yV1EVhcs2Ma7Nxlgo4KtjjIfUKl4TFsUoByCRX6WUwrrG9gZr1zoxiQ4jACOsqUYb GgyRvCsOwf8Z69zbjp4ryYCnZREHaqeojUszYwH1Czbl/cGbnxvI1iqOmQy/ZfS1zb/5 5vbg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701123017; x=1701727817; 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=jKzr4H8qcCWkzlhhc5mjc/fFOHye0m+UsUUrI2SedSA=; b=tkdWvdEZHCbUv3/+4Z4zc0b5VSgJeglJ5MXgHu1rCBNXaEbXG6u4HdJxIzxSmzhPcq HLEQIIU0S49HSmyRvxfJfSalFSkC47S7pSW9KC3T+lBKTHCYLBHOm2whh+J1rtK9yiyC 2GfsAYqVsPcvem7Sz4pIwBVEqfWud3ioYhKApVV7cGRC2VhSyI4fsKvyJnkhUlOF63ZY Vqh7ezcOuvYdX+Hv1IPtaPa5tE1IcddvWWwzXizByfVUEE/eCl8+Ovlw+sRwbJ1mwvhv AwFXSCQX0S5pPQSXCGfJIPwlOCTqBW4hPqTqHtTdnbpXM/fb+dG5lwvzQ7wKSl/AXGM6 k4Ig== X-Gm-Message-State: AOJu0YwpfRwkZshXc3nWcqsbQsshyGMlek/zDWJUgDtsMAhu7+QZikw8 eR4rRG9lHLeBB8o6vX/l2wQYcEBzNqqF X-Google-Smtp-Source: AGHT+IFJle4INsVGPSDBR1xRQd8J7thNGlnSrJnGQPECathmKLurp7jYbvbJe+Y8Yr2fTDevXLkgMuHftixt X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:829:6e77:9093:f39b]) (user=irogers job=sendgmr) by 2002:a05:690c:480d:b0:5ce:a88:8436 with SMTP id hc13-20020a05690c480d00b005ce0a888436mr379574ywb.10.1701123016797; Mon, 27 Nov 2023 14:10:16 -0800 (PST) Date: Mon, 27 Nov 2023 14:08:35 -0800 In-Reply-To: <20231127220902.1315692-1-irogers@google.com> Message-Id: <20231127220902.1315692-24-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 23/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 , 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 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.43.0.rc1.413.gea7ed67945-goog