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
This commit is contained in:
Bastien Nocera 2021-08-23 12:40:31 +02:00
parent 06af2327e4
commit b02b1396c5
2 changed files with 38 additions and 0 deletions

View file

@ -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;
}

View file

@ -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);