summaryrefslogtreecommitdiff
path: root/simpleperf/workload.cpp
diff options
context:
space:
mode:
authorYabin <yabinc@google.com>2022-08-18 17:01:54 -0700
committerYabin Cui <yabinc@google.com>2022-08-29 14:12:49 -0700
commitff1c578a0cb239dceb0f0c8ab333bd4d045ff2d8 (patch)
tree361f01179e8caf5f62ce1cc66b4635c06707cb66 /simpleperf/workload.cpp
parent3e6c8ea1a7623771be4f8b60422ebc8a1b4d7730 (diff)
downloadextras-ff1c578a0cb239dceb0f0c8ab333bd4d045ff2d8.tar.gz
simpleperf: update --print-hw-counter to check each cpu.
Little/Big cores may have different numbers of CPU PMU hardware counters. So check them separately. Bug: 243034569 Test: run simpleperf_unit_test Change-Id: I33527d69bc935b8523482feaf98378c5f6641762 (cherry picked from commit 6b771a2e12740f4bbcef515d772e62b364d87858)
Diffstat (limited to 'simpleperf/workload.cpp')
-rw-r--r--simpleperf/workload.cpp13
1 files changed, 13 insertions, 0 deletions
diff --git a/simpleperf/workload.cpp b/simpleperf/workload.cpp
index 4bb7c540..142ed713 100644
--- a/simpleperf/workload.cpp
+++ b/simpleperf/workload.cpp
@@ -18,6 +18,7 @@
#include <errno.h>
#include <fcntl.h>
+#include <sched.h>
#include <sys/prctl.h>
#include <sys/wait.h>
#include <unistd.h>
@@ -160,6 +161,18 @@ void Workload::ChildProcessFn(int start_signal_fd, int exec_child_fd) {
}
}
+bool Workload::SetCpuAffinity(int cpu) {
+ CHECK_EQ(work_state_, NotYetStartNewProcess);
+ cpu_set_t mask;
+ CPU_ZERO(&mask);
+ CPU_SET(cpu, &mask);
+ if (sched_setaffinity(GetPid(), sizeof(mask), &mask) != 0) {
+ PLOG(ERROR) << "sched_setaffinity failed";
+ return false;
+ }
+ return true;
+}
+
bool Workload::Start() {
CHECK_EQ(work_state_, NotYetStartNewProcess);
char start_signal = 1;