Re: [PATCH v3 09/22] perf map: Add const to map_ip and unmap_ip

Arnaldo Carvalho de Melo
2022-02-11T17:28:25Z

Em Fri, Feb 11, 2022 at 02:34:02AM -0800, Ian Rogers escreveu:
> Functions purely determine a value from the map and don't need to modify
> it. Move functions to C file as they are most commonly used via a
> function pointer.

Builds, applied.

- Arnaldo

> Signed-off-by: Ian Rogers <irogers@google.com>
> ---
> tools/perf/util/map.c | 15 +++++++++++++++
> tools/perf/util/map.h | 24 ++++++++----------------
> 2 files changed, 23 insertions(+), 16 deletions(-)
>
> diff --git a/tools/perf/util/map.c b/tools/perf/util/map.c
> index 2cfe5744b86c..b98fb000eb5c 100644
> --- a/tools/perf/util/map.c
> +++ b/tools/perf/util/map.c
> @@ -563,3 +563,18 @@ struct maps *map__kmaps(struct map *map)
> }
> return kmap->kmaps;
> }
> +
> +u64 map__map_ip(const struct map *map, u64 ip)
> +{
> + return ip - map->start + map->pgoff;
> +}
> +
> +u64 map__unmap_ip(const struct map *map, u64 ip)
> +{
> + return ip + map->start - map->pgoff;
> +}
> +
> +u64 identity__map_ip(const struct map *map __maybe_unused, u64 ip)
> +{
> + return ip;
> +}
> diff --git a/tools/perf/util/map.h b/tools/perf/util/map.h
> index 973dce27b253..212a9468d5e1 100644
> --- a/tools/perf/util/map.h
> +++ b/tools/perf/util/map.h
> @@ -29,9 +29,9 @@ struct map {
> u64 reloc;
>
> /* ip -> dso rip */
> - u64 (*map_ip)(struct map *, u64);
> + u64 (*map_ip)(const struct map *, u64);
> /* dso rip -> ip */
> - u64 (*unmap_ip)(struct map *, u64);
> + u64 (*unmap_ip)(const struct map *, u64);
>
> struct dso *dso;
> refcount_t refcnt;
> @@ -44,20 +44,12 @@ struct kmap *__map__kmap(struct map *map);
> struct kmap *map__kmap(struct map *map);
> struct maps *map__kmaps(struct map *map);
>
> -static inline u64 map__map_ip(struct map *map, u64 ip)
> -{
> - return ip - map->start + map->pgoff;
> -}
> -
> -static inline u64 map__unmap_ip(struct map *map, u64 ip)
> -{
> - return ip + map->start - map->pgoff;
> -}
> -
> -static inline u64 identity__map_ip(struct map *map __maybe_unused, u64 ip)
> -{
> - return ip;
> -}
> +/* ip -> dso rip */
> +u64 map__map_ip(const struct map *map, u64 ip);
> +/* dso rip -> ip */
> +u64 map__unmap_ip(const struct map *map, u64 ip);
> +/* Returns ip */
> +u64 identity__map_ip(const struct map *map __maybe_unused, u64 ip);
>
> static inline size_t map__size(const struct map *map)
> {
> --
> 2.35.1.265.g69c8d7142f-goog

--

- Arnaldo