crosperf: Add check core online in PinGovernerFrequency().

Due to Hyper-Threading is disabled, not all cpus in
/sys/devices/system/cpu/cpu* are online on the x86 DUTs. Our
PinGovernerFrequency() functions need to write performance to
scaling_governor and it fails if the cpu is offline. This patches
adds checks before writing to make sure the core is not offline.

BUG=None
TEST=Local tests.

Change-Id: I5dee6851848c18ff9caac0fb5bf5a6a18741a3c8
Reviewed-on: https://chromium-review.googlesource.com/1618095
Commit-Ready: Tiancong Wang <tcwang@google.com>
Tested-by: Tiancong Wang <tcwang@google.com>
Legacy-Commit-Queue: Commit Bot <commit-bot@chromium.org>
Reviewed-by: Manoj Gupta <manojgupta@chromium.org>
diff --git a/crosperf/suite_runner.py b/crosperf/suite_runner.py
index 0318db1..342e954 100644
--- a/crosperf/suite_runner.py
+++ b/crosperf/suite_runner.py
@@ -115,6 +115,10 @@
         'fi; '
         # Set governor to performance for each cpu
         'for f in /sys/devices/system/cpu/cpu*/cpufreq; do '
+        # Skip writing scaling_governor if cpu is not online.
+        '[[ -e ${f/cpufreq/online} ]] && grep -q 0 ${f/cpufreq/online} '
+        '&& continue; '
+        # The cpu is online, can update.
         'cd $f; '
         'echo performance > scaling_governor; '
         # Uncomment rest of lines to enable setting frequency by crosperf
diff --git a/crosperf/suite_runner_unittest.py b/crosperf/suite_runner_unittest.py
index 081c828..0c8d17d 100755
--- a/crosperf/suite_runner_unittest.py
+++ b/crosperf/suite_runner_unittest.py
@@ -206,6 +206,10 @@
         'fi; '
         # Set governor to performance for each cpu
         'for f in /sys/devices/system/cpu/cpu*/cpufreq; do '
+        # Skip writing scaling_governor if cpu is not online.
+        '[[ -e ${f/cpufreq/online} ]] && grep -q 0 ${f/cpufreq/online} '
+        '&& continue; '
+        # This cpu is online, can update.
         'cd $f; '
         'echo performance > scaling_governor; '
         'done')