diff --git a/Makefile.am b/Makefile.am index fbc52c9e..8ad74449 100644 --- a/Makefile.am +++ b/Makefile.am @@ -70,12 +70,6 @@ thermald_SOURCES = \ src/thd_cdev_rapl_dram.cpp \ src/thd_cdev_backlight.cpp \ src/thd_int3400.cpp \ - src/thd_cdev_kbl_amdgpu.cpp \ - src/thd_sensor_kbl_amdgpu_power.cpp \ - src/thd_sensor_kbl_amdgpu_thermal.cpp \ - src/thd_zone_kbl_g_mcp.cpp \ - src/thd_sensor_kbl_g_mcp.cpp \ - src/thd_zone_kbl_amdgpu.cpp \ src/thd_sensor_rapl_power.cpp \ src/thd_zone_rapl_power.cpp \ src/thd_gddv.cpp \ diff --git a/README.txt b/README.txt index c1744982..6fad7caf 100644 --- a/README.txt +++ b/README.txt @@ -111,7 +111,10 @@ Releases Release 2.5.8 - Lunar Lake support -- Deprecate modem support +- Arrow Lake support +- Remove coverity errors to minimum +- Add a script to plot temperature and trips from debug log +- Deprecate modem/KBL-G support - Remove dbus-glib-devel as requirment Release 2.5.7 diff --git a/configure.ac b/configure.ac index dd2da155..8cc5fe0d 100644 --- a/configure.ac +++ b/configure.ac @@ -1,7 +1,7 @@ AC_PREREQ(1.0) m4_define([td_major_version], [2]) -m4_define([td_minor_version], [5.8-rc1]) +m4_define([td_minor_version], [5.8]) m4_define([td_version], [td_major_version.td_minor_version]) diff --git a/src/main.cpp b/src/main.cpp index 1ea74b76..ac73418b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -289,7 +289,10 @@ int main(int argc, char *argv[]) { fprintf(stderr, "Cannot create '%s': %s", TDRUNDIR, strerror(errno)); exit(EXIT_FAILURE); } - g_mkdir_with_parents(TDCONFDIR, 0755); // Don't care return value as directory + if (g_mkdir_with_parents(TDCONFDIR, 0755) != 0) { + // Don't care return value as directory + fprintf(stderr, "Cannot create '%s': %s", TDCONFDIR, strerror(errno)); + } // may already exist if (log_info) { thd_log_level |= G_LOG_LEVEL_INFO; diff --git a/src/thd_cdev.cpp b/src/thd_cdev.cpp index b27ac768..1b8b39bb 100644 --- a/src/thd_cdev.cpp +++ b/src/thd_cdev.cpp @@ -254,17 +254,19 @@ int cthd_cdev::thd_cdev_set_state(int set_point, int target_temp, bool found = false; bool first_entry = false; - if (zone_trip_limits.size() == 0) + if (zone_trip_limits.size() == 0) { first_entry = true; - - // Search for the zone and trip id in the list - for (unsigned int i = 0; i < zone_trip_limits.size(); ++i) { - if (zone_trip_limits[i].zone == zone_id - && zone_trip_limits[i].trip == trip_id) { - found = true; - break; + } else { + // Search for the zone and trip id in the list + for (unsigned int i = 0; i < zone_trip_limits.size(); ++i) { + if (zone_trip_limits[i].zone == zone_id + && zone_trip_limits[i].trip == trip_id) { + found = true; + break; + } } } + // If not found in the list add to the list if (!found) { zone_trip_limits_t limit; @@ -326,7 +328,16 @@ int cthd_cdev::thd_cdev_set_state(int set_point, int target_temp, zone_trip_limits_t limit; - limit = zone_trip_limits[zone_trip_limits.size() - 1]; + /* The below check to keep static analysis happy. There is no way + * zone_trip_limits.size() == 0. + * The above !found case ensures atleast size == 1 + */ + unsigned int zone_trips_size = zone_trip_limits.size(); + + if (!zone_trips_size) + zone_trips_size = 1; + + limit = zone_trip_limits[zone_trips_size - 1]; target_state_valid = limit.target_state_valid; target_value = limit.target_value; diff --git a/src/thd_cdev.h b/src/thd_cdev.h index ca3e5422..6473df49 100644 --- a/src/thd_cdev.h +++ b/src/thd_cdev.h @@ -186,7 +186,7 @@ class cthd_cdev { virtual int map_target_state(int target_valid, int target_state) { return target_state; } - virtual void set_adaptive_target(struct adaptive_target) {}; + virtual void set_adaptive_target(struct adaptive_target &target) {}; void set_debounce_interval(int interval) { debounce_interval = interval; } @@ -240,10 +240,10 @@ class cthd_cdev { return cdev_sysfs.get_base_path(); } void set_cdev_type(std::string _type_str) { - type_str = _type_str; + type_str = std::move(_type_str); } void set_cdev_alias(std::string _alias_str) { - alias_str = _alias_str; + alias_str = std::move(_alias_str); } void set_pid_param(double kp, double ki, double kd) { pid_ctrl.kp = kp; @@ -257,7 +257,7 @@ class cthd_cdev { } void thd_cdev_set_write_prefix(std::string prefix) { - write_prefix = prefix; + write_prefix = std::move(prefix); } void cdev_dump() { diff --git a/src/thd_cdev_gen_sysfs.h b/src/thd_cdev_gen_sysfs.h index f5c76a4b..4cb6c82a 100644 --- a/src/thd_cdev_gen_sysfs.h +++ b/src/thd_cdev_gen_sysfs.h @@ -31,7 +31,7 @@ class cthd_gen_sysfs_cdev: public cthd_cdev { public: cthd_gen_sysfs_cdev(unsigned int _index, std::string control_path) : - cthd_cdev(_index, control_path) { + cthd_cdev(_index, std::move(control_path)) { } virtual void set_curr_state(int state, int arg); virtual void set_curr_state_raw(int state, int arg); diff --git a/src/thd_cdev_kbl_amdgpu.cpp b/src/thd_cdev_kbl_amdgpu.cpp deleted file mode 100644 index bc7f01ca..00000000 --- a/src/thd_cdev_kbl_amdgpu.cpp +++ /dev/null @@ -1,144 +0,0 @@ -/* - * thd_cdev_kbl_amdgpu: amdgpu power control - * - * Copyright (C) 2018 Intel Corporation. All rights reserved. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License version - * 2 or later as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301, USA. - * - * - * Author Name - * - */ - -#include - -#include "thd_cdev_kbl_amdgpu.h" - -cthd_cdev_kgl_amdgpu::cthd_cdev_kgl_amdgpu(unsigned int _index, int _cpu_index) : - cthd_cdev(_index, ""),activated(0) { - DIR *dir; - struct dirent *entry; - const std::string base_path = "/sys/class/hwmon/"; - - if ((dir = opendir(base_path.c_str())) != NULL) { - while ((entry = readdir(dir)) != NULL) { - // Check name - std::string name_path = base_path + entry->d_name + "/name"; - - std::ifstream ifs(name_path.c_str(), std::ifstream::in); - if (ifs.good()) { - std::string line; - while (std::getline(ifs, line)) { - if (line == "amdgpu") { - cdev_sysfs.update_path(base_path + entry->d_name + "/"); - } - } - ifs.close(); - } - } - closedir(dir); - } -} - -int cthd_cdev_kgl_amdgpu::get_curr_state() { - if (activated) - return get_curr_state(true); - else - return min_state; -} - -int cthd_cdev_kgl_amdgpu::get_curr_state(bool read_again) { - int ret; - int state; - - ret = cdev_sysfs.read("power1_average", &state); - if (ret < 0) { - return min_state; - } - - //workaround: Looks for comment in set_curr_state - if (state == 1000000) - state = max_state; - - return state; -} - -void cthd_cdev_kgl_amdgpu::set_curr_state(int state, int arg) { - int new_state = state; - - if (!arg) { - activated = 0; - thd_log_info("ignore \n"); - new_state = min_state; - } else - activated = 1; - - // When power1_cap = 0 is written to sysfs it changes to max powercap value - // So this is a workaround - if (state == 0) - new_state = min_state; - - if (cdev_sysfs.write("power1_cap", new_state) > 0) - curr_state = state; - - thd_log_info("set cdev state index %d state %d wr:%d\n", index, state, state); -} - -void cthd_cdev_kgl_amdgpu::set_curr_state_raw(int state, int arg) { - set_curr_state(state, arg); -} - -int cthd_cdev_kgl_amdgpu::update() { - // min and max are opposite of actual sysfs value in thermald terms - if (cdev_sysfs.exists("power1_cap_min")) { - std::string type_str; - int ret; - - ret = cdev_sysfs.read("power1_cap_min", &max_state); - if (ret < 0) { - thd_log_info("cthd_cdev_kgl_amdgpu : not present\n"); - return THD_ERROR; - } - } else { - return THD_ERROR; - } - - if (cdev_sysfs.exists("power1_cap_max")) { - std::string type_str; - int ret; - - ret = cdev_sysfs.read("power1_cap_max", &min_state); - if (ret < 0) { - thd_log_info("cthd_cdev_kgl_amdgpu : not present\n"); - return THD_ERROR; - } - } else { - return THD_ERROR; - } - - set_inc_dec_value(-(min_state * (float) 10 / 100)); - set_pid_param(-0.4, 0, 0); - - return THD_SUCCESS; -} - -int cthd_cdev_kgl_amdgpu::map_target_state(int target_valid, int target_state) { - return 0; -} - -int cthd_cdev_kgl_amdgpu::get_phy_max_state() { - - return min_state; -} diff --git a/src/thd_cdev_kbl_amdgpu.h b/src/thd_cdev_kbl_amdgpu.h deleted file mode 100644 index 2da57a83..00000000 --- a/src/thd_cdev_kbl_amdgpu.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * thd_cdev_kbl_amdgpu: amdgpu power control - * - * Copyright (C) 2018 Intel Corporation. All rights reserved. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License version - * 2 or later as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301, USA. - * - * - * Author Name - * - */ - -#ifndef SRC_THD_CDEV_KBL_AMD_GPU_H_ -#define SRC_THD_CDEV_KBL_AMD_GPU_H_ - -#include "thd_cdev.h" - -class cthd_cdev_kgl_amdgpu: public cthd_cdev { -private: - int activated; -public: - cthd_cdev_kgl_amdgpu(unsigned int _index, int _cpu_index); - void set_curr_state(int state, int arg); - void set_curr_state_raw(int state, int arg); - int get_curr_state(); - int get_curr_state(bool read_again); - int update(); - int map_target_state(int target_valid, int target_state); - int get_phy_max_state(); -}; - -#endif /* SRC_THD_CDEV_BACKLIGHT_H_ */ diff --git a/src/thd_cdev_rapl.cpp b/src/thd_cdev_rapl.cpp index 675745d8..e55b4c33 100644 --- a/src/thd_cdev_rapl.cpp +++ b/src/thd_cdev_rapl.cpp @@ -324,10 +324,11 @@ void cthd_sysfs_cdev_rapl::set_tcc(int tcc) { if (!sysfs.exists("tcc_offset_degree_celsius")) return; - sysfs.write("tcc_offset_degree_celsius", tcc); + if (sysfs.write("tcc_offset_degree_celsius", tcc) == -1) + thd_log_debug("TCC write failed\n"); } -void cthd_sysfs_cdev_rapl::set_adaptive_target(struct adaptive_target target) { +void cthd_sysfs_cdev_rapl::set_adaptive_target(struct adaptive_target &target) { int argument = std::stoi(target.argument, NULL); if (target.code == "PL1MAX") { int pl1_rapl; diff --git a/src/thd_cdev_rapl.h b/src/thd_cdev_rapl.h index 02f4934d..95259764 100644 --- a/src/thd_cdev_rapl.h +++ b/src/thd_cdev_rapl.h @@ -86,10 +86,16 @@ class cthd_sysfs_cdev_rapl: public cthd_cdev { false), power_on_constraint_0_pwr(0), power_on_constraint_0_time_window( 0), power_on_enable_status(0), device_name("TCPU.D0") { + pl1_max_pwr = 0; + pl1_min_pwr = 0; + pl1_min_window = 0; + pl1_max_window = 0; + pl1_step_pwr = 0; + pl1_valid = 0; } cthd_sysfs_cdev_rapl(unsigned int _index, int package, std::string contol_path) : - cthd_cdev(_index, contol_path), phy_max(0), package_id( + cthd_cdev(_index, std::move(contol_path)), phy_max(0), package_id( package), constraint_index( 0), pl2_index( -1), dynamic_phy_max_enable(false), pl0_max_pwr( @@ -99,6 +105,12 @@ class cthd_sysfs_cdev_rapl: public cthd_cdev { false), power_on_constraint_0_pwr(0), power_on_constraint_0_time_window( 0), power_on_enable_status(0), device_name("TCPU.D0") { + pl1_max_pwr = 0; + pl1_min_pwr = 0; + pl1_min_window = 0; + pl1_max_window = 0; + pl1_step_pwr = 0; + pl1_valid = 0; } virtual void set_curr_state(int state, int arg); @@ -108,7 +120,7 @@ class cthd_sysfs_cdev_rapl: public cthd_cdev { virtual int update(); virtual void set_curr_state_raw(int state, int arg); void set_tcc(int tcc); - void set_adaptive_target(struct adaptive_target target); + void set_adaptive_target(struct adaptive_target &target); void thd_cdev_set_min_state_param(int arg); int get_phy_max_state() { return phy_max; diff --git a/src/thd_cdev_rapl_dram.cpp b/src/thd_cdev_rapl_dram.cpp index 20227fd4..ace38fc9 100644 --- a/src/thd_cdev_rapl_dram.cpp +++ b/src/thd_cdev_rapl_dram.cpp @@ -62,7 +62,7 @@ int cthd_sysfs_cdev_rapl_dram::update() { if (!found) return THD_ERROR; - cdev_sysfs.update_path(path_name); + cdev_sysfs.update_path(std::move(path_name)); return cthd_sysfs_cdev_rapl::update(); } diff --git a/src/thd_cdev_therm_sys_fs.h b/src/thd_cdev_therm_sys_fs.h index aad52cf0..1e08ec97 100644 --- a/src/thd_cdev_therm_sys_fs.h +++ b/src/thd_cdev_therm_sys_fs.h @@ -32,7 +32,7 @@ class cthd_sysfs_cdev: public cthd_cdev { public: cthd_sysfs_cdev(unsigned int _index, std::string control_path) : - cthd_cdev(_index, control_path) { + cthd_cdev(_index, std::move(control_path)) { } virtual void set_curr_state(int state, int arg); virtual int get_curr_state(); diff --git a/src/thd_cpu_default_binding.cpp b/src/thd_cpu_default_binding.cpp index 7132ebe6..e8e32b38 100644 --- a/src/thd_cpu_default_binding.cpp +++ b/src/thd_cpu_default_binding.cpp @@ -187,8 +187,8 @@ void cthd_cpu_default_binding::update_zone_stat(std::string zone_name, } bool cthd_cpu_default_binding::check_cpu_load() { - unsigned int max_power; - unsigned int min_power; + unsigned int max_power = 0; + unsigned int min_power = 0; unsigned int power; power = thd_engine->rapl_power_meter.rapl_action_get_power(PACKAGE, diff --git a/src/thd_engine.cpp b/src/thd_engine.cpp index eb3adeba..2689c06f 100644 --- a/src/thd_engine.cpp +++ b/src/thd_engine.cpp @@ -48,7 +48,7 @@ static void *cthd_engine_thread(void *arg); cthd_engine::cthd_engine(std::string _uuid) : current_cdev_index(0), current_zone_index(0), current_sensor_index(0), parse_thermal_zone_success( - false), parse_thermal_cdev_success(false), uuid(_uuid), parser_disabled( + false), parse_thermal_cdev_success(false), uuid(std::move(_uuid)), parser_disabled( false), adaptive_mode(false), poll_timeout_msec(-1), wakeup_fd( -1), uevent_fd(-1), control_mode(COMPLEMENTRY), write_pipe_fd( 0), preference(0), status(true), thz_last_uevent_time(0), thz_last_temp_ind_time( @@ -717,6 +717,9 @@ static supported_ids_t id_table[] = { { 6, 0xbf }, // Raptorlake S { 6, 0xaa }, // Mateor Lake L { 6, 0xbd }, // Lunar Lake M + { 6, 0xc6 }, // Arrow Lake + { 6, 0xc5 }, // Arrow Lake H + { 6, 0xb5 }, // Arrow Lake U { 0, 0 } // Last Invalid entry }; @@ -895,7 +898,7 @@ void cthd_engine::thd_read_default_cooling_devices() { } ppcc_t* cthd_engine::get_ppcc_param(std::string name) { - return parser.get_ppcc_param(name); + return parser.get_ppcc_param(std::move(name)); } cthd_zone* cthd_engine::search_zone(std::string name) { @@ -1031,7 +1034,7 @@ int cthd_engine::user_add_sensor(std::string name, std::string path) { return THD_SUCCESS; } } - sensor = new cthd_sensor(current_sensor_index, path, name, SENSOR_TYPE_RAW); + sensor = new cthd_sensor(current_sensor_index, std::move(path), std::move(name), SENSOR_TYPE_RAW); if (sensor->sensor_update() != THD_SUCCESS) { delete sensor; pthread_mutex_unlock(&thd_engine_mutex); @@ -1071,8 +1074,8 @@ int cthd_engine::user_add_virtual_sensor(std::string name, } cthd_sensor_virtual *virt_sensor; - virt_sensor = new cthd_sensor_virtual(current_sensor_index, name, - dep_sensor, slope, intercept); + virt_sensor = new cthd_sensor_virtual(current_sensor_index, std::move(name), + std::move(dep_sensor), slope, intercept); if (virt_sensor->sensor_update() != THD_SUCCESS) { delete virt_sensor; pthread_mutex_unlock(&thd_engine_mutex); @@ -1114,7 +1117,7 @@ int cthd_engine::user_set_psv_temp(std::string name, unsigned int temp) { int ret; pthread_mutex_lock(&thd_engine_mutex); - zone = get_zone(name); + zone = get_zone(std::move(name)); if (!zone) { pthread_mutex_unlock(&thd_engine_mutex); thd_log_warn("user_set_psv_temp\n"); @@ -1132,7 +1135,7 @@ int cthd_engine::user_set_max_temp(std::string name, unsigned int temp) { int ret; pthread_mutex_lock(&thd_engine_mutex); - zone = get_zone(name); + zone = get_zone(std::move(name)); if (!zone) { pthread_mutex_unlock(&thd_engine_mutex); thd_log_warn("user_set_max_temp\n"); @@ -1150,7 +1153,7 @@ int cthd_engine::user_add_zone(std::string zone_name, unsigned int trip_temp, int ret = THD_SUCCESS; cthd_zone_dynamic *zone = new cthd_zone_dynamic(current_zone_index, - zone_name, trip_temp, PASSIVE, sensor_name, cdev_name); + std::move(zone_name), trip_temp, PASSIVE, std::move(sensor_name), std::move(cdev_name)); if (!zone) { return THD_ERROR; } @@ -1176,7 +1179,7 @@ int cthd_engine::user_set_zone_status(std::string name, int status) { cthd_zone *zone; pthread_mutex_lock(&thd_engine_mutex); - zone = get_zone(name); + zone = get_zone(std::move(name)); if (!zone) { pthread_mutex_unlock(&thd_engine_mutex); return THD_ERROR; @@ -1197,7 +1200,7 @@ int cthd_engine::user_get_zone_status(std::string name, int *status) { cthd_zone *zone; pthread_mutex_lock(&thd_engine_mutex); - zone = get_zone(name); + zone = get_zone(std::move(name)); if (!zone) { pthread_mutex_unlock(&thd_engine_mutex); return THD_ERROR; @@ -1241,12 +1244,12 @@ int cthd_engine::user_add_cdev(std::string cdev_name, std::string cdev_path, if (!cdev) { cthd_gen_sysfs_cdev *cdev_sysfs; - cdev_sysfs = new cthd_gen_sysfs_cdev(current_cdev_index, cdev_path); + cdev_sysfs = new cthd_gen_sysfs_cdev(current_cdev_index, std::move(cdev_path)); if (!cdev_sysfs) { pthread_mutex_unlock(&thd_engine_mutex); return THD_ERROR; } - cdev_sysfs->set_cdev_type(cdev_name); + cdev_sysfs->set_cdev_type(std::move(cdev_name)); if (cdev_sysfs->update() != THD_SUCCESS) { delete cdev_sysfs; pthread_mutex_unlock(&thd_engine_mutex); diff --git a/src/thd_engine.h b/src/thd_engine.h index 4ad70f3f..998c4d6d 100644 --- a/src/thd_engine.h +++ b/src/thd_engine.h @@ -228,7 +228,7 @@ class cthd_engine { return preference; } void set_config_file(std::string conf_file) { - config_file = conf_file; + config_file = std::move(conf_file); } std::string get_config_file() { return config_file; diff --git a/src/thd_engine_adaptive.cpp b/src/thd_engine_adaptive.cpp index 620a6828..d0671964 100644 --- a/src/thd_engine_adaptive.cpp +++ b/src/thd_engine_adaptive.cpp @@ -350,7 +350,7 @@ int cthd_engine_adaptive::install_itmt(struct itmt_entry *itmt_entry) { return 0; } -int cthd_engine_adaptive::set_itmt_target(struct adaptive_target target) { +int cthd_engine_adaptive::set_itmt_target(struct adaptive_target &target) { struct itmt *itmt; thd_log_info("set_int3400 ITMT target %s\n", target.argument.c_str()); @@ -384,7 +384,7 @@ int cthd_engine_adaptive::set_itmt_target(struct adaptive_target target) { } -void cthd_engine_adaptive::set_int3400_target(struct adaptive_target target) { +void cthd_engine_adaptive::set_int3400_target(struct adaptive_target &target) { if (target.code == "ITMT") { if (set_itmt_target(target) == THD_SUCCESS) { @@ -602,6 +602,7 @@ int cthd_engine_adaptive::thd_engine_init(bool ignore_cpuid_check, check_cpu_id(); if (!processor_id_match()) { thd_log_msg("Unsupported cpu model or platform\n"); + thd_log_msg("Try option --ignore-cpuid-check to disable this compatibility test\n"); exit(EXIT_SUCCESS); } } diff --git a/src/thd_engine_adaptive.h b/src/thd_engine_adaptive.h index ecfe9126..d3f78d33 100644 --- a/src/thd_engine_adaptive.h +++ b/src/thd_engine_adaptive.h @@ -48,12 +48,12 @@ class cthd_engine_adaptive: public cthd_engine_default { int int3400_installed; int current_matched_target; - int set_itmt_target(struct adaptive_target target); + int set_itmt_target(struct adaptive_target &target); int install_passive(struct psv *psv); int install_itmt(struct itmt_entry *itmt_entry); void psvt_consolidate(); void set_trip(std::string device, std::string argument); - void set_int3400_target(struct adaptive_target target); + void set_int3400_target(struct adaptive_target &target); void exec_fallback_target(int target); void execute_target(struct adaptive_target &target); void install_passive_default(); @@ -77,12 +77,12 @@ class cthd_engine_adaptive: public cthd_engine_default { ~cthd_engine_adaptive() { } ppcc_t* get_ppcc_param(std::string name) { - return gddv.get_ppcc_param(name); + return gddv.get_ppcc_param(std::move(name)); } int search_idsp(std::string name) { - return gddv.search_idsp(name); + return gddv.search_idsp(std::move(name)); } int thd_engine_init(bool ignore_cpuid_check, bool adaptive); diff --git a/src/thd_engine_default.cpp b/src/thd_engine_default.cpp index c039831b..5c957793 100644 --- a/src/thd_engine_default.cpp +++ b/src/thd_engine_default.cpp @@ -37,14 +37,6 @@ #include "thd_sensor_virtual.h" #include "thd_cdev_backlight.h" #include "thd_int3400.h" -#include "thd_sensor_kbl_amdgpu_thermal.h" -#include "thd_sensor_kbl_amdgpu_power.h" -#include "thd_cdev_kbl_amdgpu.h" -#include "thd_zone_kbl_amdgpu.h" -#include "thd_sensor_kbl_g_mcp.h" -#include "thd_zone_kbl_g_mcp.h" -#include "thd_cdev_kbl_amdgpu.h" -#include "thd_zone_kbl_g_mcp.h" #include "thd_sensor_rapl_power.h" #include "thd_zone_rapl_power.h" @@ -178,30 +170,6 @@ int cthd_engine_default::read_thermal_sensors() { thd_log_warn("Thermal DTS: No coretemp sysfs found\n"); } - cthd_sensor_kbl_amdgpu_thermal *amdgpu_thermal = new cthd_sensor_kbl_amdgpu_thermal(index); - if (amdgpu_thermal->sensor_update() == THD_SUCCESS) { - sensors.push_back(amdgpu_thermal); - ++index; - } else { - delete amdgpu_thermal; - } - - cthd_sensor_kbl_amdgpu_power *amdgpu_power = new cthd_sensor_kbl_amdgpu_power(index); - if (amdgpu_power->sensor_update() == THD_SUCCESS) { - sensors.push_back(amdgpu_power); - ++index; - } else { - delete amdgpu_power; - } - - cthd_sensor_kbl_g_mcp *mcp_power = new cthd_sensor_kbl_g_mcp(index); - if (mcp_power->sensor_update() == THD_SUCCESS) { - sensors.push_back(mcp_power); - ++index; - } else { - delete mcp_power; - } - if (debug_mode_on()) { // Only used for debug power using ThermalMonitor cthd_sensor_rapl_power *rapl_power = new cthd_sensor_rapl_power(index); @@ -774,18 +742,6 @@ int cthd_engine_default::read_cooling_devices() { delete backlight_dev; } - cthd_cdev *cdev_amdgpu = search_cdev("amdgpu"); - if (!cdev_amdgpu) { - cthd_cdev_kgl_amdgpu *cdev_amdgpu = new cthd_cdev_kgl_amdgpu( - current_cdev_index, 0); - cdev_amdgpu->set_cdev_type("amdgpu"); - if (cdev_amdgpu->update() == THD_SUCCESS) { - cdevs.push_back(cdev_amdgpu); - ++current_cdev_index; - } else - delete cdev_amdgpu; - } - // Add from XML cooling device config if (!parser_init() && parser.platform_matched()) { for (int i = 0; i < parser.cdev_count(); ++i) { diff --git a/src/thd_engine_default.h b/src/thd_engine_default.h index 7ce4a491..6cf0119b 100644 --- a/src/thd_engine_default.h +++ b/src/thd_engine_default.h @@ -57,7 +57,7 @@ class cthd_engine_default: public cthd_engine { tcc_offset_low(0), force_mmio_rapl(false) { } cthd_engine_default(std::string _uuid) : - cthd_engine(_uuid), + cthd_engine(std::move(_uuid)), workaround_interval(0), tcc_offset_checked(0), tcc_offset_low(0), force_mmio_rapl(false) { } diff --git a/src/thd_gddv.cpp b/src/thd_gddv.cpp index 4bb03c45..151190e0 100644 --- a/src/thd_gddv.cpp +++ b/src/thd_gddv.cpp @@ -455,8 +455,8 @@ void cthd_gddv::dump_apct() { thd_log_info( "\ttarget:%d device:%s condition:%s comparison:%s argument:%d" - " operation:%s time_comparison:%d time:%d" - " stare:%d state_entry_time:%d \n", + " operation:%s time_comparison:%d time:%ld" + " stare:%d state_entry_time:%ld \n", condition_set[j].target, condition_set[j].device.c_str(), cond_name.c_str(), comp_str.c_str(), condition_set[j].argument, op_str.c_str(), @@ -1173,7 +1173,7 @@ int cthd_gddv::evaluate_oem_condition(struct condition condition) { } int value = std::stoi(data, NULL); - return compare_condition(condition, value); + return compare_condition(std::move(condition), value); } return THD_ERROR; @@ -1192,7 +1192,7 @@ int cthd_gddv::evaluate_temperature_condition( else sensor_name = condition.device.substr(pos + 1); - cthd_sensor *sensor = thd_engine->search_sensor(sensor_name); + cthd_sensor *sensor = thd_engine->search_sensor(std::move(sensor_name)); if (!sensor) { thd_log_info("Unable to find a sensor for %s\n", condition.device.c_str()); @@ -1205,7 +1205,7 @@ int cthd_gddv::evaluate_temperature_condition( // Conditions are specified in decikelvin, temperatures are in // millicelsius. value = value / 100 + 2732; - return compare_condition(condition, value); + return compare_condition(std::move(condition), value); } #ifdef ANDROID @@ -1227,7 +1227,7 @@ int cthd_gddv::evaluate_lid_condition(struct condition condition) { int lid_closed = libevdev_get_event_value(lid_dev, EV_SW, SW_LID); value = !lid_closed; } - return compare_condition(condition, value); + return compare_condition(std::move(condition), value); } #endif @@ -1236,7 +1236,7 @@ int cthd_gddv::evaluate_workload_condition( // We don't have a good way to assert workload at the moment, so just // default to bursty - return compare_condition(condition, 3); + return compare_condition(std::move(condition), 3); } #ifdef ANDROID @@ -1268,14 +1268,14 @@ int cthd_gddv::evaluate_platform_type_condition( if (tablet) value = 2; } - return compare_condition(condition, value); + return compare_condition(std::move(condition), value); } #endif int cthd_gddv::evaluate_power_slider_condition( struct condition condition) { - return compare_condition(condition, power_slider); + return compare_condition(std::move(condition), power_slider); } #ifdef ANDROID @@ -1312,7 +1312,7 @@ int cthd_gddv::evaluate_ac_condition(struct condition condition) { if (on_battery) value = 1; - return compare_condition(condition, value); + return compare_condition(std::move(condition), value); } #endif @@ -1365,7 +1365,7 @@ int cthd_gddv::evaluate_condition(struct condition condition) { if (condition.time && condition.state_entry_time == 0) { condition.state_entry_time = time(NULL); } - ret = compare_time(condition); + ret = compare_time(std::move(condition)); } else { condition.state_entry_time = 0; } diff --git a/src/thd_gddv.h b/src/thd_gddv.h index f4dc8372..92ffe890 100644 --- a/src/thd_gddv.h +++ b/src/thd_gddv.h @@ -128,10 +128,10 @@ struct condition { int argument; enum adaptive_operation operation; enum adaptive_comparison time_comparison; - int time; + time_t time; int target; int state; - int state_entry_time; + time_t state_entry_time; int ignore_condition; }; diff --git a/src/thd_int3400.cpp b/src/thd_int3400.cpp index c1283dee..c5b1d8bf 100644 --- a/src/thd_int3400.cpp +++ b/src/thd_int3400.cpp @@ -29,7 +29,7 @@ #include #include -cthd_INT3400::cthd_INT3400(std::string _uuid) : uuid(_uuid), base_path("") { +cthd_INT3400::cthd_INT3400(std::string _uuid) : uuid(std::move(_uuid)), base_path("") { csys_fs cdev_sysfs(""); if (cdev_sysfs.exists("/sys/bus/acpi/devices/INT3400:00/physical_node/uuids")) { diff --git a/src/thd_parse.cpp b/src/thd_parse.cpp index 5a6bfd2d..c68a35e9 100644 --- a/src/thd_parse.cpp +++ b/src/thd_parse.cpp @@ -617,7 +617,7 @@ int cthd_parse::parse_new_platform(xmlNode * a_node, xmlDoc *doc, thermal_info_t *info_ptr) { xmlNode *cur_node = NULL; unsigned char *tmp_value; - thermal_info_t info; + thermal_info_t info = {}; for (cur_node = a_node; cur_node; cur_node = cur_node->next) { if (cur_node->type == XML_ELEMENT_NODE) { diff --git a/src/thd_rapl_power_meter.cpp b/src/thd_rapl_power_meter.cpp index 75d90978..d8e8f137 100644 --- a/src/thd_rapl_power_meter.cpp +++ b/src/thd_rapl_power_meter.cpp @@ -107,7 +107,7 @@ void cthd_rapl_power_meter::rapl_read_domains(const char *dir_name) { domain.type = DRAM; } if (measure_mask & domain.type) { - domain.name = buffer; + domain.name = std::move(buffer); domain.path = std::string(dir_name) + std::string(dir_entry->d_name); domain_list.push_back(domain); diff --git a/src/thd_sensor.cpp b/src/thd_sensor.cpp index 49a14901..cfbf8544 100644 --- a/src/thd_sensor.cpp +++ b/src/thd_sensor.cpp @@ -28,7 +28,7 @@ cthd_sensor::cthd_sensor(int _index, std::string control_path, std::string _type_str, int _type) : index(_index), type(_type), sensor_sysfs(control_path.c_str()), sensor_active( - false), type_str(_type_str), async_capable(false), virtual_sensor( + false), type_str(std::move(_type_str)), async_capable(false), virtual_sensor( false), thresholds(0), scale(1) { } diff --git a/src/thd_sensor.h b/src/thd_sensor.h index df84d059..300271fb 100644 --- a/src/thd_sensor.h +++ b/src/thd_sensor.h @@ -69,7 +69,7 @@ class cthd_sensor { int set_threshold(int index, int temp); ; void update_path(std::string str) { - sensor_sysfs.update_path(str); + sensor_sysfs.update_path(std::move(str)); } void set_async_capable(bool capable) { async_capable = capable; diff --git a/src/thd_sensor_kbl_amdgpu_power.cpp b/src/thd_sensor_kbl_amdgpu_power.cpp deleted file mode 100644 index b69554bc..00000000 --- a/src/thd_sensor_kbl_amdgpu_power.cpp +++ /dev/null @@ -1,56 +0,0 @@ -/* - * thd_sensor_kbl_amdgpu_power.cpp: Power Sensor for KBL-G amdgpu - * - * Copyright (C) 2018 Intel Corporation. All rights reserved. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License version - * 2 or later as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301, USA. - * - * - * Author Name - * - */ - -#include - -#include "thd_sensor_kbl_amdgpu_power.h" - -cthd_sensor_kbl_amdgpu_power::cthd_sensor_kbl_amdgpu_power(int index) : - cthd_sensor(index, "", "amdgpu-power", SENSOR_TYPE_RAW) { - - DIR *dir; - struct dirent *entry; - const std::string base_path = "/sys/class/hwmon/"; - - if ((dir = opendir(base_path.c_str())) != NULL) { - while ((entry = readdir(dir)) != NULL) { - // Check name - std::string name_path = base_path + entry->d_name + "/name"; - - std::ifstream ifs(name_path.c_str(), std::ifstream::in); - if (ifs.good()) { - std::string line; - while (std::getline(ifs, line)) { - if (line == "amdgpu") { - update_path( - base_path + entry->d_name + "/power1_average"); - set_scale(1000); - } - } - ifs.close(); - } - } - closedir(dir); - } -} diff --git a/src/thd_sensor_kbl_amdgpu_power.h b/src/thd_sensor_kbl_amdgpu_power.h deleted file mode 100644 index 32a934ea..00000000 --- a/src/thd_sensor_kbl_amdgpu_power.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * thd_sensor_kbl_amdgpu_power.h: Power Sensor for KBL-G amdgpu - * - * Copyright (C) 2018 Intel Corporation. All rights reserved. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License version - * 2 or later as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301, USA. - * - * - * Author Name - * - */ - -#ifndef THD_SENSOR_KBL_AMD_GPU_POWER_H -#define THD_SENSOR_KBL_AMD_GPU_POWER_H - -#include "thd_sensor.h" - -class cthd_sensor_kbl_amdgpu_power: public cthd_sensor { -private: -public: - cthd_sensor_kbl_amdgpu_power(int index); -}; - -#endif diff --git a/src/thd_sensor_kbl_amdgpu_thermal.cpp b/src/thd_sensor_kbl_amdgpu_thermal.cpp deleted file mode 100644 index 9a732bce..00000000 --- a/src/thd_sensor_kbl_amdgpu_thermal.cpp +++ /dev/null @@ -1,54 +0,0 @@ -/* - * thd_sensor_kbl_amdgpu_thermal.cpp: Thermal Sensor for KBL-G amdgpu - * - * Copyright (C) 2018 Intel Corporation. All rights reserved. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License version - * 2 or later as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301, USA. - * - * - * Author Name - * - */ - -#include - -#include "thd_sensor_kbl_amdgpu_thermal.h" - -cthd_sensor_kbl_amdgpu_thermal::cthd_sensor_kbl_amdgpu_thermal(int index) : - cthd_sensor(index, "", "amdgpu-temperature", SENSOR_TYPE_RAW) { - - DIR *dir; - struct dirent *entry; - const std::string base_path = "/sys/class/hwmon/"; - - if ((dir = opendir(base_path.c_str())) != NULL) { - while ((entry = readdir(dir)) != NULL) { - // Check name - std::string name_path = base_path + entry->d_name + "/name"; - - std::ifstream ifs(name_path.c_str(), std::ifstream::in); - if (ifs.good()) { - std::string line; - while (std::getline(ifs, line)) { - if (line == "amdgpu") { - update_path(base_path + entry->d_name + "/temp1_input"); - } - } - ifs.close(); - } - } - closedir(dir); - } -} diff --git a/src/thd_sensor_kbl_amdgpu_thermal.h b/src/thd_sensor_kbl_amdgpu_thermal.h deleted file mode 100644 index 7bd90432..00000000 --- a/src/thd_sensor_kbl_amdgpu_thermal.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * thd_sensor_kbl_amdgpu_thermal.h: Thermal Sensor for KBL-G amdgpu - * - * Copyright (C) 2018 Intel Corporation. All rights reserved. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License version - * 2 or later as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301, USA. - * - * - * Author Name - * - */ - -#ifndef THD_SENSOR_KBL_AMD_GPU_THERMAL_H -#define THD_SENSOR_KBL_AMD_GPU_THERMAL_H - -#include "thd_sensor.h" - -class cthd_sensor_kbl_amdgpu_thermal: public cthd_sensor { -private: -public: - cthd_sensor_kbl_amdgpu_thermal(int index); -}; - -#endif diff --git a/src/thd_sensor_kbl_g_mcp.cpp b/src/thd_sensor_kbl_g_mcp.cpp deleted file mode 100644 index 70ee682b..00000000 --- a/src/thd_sensor_kbl_g_mcp.cpp +++ /dev/null @@ -1,78 +0,0 @@ -/* - * thd_sensor_kbl_amdgpu_power.cpp: Power Sensor for KBL-G amdgpu - * - * Copyright (C) 2018 Intel Corporation. All rights reserved. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License version - * 2 or later as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301, USA. - * - * - * Author Name - * - */ - -#include - -#include "thd_sensor_kbl_g_mcp.h" -#include "thd_engine.h" - -cthd_sensor_kbl_g_mcp::cthd_sensor_kbl_g_mcp(int index) : - cthd_sensor(index, "", "kbl-g-mcp", SENSOR_TYPE_RAW) { - - DIR *dir; - struct dirent *entry; - const std::string base_path = "/sys/class/hwmon/"; - - if ((dir = opendir(base_path.c_str())) != NULL) { - while ((entry = readdir(dir)) != NULL) { - // Check name - std::string name_path = base_path + entry->d_name + "/name"; - - std::ifstream ifs(name_path.c_str(), std::ifstream::in); - if (ifs.good()) { - std::string line; - while (std::getline(ifs, line)) { - if (line == "amdgpu") { - update_path( - base_path + entry->d_name + "/power1_average"); - set_scale(1000); - } - } - ifs.close(); - } - } - closedir(dir); - } -} - -unsigned int cthd_sensor_kbl_g_mcp::read_temperature() -{ - csys_fs sysfs; - std::string buffer; - int gpu_power; - int ret; - - thd_engine->rapl_power_meter.rapl_start_measure_power(); - - ret = sensor_sysfs.read("", &gpu_power); - if (ret <= 0) - gpu_power = 0; - - unsigned int pkg_power = thd_engine->rapl_power_meter.rapl_action_get_power( - PACKAGE); - thd_log_debug("Sensor %s :temp %u %u total %u \n", type_str.c_str(), - gpu_power, pkg_power, gpu_power + pkg_power); - - return (unsigned int)(gpu_power + pkg_power); -} diff --git a/src/thd_sensor_kbl_g_mcp.h b/src/thd_sensor_kbl_g_mcp.h deleted file mode 100644 index 025ab631..00000000 --- a/src/thd_sensor_kbl_g_mcp.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - * thd_sensor_kbl_amdgpu_power.h: Power Sensor for KBL-G amdgpu - * - * Copyright (C) 2018 Intel Corporation. All rights reserved. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License version - * 2 or later as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301, USA. - * - * - * Author Name - * - */ - -#ifndef THD_SENSOR_KBL_G_MCP_H -#define THD_SENSOR_KBL_G_MCP_H - -#include "thd_sensor.h" - -class cthd_sensor_kbl_g_mcp: public cthd_sensor { -private: -public: - cthd_sensor_kbl_g_mcp(int index); - unsigned int read_temperature(); -}; - -#endif diff --git a/src/thd_sensor_virtual.cpp b/src/thd_sensor_virtual.cpp index 4cdd9666..568064a3 100644 --- a/src/thd_sensor_virtual.cpp +++ b/src/thd_sensor_virtual.cpp @@ -26,8 +26,8 @@ cthd_sensor_virtual::cthd_sensor_virtual(int _index, std::string _type_str, std::string _link_type_str, double _multiplier, double _offset) : - cthd_sensor(_index, "none", _type_str), link_sensor(NULL), link_type_str( - _link_type_str), multiplier(_multiplier), offset(_offset) { + cthd_sensor(_index, "none", std::move(_type_str)), link_sensor(NULL), link_type_str( + std::move(_link_type_str)), multiplier(_multiplier), offset(_offset) { virtual_sensor = true; } @@ -59,7 +59,7 @@ unsigned int cthd_sensor_virtual::read_temperature() { int cthd_sensor_virtual::sensor_update_param(std::string new_dep_sensor, double slope, double intercept) { - cthd_sensor *sensor = thd_engine->search_sensor(new_dep_sensor); + cthd_sensor *sensor = thd_engine->search_sensor(std::move(new_dep_sensor)); if (sensor) link_sensor = sensor; diff --git a/src/thd_sys_fs.cpp b/src/thd_sys_fs.cpp index 05df47ab..a45e4b5b 100644 --- a/src/thd_sys_fs.cpp +++ b/src/thd_sys_fs.cpp @@ -71,26 +71,29 @@ int csys_fs::write(const std::string &path, unsigned int data) { } int csys_fs::read(const std::string &path, char *buf, int len) { + if (!buf) + return -EINVAL; + std::string p = base_path + path; int fd = ::open(p.c_str(), O_RDONLY); - int orig_len = len; + size_t curr_len = len; if (fd < 0) { thd_log_info("sysfs read failed %s\n", p.c_str()); return -errno; } - while (len > 0) { - int ret = ::read(fd, buf, len); - if (ret < 0) { + while (curr_len > 0) { + ssize_t ret = ::read(fd, buf, curr_len); + if (ret <= 0 || ret > len || ret >= INT_MAX) { thd_log_info("sysfs read failed %s\n", p.c_str()); close(fd); - return ret; + return -1; } - buf += ret; - len -= ret; + buf += (int) ret; + curr_len -= ret; } close(fd); - return orig_len - len; + return len; } int csys_fs::read(const std::string &path, unsigned int position, char *buf, diff --git a/src/thd_sys_fs.h b/src/thd_sys_fs.h index ce6ce1eb..e090c82e 100644 --- a/src/thd_sys_fs.h +++ b/src/thd_sys_fs.h @@ -74,7 +74,7 @@ class csys_fs { mode_t get_mode(const std::string &path); void update_path(std::string path) { - base_path = path; + base_path = std::move(path); } }; diff --git a/src/thd_trip_point.cpp b/src/thd_trip_point.cpp index 70a272ad..ef77282f 100644 --- a/src/thd_trip_point.cpp +++ b/src/thd_trip_point.cpp @@ -44,7 +44,7 @@ void cthd_trip_point::set_dependency(std::string cdev, std::string state_str) { cthd_cdev *cdev_ptr; - cdev_ptr = thd_engine->search_cdev(cdev); + cdev_ptr = thd_engine->search_cdev(std::move(cdev)); if (cdev_ptr) { int match; int state_index = 0; @@ -142,7 +142,6 @@ bool cthd_trip_point::thd_trip_point_check(int id, unsigned int read_temp, } if (type == CRITICAL) { - int ret = -1; if (!ignore_critical && read_temp >= temp) { thd_log_warn("critical temp reached \n"); @@ -153,15 +152,18 @@ bool cthd_trip_point::thd_trip_point_check(int id, unsigned int read_temp, crit_trip_count = 0; sync(); #ifdef ANDROID + int ret; + ret = property_set("sys.powerctl", "shutdown,thermal"); -#else - reboot(RB_POWER_OFF); -#endif if (ret != 0) thd_log_warn("power off failed ret=%d err=%s\n", ret, strerror(errno)); else thd_log_warn("power off initiated\n"); +#else + thd_log_warn("power off initiated\n"); + reboot(RB_POWER_OFF); +#endif return true; } diff --git a/src/thd_trt_art_reader.h b/src/thd_trt_art_reader.h index c9132b08..a10f08e1 100644 --- a/src/thd_trt_art_reader.h +++ b/src/thd_trt_art_reader.h @@ -48,7 +48,7 @@ struct rel_object_t { rel_object_t(std::string name, int _temperature = 0, int _step = 0) { target_device = name; - target_sensor = name; + target_sensor = std::move(name); temperature = _temperature; step = _step; } diff --git a/src/thd_zone_dynamic.cpp b/src/thd_zone_dynamic.cpp index 01782344..765291ef 100644 --- a/src/thd_zone_dynamic.cpp +++ b/src/thd_zone_dynamic.cpp @@ -27,8 +27,8 @@ cthd_zone_dynamic::cthd_zone_dynamic(int index, std::string _name, unsigned int _trip_temp, trip_point_type_t _trip_type, std::string _sensor, std::string _cdev) : - cthd_zone(index, ""), name(_name), trip_temp(_trip_temp), trip_type(_trip_type), sensor_name( - _sensor), cdev_name(_cdev) { + cthd_zone(index, ""), name(std::move(_name)), trip_temp(_trip_temp), trip_type(_trip_type), sensor_name( + std::move(_sensor)), cdev_name(std::move(_cdev)) { type_str = name; } diff --git a/src/thd_zone_generic.cpp b/src/thd_zone_generic.cpp index 3d60bf7d..c05752a0 100644 --- a/src/thd_zone_generic.cpp +++ b/src/thd_zone_generic.cpp @@ -28,7 +28,7 @@ cthd_zone_generic::cthd_zone_generic(int index, int _config_index, std::string type) : cthd_zone(index, ""), config_index(_config_index) { - type_str = type; + type_str = std::move(type); } diff --git a/src/thd_zone_kbl_amdgpu.cpp b/src/thd_zone_kbl_amdgpu.cpp deleted file mode 100644 index 70459813..00000000 --- a/src/thd_zone_kbl_amdgpu.cpp +++ /dev/null @@ -1,124 +0,0 @@ -/* - * thd_zone_kbl_amdgpu.cpp: thermal zone for KBL-G amdgpu - * - * Copyright (C) 2018 Intel Corporation. All rights reserved. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License version - * 2 or later as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301, USA. - * - * - * Author Name - * - */ - -#include - -#include "thd_engine_default.h" -#include "thd_sys_fs.h" -#include "thd_zone_kbl_amdgpu.h" - -cthd_zone_kbl_amdgpu::cthd_zone_kbl_amdgpu(int index): cthd_zone(index, ""), sensor(NULL), dts_sysfs("/sys/class/hwmon/"){ - type_str = "amdgpu"; -} - -int cthd_zone_kbl_amdgpu::zone_bind_sensors() { - - cthd_sensor *sensor; - - - sensor = thd_engine->search_sensor("amdgpu-temperature"); - if (sensor) { - bind_sensor(sensor); - return THD_SUCCESS; - } - - return THD_ERROR; -} - -int cthd_zone_kbl_amdgpu::read_trip_points() { - cthd_cdev *cdev; - DIR *dir; - - struct dirent *entry; - const std::string base_path = "/sys/class/hwmon/"; - int crit_temp = 0; - - thd_log_info("cthd_zone_kbl_amdgpu::read_trip_points \n"); - - if ((dir = opendir(base_path.c_str())) != NULL) { - while ((entry = readdir(dir)) != NULL) { - // Check name - std::string name_path = base_path + entry->d_name + "/name"; - - std::ifstream ifs(name_path.c_str(), std::ifstream::in); - if (ifs.good()) { - std::string line; - while (std::getline(ifs, line)) { - if (line == "amdgpu") { - std::string path = base_path + entry->d_name + "/"; - csys_fs hwmon_sysfs(path.c_str()); - - if (!hwmon_sysfs.exists("temp1_crit")) { - thd_log_info("path failed %s\n", path.c_str()); - closedir(dir); - return THD_ERROR; - } - int ret = hwmon_sysfs.read("temp1_crit", &crit_temp); - if (ret < 0) { - thd_log_info("crit temp failed\n"); - closedir(dir); - return THD_ERROR; - } - } - } - ifs.close(); - } - } - closedir(dir); - } - - if (!crit_temp) - return THD_ERROR; - - cdev = thd_engine->search_cdev("amdgpu"); - if (!cdev) { - thd_log_info("amdgpu failed\n"); - - return THD_ERROR; - } - - cthd_trip_point trip_pt_passive(0, PASSIVE, crit_temp - 10000, - 0, index, DEFAULT_SENSOR_ID); - - trip_pt_passive.thd_trip_point_add_cdev(*cdev, - cthd_trip_point::default_influence); - - trip_points.push_back(trip_pt_passive); - - cthd_trip_point trip_pt_critical(1, CRITICAL, crit_temp, - 0, index, DEFAULT_SENSOR_ID); - trip_pt_passive.thd_trip_point_add_cdev(*cdev, - cthd_trip_point::default_influence); - - trip_points.push_back(trip_pt_critical); - - thd_log_info("cthd_zone_kbl_amdgpu::read_trip_points OK\n"); - - return THD_SUCCESS; -} - - -int cthd_zone_kbl_amdgpu::read_cdev_trip_points() { - return THD_SUCCESS; -} diff --git a/src/thd_zone_kbl_amdgpu.h b/src/thd_zone_kbl_amdgpu.h deleted file mode 100644 index b2389983..00000000 --- a/src/thd_zone_kbl_amdgpu.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - * thd_zone_kbl_amdgpu.h: thermal zone for KBL-G amdgpu - * - * Copyright (C) 2018 Intel Corporation. All rights reserved. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License version - * 2 or later as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301, USA. - * - * - * Author Name - * - */ - -#ifndef THD_ZONE_KBL_AMD_GPU_H -#define THD_ZONE_KBL_AMD_GPU_H - -#include "thd_zone.h" - -class cthd_zone_kbl_amdgpu: public cthd_zone { -protected: - cthd_sensor *sensor; - csys_fs dts_sysfs; -public: - cthd_zone_kbl_amdgpu(int index); - int read_trip_points(); - int zone_bind_sensors(); - int read_cdev_trip_points(); -}; - -#endif diff --git a/src/thd_zone_kbl_g_mcp.cpp b/src/thd_zone_kbl_g_mcp.cpp deleted file mode 100644 index fcd7f667..00000000 --- a/src/thd_zone_kbl_g_mcp.cpp +++ /dev/null @@ -1,106 +0,0 @@ -/* - * thd_zone_kbl_amdgpu.cpp: thermal zone for KBL-G amdgpu - * - * Copyright (C) 2018 Intel Corporation. All rights reserved. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License version - * 2 or later as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301, USA. - * - * - * Author Name - * - */ - -#include - -#include "thd_engine_default.h" -#include "thd_sys_fs.h" -#include "thd_zone_kbl_g_mcp.h" - -cthd_zone_kbl_g_mcp::cthd_zone_kbl_g_mcp(int index): cthd_zone(index, ""), sensor(NULL), dts_sysfs("/sys/class/hwmon/"){ - type_str = "kbl-g-mcp"; -} - -int cthd_zone_kbl_g_mcp::zone_bind_sensors() { - - cthd_sensor *sensor; - - - sensor = thd_engine->search_sensor("kbl-g-mcp"); - if (sensor) { - bind_sensor(sensor); - return THD_SUCCESS; - } - - return THD_ERROR; -} - -int cthd_zone_kbl_g_mcp::read_trip_points() { - cthd_cdev *cdev_gpu, *cdev_cpu; - - thd_log_info("cthd_zone_kbl_g_mcp::read_trip_points \n"); - - cdev_gpu = thd_engine->search_cdev("amdgpu"); - if (!cdev_gpu) { - thd_log_info("amdgpu failed\n"); - - return THD_ERROR; - } - - int gpu_max_power = cdev_gpu->get_phy_max_state(); - - cdev_cpu = thd_engine->search_cdev("rapl_controller"); - if (!cdev_cpu) { - thd_log_info("rapl_controller, failed\n"); - - return THD_ERROR; - } - - int cpu_max_power = cdev_cpu->get_phy_max_state(); - - thd_log_debug("gpu %d cpu %d\n", gpu_max_power, cpu_max_power); - int total_power = gpu_max_power + cpu_max_power; - - cthd_trip_point trip_pt_passive(0, PASSIVE, total_power , - 0, index, DEFAULT_SENSOR_ID, PARALLEL); - - pid_param_t pid_param; - pid_param.valid = 1; - pid_param.kp = -0.4f; - pid_param.ki = 0.0f; - pid_param.kd = 0.0f; - thd_log_info("==pid valid %f:%f:%f\n", pid_param.kp, pid_param.ki, pid_param.kd); - trip_pt_passive.thd_trip_point_add_cdev(*cdev_gpu, - cthd_trip_point::default_influence, thd_engine->get_poll_interval(), - 0, 0, &pid_param); - - pid_param.kp = -0.6f; - pid_param.ki = 0.0f; - pid_param.kd = 0.0f; - - trip_pt_passive.thd_trip_point_add_cdev(*cdev_cpu, - cthd_trip_point::default_influence, thd_engine->get_poll_interval(), - 0, 0, &pid_param); - - trip_points.push_back(trip_pt_passive); - - thd_log_info("cthd_zone_kbl_g_mcp::read_trip_points OK\n"); - - return THD_SUCCESS; -} - - -int cthd_zone_kbl_g_mcp::read_cdev_trip_points() { - return THD_SUCCESS; -} diff --git a/src/thd_zone_kbl_g_mcp.h b/src/thd_zone_kbl_g_mcp.h deleted file mode 100644 index 66ccfcd1..00000000 --- a/src/thd_zone_kbl_g_mcp.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - * thd_zone_kbl_amdgpu.h: thermal zone for KBL-G amdgpu - * - * Copyright (C) 2018 Intel Corporation. All rights reserved. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License version - * 2 or later as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301, USA. - * - * - * Author Name - * - */ - -#ifndef THD_ZONE_KBL_G_MCP_H -#define THD_ZONE_KBL_G_MCP_H - -#include "thd_zone.h" - -class cthd_zone_kbl_g_mcp: public cthd_zone { -protected: - cthd_sensor *sensor; - csys_fs dts_sysfs; -public: - cthd_zone_kbl_g_mcp(int index); - int read_trip_points(); - int zone_bind_sensors(); - int read_cdev_trip_points(); -}; - -#endif diff --git a/src/thd_zone_therm_sys_fs.cpp b/src/thd_zone_therm_sys_fs.cpp index 2dc8fd99..48be1ed8 100644 --- a/src/thd_zone_therm_sys_fs.cpp +++ b/src/thd_zone_therm_sys_fs.cpp @@ -27,7 +27,7 @@ #include cthd_sysfs_zone::cthd_sysfs_zone(int count, std::string path) : - cthd_zone(count, path), trip_point_cnt(0) { + cthd_zone(count, std::move(path)), trip_point_cnt(0) { std::stringstream tc_type_dev; tc_type_dev << index << "/type"; @@ -50,7 +50,8 @@ cthd_sysfs_zone::~cthd_sysfs_zone() { temp_stream << trip_sysfs.str() << i << "_temp"; if (initial_trip_values[i] >= 0 && zone_sysfs.exists(temp_stream.str())) { - zone_sysfs.write(temp_stream.str(), initial_trip_values[i]); + if (zone_sysfs.write(temp_stream.str(), initial_trip_values[i]) == -1) + thd_log_debug("Tzone_sysfs.write failed for %d\n", initial_trip_values[i]); } } } diff --git a/test/thermald_debug_output_graph.py b/test/thermald_debug_output_graph.py new file mode 100644 index 00000000..db3b7e5f --- /dev/null +++ b/test/thermald_debug_output_graph.py @@ -0,0 +1,258 @@ +# This script will plot temperature and trip graph from the thermald debug output +# Run thermald with loglevel=debug +# For example: +# +# systemctl stop thermald +# thermald --no-daemon --loglevel=debug --adaptive --ignore-cpuid-check +# Run your workload, and when done copy the output dumped on the screen +# to a file. For example if the output file is +# This output file is input to this script "thermald_log.txt" +# Then use: +# python thermald_debug_output_graph.py thermald_log.txt +# +# Prerequisites: +# Python version 3.x or higher +# gnuplot 5.0 or higher +# python3-gnuplot 1.8 or higher +# (Most of the distributions have these required packages. They may be called +# gnuplot-py, python-gnuplot or python3-gnuplot, gnuplot-nox, ... ) +# In case Gnuplot is not present, the script will use pygnuplot. To do so, install +# pygnuplot using pip install pygnuplot. In case can't install with pip, download +# the pygnuplot.py file from https://pypi.org/project/py-gnuplot +# To install use "python3 setup.py install". It may ask for pandas, install it +# using "pip install pandas" or from distro install python3-pandas. + +import sys +import re + +use_pygnuplot = False + +try: + import Gnuplot +except ImportError: + from pygnuplot import gnuplot + use_pygnuplot = True + +sensors = [] +temperature = [[]] +temperature_count = [] +max_range = 0 + +zones = [] +trips = [[]] + +# Parse file for temperature + + +def plot_temperature(): + output_png = "temperature.png" + if use_pygnuplot: + g_plot = gnuplot.Gnuplot() + else: + g_plot = Gnuplot.Gnuplot() + + g_plot('set ylabel "Degree C"') + g_plot('set xlabel "Samples"') + g_plot("set yrange [0:100]") + g_plot("set key autotitle columnhead") + g_plot('set title "Temperature plot"') + g_plot("set term png size 1200, 600") + g_plot('set output "' + output_png + '"') + print("Ploting using gnuplot, the output file name is : ", output_png) +# g_plot('plot "' + output_png + '" using 1:(column(n)) w lines title columnhead(n), for [n=2:50] "trips.csv" using 1:(column(n)) w dots title # columnhead(n)') + g_plot( + 'plot for [n=2:12] "temperature.csv" u 1:(column(n)) w lines title columnhead(n), for [n=2:50] "trips.csv" u 1:(column(n)) w dots title columnhead(n)' + ) + + +def parse_trips(log_file): + print("parsing trips from", log_file) + log_fd = open(log_file, "r") + data = log_fd.readlines() + match_index = 0 + line_index = 0 + for line in data: + x = re.search("ZONE DUMP BEGIN", line) + if x: + match_index = line_index + line_index = line_index + 1 + + for x in range(match_index, line_index): + s = re.search("Zone.*:", data[x]) + if s: + tokens = data[x].split() + zone = tokens[2].split(",") + zones.append(zone[0]) + + y = re.search("ZONE DUMP END", data[x]) + if y: + break + + index = 0 + trips.append([]) + # 3 for point to 3rd line starting from "ZONE DUMP BEGIN" + for x in range(match_index + 3, line_index): + s = re.search("passive temp:*", data[x]) + if s: + tokens = data[x].split() + trip = tokens[3].split(":") + str1 = str(int(trip[1]) / 1000) + trips[index].append(str1) + + z = re.search("Zone.*:", data[x]) + if z: + index = index + 1 + trips.append([]) + + y = re.search("ZONE DUMP END", data[x]) + if y: + break + + max_index = index + + f_handle = open("trips.csv", "w") + + string_buffer = "index, " + + for x in range(len(zones)): + id = 0 + for y in range(len(trips[x])): + string_buffer += zones[x] + string_buffer += "_trip_0" + string_buffer += str(id) + if x != (len(zones) - 1) and y != (len(trips) - 1): + string_buffer += ", " + id = id + 1 + + string_buffer += "\n" + f_handle.write(string_buffer) + + string_buffer = "0," + + for i in range(max_range): + string_buffer = str(i) + string_buffer += ", " + for x in range(len(zones)): + for y in range(len(trips[x])): + string_buffer += trips[x][y] + if x != (len(zones) - 1) and y != (len(trips) - 1): + string_buffer += ", " + + string_buffer += "\n" + f_handle.write(string_buffer) + + f_handle.close() + + f_handle.close() + + +def parse_temperature(log_file): + # Parse file for temperature + global max_range + + print("parsing temperature from", log_file) + + sensors.append("PL1") + temperature_count.append(0) + temp = [] + temperature.append(temp) + + log_fd = open(log_file, "r") + data = log_fd.readlines() + next_line = 0 + for line in data: + next_line = next_line + 1 + x = re.search(".*wr:", line) + if x: + tokens = line.split() + tokens = tokens[7].split(":") + str1 = tokens[1] + val = int(str1) + val = val / 1000000 + if (val > 100): + continue; + str1 = str(val) + temperature[0].append(str1) + temperature_count[0] = temperature_count[0] + 1 + if max_range < temperature_count[0]: + max_range = temperature_count[0] + + x = re.search("Sensor.*:temp", line) + if not x: + x = re.search("Sensor.*:power", line) + + if x: + if "compare" in data[next_line]: + continue + tokens = line.split() + skip = 0 + i = 0 + for sensor in sensors: + if sensor == tokens[1]: + skip = 1 + break + i = i + 1 + if skip == 0: + sensors.append(tokens[1]) + temperature_count.append(0) + temp = [] + temperature.append(temp) + + str1 = str(int(tokens[3]) / 1000) + + temperature[i].append(str1) + + temperature_count[i] = temperature_count[i] + 1 + if max_range < temperature_count[i]: + max_range = temperature_count[i] + + f_handle = open("temperature.csv", "w") + + last_val= [] + string_buffer = "index, " + for x in range(len(sensors)): + last_val.append(0) + if x == len(sensors) - 1: + string_buffer += sensors[x] + else: + string_buffer += sensors[x] + ", " + + string_buffer += "\n" + f_handle.write(string_buffer) + + index = 0 + for y in range(max_range): + string_buffer = str(index) + ", " + index = index + 1 + for x in range(len(sensors)): + if y < temperature_count[x]: + last_val[x] = temperature[x][y] + if x == len(sensors) - 1: + string_buffer += temperature[x][y] + else: + string_buffer += temperature[x][y] + ", " + + else: + string_buffer += last_val[x] + ", " + + string_buffer += "\n" + f_handle.write(string_buffer) + + f_handle.close() + + log_fd.close() + + +# Main entry point +# Get the debug file name from command line +print("Number of arguments:", len(sys.argv), "arguments.") +print("Argument List:", str(sys.argv)) + +if len(sys.argv) < 2: + print("Error: Need the logfile as argument") + sys.exit() + +# Parse temperature +parse_temperature(str(sys.argv[1])) +parse_trips(str(sys.argv[1])) +plot_temperature()