aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools/ThermalManager.h
blob: 747cf52691362f7a5c52fe0f38d63b99c209e740 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/*
 * Copyright 2016 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#ifndef ThermalManager_DEFINED
#define ThermalManager_DEFINED

#include "../private/SkTArray.h"
#include "SkString.h"

#if defined(SK_BUILD_FOR_ANDROID) || defined(SK_BUILD_FOR_UNIX)
#    define THERMAL_MANAGER_SUPPORTED
#endif

#ifdef THERMAL_MANAGER_SUPPORTED

/*
 * This simple class monitors the thermal part of sysfs to ensure we don't trigger thermal events
 */

class ThermalManager {
public:
    ThermalManager(int32_t threshold, uint32_t sleepIntervalMs, uint32_t timeoutMs);

    bool coolOffIfNecessary();

private:
    static int32_t OpenFileAndReadInt32(const char* path);

    // current temperature can be read from /thermalZonePath/temp
    static int32_t GetTemp(SkString thermalZonePath) {
        SkString temperatureFilePath(thermalZonePath);
        temperatureFilePath.appendf("/temp");
        return OpenFileAndReadInt32(temperatureFilePath.c_str());
    }

    struct TripPoint {
        TripPoint(SkString thermalZoneRoot, SkString pointName, int32_t threshold);

        bool willTrip();

        SkString fThermalZoneRoot;
        SkString fPointName;
        int32_t fBase;
        int32_t fPoint;
        int32_t fThreshold;

        // Certain trip points seem to start tripped.  For example, I have seen trip points of 0 or
        // negative numbers.
        bool fDisabled;
    };

    SkTArray<TripPoint> fTripPoints;
    uint32_t fSleepIntervalMs;
    uint32_t fTimeoutMs;
};
#endif
#endif