From 456054118d63ac7c0f8c1a833aa4d41a27c0083d Mon Sep 17 00:00:00 2001 From: Vilas R K Date: Wed, 16 Aug 2023 21:13:44 +0530 Subject: [PATCH] Determine x86_pkg_temp path Dynamically. In the existing implementation x86_pkg_temp path is fixed, but in case of IVI it is observed x86_pkg_temp path is changed to different thermal zone. This fix will determaine x86_pkg_temp path dynamically to monitor CPU temperature. Tracked-On: OAM-111780 Signed-off-by: Vilas R K --- thermal/Thermal.cpp | 52 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/thermal/Thermal.cpp b/thermal/Thermal.cpp index af10eac..3a72a53 100644 --- a/thermal/Thermal.cpp +++ b/thermal/Thermal.cpp @@ -16,6 +16,11 @@ #include #include +#include +#include +#include +#include +#include #include #include @@ -169,14 +174,59 @@ struct temp_info { uint32_t temp; }; +std::vector getThermalZonePaths() { + std::vector thermalZonePaths; + + glob_t globResult; + if (glob("/sys/class/thermal/thermal_zone*", 0, nullptr, &globResult) == 0) { + for (size_t i = 0; i < globResult.gl_pathc; ++i) { + thermalZonePaths.push_back(globResult.gl_pathv[i]); + } + globfree(&globResult); + } + + return thermalZonePaths; +} + +std::string readTypeAttribute(const std::string& thermalZonePath) { + std::ifstream typeFile(thermalZonePath + "/type"); + if (!typeFile.is_open()) { + return ""; + } + + std::string type; + typeFile >> type; + typeFile.close(); + + return type; +} + +std::string getThermalZoneCPUTemperaturePath(){ + std::vector thermalZonePaths = getThermalZonePaths(); + + for (const std::string& thermalZonePath : thermalZonePaths) { + std::string thermalType = readTypeAttribute(thermalZonePath); + if (!thermalType.empty()) { + if (thermalType == "x86_pkg_temp") { + return thermalZonePath + "/temp"; + } + } + } + return ""; +} + static int get_soc_pkg_temperature(float* temp) { float fTemp = 0; int len = 0; FILE *file = NULL; - file = fopen(SYSFS_TEMPERATURE_CPU, "r"); + std::string thermalTypePath = getThermalZoneCPUTemperaturePath(); + ALOGE("Thermal zone path Temp path for x86_pkg_temp:%s", thermalTypePath.c_str()); + if(thermalTypePath.empty()) + return -errno; + file = fopen(thermalTypePath.c_str(), "r"); if (file == NULL) { ALOGE("%s: failed to open file: %s", __func__, strerror(errno)); return -errno;