mirror of
https://github.com/Evolution-X-Devices/device_google_wahoo
synced 2026-01-29 23:19:52 +00:00
Merge "THERMAL HAL API 1.0 impl for Wahoo" into oc-dr1-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
4e102dfdcb
@@ -345,8 +345,7 @@ PRODUCT_PACKAGES += \
|
||||
|
||||
# Thermal packages
|
||||
PRODUCT_PACKAGES += \
|
||||
android.hardware.thermal@1.0-impl \
|
||||
android.hardware.thermal@1.0-service
|
||||
android.hardware.thermal@1.0-service.wahoo
|
||||
|
||||
#GNSS HAL
|
||||
PRODUCT_PACKAGES += \
|
||||
|
||||
1
sepolicy/vendor/file_contexts
vendored
1
sepolicy/vendor/file_contexts
vendored
@@ -165,6 +165,7 @@
|
||||
/vendor/bin/oemlock-bridge u:object_r:hal_bootctl_default_exec:s0
|
||||
/vendor/bin/hw/android\.hardware\.usb@1\.1-service.wahoo u:object_r:hal_usb_default_exec:s0
|
||||
/vendor/bin/hw/android\.hardware\.power@1\.1-service.wahoo u:object_r:hal_power_default_exec:s0
|
||||
/vendor/bin/hw/android\.hardware\.thermal@1\.0-service.wahoo u:object_r:hal_thermal_default_exec:s0
|
||||
/vendor/bin/chre u:object_r:chre_exec:s0
|
||||
/vendor/bin/time_daemon u:object_r:time_daemon_exec:s0
|
||||
/vendor/bin/imsrcsd u:object_r:hal_rcsservice_exec:s0
|
||||
|
||||
37
thermal/Android.mk
Normal file
37
thermal/Android.mk
Normal file
@@ -0,0 +1,37 @@
|
||||
#
|
||||
# Copyright 2017 The Android Open Source Project
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
LOCAL_PATH := $(call my-dir)
|
||||
|
||||
include $(CLEAR_VARS)
|
||||
|
||||
LOCAL_MODULE_RELATIVE_PATH := hw
|
||||
LOCAL_PROPRIETARY_MODULE := true
|
||||
LOCAL_MODULE_OWNER := qcom
|
||||
LOCAL_MODULE_TAGS := optional
|
||||
|
||||
LOCAL_MODULE := android.hardware.thermal@1.0-service.wahoo
|
||||
LOCAL_INIT_RC := android.hardware.thermal@1.0-service.wahoo.rc
|
||||
LOCAL_SRC_FILES := service.cpp Thermal.cpp thermal-helper.cpp
|
||||
|
||||
LOCAL_SHARED_LIBRARIES := \
|
||||
libhidlbase \
|
||||
libhidltransport \
|
||||
libutils \
|
||||
libbase \
|
||||
android.hardware.thermal@1.0 \
|
||||
|
||||
include $(BUILD_EXECUTABLE)
|
||||
119
thermal/Thermal.cpp
Normal file
119
thermal/Thermal.cpp
Normal file
@@ -0,0 +1,119 @@
|
||||
/*
|
||||
* Copyright (C) 2017 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <cerrno>
|
||||
#include <vector>
|
||||
|
||||
#include <android-base/logging.h>
|
||||
|
||||
#include "Thermal.h"
|
||||
#include "thermal-helper.h"
|
||||
|
||||
namespace android {
|
||||
namespace hardware {
|
||||
namespace thermal {
|
||||
namespace V1_0 {
|
||||
namespace implementation {
|
||||
|
||||
Thermal::Thermal() : enabled(initThermal()) {}
|
||||
|
||||
// Methods from ::android::hardware::thermal::V1_0::IThermal follow.
|
||||
Return<void> Thermal::getTemperatures(getTemperatures_cb _hidl_cb) {
|
||||
ThermalStatus status;
|
||||
status.code = ThermalStatusCode::SUCCESS;
|
||||
hidl_vec<Temperature> temperatures;
|
||||
temperatures.resize(kTemperatureNum);
|
||||
|
||||
if (!enabled) {
|
||||
status.code = ThermalStatusCode::FAILURE;
|
||||
status.debugMessage = "Unsupported hardware";
|
||||
_hidl_cb(status, temperatures);
|
||||
return Void();
|
||||
}
|
||||
|
||||
ssize_t ret = fillTemperatures(&temperatures);
|
||||
if (ret < 0) {
|
||||
status.code = ThermalStatusCode::FAILURE;
|
||||
status.debugMessage = strerror(-ret);
|
||||
}
|
||||
_hidl_cb(status, temperatures);
|
||||
|
||||
for (auto& t : temperatures) {
|
||||
LOG(DEBUG) << "getTemperatures "
|
||||
<< " Type: " << static_cast<int>(t.type)
|
||||
<< " Name: " << t.name
|
||||
<< " CurrentValue: " << t.currentValue
|
||||
<< " ThrottlingThreshold: " << t.throttlingThreshold
|
||||
<< " ShutdownThreshold: " << t.shutdownThreshold
|
||||
<< " VrThrottlingThreshold: " << t.vrThrottlingThreshold;
|
||||
}
|
||||
|
||||
return Void();
|
||||
}
|
||||
|
||||
Return<void> Thermal::getCpuUsages(getCpuUsages_cb _hidl_cb) {
|
||||
ThermalStatus status;
|
||||
status.code = ThermalStatusCode::SUCCESS;
|
||||
hidl_vec<CpuUsage> cpuUsages;
|
||||
cpuUsages.resize(kCpuNum);
|
||||
|
||||
if (!enabled) {
|
||||
status.code = ThermalStatusCode::FAILURE;
|
||||
status.debugMessage = "Unsupported hardware";
|
||||
_hidl_cb(status, cpuUsages);
|
||||
return Void();
|
||||
}
|
||||
|
||||
ssize_t ret = fillCpuUsages(&cpuUsages);
|
||||
if (ret < 0) {
|
||||
status.code = ThermalStatusCode::FAILURE;
|
||||
status.debugMessage = strerror(-ret);
|
||||
}
|
||||
|
||||
for (auto& u : cpuUsages) {
|
||||
LOG(DEBUG) << "getCpuUsages "
|
||||
<< " Name: " << u.name
|
||||
<< " Active: " << u.active
|
||||
<< " Total: " << u.total
|
||||
<< " IsOnline: " << u.isOnline;
|
||||
}
|
||||
|
||||
_hidl_cb(status, cpuUsages);
|
||||
return Void();
|
||||
}
|
||||
|
||||
Return<void> Thermal::getCoolingDevices(getCoolingDevices_cb _hidl_cb) {
|
||||
ThermalStatus status;
|
||||
status.code = ThermalStatusCode::SUCCESS;
|
||||
hidl_vec<CoolingDevice> coolingDevices;
|
||||
|
||||
if (!enabled) {
|
||||
status.code = ThermalStatusCode::FAILURE;
|
||||
status.debugMessage = "Unsupported hardware";
|
||||
_hidl_cb(status, coolingDevices);
|
||||
return Void();
|
||||
}
|
||||
|
||||
LOG(DEBUG) << "No Cooling Device";
|
||||
_hidl_cb(status, coolingDevices);
|
||||
return Void();
|
||||
}
|
||||
|
||||
} // namespace implementation
|
||||
} // namespace V1_0
|
||||
} // namespace thermal
|
||||
} // namespace hardware
|
||||
} // namespace android
|
||||
57
thermal/Thermal.h
Normal file
57
thermal/Thermal.h
Normal file
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright (C) 2017 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef ANDROID_HARDWARE_THERMAL_V1_0_WAHOO_THERMAL_H
|
||||
#define ANDROID_HARDWARE_THERMAL_V1_0_WAHOO_THERMAL_H
|
||||
|
||||
#include <android/hardware/thermal/1.0/IThermal.h>
|
||||
#include <hidl/Status.h>
|
||||
#include <hidl/MQDescriptor.h>
|
||||
|
||||
namespace android {
|
||||
namespace hardware {
|
||||
namespace thermal {
|
||||
namespace V1_0 {
|
||||
namespace implementation {
|
||||
|
||||
using ::android::hardware::thermal::V1_0::CoolingDevice;
|
||||
using ::android::hardware::thermal::V1_0::CpuUsage;
|
||||
using ::android::hardware::thermal::V1_0::IThermal;
|
||||
using ::android::hardware::thermal::V1_0::Temperature;
|
||||
using ::android::hardware::thermal::V1_0::ThermalStatus;
|
||||
using ::android::hardware::Return;
|
||||
using ::android::hardware::Void;
|
||||
using ::android::hardware::hidl_vec;
|
||||
using ::android::hardware::hidl_string;
|
||||
using ::android::sp;
|
||||
|
||||
struct Thermal : public IThermal {
|
||||
Thermal();
|
||||
// Methods from ::android::hardware::thermal::V1_0::IThermal follow.
|
||||
Return<void> getTemperatures(getTemperatures_cb _hidl_cb) override;
|
||||
Return<void> getCpuUsages(getCpuUsages_cb _hidl_cb) override;
|
||||
Return<void> getCoolingDevices(getCoolingDevices_cb _hidl_cb) override;
|
||||
|
||||
private:
|
||||
bool enabled;
|
||||
};
|
||||
|
||||
} // namespace implementation
|
||||
} // namespace V1_0
|
||||
} // namespace thermal
|
||||
} // namespace hardware
|
||||
} // namespace android
|
||||
|
||||
#endif // ANDROID_HARDWARE_THERMAL_V1_0_WAHOO_THERMAL_H
|
||||
4
thermal/android.hardware.thermal@1.0-service.wahoo.rc
Normal file
4
thermal/android.hardware.thermal@1.0-service.wahoo.rc
Normal file
@@ -0,0 +1,4 @@
|
||||
service thermal-hal-1-0 /vendor/bin/hw/android.hardware.thermal@1.0-service.wahoo
|
||||
class hal
|
||||
user nobody
|
||||
group nobody
|
||||
63
thermal/service.cpp
Normal file
63
thermal/service.cpp
Normal file
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Copyright (C) 2017 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <android-base/logging.h>
|
||||
#include <hidl/HidlTransportSupport.h>
|
||||
#include "Thermal.h"
|
||||
|
||||
using android::sp;
|
||||
using android::status_t;
|
||||
using android::OK;
|
||||
|
||||
// libhwbinder:
|
||||
using android::hardware::configureRpcThreadpool;
|
||||
using android::hardware::joinRpcThreadpool;
|
||||
|
||||
// Generated HIDL files
|
||||
using android::hardware::thermal::V1_0::IThermal;
|
||||
using android::hardware::thermal::V1_0::implementation::Thermal;
|
||||
|
||||
int main() {
|
||||
|
||||
status_t status;
|
||||
android::sp<IThermal> service = nullptr;
|
||||
|
||||
LOG(INFO) << "Thermal HAL Service 1.0 is starting";
|
||||
|
||||
service = new Thermal();
|
||||
if (service == nullptr) {
|
||||
LOG(ERROR) << "Can not create an instance of Thermal HAL Iface, exiting";
|
||||
|
||||
goto shutdown;
|
||||
}
|
||||
|
||||
configureRpcThreadpool(1, true /*callerWillJoin*/);
|
||||
|
||||
status = service->registerAsService();
|
||||
if (status != OK) {
|
||||
LOG(ERROR) << "Could not register service for Thermal HAL Iface (" << status << ")";
|
||||
goto shutdown;
|
||||
}
|
||||
|
||||
LOG(INFO) << "Thermal Service is ready";
|
||||
joinRpcThreadpool();
|
||||
// Should not pass this line
|
||||
|
||||
shutdown:
|
||||
// In normal operation, we don't expect the thread pool to exit
|
||||
LOG(ERROR) << "Thermal Service is shutting down";
|
||||
return 1;
|
||||
}
|
||||
293
thermal/thermal-helper.cpp
Normal file
293
thermal/thermal-helper.cpp
Normal file
@@ -0,0 +1,293 @@
|
||||
/*
|
||||
* Copyright (C) 2017 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <cctype>
|
||||
#include <cerrno>
|
||||
#include <cinttypes>
|
||||
#include <cmath>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
|
||||
#include <android-base/logging.h>
|
||||
#include <android-base/properties.h>
|
||||
#include <android-base/stringprintf.h>
|
||||
|
||||
#include "thermal-helper.h"
|
||||
|
||||
namespace android {
|
||||
namespace hardware {
|
||||
namespace thermal {
|
||||
namespace V1_0 {
|
||||
namespace implementation {
|
||||
|
||||
static unsigned int gSkinSensorNum;
|
||||
static unsigned int gTsensOffset;
|
||||
static unsigned int gSkinThrottlingThreshold;
|
||||
static unsigned int gSkinShutdownThreshold;
|
||||
static unsigned int gVrThrottledBelowMin;
|
||||
|
||||
/**
|
||||
* Initialization constants based on platform
|
||||
*
|
||||
* @return true on success or false on error.
|
||||
*/
|
||||
bool initThermal() {
|
||||
std::string hardware = android::base::GetProperty("ro.hardware", "");
|
||||
if (hardware == "walleye") {
|
||||
LOG(ERROR) << "Initialization on Walleye";
|
||||
gSkinSensorNum = kWalleyeSkinSensorNum;
|
||||
gTsensOffset = kWalleyeTsensOffset;
|
||||
gSkinThrottlingThreshold = kWalleyeSkinThrottlingThreshold;
|
||||
gSkinShutdownThreshold = kWalleyeSkinShutdownThreshold;
|
||||
gVrThrottledBelowMin = kWalleyeVrThrottledBelowMin;
|
||||
} else if (hardware == "taimen") {
|
||||
std::string rev = android::base::GetProperty("ro.revision", "");
|
||||
if (rev == "rev_a" || rev == "rev_b") {
|
||||
LOG(ERROR) << "Initialization on Taimen pre revision C";
|
||||
gSkinSensorNum = kTaimenRabSkinSensorNum;
|
||||
gTsensOffset = kTaimenRabTsensOffset;
|
||||
gSkinThrottlingThreshold = kTaimenRabSkinThrottlingThreshold;
|
||||
gSkinShutdownThreshold = kTaimenRabSkinShutdownThreshold;
|
||||
gVrThrottledBelowMin = kTaimenRabVrThrottledBelowMin;
|
||||
} else {
|
||||
LOG(ERROR) << "Initialization on Taimen revision C and later";
|
||||
gSkinSensorNum = kTaimenRcSkinSensorNum;
|
||||
gTsensOffset = kTaimenRcTsensOffset;
|
||||
gSkinThrottlingThreshold = kTaimenRcSkinThrottlingThreshold;
|
||||
gSkinShutdownThreshold = kTaimenRcSkinShutdownThreshold;
|
||||
gVrThrottledBelowMin = kTaimenRcVrThrottledBelowMin;
|
||||
}
|
||||
} else {
|
||||
LOG(ERROR) << "Unsupported hardware: " << hardware;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads device temperature.
|
||||
*
|
||||
* @param sensor_num Number of sensor file with temperature.
|
||||
* @param type Device temperature type.
|
||||
* @param name Device temperature name.
|
||||
* @param mult Multiplier used to translate temperature to Celsius.
|
||||
* @param throttling_threshold Throttling threshold for the temperature.
|
||||
* @param shutdown_threshold Shutdown threshold for the temperature.
|
||||
* @param out Pointer to temperature_t structure that will be filled with current
|
||||
* values.
|
||||
*
|
||||
* @return 0 on success or negative value -errno on error.
|
||||
*/
|
||||
static ssize_t readTemperature(int sensor_num, TemperatureType type, const char *name, float mult,
|
||||
float throttling_threshold, float shutdown_threshold,
|
||||
float vr_throttling_threshold, Temperature *out) {
|
||||
FILE *file;
|
||||
char file_name[PATH_MAX];
|
||||
float temp;
|
||||
|
||||
sprintf(file_name, kTemperatureFileFormat, sensor_num);
|
||||
file = fopen(file_name, "r");
|
||||
if (file == NULL) {
|
||||
PLOG(ERROR) << "readTemperature: failed to open file (" << file_name << ")";
|
||||
return -errno;
|
||||
}
|
||||
if (1 != fscanf(file, "%f", &temp)) {
|
||||
fclose(file);
|
||||
PLOG(ERROR) << "readTemperature: failed to read a float";
|
||||
return errno ? -errno : -EIO;
|
||||
}
|
||||
|
||||
fclose(file);
|
||||
|
||||
(*out).type = type;
|
||||
(*out).name = name;
|
||||
(*out).currentValue = temp * mult;
|
||||
(*out).throttlingThreshold = throttling_threshold;
|
||||
(*out).shutdownThreshold = shutdown_threshold;
|
||||
(*out).vrThrottlingThreshold = vr_throttling_threshold;
|
||||
|
||||
LOG(DEBUG) << android::base::StringPrintf(
|
||||
"readTemperature: %d, %d, %s, %g, %g, %g, %g",
|
||||
sensor_num, type, name, temp * mult, throttling_threshold,
|
||||
shutdown_threshold, vr_throttling_threshold);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static ssize_t getCpuTemperatures(hidl_vec<Temperature> *temperatures) {
|
||||
size_t cpu;
|
||||
|
||||
for (cpu = 0; cpu < kCpuNum; cpu++) {
|
||||
if (cpu >= temperatures->size()) {
|
||||
break;
|
||||
}
|
||||
// temperature in decidegrees Celsius.
|
||||
ssize_t result = readTemperature(kCpuTsensOffset[cpu] + gTsensOffset, TemperatureType::CPU, kCpuLabel[cpu],
|
||||
0.1, kCpuThrottlingThreshold, kCpuShutdownThreshold, kCpuThrottlingThreshold,
|
||||
&(*temperatures)[cpu]);
|
||||
if (result != 0) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
return cpu;
|
||||
}
|
||||
|
||||
ssize_t fillTemperatures(hidl_vec<Temperature> *temperatures) {
|
||||
ssize_t result = 0;
|
||||
size_t current_index = 0;
|
||||
|
||||
if (temperatures == NULL || temperatures->size() < kTemperatureNum) {
|
||||
LOG(ERROR) << "fillTemperatures: incorrect buffer";
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
result = getCpuTemperatures(temperatures);
|
||||
if (result < 0) {
|
||||
return result;
|
||||
}
|
||||
current_index += result;
|
||||
|
||||
// GPU temperature.
|
||||
if (current_index < temperatures->size()) {
|
||||
// temperature in decidegrees Celsius.
|
||||
result = readTemperature(gTsensOffset + kGpuTsensOffset, TemperatureType::GPU, kGpuLabel, 0.1,
|
||||
NAN, NAN, NAN, &(*temperatures)[current_index]);
|
||||
if (result < 0) {
|
||||
return result;
|
||||
}
|
||||
current_index++;
|
||||
}
|
||||
|
||||
// Battery temperature.
|
||||
if (current_index < temperatures->size()) {
|
||||
// battery: temperature in millidegrees Celsius.
|
||||
result = readTemperature(kBatterySensorNum, TemperatureType::BATTERY, kBatteryLabel,
|
||||
0.001, NAN, kBatteryShutdownThreshold, NAN,
|
||||
&(*temperatures)[current_index]);
|
||||
if (result < 0) {
|
||||
return result;
|
||||
}
|
||||
current_index++;
|
||||
}
|
||||
|
||||
// Skin temperature.
|
||||
if (current_index < temperatures->size()) {
|
||||
// temperature in Celsius.
|
||||
result = readTemperature(gSkinSensorNum, TemperatureType::SKIN, kSkinLabel, 1.,
|
||||
gSkinThrottlingThreshold, gSkinShutdownThreshold, gVrThrottledBelowMin,
|
||||
&(*temperatures)[current_index]);
|
||||
if (result < 0) {
|
||||
return result;
|
||||
}
|
||||
current_index++;
|
||||
}
|
||||
return kTemperatureNum;
|
||||
}
|
||||
|
||||
ssize_t fillCpuUsages(hidl_vec<CpuUsage> *cpuUsages) {
|
||||
int vals, cpu_num, online;
|
||||
ssize_t read;
|
||||
uint64_t user, nice, system, idle, active, total;
|
||||
char *line = NULL;
|
||||
size_t len = 0;
|
||||
size_t size = 0;
|
||||
char file_name[PATH_MAX];
|
||||
FILE *file;
|
||||
FILE *cpu_file;
|
||||
|
||||
if (cpuUsages == NULL || cpuUsages->size() < kCpuNum ) {
|
||||
LOG(ERROR) << "fillCpuUsages: incorrect buffer";
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
file = fopen(kCpuUsageFile, "r");
|
||||
if (file == NULL) {
|
||||
PLOG(ERROR) << "fillCpuUsages: failed to open file (" << kCpuUsageFile << ")";
|
||||
return -errno;
|
||||
}
|
||||
|
||||
while ((read = getline(&line, &len, file)) != -1) {
|
||||
// Skip non "cpu[0-9]" lines.
|
||||
if (strnlen(line, read) < 4 || strncmp(line, "cpu", 3) != 0 || !isdigit(line[3])) {
|
||||
free(line);
|
||||
line = NULL;
|
||||
len = 0;
|
||||
continue;
|
||||
}
|
||||
|
||||
vals = sscanf(line, "cpu%d %" SCNu64 " %" SCNu64 " %" SCNu64 " %" SCNu64, &cpu_num, &user,
|
||||
&nice, &system, &idle);
|
||||
|
||||
free(line);
|
||||
line = NULL;
|
||||
len = 0;
|
||||
|
||||
if (vals != 5 || size == kCpuNum) {
|
||||
if (vals != 5) {
|
||||
PLOG(ERROR) << "fillCpuUsages: failed to read CPU information from file ("
|
||||
<< kCpuUsageFile << ")";
|
||||
} else {
|
||||
PLOG(ERROR) << "fillCpuUsages: file has incorrect format ("
|
||||
<< kCpuUsageFile << ")";
|
||||
}
|
||||
fclose(file);
|
||||
return errno ? -errno : -EIO;
|
||||
}
|
||||
|
||||
active = user + nice + system;
|
||||
total = active + idle;
|
||||
|
||||
// Read online CPU information.
|
||||
snprintf(file_name, PATH_MAX, kCpuOnlineFileFormat, cpu_num);
|
||||
cpu_file = fopen(file_name, "r");
|
||||
online = 0;
|
||||
if (cpu_file == NULL) {
|
||||
PLOG(ERROR) << "fillCpuUsages: failed to open file (" << file_name << ")";
|
||||
fclose(file);
|
||||
return -errno;
|
||||
}
|
||||
if (1 != fscanf(cpu_file, "%d", &online)) {
|
||||
PLOG(ERROR) << "fillCpuUsages: failed to read CPU online information from file ("
|
||||
<< file_name << ")";
|
||||
fclose(file);
|
||||
fclose(cpu_file);
|
||||
return errno ? -errno : -EIO;
|
||||
}
|
||||
fclose(cpu_file);
|
||||
|
||||
(*cpuUsages)[size].name = kCpuLabel[size];
|
||||
(*cpuUsages)[size].active = active;
|
||||
(*cpuUsages)[size].total = total;
|
||||
(*cpuUsages)[size].isOnline = static_cast<bool>(online);
|
||||
|
||||
LOG(DEBUG) << "fillCpuUsages: "<< kCpuLabel[size] << ": "
|
||||
<< active << " " << total << " " << online;
|
||||
size++;
|
||||
}
|
||||
fclose(file);
|
||||
|
||||
if (size != kCpuNum) {
|
||||
PLOG(ERROR) << "fillCpuUsages: file has incorrect format (" << kCpuUsageFile << ")";
|
||||
return -EIO;
|
||||
}
|
||||
return kCpuNum;
|
||||
}
|
||||
|
||||
} // namespace implementation
|
||||
} // namespace V1_0
|
||||
} // namespace thermal
|
||||
} // namespace hardware
|
||||
} // namespace android
|
||||
100
thermal/thermal-helper.h
Normal file
100
thermal/thermal-helper.h
Normal file
@@ -0,0 +1,100 @@
|
||||
/*
|
||||
* Copyright (c) 2017, The Linux Foundation. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
* * * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
* * Neither the name of The Linux Foundation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
||||
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
||||
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef __THERMAL_HELPER_H__
|
||||
#define __THERMAL_HELPER_H__
|
||||
|
||||
#include <android/hardware/thermal/1.0/IThermal.h>
|
||||
|
||||
namespace android {
|
||||
namespace hardware {
|
||||
namespace thermal {
|
||||
namespace V1_0 {
|
||||
namespace implementation {
|
||||
|
||||
using ::android::hardware::thermal::V1_0::CpuUsage;
|
||||
using ::android::hardware::thermal::V1_0::Temperature;
|
||||
|
||||
constexpr const char *kCpuUsageFile = "/proc/stat";
|
||||
constexpr const char *kTemperatureFileFormat = "/sys/class/thermal/thermal_zone%d/temp";
|
||||
constexpr const char *kCpuOnlineFileFormat = "/sys/devices/system/cpu/cpu%d/online";
|
||||
|
||||
// thermal-engine.conf
|
||||
constexpr unsigned int kWalleyeSkinSensorNum = 9;
|
||||
constexpr unsigned int kWalleyeTsensOffset = 11;
|
||||
constexpr unsigned int kWalleyeSkinThrottlingThreshold = 40;
|
||||
constexpr unsigned int kWalleyeSkinShutdownThreshold = 56;
|
||||
constexpr unsigned int kWalleyeVrThrottledBelowMin = 52;
|
||||
|
||||
constexpr unsigned int kTaimenRabSkinSensorNum = 7;
|
||||
constexpr unsigned int kTaimenRabTsensOffset = 8;
|
||||
constexpr unsigned int kTaimenRabSkinThrottlingThreshold = 49;
|
||||
constexpr unsigned int kTaimenRabSkinShutdownThreshold = 66;
|
||||
constexpr unsigned int kTaimenRabVrThrottledBelowMin = 62;
|
||||
|
||||
constexpr unsigned int kTaimenRcSkinSensorNum = 7;
|
||||
constexpr unsigned int kTaimenRcTsensOffset = 8;
|
||||
constexpr unsigned int kTaimenRcSkinThrottlingThreshold = 38;
|
||||
constexpr unsigned int kTaimenRcSkinShutdownThreshold = 54;
|
||||
constexpr unsigned int kTaimenRcVrThrottledBelowMin = 50;
|
||||
|
||||
|
||||
constexpr unsigned int kBatterySensorNum = 0;
|
||||
constexpr unsigned int kGpuTsensOffset = 11;
|
||||
constexpr unsigned int kCpuNum = 8;
|
||||
|
||||
constexpr const char *kGpuLabel = "GPU";
|
||||
constexpr const char *kBatteryLabel = "battery";
|
||||
constexpr const char *kSkinLabel = "skin";
|
||||
constexpr const char *kCpuLabel[kCpuNum] = {"CPU0", "CPU1", "CPU2", "CPU3", "CPU4", "CPU5", "CPU6", "CPU7"};
|
||||
constexpr int kCpuTsensOffset[kCpuNum] = {1, 2, 4, 3, 5, 6, 7, 8};
|
||||
|
||||
// Sum of kCpuNum + 3 for GPU, BATTERY, and SKIN.
|
||||
constexpr unsigned int kTemperatureNum = 3 + kCpuNum;
|
||||
|
||||
// qcom, therm-reset-temp
|
||||
constexpr unsigned int kCpuShutdownThreshold = 115;
|
||||
// qcom,freq-mitigation-temp
|
||||
constexpr unsigned int kCpuThrottlingThreshold = 95;
|
||||
|
||||
// config_shutdownBatteryTemperature in overlay/frameworks/base/core/res/res/values/config.xml
|
||||
constexpr unsigned int kBatteryShutdownThreshold = 60;
|
||||
|
||||
|
||||
bool initThermal();
|
||||
ssize_t fillTemperatures(hidl_vec<Temperature> *temperatures);
|
||||
ssize_t fillCpuUsages(hidl_vec<CpuUsage> *cpuUsages);
|
||||
|
||||
} // namespace implementation
|
||||
} // namespace V1_0
|
||||
} // namespace thermal
|
||||
} // namespace hardware
|
||||
} // namespace android
|
||||
|
||||
#endif //__THERMAL_HELPER_H__
|
||||
Reference in New Issue
Block a user