linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Namhyung Kim <namhyung@kernel.org>
To: James Clark <james.clark@arm.com>
Cc: linux-perf-users@vger.kernel.org, atrajeev@linux.vnet.ibm.com,
	 irogers@google.com, Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@redhat.com>,
	 Arnaldo Carvalho de Melo <acme@kernel.org>,
	Mark Rutland <mark.rutland@arm.com>,
	 Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	Jiri Olsa <jolsa@kernel.org>,
	 Adrian Hunter <adrian.hunter@intel.com>,
	"Liang, Kan" <kan.liang@linux.intel.com>,
	 linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2/4] perf maps: Re-use __maps__free_maps_by_name()
Date: Tue, 7 May 2024 21:06:39 -0700	[thread overview]
Message-ID: <CAM9d7chQ9UW3+axnCSCYeOi3mRSwJbSmUS0YzTRa8tuXr1TbBA@mail.gmail.com> (raw)
In-Reply-To: <20240507141210.195939-3-james.clark@arm.com>

On Tue, May 7, 2024 at 7:13 AM James Clark <james.clark@arm.com> wrote:
>
> maps__merge_in() hard codes the steps to free the maps_by_name list. It
> seems to not map__put() each element before freeing, and it sets
> maps_by_name_sorted to true after freeing, which may be harmless but
> is inconsistent with maps__init() and other functions.
>
> maps__maps_by_name_addr() is also quite hard to read because we already
> have maps__maps_by_name() and maps__maps_by_address(), but the function
> is only used in that place so delete it.

Agreed, I feel like we need some more cleanup here.

Thanks,
Namhyung


>
> Signed-off-by: James Clark <james.clark@arm.com>
> ---
>  tools/perf/util/maps.c | 14 +++++++-------
>  1 file changed, 7 insertions(+), 7 deletions(-)
>
> diff --git a/tools/perf/util/maps.c b/tools/perf/util/maps.c
> index 61eb742d91e3..16b39db594f4 100644
> --- a/tools/perf/util/maps.c
> +++ b/tools/perf/util/maps.c
> @@ -124,11 +124,6 @@ static void maps__set_maps_by_address(struct maps *maps, struct map **new)
>
>  }
>
> -static struct map ***maps__maps_by_name_addr(struct maps *maps)
> -{
> -       return &RC_CHK_ACCESS(maps)->maps_by_name;
> -}
> -
>  static void maps__set_nr_maps_allocated(struct maps *maps, unsigned int nr_maps_allocated)
>  {
>         RC_CHK_ACCESS(maps)->nr_maps_allocated = nr_maps_allocated;
> @@ -284,6 +279,9 @@ void maps__put(struct maps *maps)
>
>  static void __maps__free_maps_by_name(struct maps *maps)
>  {
> +       if (!maps__maps_by_name(maps))
> +               return;
> +
>         /*
>          * Free everything to try to do it from the rbtree in the next search
>          */
> @@ -291,6 +289,9 @@ static void __maps__free_maps_by_name(struct maps *maps)
>                 map__put(maps__maps_by_name(maps)[i]);
>
>         zfree(&RC_CHK_ACCESS(maps)->maps_by_name);
> +
> +       /* Consistent with maps__init(). When maps_by_name == NULL, maps_by_name_sorted == false */
> +       maps__set_maps_by_name_sorted(maps, false);
>  }
>
>  static int map__start_cmp(const void *a, const void *b)
> @@ -1167,8 +1168,7 @@ int maps__merge_in(struct maps *kmaps, struct map *new_map)
>         }
>         maps__set_maps_by_address(kmaps, merged_maps_by_address);
>         maps__set_maps_by_address_sorted(kmaps, true);
> -       zfree(maps__maps_by_name_addr(kmaps));
> -       maps__set_maps_by_name_sorted(kmaps, true);
> +       __maps__free_maps_by_name(kmaps);
>         maps__set_nr_maps_allocated(kmaps, merged_nr_maps_allocated);
>
>         /* Copy entries before the new_map that can't overlap. */
> --
> 2.34.1
>

  reply	other threads:[~2024-05-08  4:06 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-07 14:12 [PATCH 0/4] perf maps/symbols: Various assert fixes James Clark
2024-05-07 14:12 ` [PATCH 1/4] perf symbols: Remove map from list before updating addresses James Clark
2024-05-07 14:12 ` [PATCH 2/4] perf maps: Re-use __maps__free_maps_by_name() James Clark
2024-05-08  4:06   ` Namhyung Kim [this message]
2024-05-08 22:06   ` Ian Rogers
2024-05-07 14:12 ` [PATCH 3/4] perf symbols: Update kcore map before merging in remaining symbols James Clark
2024-05-08  4:10   ` Namhyung Kim
2024-05-08  9:14     ` James Clark
2024-05-08 14:19       ` Leo Yan
2024-05-07 14:12 ` [PATCH 4/4] perf symbols: Fix ownership of string in dso__load_vmlinux() James Clark
2024-05-08 22:14   ` Ian Rogers
2024-05-07 15:11 ` [PATCH 0/4] perf maps/symbols: Various assert fixes Arnaldo Carvalho de Melo
2024-05-07 15:12   ` Arnaldo Carvalho de Melo
2024-05-08  7:52     ` James Clark

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAM9d7chQ9UW3+axnCSCYeOi3mRSwJbSmUS0YzTRa8tuXr1TbBA@mail.gmail.com \
    --to=namhyung@kernel.org \
    --cc=acme@kernel.org \
    --cc=adrian.hunter@intel.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=atrajeev@linux.vnet.ibm.com \
    --cc=irogers@google.com \
    --cc=james.clark@arm.com \
    --cc=jolsa@kernel.org \
    --cc=kan.liang@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).