[PATCH 05/22] perf tools: Do hugetlb handling in more systems

From: Arnaldo Carvalho de Melo
Date: Tue Sep 20 2016 - 16:08:24 EST


From: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>

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@xxxxxxxxx>
Cc: David Ahern <dsahern@xxxxxxxxx>
Cc: Jiri Olsa <jolsa@xxxxxxxxxx>
Cc: Namhyung Kim <namhyung@xxxxxxxxxx>
Cc: Wang Nan <wangnan0@xxxxxxxxxx>
Cc: Zefan Li <lizefan@xxxxxxxxxx>
Link: http://lkml.kernel.org/n/tip-wv6oqbfkpxbix4umj2kcfmaz@xxxxxxxxxxxxxx
Signed-off-by: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>
---
tools/perf/util/event.c | 7 ++-----
tools/perf/util/map.c | 9 ++-------
2 files changed, 4 insertions(+), 12 deletions(-)

diff --git a/tools/perf/util/event.c b/tools/perf/util/event.c
index 6c3017139c67..2880e2226fdb 100644
--- a/tools/perf/util/event.c
+++ b/tools/perf/util/event.c
@@ -1,5 +1,5 @@
#include <linux/types.h>
-#include <sys/mman.h>
+#include <uapi/linux/mman.h> /* To get things like MAP_HUGETLB even on older libc headers */
#include <api/fs/fs.h>
#include "event.h"
#include "debug.h"
@@ -249,10 +249,8 @@ int perf_event__synthesize_mmap_events(struct perf_tool *tool,
bool truncation = false;
unsigned long long timeout = proc_map_timeout * 1000000ULL;
int rc = 0;
-#ifdef MAP_HUGETLB
const char *hugetlbfs_mnt = hugetlbfs__mountpoint();
int hugetlbfs_mnt_len = hugetlbfs_mnt ? strlen(hugetlbfs_mnt) : 0;
-#endif

if (machine__is_default_guest(machine))
return 0;
@@ -347,12 +345,11 @@ out:

if (!strcmp(execname, ""))
strcpy(execname, anonstr);
-#ifdef MAP_HUGETLB
+
if (!strncmp(execname, hugetlbfs_mnt, hugetlbfs_mnt_len)) {
strcpy(execname, anonstr);
event->mmap2.flags |= MAP_HUGETLB;
}
-#endif

size = strlen(execname) + 1;
memcpy(event->mmap2.filename, execname, size);
diff --git a/tools/perf/util/map.c b/tools/perf/util/map.c
index d51a1257973b..c662fef95d14 100644
--- a/tools/perf/util/map.c
+++ b/tools/perf/util/map.c
@@ -6,7 +6,7 @@
#include <string.h>
#include <stdio.h>
#include <unistd.h>
-#include <sys/mman.h>
+#include <uapi/linux/mman.h> /* To get things like MAP_HUGETLB even on older libc headers */
#include "map.h"
#include "thread.h"
#include "strlist.h"
@@ -27,12 +27,7 @@ const char *map_type__name[MAP__NR_TYPES] = {

static inline int is_anon_memory(const char *filename, u32 flags)
{
- u32 anon_flags = 0;
-
-#ifdef MAP_HUGETLB
- anon_flags |= MAP_HUGETLB;
-#endif
- return flags & anon_flags ||
+ return flags & MAP_HUGETLB ||
!strcmp(filename, "//anon") ||
!strncmp(filename, "/dev/zero", sizeof("/dev/zero") - 1) ||
!strncmp(filename, "/anon_hugepage", sizeof("/anon_hugepage") - 1);
--
2.7.4