diff options
author | 2016-02-09 07:18:08 -0800 | |
---|---|---|
committer | 2016-02-09 07:18:08 -0800 | |
commit | 3ebd050be551e9d1364dbd115708e8f86397cd6f (patch) | |
tree | bc3faddef38752c2f22ce373d28e90cb48581020 /tools/ThermalManager.h | |
parent | 4984b85037bf0733d848318dfaff03ab85204a6f (diff) |
Create a thermal manager class and wire it in to nanobench behind a flag
BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1671573002
Review URL: https://codereview.chromium.org/1671573002
Diffstat (limited to 'tools/ThermalManager.h')
-rw-r--r-- | tools/ThermalManager.h | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/tools/ThermalManager.h b/tools/ThermalManager.h new file mode 100644 index 0000000000..74e9dd1eac --- /dev/null +++ b/tools/ThermalManager.h @@ -0,0 +1,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 "SkString.h" +#include "SkTArray.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 |