Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(21)

Unified Diff: tools/ThermalManager.cpp

Issue 1671573002: Create a thermal manager class and wire it in to nanobench behind a flag (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: tweaks Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« tools/ThermalManager.h ('K') | « tools/ThermalManager.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/ThermalManager.cpp
diff --git a/tools/ThermalManager.cpp b/tools/ThermalManager.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..9853d9de3075ed781f287898e513274bfb1914ab
--- /dev/null
+++ b/tools/ThermalManager.cpp
@@ -0,0 +1,91 @@
+/*
+ * Copyright 2016 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "ThermalManager.h"
+
+#if USE_THERMAL_MANAGER
+
+#include "SkOSFile.h"
+
+#include <stdio.h>
+
+ThermalManager::ThermalManager(int32_t threshold) {
+ static const char* kThermalZonePath = "/sys/class/thermal/";
+ SkOSFile::Iter it(kThermalZonePath);
+ SkString path;
+ while (it.next(&path, true)) {
+ if (!path.contains("thermal_zone")) {
+ continue;
+ }
+
+ SkString fullPath(kThermalZonePath);
+ fullPath.append(path);
+ SkOSFile::Iter thermalZoneIt(fullPath.c_str());
+
+ SkString filename;
+ while (thermalZoneIt.next(&filename)) {
+ if (!(filename.contains("trip_point") && filename.contains("temp"))) {
+ continue;
+ }
+
+ fTripPoints.push_back(TripPoint(fullPath, filename, threshold));
+ }
+ }
+}
+
+bool ThermalManager::coolOffIfNecessary(uint32_t sleepInterval, uint32_t maxSleeps) {
+ uint32_t i = 0, sleeps = 0;
+ while (i < (uint32_t)fTripPoints.count() && sleeps++ < maxSleeps) {
+ if (fTripPoints[i].willTrip()) {
+ sleep(sleepInterval);
+ } else {
+ i++;
+ }
+ }
+
+ return sleeps < maxSleeps;
+}
+
+int32_t ThermalManager::OpenFileAndReadInt32(const char* path) {
+ FILE* tempFile = fopen(path, "r");
+ SkASSERT(tempFile);
+ int32_t value;
+ SkDEBUGCODE(int ret = )fscanf(tempFile, "%d", &value);
+ SkASSERT(ret);
+ fclose(tempFile);
+ return value;
+}
+
+ThermalManager::TripPoint::TripPoint(SkString thermalZoneRoot, SkString pointName,
+ int32_t threshold)
+ : fThermalZoneRoot(thermalZoneRoot)
+ , fPointName(pointName) {
+ SkString fullPath(thermalZoneRoot);
+ fullPath.appendf("/%s", pointName.c_str());
+ fPoint = OpenFileAndReadInt32(fullPath.c_str());
+ fBase = GetTemp(fThermalZoneRoot);
+ fDisabled = fBase >= fPoint + fThreshold; // We disable any trip point which start off
djsollen 2016/02/05 04:54:15 why do we need to disable these?
joshualitt 2016/02/05 13:50:20 I added a comment in the header. Some trip points
+ // triggered
+ fThreshold = threshold;
+ if (!fDisabled) {
+ SkDebugf("Trip point %s base - %d trip point-%d\n", fullPath.c_str(),
+ fBase, fPoint);
+ }
+}
+
+bool ThermalManager::TripPoint::willTrip() {
+ int32_t currentTemp = GetTemp(fThermalZoneRoot);
+ bool wouldTrip = !fDisabled && currentTemp + fThreshold >= fPoint;
+
+ if (wouldTrip) {
+ SkDebugf("%s/%s would trip {%d,%d,%d,%d}\n", fThermalZoneRoot.c_str(),
+ fPointName.c_str(), fBase, currentTemp, fPoint, fThreshold);
+ }
+ return wouldTrip;
+}
+
+#endif
« tools/ThermalManager.h ('K') | « tools/ThermalManager.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698