Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 /* | |
| 2 * Copyright 2016 Google Inc. | |
| 3 * | |
| 4 * Use of this source code is governed by a BSD-style license that can be | |
| 5 * found in the LICENSE file. | |
| 6 */ | |
| 7 | |
| 8 #include "ThermalManager.h" | |
| 9 | |
| 10 #if USE_THERMAL_MANAGER | |
| 11 | |
| 12 #include "SkOSFile.h" | |
| 13 | |
| 14 #include <stdio.h> | |
| 15 | |
| 16 ThermalManager::ThermalManager(int32_t threshold) { | |
| 17 static const char* kThermalZonePath = "/sys/class/thermal/"; | |
| 18 SkOSFile::Iter it(kThermalZonePath); | |
| 19 SkString path; | |
| 20 while (it.next(&path, true)) { | |
| 21 if (!path.contains("thermal_zone")) { | |
| 22 continue; | |
| 23 } | |
| 24 | |
| 25 SkString fullPath(kThermalZonePath); | |
| 26 fullPath.append(path); | |
| 27 SkOSFile::Iter thermalZoneIt(fullPath.c_str()); | |
| 28 | |
| 29 SkString filename; | |
| 30 while (thermalZoneIt.next(&filename)) { | |
| 31 if (!(filename.contains("trip_point") && filename.contains("temp"))) { | |
| 32 continue; | |
| 33 } | |
| 34 | |
| 35 fTripPoints.push_back(TripPoint(fullPath, filename, threshold)); | |
| 36 } | |
| 37 } | |
| 38 } | |
| 39 | |
| 40 bool ThermalManager::coolOffIfNecessary(uint32_t sleepInterval, uint32_t maxSlee ps) { | |
| 41 uint32_t i = 0, sleeps = 0; | |
| 42 while (i < (uint32_t)fTripPoints.count() && sleeps++ < maxSleeps) { | |
| 43 if (fTripPoints[i].willTrip()) { | |
| 44 sleep(sleepInterval); | |
| 45 } else { | |
| 46 i++; | |
| 47 } | |
| 48 } | |
| 49 | |
| 50 return sleeps < maxSleeps; | |
| 51 } | |
| 52 | |
| 53 int32_t ThermalManager::OpenFileAndReadInt32(const char* path) { | |
| 54 FILE* tempFile = fopen(path, "r"); | |
| 55 SkASSERT(tempFile); | |
| 56 int32_t value; | |
| 57 SkDEBUGCODE(int ret = )fscanf(tempFile, "%d", &value); | |
| 58 SkASSERT(ret); | |
| 59 fclose(tempFile); | |
| 60 return value; | |
| 61 } | |
| 62 | |
| 63 ThermalManager::TripPoint::TripPoint(SkString thermalZoneRoot, SkString pointNam e, | |
| 64 int32_t threshold) | |
| 65 : fThermalZoneRoot(thermalZoneRoot) | |
| 66 , fPointName(pointName) { | |
| 67 SkString fullPath(thermalZoneRoot); | |
| 68 fullPath.appendf("/%s", pointName.c_str()); | |
| 69 fPoint = OpenFileAndReadInt32(fullPath.c_str()); | |
| 70 fBase = GetTemp(fThermalZoneRoot); | |
| 71 fDisabled = fBase >= fPoint + fThreshold; // We disable any trip point whic h 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
| |
| 72 // triggered | |
| 73 fThreshold = threshold; | |
| 74 if (!fDisabled) { | |
| 75 SkDebugf("Trip point %s base - %d trip point-%d\n", fullPath.c_str(), | |
| 76 fBase, fPoint); | |
| 77 } | |
| 78 } | |
| 79 | |
| 80 bool ThermalManager::TripPoint::willTrip() { | |
| 81 int32_t currentTemp = GetTemp(fThermalZoneRoot); | |
| 82 bool wouldTrip = !fDisabled && currentTemp + fThreshold >= fPoint; | |
| 83 | |
| 84 if (wouldTrip) { | |
| 85 SkDebugf("%s/%s would trip {%d,%d,%d,%d}\n", fThermalZoneRoot.c_str(), | |
| 86 fPointName.c_str(), fBase, currentTemp, fPoint, fThreshold); | |
| 87 } | |
| 88 return wouldTrip; | |
| 89 } | |
| 90 | |
| 91 #endif | |
| OLD | NEW |