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.
This commit is contained in:
Bastien Nocera 2021-03-19 13:52:12 +01:00
parent ce40560a84
commit d6be3a95b8
2 changed files with 22 additions and 5 deletions

View file

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

View file

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