diff -Nru thermald-1.7.0/debian/changelog thermald-1.7.0/debian/changelog --- thermald-1.7.0/debian/changelog 2018-04-20 01:08:23.000000000 +0000 +++ thermald-1.7.0/debian/changelog 2019-01-14 23:29:41.000000000 +0000 @@ -1,3 +1,19 @@ +thermald (1.7.0-5ubuntu2) bionic; urgency=medium + + * Honor ACPI _CRT for processor thermal zone (LP: #1803360) + There are some new fanless platforms use DPTF's virtual sensor + instead of INT340X devices. Because of that, the _PSV is no + longer in use, at least not directly, hence its value may set + higher then _CRT. To a fanless system that means no cooling + device gets activated before _CRT, so the system will be + considered overheated by Linux kernel, and gets shutdown by the + kernel. Upstream fixes: + - 7af3eef07dc7 Ignore _TRT and B0D4 device if passive 1 UUID not present + (prerequisite) + - 97976782dd26 Honor ACPI _CRT for processor thermal zone + + -- Colin King Mon, 14 Jan 2019 23:29:41 +0000 + thermald (1.7.0-5ubuntu1) bionic; urgency=medium [ Ben Caradoc-Davies ] diff -Nru thermald-1.7.0/debian/patches/0007-Ignore-_TRT-and-B0D4-device-if-passive-1-UUID-not-pr.patch thermald-1.7.0/debian/patches/0007-Ignore-_TRT-and-B0D4-device-if-passive-1-UUID-not-pr.patch --- thermald-1.7.0/debian/patches/0007-Ignore-_TRT-and-B0D4-device-if-passive-1-UUID-not-pr.patch 1970-01-01 00:00:00.000000000 +0000 +++ thermald-1.7.0/debian/patches/0007-Ignore-_TRT-and-B0D4-device-if-passive-1-UUID-not-pr.patch 2019-01-14 23:29:41.000000000 +0000 @@ -0,0 +1,251 @@ +From 7af3eef07dc7a4e74c0c6e1ffdcbb36b427a1572 Mon Sep 17 00:00:00 2001 +From: Srinivas Pandruvada +Date: Thu, 24 May 2018 14:49:29 -0700 +Subject: [PATCH] Ignore _TRT and B0D4 device if passive 1 UUID not present +Content-Type: text/plain; charset="utf-8" +Content-Transfer-Encoding: 8bit + +There are some laptops which are not tested with passive 1 table +(_TRT) and have bad thermal passive trip point in dependent +B0D4 processor cooling device. For example "HP Spectre Laptop - 13". + +This causes thermald to throttle agressively using bad data, so +use these table and passive 1 trip for B0D4, if INT3400 +/sys/bus/acpi/devices/INT3400:00/physical_node/uuids/available_uuids +explicitly indicate support of passive 1 UUID. +--- + Android.mk | 3 +- + Makefile.am | 3 +- + src/thd_engine.cpp | 5 ++++ + src/thd_engine_default.cpp | 9 +++++- + src/thd_int3400.cpp | 58 ++++++++++++++++++++++++++++++++++++++ + src/thd_int3400.h | 38 +++++++++++++++++++++++++ + src/thd_trt_art_reader.cpp | 8 ++++++ + 7 files changed, 121 insertions(+), 3 deletions(-) + create mode 100644 src/thd_int3400.cpp + create mode 100644 src/thd_int3400.h + +diff --git a/Android.mk b/Android.mk +index 8193c3a..44dde2c 100644 +--- a/Android.mk ++++ b/Android.mk +@@ -32,7 +32,8 @@ LOCAL_SRC_FILES := \ + src/thd_trt_art_reader.cpp \ + src/thd_cdev_rapl_dram.cpp \ + src/thd_cpu_default_binding.cpp \ +- src/thd_cdev_backlight.cpp ++ src/thd_cdev_backlight.cpp \ ++ src/thd_int3400.cpp + + LOCAL_C_INCLUDES += external/libxml2/include + +diff --git a/Makefile.am b/Makefile.am +index 68c89d0..4758a37 100644 +--- a/Makefile.am ++++ b/Makefile.am +@@ -81,7 +81,8 @@ thermald_SOURCES = \ + src/thd_cdev_rapl_dram.cpp \ + src/thd_cpu_default_binding.cpp \ + src/thd_cdev_backlight.cpp \ +- src/thd_cdev_modem.cpp ++ src/thd_cdev_modem.cpp \ ++ src/thd_int3400.cpp + + man5_MANS = man/thermal-conf.xml.5 + man8_MANS = man/thermald.8 +diff --git a/src/thd_engine.cpp b/src/thd_engine.cpp +index deedb61..11712b6 100644 +--- a/src/thd_engine.cpp ++++ b/src/thd_engine.cpp +@@ -42,6 +42,7 @@ + #include "thd_zone_therm_sys_fs.h" + #include "thd_zone_dynamic.h" + #include "thd_cdev_gen_sysfs.h" ++#include "thd_int3400.h" + + static void *cthd_engine_thread(void *arg); + +@@ -501,8 +502,12 @@ void cthd_engine::takeover_thermal_control() { + DIR *dir; + struct dirent *entry; + const std::string base_path = "/sys/class/thermal/"; ++ cthd_INT3400 int3400; + + thd_log_info("Taking over thermal control \n"); ++ ++ int3400.set_default_uuid(); ++ + if ((dir = opendir(base_path.c_str())) != NULL) { + while ((entry = readdir(dir)) != NULL) { + if (!strncmp(entry->d_name, "thermal_zone", +diff --git a/src/thd_engine_default.cpp b/src/thd_engine_default.cpp +index 6fe6667..51dbbba 100644 +--- a/src/thd_engine_default.cpp ++++ b/src/thd_engine_default.cpp +@@ -36,6 +36,7 @@ + #include "thd_cdev_rapl_dram.h" + #include "thd_sensor_virtual.h" + #include "thd_cdev_backlight.h" ++#include "thd_int3400.h" + + #ifdef GLIB_SUPPORT + #include "thd_cdev_modem.h" +@@ -221,7 +222,13 @@ bool cthd_engine_default::add_int340x_processor_dev(void) + return false; + + /* Specialized processor thermal device names */ +- cthd_zone *processor_thermal = search_zone("B0D4"); ++ cthd_zone *processor_thermal = NULL; ++ cthd_INT3400 int3400; ++ ++ if (int3400.match_supported_uuid() == THD_SUCCESS) { ++ processor_thermal = search_zone("B0D4"); ++ } ++ + if (!processor_thermal) + processor_thermal = search_zone("B0DB"); + if (!processor_thermal) +diff --git a/src/thd_int3400.cpp b/src/thd_int3400.cpp +new file mode 100644 +index 0000000..cb7fb1d +--- /dev/null ++++ b/src/thd_int3400.cpp +@@ -0,0 +1,58 @@ ++/* ++ * thd_int3400.cpp: Load and check INT3400 uuids for match ++ * ++ * 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 "thd_int3400.h" ++#include ++#include ++#include ++#include ++ ++int cthd_INT3400::match_supported_uuid(void) { ++ std::string filename = ++ "/sys/bus/acpi/devices/INT3400:00/physical_node/uuids/available_uuids"; ++ ++ std::ifstream ifs(filename.c_str(), std::ifstream::in); ++ if (ifs.good()) { ++ std::string line; ++ while (std::getline(ifs, line)) { ++ thd_log_debug("uuid: %s\n", line.c_str()); ++ if (line == "42A441D6-AE6A-462b-A84B-4A8CE79027D3") ++ return THD_SUCCESS; ++ } ++ ifs.close(); ++ } ++ ++ return THD_ERROR; ++} ++ ++void cthd_INT3400::set_default_uuid(void) { ++ std::string filename = ++ "/sys/bus/acpi/devices/INT3400:00/physical_node/uuids/current_uuid"; ++ ++ std::ofstream ofs(filename.c_str(), std::ofstream::out); ++ if (ofs.good()) { ++ thd_log_info("Set Default UUID: 42A441D6-AE6A-462b-A84B-4A8CE79027D3\n"); ++ ofs << "42A441D6-AE6A-462b-A84B-4A8CE79027D3"; ++ } ++} +diff --git a/src/thd_int3400.h b/src/thd_int3400.h +new file mode 100644 +index 0000000..a3fc957 +--- /dev/null ++++ b/src/thd_int3400.h +@@ -0,0 +1,38 @@ ++/* ++ * thd_int3400.h: Load and check INT3400 uuids for match ++ * ++ * 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_INT3400_UUID_H_ ++#define SRC_THD_INT3400_UUID_H_ ++ ++#include "thd_common.h" ++#include ++#include ++ ++class cthd_INT3400 { ++public: ++ int match_supported_uuid(void); ++ void set_default_uuid(void); ++}; ++ ++#endif /* SRC_THD_INT3400_UUID_H_ */ +diff --git a/src/thd_trt_art_reader.cpp b/src/thd_trt_art_reader.cpp +index 55be927..2ea8719 100644 +--- a/src/thd_trt_art_reader.cpp ++++ b/src/thd_trt_art_reader.cpp +@@ -27,6 +27,7 @@ + + #include "thd_trt_art_reader.h" + #include "acpi_thermal_rel_ioct.h" ++#include "thd_int3400.h" + + using namespace std; + +@@ -147,6 +148,7 @@ int cthd_acpi_rel::generate_conf(std::string file_name) { + string prefix; + int art_status; + int ret = 0; ++ cthd_INT3400 int3400; + + std::ifstream conf_file_check(file_name.c_str()); + if (conf_file_check.is_open()) { +@@ -163,6 +165,12 @@ int cthd_acpi_rel::generate_conf(std::string file_name) { + PRINT_ERROR("TRT/ART read failed\n"); + return -1; + } ++ ++ if (int3400.match_supported_uuid() != THD_SUCCESS) { ++ thd_log_info("Passive 1 UUID is not present, hence ignore _TRT, as it may have junk!!"); ++ return -1; ++ } ++ + conf_file.open(file_name.c_str()); + if (!conf_file.is_open()) { + PRINT_ERROR("failed to open output file [%s]\n", file_name.c_str()); +-- +2.19.1 + diff -Nru thermald-1.7.0/debian/patches/0008-Honor-ACPI-_CRT-for-processor-thermal-zone.patch thermald-1.7.0/debian/patches/0008-Honor-ACPI-_CRT-for-processor-thermal-zone.patch --- thermald-1.7.0/debian/patches/0008-Honor-ACPI-_CRT-for-processor-thermal-zone.patch 1970-01-01 00:00:00.000000000 +0000 +++ thermald-1.7.0/debian/patches/0008-Honor-ACPI-_CRT-for-processor-thermal-zone.patch 2019-01-14 23:29:41.000000000 +0000 @@ -0,0 +1,66 @@ +From 97976782dd26b4d592ccb97eb89c2a3a871a22a9 Mon Sep 17 00:00:00 2001 +From: Kai-Heng Feng +Date: Mon, 29 Oct 2018 15:23:54 +0800 +Subject: [PATCH] Honor ACPI _CRT for processor thermal zone +Content-Type: text/plain; charset="utf-8" +Content-Transfer-Encoding: 8bit + +There are some new fanless platforms use DPTF's virtual sensor instead +of INT340X devices. + +Because of that, the _PSV is no longer in use, at least not directly, +hence its value may set higher then _CRT. To a fanless system that means +no cooling device gets activated before _CRT, so the system will be +considered overheated by Linux kernel, and gets shutdown by the kernel. + +To avoid that, we use _CRT - 15C as our new _PSV value. +A 15C margin below _CRT should be enough for passive cooling devices to +clamp the temperature down. + +This is a compromise, but we need this until we have full DPTF support. +--- + src/thd_engine_default.cpp | 23 +++++++++++++++++++++-- + 1 file changed, 21 insertions(+), 2 deletions(-) + +Index: thermald-1.7.0/src/thd_engine_default.cpp +=================================================================== +--- thermald-1.7.0.orig/src/thd_engine_default.cpp ++++ thermald-1.7.0/src/thd_engine_default.cpp +@@ -222,8 +222,9 @@ bool cthd_engine_default::add_int340x_pr + return false; + + /* Specialized processor thermal device names */ +- cthd_zone *processor_thermal = NULL; ++ cthd_zone *processor_thermal = NULL, *acpi_thermal = NULL; + cthd_INT3400 int3400; ++ unsigned int passive, new_passive = 0, critical = 0; + + if (int3400.match_supported_uuid() == THD_SUCCESS) { + processor_thermal = search_zone("B0D4"); +@@ -239,7 +240,25 @@ bool cthd_engine_default::add_int340x_pr + for (unsigned int i = 0; i < processor_thermal->get_trip_count(); ++i) { + cthd_trip_point *trip = processor_thermal->get_trip_at_index(i); + if (trip && trip->get_trip_type() == PASSIVE +- && trip->get_trip_temp()) { ++ && (passive = trip->get_trip_temp())) { ++ ++ /* Need to honor ACPI _CRT, otherwise the system could be shut down by Linux kernel */ ++ acpi_thermal = search_zone("acpitz"); ++ if (acpi_thermal) { ++ for (unsigned int i = 0; i < acpi_thermal->get_trip_count(); ++i) { ++ cthd_trip_point *crit = acpi_thermal->get_trip_at_index(i); ++ if (crit && crit->get_trip_type() == CRITICAL) { ++ critical = crit->get_trip_temp(); ++ break; ++ } ++ } ++ } ++ ++ if (critical && passive + 5 * 1000 >= critical) { ++ new_passive = critical - 15 * 1000; ++ if (new_passive < critical) ++ trip->thd_trip_update_set_point(new_passive); ++ } + + thd_log_info("Processor thermal device is present \n"); + thd_log_info("It will act as CPU thermal zone !! \n"); diff -Nru thermald-1.7.0/debian/patches/series thermald-1.7.0/debian/patches/series --- thermald-1.7.0/debian/patches/series 2018-04-20 01:08:23.000000000 +0000 +++ thermald-1.7.0/debian/patches/series 2019-01-14 23:29:41.000000000 +0000 @@ -1,3 +1,5 @@ 0001-Remove-upstart-support.patch 0002-Don-t-keep-on-reading-a-sensor-if-the-temperature-is.patch 0003-thermald-fix-uninitialised-member.patch +0007-Ignore-_TRT-and-B0D4-device-if-passive-1-UUID-not-pr.patch +0008-Honor-ACPI-_CRT-for-processor-thermal-zone.patch