From d6be3a95b8f22856266457ed7902c4f33f0f7d12 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Fri, 19 Mar 2021 13:52:12 +0100 Subject: [PATCH] platform-profile: Work-around dytc_lapmode behaviour The dytc_lapmode behaviour is pretty wonky. Instead of behaving like a proximity sensor, it tells us whether it's actively changing the performance profile, so it gets reset when something, whether the user or more likely the daemon, changes the profile to balanced. Work-around this by not changing the kernel platform_profile when the performance mode gets inhibited, but advertise it as "balanced" to end-users. The profile will get reset to "performance" when the inhibition finishes, but only for hardware that uses the dytc_lapmode. Whether or not this behaviour needs to apply to all drivers will need design discussions. --- src/ppd-driver-platform-profile.c | 14 ++++++++++++++ tests/integration-test | 13 ++++++++----- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/src/ppd-driver-platform-profile.c b/src/ppd-driver-platform-profile.c index 9e20ee8..3fc50fb 100644 --- a/src/ppd-driver-platform-profile.c +++ b/src/ppd-driver-platform-profile.c @@ -161,6 +161,11 @@ update_dytc_lapmode_state (PpdDriverPlatformProfile *self) g_object_set (G_OBJECT (self), "performance-inhibited", self->lapmode ? "lap-detected" : NULL, NULL); + if (!self->lapmode) { + /* And at the end of the inhibition, tell the core that + * we've changed back to performance */ + ppd_driver_emit_profile_changed (PPD_DRIVER (self), self->acpi_platform_profile); + } } static void @@ -216,6 +221,15 @@ ppd_driver_platform_profile_activate_profile (PpdDriver *drive g_return_val_if_fail (self->acpi_platform_profile_mon, FALSE); + if (reason == PPD_PROFILE_ACTIVATION_REASON_INHIBITION) { + g_return_val_if_fail (profile == PPD_PROFILE_BALANCED, FALSE); + if (self->lapmode_mon && + self->acpi_platform_profile == PPD_PROFILE_PERFORMANCE) { + g_debug ("Keeping performance profile set internally or dytc_lapmode would break"); + return TRUE; + } + } + if (self->acpi_platform_profile == profile) { g_debug ("Can't switch to %s mode, already there", ppd_profile_to_str (profile)); diff --git a/tests/integration-test b/tests/integration-test index 3e531ed..f7e0b01 100755 --- a/tests/integration-test +++ b/tests/integration-test @@ -415,11 +415,14 @@ class Tests(dbusmock.DBusTestCase): self.assertEqual(profiles[2]['Driver'], 'platform_profile') self.assertEqual(profiles[2]['Profile'], 'performance') self.assertEqual(self.get_dbus_property('ActiveProfile'), 'performance') + self.assertEqual(self.read_sysfs_file("sys/firmware/acpi/platform_profile"), b'performance') # lapmode detected, but performance wasn't selected anyway self.testbed.set_attribute(self.tp_acpi, 'dytc_lapmode', '1\n') self.assertEventually(lambda: self.get_dbus_property('PerformanceInhibited') == 'lap-detected') self.assertEqual(self.get_dbus_property('ActiveProfile'), 'balanced') + # Internal profile didn't change + self.assertEqual(self.read_sysfs_file("sys/firmware/acpi/platform_profile"), b'performance') # Reset lapmode self.testbed.set_attribute(self.tp_acpi, 'dytc_lapmode', '0\n') @@ -432,15 +435,15 @@ class Tests(dbusmock.DBusTestCase): # And turn on lapmode self.testbed.set_attribute(self.tp_acpi, 'dytc_lapmode', '1\n') - self.assertEventually(lambda: self.read_sysfs_file("sys/firmware/acpi/platform_profile") == b'balanced') - - self.assertEqual(self.get_dbus_property('ActiveProfile'), 'balanced') + self.assertEventually(lambda: self.get_dbus_property('ActiveProfile') == 'balanced') self.assertEqual(self.get_dbus_property('PerformanceInhibited'), 'lap-detected') + # Internal profile didn't change + self.assertEqual(self.read_sysfs_file("sys/firmware/acpi/platform_profile"), b'performance') - # Turn off lapmode, profile stays balanced + # Turn off lapmode, profile is back to performance self.testbed.set_attribute(self.tp_acpi, 'dytc_lapmode', '0\n') self.assertEventually(lambda: self.get_dbus_property('PerformanceInhibited') == '') - self.assertEventually(lambda: self.read_sysfs_file("sys/firmware/acpi/platform_profile") == b'balanced') + self.assertEventually(lambda: self.read_sysfs_file("sys/firmware/acpi/platform_profile") == b'performance') # Switch to power-saver mode self.set_dbus_property('ActiveProfile', GLib.Variant.new_string('power-saver'))