summaryrefslogtreecommitdiff
path: root/simpleperf/workload.cpp
diff options
context:
space:
mode:
authorAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2022-08-31 23:30:01 +0000
committerAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2022-08-31 23:30:01 +0000
commite4df6724d440458f7c3ed6f4e709b42a492a52a8 (patch)
tree7423d08ebb843064b0a468d3007a7e6f56287aa2 /simpleperf/workload.cpp
parent48f188ddea5c4925121a34655187585dcdb04794 (diff)
parente275d1e943acdaeaaa644dc7cb1db5c4cf73f4e8 (diff)
downloadextras-android13-qpr1-s4-release.tar.gz
Change-Id: I17038ae8868dee099c35012fea1ac753422720e3
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..92c6537b 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(WARNING) << "sched_setaffinity failed";
+ return false;
+ }
+ return true;
+}
+
bool Workload::Start() {
CHECK_EQ(work_state_, NotYetStartNewProcess);
char start_signal = 1;