Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@ Checks: '
-bugprone-assignment-in-if-condition,
-bugprone-branch-clone,
-bugprone-casting-through-void,
-bugprone-derived-method-shadowing-base-method,
-bugprone-easily-swappable-parameters,
-bugprone-implicit-widening-of-multiplication-result,
-bugprone-invalid-enum-default-initialization,
-bugprone-macro-parentheses,
-bugprone-multi-level-implicit-pointer-conversion,
-bugprone-narrowing-conversions,
-bugprone-reserved-identifier,
-bugprone-throwing-static-initialization,
-bugprone-unchecked-string-to-number-conversion,
clang-analyzer-*,
-clang-analyzer-optin.core.EnumCastOutOfRange,
-clang-analyzer-optin.cplusplus.VirtualCall,
Expand Down
5 changes: 3 additions & 2 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ thermald_SOURCES = \
src/thd_platform.cpp \
src/thd_platform_intel.cpp \
src/thd_platform_arm.cpp \
src/thd_util.cpp
src/thd_util.cpp \
src/thd_features_parse.cpp

man5_MANS = man/thermal-conf.xml.5
man8_MANS = man/thermald.8
Expand All @@ -90,7 +91,7 @@ thermald-resource.c: $(top_srcdir)/thermald-resource.gresource.xml
CLEANFILES = $(BUILT_SOURCES)

