libtimeinstate: fix bug in clearUidCpuFreqTimes

In a preallocated bpf hash table, deleting a map element makes it
available for reuse without clearing the data it holds. This reuse can
occur when a bpf program calls bpf_map_update_elem with a key not
already present in the map. If the map is percpu, bpf_map_update_elem
will overwrite the reused entry's data for the current CPU but not for
other CPUs, resulting in stale data that is now associated with the
wrong key.

For time in state, this can show up as impossible data (e.g. reporting
that a UID ran on one cluster at a frequency only available on a
different cluster), which is detected by the SingleAndAllUidConsistent
test since getUidCpuFreqTimes() only looks up potentially valid keys
while getUidsCpuFreqTimes() iterates through every map entry.

Avoid this problem by zeroing out each entry's data prior to deleting
it from the map. Also modify getUidCpuFreqTimes and
getUidsCpuFreqTimes to check for impossible data and fail if any is
detected, since it's a sign that other map entries may also be wrong.

Bug: 138317993
Test: libtimeinstate_test can now be run repeatedly without
SingleAndAllUidConsistent test eventually failing
Signed-off-by: Connor O'Brien <connoro@google.com>

Change-Id: I17dd407f897d1e86eb85cc99842a581d88e5bc78
(cherry picked from commit 6c501ea04e486d9bf5c8a08d0d63dadcd9be83a9)
Merged-In: I17dd407f897d1e86eb85cc99842a581d88e5bc78
1 file changed