summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVincent Zhang <xunz@nvidia.com>2019-05-28 10:51:03 +0800
committerYabin Cui <yabinc@google.com>2019-06-25 11:13:03 -0700
commit758c2ddabbd68af14880f84b375a5819c52c7968 (patch)
treea2201a5d1182123270bd6891a6e25fe3e9b68bae
parent429c4770daf538112ba0424b919450e5e1228754 (diff)
downloadextras-758c2ddabbd68af14880f84b375a5819c52c7968.tar.gz
simpleperf: Add bottom up memory layout support
There are chances that instead of allocating a vma on every mmap() call, an existing vma gets chosen and expanded. On system that using legacy memory layout(mmap grows bottom up), vma_merge() updates the vm_end instead of vm_start in the chosen vma, which results in a false mismatch (record.data->addr == thread_arg.mmap_start_addr) in GetClockDiff(). To make simpleperf compatible with bottom up memory layout, we need to force vma allocation on mmap() calls, one approach is by assigning name to each anonymous mmap region. Bug: 136012903 Test: run CtsSimpleperfTestCases. Change-Id: I4c833105d9921a5db1493c60fcf6d06eb2cd3a96
-rw-r--r--simpleperf/environment.h6
-rw-r--r--simpleperf/perf_clock.cpp4
2 files changed, 10 insertions, 0 deletions
diff --git a/simpleperf/environment.h b/simpleperf/environment.h
index 7f8683de..8886e470 100644
--- a/simpleperf/environment.h
+++ b/simpleperf/environment.h
@@ -23,6 +23,7 @@
#if defined(__linux__)
#include <sys/syscall.h>
#include <unistd.h>
+#include <sys/prctl.h>
#endif
#include <functional>
@@ -35,6 +36,11 @@
#include "build_id.h"
#include "perf_regs.h"
+#if defined(__ANDROID__)
+ #define PR_SET_VMA 0x53564d41
+ #define PR_SET_VMA_ANON_NAME 0
+#endif
+
std::vector<int> GetOnlineCpus();
std::vector<int> GetCpusFromString(const std::string& s);
diff --git a/simpleperf/perf_clock.cpp b/simpleperf/perf_clock.cpp
index 127470e7..127fd21d 100644
--- a/simpleperf/perf_clock.cpp
+++ b/simpleperf/perf_clock.cpp
@@ -70,6 +70,10 @@ static void ThreadA(ThreadArg* thread_arg) {
}
array[i].end_system_time_in_ns = GetSystemClock();
+
+#if defined(__ANDROID__)
+ prctl(PR_SET_VMA, PR_SET_VMA_ANON_NAME, array[i].mmap_start_addr, 4096, "anony_map_region");
+#endif
}
size_t best_index = 0;
uint64_t min_duration_in_ns = UINT64_MAX;