summaryrefslogtreecommitdiff
path: root/simpleperf/workload.cpp
diff options
context:
space:
mode:
authorSamip Garg <samgarg@google.com>2022-11-17 11:29:02 -0800
committerSamip Garg <samgarg@google.com>2022-12-08 18:09:55 +0000
commite65f708054668046d09560bb13943373b6b5a274 (patch)
tree1dd5c9a3b955c541c00b4621fa3e02051606f028 /simpleperf/workload.cpp
parentdf142880e86418dad6b40fddb001ebd897919595 (diff)
parentdd4402341ecff9c89e60b739b62dfde4f3002370 (diff)
downloadextras-e65f708054668046d09560bb13943373b6b5a274.tar.gz
Snap tm-dev to android13-tests-dev
Bug:259849956 Merge ab/9299233 Merged-In: Ib4c566b0bd0e5c761d9c78620caa13703c10589c Change-Id: If320111be77cb6d02307b8442148140a0c494169
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;