Skip to content

Commit

Permalink
Determine x86_pkg_temp path Dynamically.
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
vilasrk committed Aug 17, 2023
1 parent 871bc81 commit 4560541
Showing 1 changed file with 51 additions and 1 deletion.
52 changes: 51 additions & 1 deletion thermal/Thermal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@

#include <cmath>
#include <set>
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <glob.h>

#include <android-base/logging.h>
#include <hidl/HidlTransportSupport.h>
Expand Down Expand Up @@ -169,14 +174,59 @@ struct temp_info {
uint32_t temp;
};

std::vector<std::string> getThermalZonePaths() {
std::vector<std::string> 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<std::string> 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;
Expand Down

0 comments on commit 4560541

Please sign in to comment.