From: Namhyung Kim <namhyung@kernel.org>
To: Andrii Nakryiko <andrii.nakryiko@gmail.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>,
Ian Rogers <irogers@google.com>,
Kan Liang <kan.liang@linux.intel.com>,
Jiri Olsa <jolsa@kernel.org>,
Adrian Hunter <adrian.hunter@intel.com>,
Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@kernel.org>,
LKML <linux-kernel@vger.kernel.org>,
linux-perf-users@vger.kernel.org, bpf@vger.kernel.org
Subject: Re: [PATCH 1/2] perf tools: Fix possible compiler warnings in hashmap
Date: Fri, 11 Oct 2024 09:44:46 -0700 [thread overview]
Message-ID: <ZwlV_jyx3OjfQxwS@google.com> (raw)
In-Reply-To: <CAEf4BzYQenNtKPmWV=P3EsnqBsjNuAeXpC5ypL1k2z-H60i0=w@mail.gmail.com>
On Thu, Oct 10, 2024 at 06:48:26PM -0700, Andrii Nakryiko wrote:
> On Wed, Oct 9, 2024 at 1:20 PM Namhyung Kim <namhyung@kernel.org> wrote:
> >
> > The hashmap__for_each_entry[_safe] is accessing 'map' as if it's a
> > pointer. But it does without parentheses so passing a static hash map
> > with an ampersand (like &slab_hash below) caused compiler warnings due
> > to unmatched types.
> >
> > In file included from util/bpf_lock_contention.c:5:
> > util/bpf_lock_contention.c: In function ‘exit_slab_cache_iter’:
> > linux/tools/perf/util/hashmap.h:169:32: error: invalid type argument of ‘->’ (have ‘struct hashmap’)
> > 169 | for (bkt = 0; bkt < map->cap; bkt++) \
> > | ^~
> > util/bpf_lock_contention.c:105:9: note: in expansion of macro ‘hashmap__for_each_entry’
> > 105 | hashmap__for_each_entry(&slab_hash, cur, bkt)
> > | ^~~~~~~~~~~~~~~~~~~~~~~
> > /home/namhyung/project/linux/tools/perf/util/hashmap.h:170:31: error: invalid type argument of ‘->’ (have ‘struct hashmap’)
> > 170 | for (cur = map->buckets[bkt]; cur; cur = cur->next)
> > | ^~
> > util/bpf_lock_contention.c:105:9: note: in expansion of macro ‘hashmap__for_each_entry’
> > 105 | hashmap__for_each_entry(&slab_hash, cur, bkt)
> > | ^~~~~~~~~~~~~~~~~~~~~~~
> >
> > Cc: bpf@vger.kernel.org
> > Signed-off-by: Namhyung Kim <namhyung@kernel.org>
> > ---
> > I've discovered this while prototyping the slab symbolization for perf
> > lock contention. So this code is not available yet but I'd like to fix
> > the problem first.
> >
> > Also noticed bpf has the same code and the same problem. I'll send a
> > separate patch for them.
> >
>
> Yep, please do. Fixes look good, thanks.
Sure will do, can I get your Acked-by for this patch?
Thanks,
Namhyung
>
> > tools/perf/util/hashmap.h | 20 ++++++++++----------
> > 1 file changed, 10 insertions(+), 10 deletions(-)
> >
> > diff --git a/tools/perf/util/hashmap.h b/tools/perf/util/hashmap.h
> > index c12f8320e6682d50..0c4f155e8eb745d9 100644
> > --- a/tools/perf/util/hashmap.h
> > +++ b/tools/perf/util/hashmap.h
> > @@ -166,8 +166,8 @@ bool hashmap_find(const struct hashmap *map, long key, long *value);
> > * @bkt: integer used as a bucket loop cursor
> > */
> > #define hashmap__for_each_entry(map, cur, bkt) \
> > - for (bkt = 0; bkt < map->cap; bkt++) \
> > - for (cur = map->buckets[bkt]; cur; cur = cur->next)
> > + for (bkt = 0; bkt < (map)->cap; bkt++) \
> > + for (cur = (map)->buckets[bkt]; cur; cur = cur->next)
> >
> > /*
> > * hashmap__for_each_entry_safe - iterate over all entries in hashmap, safe
> > @@ -178,8 +178,8 @@ bool hashmap_find(const struct hashmap *map, long key, long *value);
> > * @bkt: integer used as a bucket loop cursor
> > */
> > #define hashmap__for_each_entry_safe(map, cur, tmp, bkt) \
> > - for (bkt = 0; bkt < map->cap; bkt++) \
> > - for (cur = map->buckets[bkt]; \
> > + for (bkt = 0; bkt < (map)->cap; bkt++) \
> > + for (cur = (map)->buckets[bkt]; \
> > cur && ({tmp = cur->next; true; }); \
> > cur = tmp)
> >
> > @@ -190,19 +190,19 @@ bool hashmap_find(const struct hashmap *map, long key, long *value);
> > * @key: key to iterate entries for
> > */
> > #define hashmap__for_each_key_entry(map, cur, _key) \
> > - for (cur = map->buckets \
> > - ? map->buckets[hash_bits(map->hash_fn((_key), map->ctx), map->cap_bits)] \
> > + for (cur = (map)->buckets \
> > + ? (map)->buckets[hash_bits((map)->hash_fn((_key), (map)->ctx), (map)->cap_bits)] \
> > : NULL; \
> > cur; \
> > cur = cur->next) \
> > - if (map->equal_fn(cur->key, (_key), map->ctx))
> > + if ((map)->equal_fn(cur->key, (_key), (map)->ctx))
> >
> > #define hashmap__for_each_key_entry_safe(map, cur, tmp, _key) \
> > - for (cur = map->buckets \
> > - ? map->buckets[hash_bits(map->hash_fn((_key), map->ctx), map->cap_bits)] \
> > + for (cur = (map)->buckets \
> > + ? (map)->buckets[hash_bits((map)->hash_fn((_key), (map)->ctx), (map)->cap_bits)] \
> > : NULL; \
> > cur && ({ tmp = cur->next; true; }); \
> > cur = tmp) \
> > - if (map->equal_fn(cur->key, (_key), map->ctx))
> > + if ((map)->equal_fn(cur->key, (_key), (map)->ctx))
> >
> > #endif /* __LIBBPF_HASHMAP_H */
> > --
> > 2.47.0.rc0.187.ge670bccf7e-goog
> >
> >
next prev parent reply other threads:[~2024-10-11 16:44 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-09 20:20 [PATCH 1/2] perf tools: Fix possible compiler warnings in hashmap Namhyung Kim
2024-10-09 20:20 ` [PATCH 2/2] perf tools: Remove unnecessary parentheses Namhyung Kim
2024-10-11 1:48 ` [PATCH 1/2] perf tools: Fix possible compiler warnings in hashmap Andrii Nakryiko
2024-10-11 16:44 ` Namhyung Kim [this message]
2024-10-11 18:00 ` Andrii Nakryiko
2024-10-16 17:12 ` Namhyung Kim
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=ZwlV_jyx3OjfQxwS@google.com \
--to=namhyung@kernel.org \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=andrii.nakryiko@gmail.com \
--cc=bpf@vger.kernel.org \
--cc=irogers@google.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=mingo@kernel.org \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.