libtimeinstate: support concurrent_{active,policy}_time
Add support for querying and clearing stats for time each UID spent
running concurrently with tasks on all other CPUs and on CPUs in the
same cluster.
Also add tests for the new functions, including consistency checks
comparing time in state vs concurrent times.
Finally, because the BPF program cannot update multiple map values
atomically, userspace reads occasionally occur in between the updates
to a UID's active and policy times. Add a check for this in our reader
functions and retry once when it is detected. For the (very rare) case
where the same race occurs when retrying, include a comment in our
consistency test to help distinguish these transient failures from a
more serious bug.
Test: libtimeinstate_test passes
Bug: 138317993
Change-Id: I429ed39d3ef82b6643fd042a74d9d403c658a8c1
Signed-off-by: Connor O'Brien <connoro@google.com>
(cherry picked from commit daceef75545ccc041fc72582fba82625ac57f575)
Merged-In: I429ed39d3ef82b6643fd042a74d9d403c658a8c1
diff --git a/libs/cputimeinstate/timeinstate.h b/libs/cputimeinstate/timeinstate.h
index 41d0af0..6d4f913 100644
--- a/libs/cputimeinstate/timeinstate.h
+++ b/libs/cputimeinstate/timeinstate.h
@@ -19,16 +19,22 @@
#define BPF_FS_PATH "/sys/fs/bpf/"
#define FREQS_PER_ENTRY 32
+#define CPUS_PER_ENTRY 8
struct time_key_t {
uint32_t uid;
uint32_t bucket;
};
-struct val_t {
+struct tis_val_t {
uint64_t ar[FREQS_PER_ENTRY];
};
+struct concurrent_val_t {
+ uint64_t active[CPUS_PER_ENTRY];
+ uint64_t policy[CPUS_PER_ENTRY];
+};
+
struct freq_idx_key_t {
uint32_t policy;
uint32_t freq;