Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9236e872 authored by Connor O'Brien's avatar Connor O'Brien
Browse files

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: default avatarConnor O'Brien <connoro@google.com>
parent 6c501ea0
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -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");
}