From b02b1396c5e9033203bf242c022092e432f91e37 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Mon, 23 Aug 2021 12:40:31 +0200 Subject: [PATCH] utils: Add "tainting" detection Throw a warning if custom fan curves are used on Asus systems as those could potentially be setup in such a way as to not match intended workloads, eg. it could make the performance profile have very little cooling and throttling in a way that would be expected of a "quiet" platform_profile. See https://patchwork.kernel.org/project/platform-driver-x86/patch/20210820095726.14131-2-luke@ljones.dev/#24397127 --- src/ppd-utils.c | 35 +++++++++++++++++++++++++++++++++++ src/ppd-utils.h | 3 +++ 2 files changed, 38 insertions(+) diff --git a/src/ppd-utils.c b/src/ppd-utils.c index 553a1e0..ac8c7d9 100644 --- a/src/ppd-utils.c +++ b/src/ppd-utils.c @@ -115,3 +115,38 @@ ppd_utils_find_device (const char *subsystem, return ret; } + +/* Custom fan curves used in asus-wmi module */ +#define ENABLED_FAN_CURVE_PROFILES "/sys/devices/platform/asus-nb-wmi/enabled_fan_curve_profiles" + +gboolean +ppd_utils_can_taint (void) +{ + g_autofree char *fan_curves_file = NULL; + gboolean ret; + + fan_curves_file = ppd_utils_get_sysfs_path (ENABLED_FAN_CURVE_PROFILES); + ret = g_file_test (fan_curves_file, G_FILE_TEST_IS_REGULAR); + g_debug ("%s %s: %s taint", ret ? "Detected" : "Didn't detect", + ENABLED_FAN_CURVE_PROFILES, ret ? "can" : "cannot"); + return ret; +} + +gboolean +ppd_utils_try_taint (void) +{ + g_autofree char *fan_curves_file = NULL; + g_autofree char *contents = NULL; + g_autoptr(GError) error = NULL; + + fan_curves_file = ppd_utils_get_sysfs_path (ENABLED_FAN_CURVE_PROFILES); + if (g_file_get_contents (fan_curves_file, &contents, NULL, &error)) { + if (g_strcmp0 (g_strchomp (contents), "") != 0) { + g_warning ("Custom fan curves are in use, please revert to defaults before reporting any problems"); + return TRUE; + } + } else { + g_debug ("Failed to open %s: %s", ENABLED_FAN_CURVE_PROFILES, error->message); + } + return FALSE; +} diff --git a/src/ppd-utils.h b/src/ppd-utils.h index 9b12e5b..3e32fc3 100644 --- a/src/ppd-utils.h +++ b/src/ppd-utils.h @@ -26,3 +26,6 @@ GFileMonitor *ppd_utils_monitor_sysfs_attr (GUdevDevice *device, GUdevDevice *ppd_utils_find_device (const char *subsystem, GCompareFunc func, gpointer user_data); + +gboolean ppd_utils_can_taint (void); +gboolean ppd_utils_try_taint (void);