From cc844ea5c383ba95f27717128114ee527e9e2b97 Mon Sep 17 00:00:00 2001 From: Lakshman Annadorai Date: Tue, 22 Nov 2022 11:57:20 -0800 Subject: Report CPU online status & avg time in state freq. - CpuInfoReader must verify all frequency policy directories for the presence of time_in_state file before marking it as missing because this file might be missing when all cores on a policy are offline. Thus, check all policies. - Split the CPU info cache into static and dynamic CPU info stats. This helps preseves all the information read from the sysfs interface. With the previous implementation, some critical information required to make certain decision (later in the implementation) were lost. - For instance, the related & affected CPU cores information are required to decide whether a CPU core is online or offline. - The current & max CPU frequency should come from the same source - either both from the frequency reported by the CPU hardware or the frequency determined by the scaling governor. - Handle the case where a CPU core is offline and the latest CPU usage stats are missing. This will be useful when collection bugreport dump. - Fix the return types to avoid boxing/unboxing ints/longs. Test: atest CpuInfoReaderTest Bug: 242722241 Change-Id: I5c51ac8b699ffe616b64de279ebab12968723160 --- .../java/com/android/server/cpu/CpuInfoReader.java | 520 +++++++++++++----- .../policy2/affected_cpus | 2 +- .../com/android/server/cpu/CpuInfoReaderTest.java | 604 +++++++++++---------- 3 files changed, 699 insertions(+), 427 deletions(-) diff --git a/services/core/java/com/android/server/cpu/CpuInfoReader.java b/services/core/java/com/android/server/cpu/CpuInfoReader.java index b13d7533f29b..ca97a9847b39 100644 --- a/services/core/java/com/android/server/cpu/CpuInfoReader.java +++ b/services/core/java/com/android/server/cpu/CpuInfoReader.java @@ -16,11 +16,15 @@ package com.android.server.cpu; +import static com.android.server.cpu.CpuMonitorService.DEBUG; +import static com.android.server.cpu.CpuMonitorService.TAG; + import android.annotation.IntDef; import android.annotation.Nullable; import android.system.Os; import android.system.OsConstants; -import android.util.ArrayMap; +import android.util.IntArray; +import android.util.LongSparseLongArray; import android.util.SparseArray; import android.util.SparseIntArray; @@ -31,8 +35,7 @@ import java.io.File; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.nio.file.Files; -import java.util.ArrayList; -import java.util.Collections; +import java.util.Arrays; import java.util.List; import java.util.Objects; import java.util.regex.Matcher; @@ -40,7 +43,6 @@ import java.util.regex.Pattern; /** Reader to read CPU information from proc and sys fs files exposed by the Kernel. */ public final class CpuInfoReader { - static final String TAG = CpuInfoReader.class.getSimpleName(); static final int FLAG_CPUSET_CATEGORY_TOP_APP = 1 << 0; static final int FLAG_CPUSET_CATEGORY_BACKGROUND = 1 << 1; @@ -67,7 +69,7 @@ public final class CpuInfoReader { + "(?[0-9]+)"); private static final Pattern TIME_IN_STATE_PATTERN = Pattern.compile("(?[0-9]+)\\s(?