Fix bug in --bionic_cpu option handling.
Make sure that all the variables are properly initialized.
Remove the code that verifies the core to enable using get_schedaffinity
since that make it impossible to change the cpu for different tests.
Change the cpu_to_lock to an int, it really didn't need to be a long.
Fix a few missing tests.
Test: Ran unit tests.
Test: Built the tests and ran on different cpus, verifying that the
Test: chosen cpu was correct.
Test: Created an xml file that had different cpus for different tests
Test: and verified that it locked to each cpu properly.
Change-Id: Ie7b4ad8f306f13d6e968d118e71bb5dc0221552a
diff --git a/benchmarks/util.cpp b/benchmarks/util.cpp
index 92e8243..ec74147 100644
--- a/benchmarks/util.cpp
+++ b/benchmarks/util.cpp
@@ -71,36 +71,17 @@
#else
-bool LockToCPU(long cpu_to_lock) {
+bool LockToCPU(int cpu_to_lock) {
cpu_set_t cpuset;
CPU_ZERO(&cpuset);
- if (sched_getaffinity(0, sizeof(cpuset), &cpuset) != 0) {
- perror("sched_getaffinity failed");
- return false;
- }
-
- if (cpu_to_lock < 0) {
- // Lock to the last active core we find.
- for (int i = 0; i < CPU_SETSIZE; i++) {
- if (CPU_ISSET(i, &cpuset)) {
- cpu_to_lock = i;
- }
- }
- } else if (!CPU_ISSET(cpu_to_lock, &cpuset)) {
- printf("Cpu %ld does not exist.\n", cpu_to_lock);
- return false;
- }
-
- if (cpu_to_lock < 0) {
- printf("Cannot find any valid cpu to lock.\n");
- return false;
- }
-
- CPU_ZERO(&cpuset);
CPU_SET(cpu_to_lock, &cpuset);
if (sched_setaffinity(0, sizeof(cpuset), &cpuset) != 0) {
- perror("sched_setaffinity failed");
+ if (errno == EINVAL) {
+ printf("Invalid cpu %d\n", cpu_to_lock);
+ } else {
+ perror("sched_setaffinity failed");
+ }
return false;
}