libtimeinstate: fix unused variable warning

Move busy loop variable to static scope in the test and add used
attribute. This silences the unused variable warning when
building.

Test: manual
Change-Id: I56c7bccfd7a9ee5a2e530b220999c364ec8733c0
Signed-off-by: Neill Kapron <nkapron@google.com>
diff --git a/libs/cputimeinstate/testtimeinstate.cpp b/libs/cputimeinstate/testtimeinstate.cpp
index 6ccc6ca..81f6a58 100644
--- a/libs/cputimeinstate/testtimeinstate.cpp
+++ b/libs/cputimeinstate/testtimeinstate.cpp
@@ -40,6 +40,9 @@
 static constexpr uint64_t NSEC_PER_SEC = 1000000000;
 static constexpr uint64_t NSEC_PER_YEAR = NSEC_PER_SEC * 60 * 60 * 24 * 365;
 
+// Declare busy loop variable globally to prevent removal during optimization
+static long sum __attribute__((used)) = 0;
+
 using std::vector;
 
 class TimeInStateTest : public testing::Test {
@@ -576,7 +579,7 @@
 
 // Keeps CPU busy with some number crunching
 void useCpu() {
-    long sum = 0;
+    sum = 0;
     for (int i = 0; i < 100000; i++) {
         sum *= i;
     }