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

Commit 442b6314 authored by Maggie White's avatar Maggie White
Browse files

thermal: Add pulled cooling device atom and a field to Temperature atom



Bug: 119688911
Test: adb shell cmd stats pull-source 10058
Test: adb shell cmd stats pull-source 10021
Test: Injected artificially high temp via emul_temp
Change-Id: I1afe53380a38f342d7f59e0c61c487e05be31d85
Signed-off-by: default avatarMaggie White <maggiewhite@google.com>
parent 69eddb0f
Loading
Loading
Loading
Loading
+32 −5
Original line number Original line Diff line number Diff line
@@ -340,6 +340,7 @@ message Atom {
        SystemIonHeapSize system_ion_heap_size = 10056;
        SystemIonHeapSize system_ion_heap_size = 10056;
        AppsOnExternalStorageInfo apps_on_external_storage_info = 10057;
        AppsOnExternalStorageInfo apps_on_external_storage_info = 10057;
        FaceSettings face_settings = 10058;
        FaceSettings face_settings = 10058;
        CoolingDevice cooling_device = 10059;
    }
    }


    // DO NOT USE field numbers above 100,000 in AOSP.
    // DO NOT USE field numbers above 100,000 in AOSP.
@@ -410,17 +411,25 @@ message KeyValuePairsAtom {
 *   frameworks/base/services/core/java/com/android/server/stats/StatsCompanionService.java
 *   frameworks/base/services/core/java/com/android/server/stats/StatsCompanionService.java
 */
 */
message ThermalThrottlingStateChanged {
message ThermalThrottlingStateChanged {
    // The type of temperature being reported (CPU, GPU, SKIN, etc)
    optional android.os.TemperatureTypeEnum sensor_type = 1;
    optional android.os.TemperatureTypeEnum sensor_type = 1;


    // Throttling state, this field is DEPRECATED
    enum State {
    enum State {
        UNKNOWN = 0;
        UNKNOWN = 0;
        START = 1;
        START = 1; // START indicated that throttling was triggered.
        STOP = 2;
        STOP = 2; // STOP indicates that throttling was cleared.
    }
    }

    optional State state = 2;
    optional State state = 2;


    // Temperature in deci degrees celsius
    optional float temperature = 3;
    optional float temperature = 3;

    // Severity of throttling
    optional android.os.ThrottlingSeverityEnum severity = 4;

    // Thermistor name
    optional string sensor_name = 5;
}
}


/**
/**
@@ -3957,8 +3966,7 @@ message BatteryLevel {
 * Pulls the temperature of various parts of the device.
 * Pulls the temperature of various parts of the device.
 * The units are tenths of a degree Celsius. Eg: 30.3C is reported as 303.
 * The units are tenths of a degree Celsius. Eg: 30.3C is reported as 303.
 *
 *
 * Pulled from:
 * Pulled from StatsCompanionService.java
 *   frameworks/base/cmds/statsd/src/external/ResourceThermalManagerPuller.cpp
 */
 */
message Temperature {
message Temperature {
    // The type of temperature being reported. Eg. CPU, GPU, SKIN, BATTERY, BCL_.
    // The type of temperature being reported. Eg. CPU, GPU, SKIN, BATTERY, BCL_.
@@ -3970,6 +3978,9 @@ message Temperature {
    // Temperature in tenths of a degree C.
    // Temperature in tenths of a degree C.
    // For BCL, it is decimillivolt, decimilliamps, and percentage * 10.
    // For BCL, it is decimillivolt, decimilliamps, and percentage * 10.
    optional int32 temperature_deci_celsius = 3;
    optional int32 temperature_deci_celsius = 3;

    // Relative severity of the throttling, see enum definition.
    optional android.os.ThrottlingSeverityEnum severity = 4;
}
}


/**
/**
@@ -5947,3 +5958,19 @@ message FaceSettings {
    // Whether or not a diverse set of poses are required during enrollment.
    // Whether or not a diverse set of poses are required during enrollment.
    optional bool unlock_diversity_required = 6;
    optional bool unlock_diversity_required = 6;
}
}

/**
 * Logs cooling devices maintained by the kernel.
 *
 * Pulled from StatsCompanionService.java
 */
message CoolingDevice {
    // The type of cooling device being reported. Eg. CPU, GPU...
    optional android.os.CoolingTypeEnum device_location = 1;
    // The name of the cooling device source. Eg. CPU0
    optional string device_name = 2;
    // Current throttle state of the cooling device. The value can any unsigned
    // integer between 0 and max_state defined in its driver. 0 means device is
    // not in throttling, higher value means deeper throttling.
    optional int32 state = 3;
}
+3 −0
Original line number Original line Diff line number Diff line
@@ -159,6 +159,9 @@ std::map<int, PullAtomInfo> StatsPullerManager::kAllPullAtomInfo = {
        // temperature
        // temperature
        {android::util::TEMPERATURE,
        {android::util::TEMPERATURE,
         {.puller = new StatsCompanionServicePuller(android::util::TEMPERATURE)}},
         {.puller = new StatsCompanionServicePuller(android::util::TEMPERATURE)}},
        // cooling_device
        {android::util::COOLING_DEVICE,
         {.puller = new StatsCompanionServicePuller(android::util::COOLING_DEVICE)}},
        // binder_calls
        // binder_calls
        {android::util::BINDER_CALLS,
        {android::util::BINDER_CALLS,
         {.additiveFields = {4, 5, 6, 8, 12},
         {.additiveFields = {4, 5, 6, 8, 12},
+35 −0
Original line number Original line Diff line number Diff line
@@ -78,6 +78,41 @@ enum TemperatureTypeEnum {
    TEMPERATURE_TYPE_NPU = 9;
    TEMPERATURE_TYPE_NPU = 9;
}
}


// Device throttling severity
// These constants are defined in hardware/interfaces/thermal/2.0/types.hal.
// Any change to the types in the thermal hal should be made here as well.
enum ThrottlingSeverityEnum {
    // Not under throttling.
    NONE = 0;
    // Light throttling where UX is not impacted.
    LIGHT = 1;
    // Moderate throttling where UX is not largely impacted.
    MODERATE = 2;
    // Severe throttling where UX is largely impacted.
    // Similar to 1.0 throttlingThreshold.
    SEVERE = 3;
    // Platform has done everything to reduce power.
    CRITICAL = 4;
    // Key components in platform are shutting down due to thermal condition.
    // Device functionalities will be limited.
    EMERGENCY = 5;
    // Need shutdown immediately.
    SHUTDOWN = 6;
};

// Device cooling device types.
// These constants are defined in hardware/interfaces/thermal/2.0/types.hal.
// Any change to the types in the thermal hal should be made here as well.
enum CoolingTypeEnum {
    FAN = 0;
    BATTERY = 1;
    CPU = 2;
    GPU = 3;
    MODEM = 4;
    NPU = 5;
    COMPONENT = 6;
};

// Wakelock types, primarily used by android/os/PowerManager.java.
// Wakelock types, primarily used by android/os/PowerManager.java.
enum WakeLockLevelEnum {
enum WakeLockLevelEnum {
    // NOTE: Wake lock levels were previously defined as a bit field, except
    // NOTE: Wake lock levels were previously defined as a bit field, except
+29 −5
Original line number Original line Diff line number Diff line
@@ -64,6 +64,7 @@ import android.os.BatteryStatsInternal;
import android.os.Binder;
import android.os.Binder;
import android.os.Build;
import android.os.Build;
import android.os.Bundle;
import android.os.Bundle;
import android.os.CoolingDevice;
import android.os.Environment;
import android.os.Environment;
import android.os.FileUtils;
import android.os.FileUtils;
import android.os.Handler;
import android.os.Handler;
@@ -1798,6 +1799,28 @@ public class StatsCompanionService extends IStatsCompanionService.Stub {
                e.writeInt(temp.getType());
                e.writeInt(temp.getType());
                e.writeString(temp.getName());
                e.writeString(temp.getName());
                e.writeInt((int) (temp.getValue() * 10));
                e.writeInt((int) (temp.getValue() * 10));
                e.writeInt(temp.getStatus());
                pulledData.add(e);
            }
        } catch (RemoteException e) {
            // Should not happen.
            Slog.e(TAG, "Disconnected from thermal service. Cannot pull temperatures.");
        } finally {
            Binder.restoreCallingIdentity(callingToken);
        }
    }

    private void pullCoolingDevices(int tagId, long elapsedNanos, long wallClockNanos,
            List<StatsLogEventWrapper> pulledData) {
        long callingToken = Binder.clearCallingIdentity();
        try {
            List<CoolingDevice> devices = sThermalService.getCurrentCoolingDevices();
            for (CoolingDevice device : devices) {
                StatsLogEventWrapper e =
                        new StatsLogEventWrapper(tagId, elapsedNanos, wallClockNanos);
                e.writeInt(device.getType());
                e.writeString(device.getName());
                e.writeInt((int) (device.getValue()));
                pulledData.add(e);
                pulledData.add(e);
            }
            }
        } catch (RemoteException e) {
        } catch (RemoteException e) {
@@ -2268,6 +2291,10 @@ public class StatsCompanionService extends IStatsCompanionService.Stub {
                pullTemperature(tagId, elapsedNanos, wallClockNanos, ret);
                pullTemperature(tagId, elapsedNanos, wallClockNanos, ret);
                break;
                break;
            }
            }
            case StatsLog.COOLING_DEVICE: {
                pullCoolingDevices(tagId, elapsedNanos, wallClockNanos, ret);
                break;
            }
            case StatsLog.DEBUG_ELAPSED_CLOCK: {
            case StatsLog.DEBUG_ELAPSED_CLOCK: {
                pullDebugElapsedClock(tagId, elapsedNanos, wallClockNanos, ret);
                pullDebugElapsedClock(tagId, elapsedNanos, wallClockNanos, ret);
                break;
                break;
@@ -2532,12 +2559,9 @@ public class StatsCompanionService extends IStatsCompanionService.Stub {
    private static final class ThermalEventListener extends IThermalEventListener.Stub {
    private static final class ThermalEventListener extends IThermalEventListener.Stub {
        @Override
        @Override
        public void notifyThrottling(Temperature temp) {
        public void notifyThrottling(Temperature temp) {
            boolean isThrottling = temp.getStatus() >= Temperature.THROTTLING_SEVERE;
            StatsLog.write(StatsLog.THERMAL_THROTTLING, temp.getType(),
            StatsLog.write(StatsLog.THERMAL_THROTTLING, temp.getType(),
                    isThrottling ?
                    StatsLog.THERMAL_THROTTLING_STATE_CHANGED__STATE__UNKNOWN,
                            StatsLog.THERMAL_THROTTLING_STATE_CHANGED__STATE__START :
                    temp.getValue(), temp.getStatus(), temp.getName());
                            StatsLog.THERMAL_THROTTLING_STATE_CHANGED__STATE__STOP,
                    temp.getValue());
        }
        }
    }
    }