Skip to content

Commit 94fddb7

Browse files
committed
perf tools: Sync hashmap.h with libbpf's
To pick up the changes in: b2f9f15 ("libbpf: Fix libbpf hashmap on (I)LP32 architectures") Silencing this warning: Warning: Kernel ABI header at 'tools/perf/util/hashmap.h' differs from latest version at 'tools/lib/bpf/hashmap.h' diff -u tools/perf/util/hashmap.h tools/lib/bpf/hashmap.h I'll eventually update the warning to remove the "Kernel ABI" part and instead state libbpf when noticing that the original is at "tools/lib/something". Cc: Adrian Hunter <[email protected]> Cc: Alexei Starovoitov <[email protected]> Cc: Andrii Nakryiko <[email protected]> Cc: Jakub Bogusz <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Namhyung Kim <[email protected]> Ian Rogers <[email protected]> Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent a2db71b commit 94fddb7

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

tools/perf/util/hashmap.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,18 @@
1111
#include <stdbool.h>
1212
#include <stddef.h>
1313
#include <limits.h>
14-
#ifndef __WORDSIZE
15-
#define __WORDSIZE (__SIZEOF_LONG__ * 8)
16-
#endif
1714

1815
static inline size_t hash_bits(size_t h, int bits)
1916
{
2017
/* shuffle bits and return requested number of upper bits */
21-
return (h * 11400714819323198485llu) >> (__WORDSIZE - bits);
18+
#if (__SIZEOF_SIZE_T__ == __SIZEOF_LONG_LONG__)
19+
/* LP64 case */
20+
return (h * 11400714819323198485llu) >> (__SIZEOF_LONG_LONG__ * 8 - bits);
21+
#elif (__SIZEOF_SIZE_T__ <= __SIZEOF_LONG__)
22+
return (h * 2654435769lu) >> (__SIZEOF_LONG__ * 8 - bits);
23+
#else
24+
# error "Unsupported size_t size"
25+
#endif
2226
}
2327

2428
typedef size_t (*hashmap_hash_fn)(const void *key, void *ctx);

0 commit comments

Comments
 (0)