Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf tools: Do hugetlb handling in more systems

The csets:

0ac3348e5024 ("perf tools: Recognize hugetlb mapping as anon mapping")
d7e404af115b ("perf record: Mark MAP_HUGETLB when synthesizing mmap events")

Added code conditional on MAP_HUGETLB, to make it build in older systems
where that define wasn't available. Now that we grabbed copies of
uapi/linux/mmap.h to have all those definitions in tools/, use it so
that we can support building the tools for older systems (without the
MAP_HUGETLB define in its libc headers) using new kernels that support
such maps.

Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Wang Nan <wangnan0@huawei.com>
Cc: Zefan Li <lizefan@huawei.com>
Link: http://lkml.kernel.org/n/tip-wv6oqbfkpxbix4umj2kcfmaz@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

+4 -12
+2 -5
tools/perf/util/event.c
··· 1 1 #include <linux/types.h> 2 - #include <sys/mman.h> 2 + #include <uapi/linux/mman.h> /* To get things like MAP_HUGETLB even on older libc headers */ 3 3 #include <api/fs/fs.h> 4 4 #include "event.h" 5 5 #include "debug.h" ··· 249 249 bool truncation = false; 250 250 unsigned long long timeout = proc_map_timeout * 1000000ULL; 251 251 int rc = 0; 252 - #ifdef MAP_HUGETLB 253 252 const char *hugetlbfs_mnt = hugetlbfs__mountpoint(); 254 253 int hugetlbfs_mnt_len = hugetlbfs_mnt ? strlen(hugetlbfs_mnt) : 0; 255 - #endif 256 254 257 255 if (machine__is_default_guest(machine)) 258 256 return 0; ··· 345 347 346 348 if (!strcmp(execname, "")) 347 349 strcpy(execname, anonstr); 348 - #ifdef MAP_HUGETLB 350 + 349 351 if (!strncmp(execname, hugetlbfs_mnt, hugetlbfs_mnt_len)) { 350 352 strcpy(execname, anonstr); 351 353 event->mmap2.flags |= MAP_HUGETLB; 352 354 } 353 - #endif 354 355 355 356 size = strlen(execname) + 1; 356 357 memcpy(event->mmap2.filename, execname, size);
+2 -7
tools/perf/util/map.c
··· 6 6 #include <string.h> 7 7 #include <stdio.h> 8 8 #include <unistd.h> 9 - #include <sys/mman.h> 9 + #include <uapi/linux/mman.h> /* To get things like MAP_HUGETLB even on older libc headers */ 10 10 #include "map.h" 11 11 #include "thread.h" 12 12 #include "strlist.h" ··· 27 27 28 28 static inline int is_anon_memory(const char *filename, u32 flags) 29 29 { 30 - u32 anon_flags = 0; 31 - 32 - #ifdef MAP_HUGETLB 33 - anon_flags |= MAP_HUGETLB; 34 - #endif 35 - return flags & anon_flags || 30 + return flags & MAP_HUGETLB || 36 31 !strcmp(filename, "//anon") || 37 32 !strncmp(filename, "/dev/zero", sizeof("/dev/zero") - 1) || 38 33 !strncmp(filename, "/anon_hugepage", sizeof("/anon_hugepage") - 1);