summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Connor O'Brien <connoro@google.com> 2019-06-06 17:48:20 -0700
committer Connor O'Brien <connoro@google.com> 2019-07-29 12:13:01 -0700
commit9236e872cd315c36bca7625751f16ec0817348c7 (patch)
tree5fc1056ff40bf8dabfdf00381d29daee360fc5af
parent6c501ea04e486d9bf5c8a08d0d63dadcd9be83a9 (diff)
libtimeinstate: support cpufreq fast switching
In order to support kernels that use fast frequency switching, the time_in_state BPF program needs to know which CPUs are members of which cpufreq policies. Add logic to startTrackingUidCpuFreqTimes() to write this information into a BPF map in order to make it available to the BPF program. Test: libtimeinstate_test passes Change-Id: I47b38457766d21c2aa0879f156fc90757c0db705 Signed-off-by: Connor O'Brien <connoro@google.com>
-rw-r--r--libs/cputimeinstate/cputimeinstate.cpp11
1 files changed, 11 insertions, 0 deletions
diff --git a/libs/cputimeinstate/cputimeinstate.cpp b/libs/cputimeinstate/cputimeinstate.cpp
index a02b28551e..6f50a1e623 100644
--- a/libs/cputimeinstate/cputimeinstate.cpp
+++ b/libs/cputimeinstate/cputimeinstate.cpp
@@ -141,6 +141,17 @@ static bool attachTracepointProgram(const std::string &eventType, const std::str
// This function should *not* be called while tracking is already active; doing so is unnecessary
// and can lead to accounting errors.
bool startTrackingUidCpuFreqTimes() {
+ if (!initGlobals()) return false;
+
+ unique_fd fd(bpf_obj_get(BPF_FS_PATH "map_time_in_state_cpu_policy_map"));
+ if (fd < 0) return false;
+
+ for (uint32_t i = 0; i < gPolicyCpus.size(); ++i) {
+ for (auto &cpu : gPolicyCpus[i]) {
+ if (writeToMapEntry(fd, &cpu, &i, BPF_ANY)) return false;
+ }
+ }
+
return attachTracepointProgram("sched", "sched_switch") &&
attachTracepointProgram("power", "cpu_frequency");
}