clang-tidy:
clang-tidy -extra-arg-before=-xc++ \
clang-tidy -extra-arg-before=-xc++ -header-filter= \
$(filter-out src/7zTypes.h src/LzmaDec.h,$(wildcard src/*.h)) \
$(filter-out src/LzmaDec.c thermald-resource.c,$(thermald_SOURCES)) \
-- $(filter-out -Wclobbered,$(AM_CXXFLAGS)) \
Expand Down
3 changes: 2 additions & 1 deletion data/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ dbusservice_DATA = org.freedesktop.thermald.conf

tdconfigdir = $(tdconfdir)
tdconfig_DATA = \
thermal-cpu-cdev-order.xml
thermal-cpu-cdev-order.xml \
thermald-features.xml

EXTRA_DIST = \
thermald.service.in \
Expand Down
11 changes: 11 additions & 0 deletions data/thermald-features.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!--
Enable/disable some features
-->

<ThermaldFeatures>
<DbusControl> 0 </DbusControl>
<XMLThermalConfig> 1 </XMLThermalConfig>
<DataVaultFromFileSystem> 1 </DataVaultFromFileSystem>
<KobjectUeventSupport> 1 </KobjectUeventSupport>
</ThermaldFeatures>

2 changes: 1 addition & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ void clean_up_lockfile(void) {

bool check_thermald_running() {

lock_file_handle = open(lock_file, O_RDWR | O_CREAT, 0600);
lock_file_handle = open(lock_file, O_RDWR | O_CREAT | O_NOFOLLOW, 0600);
if (lock_file_handle == -1) {
/* Couldn't open lock file */
thd_log_error("Could not open PID lock file %s, exiting\n", lock_file);
Expand Down
12 changes: 11 additions & 1 deletion src/thd_dbus_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ gboolean thd_dbus_interface_get_current_preference(PrefObject *obj,
thd_log_debug("thd_dbus_interface_get_current_preference\n");
g_assert(obj != nullptr);
gchar *value_out;
static char *pref_str;
char *pref_str;

pref_str = g_new(char, MAX_DBUS_REPLY_STR_LEN);

Expand Down Expand Up @@ -622,6 +622,16 @@ thd_dbus_handle_method_call(GDBusConnection *connection,

thd_log_debug("Dbus method called %s %s.\n", interface_name, method_name);

if (thd_engine->check_feature(DBUS_CONTROL) == 0) {
thd_log_info("Dbus control support is disabled by config file\n");
GError *error = g_error_new(G_DBUS_ERROR,
G_DBUS_ERROR_FAILED,
"DBUS control support is disabled by config file");
g_dbus_method_invocation_return_gerror(invocation, error);
g_error_free(error);
return;
}

if (g_strcmp0(method_name, "AddCoolingDevice") == 0) {
g_autofree gchar *cdev_name = nullptr;
g_autofree gchar *path = nullptr;
Expand Down
27 changes: 27 additions & 0 deletions src/thd_engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,23 @@ void cthd_engine::enable_power_floor_event()
++current_zone_index;
}

void cthd_engine::thd_parse_features()
{
features_parser.parser_init();
if (features_parser.start_parse() == THD_SUCCESS) {
thd_log_debug("Parsed features from XML config file\n");
int ret = features_parser.start_parse();
if (ret == THD_SUCCESS) {
thd_log_debug("Features parsed successfully from XML config file\n");
} else {
thd_log_debug("Failed to parse features from XML config file\n");
}
features_parser.parser_deinit();
} else {
thd_log_debug("No features parsed from XML config file\n");
}
}

int cthd_engine::thd_engine_init(bool ignore_cpuid_check, bool adaptive) {
int ret;

Expand Down Expand Up @@ -348,6 +365,11 @@ int cthd_engine::thd_engine_start() {
thd_log_info("Proceed without polling mode!\n");
}

if (check_feature(KOBJECT_UEVENT_SUPPORT) == 0) {
thd_log_info("Kobject uevent support is disabled by config file\n");
goto skip_kobj;
}

uevent_fd = poll_fd_cnt;
poll_fds[uevent_fd].fd = kobj_uevent.kobj_uevent_open();
if (poll_fds[uevent_fd].fd < 0) {
Expand Down Expand Up @@ -1235,6 +1257,11 @@ int cthd_engine::user_add_cdev(std::string cdev_name, std::string cdev_path,
}

int cthd_engine::parser_init() {
if (check_feature(XML_THERMAL_CONFIG) == 0) {
thd_log_info("Parser is disabled by config file\n");
parser_disabled = true;
}

if (parser_disabled)
return THD_ERROR;
if (parser_init_done)
Expand Down
11 changes: 11 additions & 0 deletions src/thd_engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include "thd_parse.h"
#include "thd_kobj_uevent.h"
#include "thd_rapl_power_meter.h"
#include "thd_features_parse.h"

#define MAX_MSG_SIZE 512
#define THD_NUM_OF_POLL_FDS 10
Expand Down Expand Up @@ -133,6 +134,8 @@ class cthd_engine {
static constexpr int soft_cdev_start_index = 100;

cthd_parse parser;
cthd_features_parse features_parser;

cthd_rapl_power_meter rapl_power_meter;

cthd_engine(std::string _uuid);
Expand All @@ -146,6 +149,7 @@ class cthd_engine {
void thd_engine_thread();
virtual int thd_engine_init(bool ignore_cpuid_check, bool adaptive = false);
virtual int thd_engine_start();
void thd_parse_features();
int thd_engine_stop();
int check_cpu_id();

Expand Down Expand Up @@ -296,6 +300,13 @@ class cthd_engine {
int parser_init();
void parser_deinit();
int debug_mode_on(void);

int check_feature(thermald_feature_names_t feature) {
if (feature >= MAX_FEATURE) {
return THD_ERROR;
}
return features_parser.feature_list[feature];
}
};

#endif /* THD_ENGINE_H_ */
19 changes: 13 additions & 6 deletions src/thd_engine_adaptive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ int cthd_engine_adaptive::install_passive(struct psv *psv) {
else
psv_zone = psv->target.substr(pos + 1);

while (psv_zone.back() == '_') {
while (!psv_zone.empty() && psv_zone.back() == '_') {
psv_zone.pop_back();
}

Expand Down Expand Up @@ -72,7 +72,7 @@ int cthd_engine_adaptive::install_passive(struct psv *psv) {
else
psv_cdev = psv->source.substr(pos + 1);

while (psv_cdev.back() == '_') {
while (!psv_cdev.empty() && psv_cdev.back() == '_') {
psv_cdev.pop_back();
}

Expand Down Expand Up @@ -136,7 +136,7 @@ void cthd_engine_adaptive::set_trip(const std::string& target, const std::string
else
psv_zone = target.substr(pos + 1);

while (psv_zone.back() == '_') {
while (!psv_zone.empty() && psv_zone.back() == '_') {
psv_zone.pop_back();
}

Expand Down Expand Up @@ -257,7 +257,7 @@ int cthd_engine_adaptive::install_itmt(struct itmt_entry *itmt_entry) {
else
itmt_zone = itmt_entry->target.substr(pos + 1);

while (itmt_zone.back() == '_') {
while (!itmt_zone.empty() && itmt_zone.back() == '_') {
itmt_zone.pop_back();
}

Expand Down Expand Up @@ -443,7 +443,10 @@ void cthd_engine_adaptive::set_int3400_target(struct adaptive_target &target) {
thd_log_warn("Adaptive policy couldn't create any zones\n");
thd_log_warn("Possibly some sensors in the PSVT are missing\n");
thd_log_warn("Restart in non adaptive mode via systemd\n");
csys_fs sysfs("/tmp/ignore_adaptive");

std::ostringstream filename;
filename << TDRUNDIR << "/" << "ignore_adaptive";
csys_fs sysfs(filename.str().c_str());
sysfs.create();
exit(EXIT_FAILURE);
}
Expand Down Expand Up @@ -625,6 +628,8 @@ int cthd_engine_adaptive::thd_engine_init(bool ignore_cpuid_check,
size_t size;
int res;

thd_parse_features();

parser_disabled = true;
force_mmio_rapl = true;

Expand All @@ -637,7 +642,9 @@ int cthd_engine_adaptive::thd_engine_init(bool ignore_cpuid_check,
}
}

csys_fs _sysfs("/tmp/ignore_adaptive");
std::ostringstream filename;
filename << TDRUNDIR << "/" << "ignore_adaptive";
csys_fs _sysfs(filename.str().c_str());
if (_sysfs.exists()) {
return THD_ERROR;
}
Expand Down
3 changes: 3 additions & 0 deletions src/thd_engine_default.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -815,13 +815,16 @@ std::unique_ptr<cthd_engine> thd_engine;
int thd_engine_create_default_engine(bool ignore_cpuid_check,
bool exclusive_control, const char *conf_file) {
int res;

thd_engine.reset(new cthd_engine_default());
if (!thd_engine)
return THD_ERROR;

if (exclusive_control)
thd_engine->set_control_mode(EXCLUSIVE);

thd_engine->thd_parse_features();

// Initialize thermald objects
thd_engine->set_poll_interval(thd_poll_interval);
if (conf_file)
Expand Down
Loading
Loading