Skip to contentSkip to conversation

platform/x86: hp-wmi: Fix platform profile option switch bug on Omen and Victus laptops

PATCH In review Alexis Belmonte 2 participants 3 messages Jul 8, 2024 x86 platform drivers

lore
Share & tools
lore
#0 lore raw

PATCH v10 1/1 platform/x86: hp-wmi: Fix platform profile option switch bug on Omen and Victus laptops

Fix a platform profile option switch/getter bug on some Omen and Victus laptops dismissing userspace choice when selecting performance mode in inadequate conditions (e.g. by being disconnected from the AC power plug) by

- hooking an ACPI notify handler through the omen_register_powersource_event_handler method that listens to AC power source changes (plugging in/out the AC power plug)

- keeping an intermediate active_platform_profile variable that is set when userspace changes the platform profile setting

- restoring the selected platform profile kept in active_platform_profile when AC power is plugged back into the laptop through the power_supply_is_system_supplied call check, unless if the user decided to alter the platform profile mid-way

Add a dependency to the POWER_SUPPLY subsystem to be able to check for power_supply_is_system_supplied.

Introduce intermediary functions to leverage platform profile <-> internal thermal profile translation code from platform_profile_omen_set and callers.

These changes makes the module compliant with the principles defined in the Platform Profile Selection page of the Kernel documentation on those kind of laptops; which is to not "(...) let userspace know about any sub-optimal conditions which are impeding reaching the requested performance level".

Since the Omen and Victus laptops share the same embedded controller system, the fix is applicable to both categories of laptops.

---
V1 -> V2: - Use register_acpi_notifier and unregister_acpi_notifier instead of
hooking straight through ACPI node \\_SB.ADP1
V2 -> V3: - Rely on power_supply_is_system_supplied() instead of an EC-specific
field to determine if the laptop is plugged in
- Refactor omen_powersource_notify_handler to omen_powersource_event
- Refactor omen_powersource_register_notifier_handler to omen_register_powersource_event_handler
- Use a mutex to protect the active_platform_profile variable from being altered while the handler is executed
V3 -> V4: - Remove the unnecessary enum declaration remains from the initial
implementation
V4 -> V5: - Drop unnecessary modifications from the patch
- Call platform_profile_omen_get in platform_profile_victus_get to avoid code duplication
- Give-up module initialization if we fail to register the ACPI notifier handler
- Fix code style issues reported by checkpatch.pl --strict
- Add intermediary/helper platform_profile_omen_set_ec and platform_profile_victus_set_ec functions to leverage code from platform_profile_omen_set and callers, thus simplifying omen_powersource_event
- Fix dead-lock when restoring active_platform_profile when the AC power is plugged back into the laptop
V5 -> V6: - Drop unnecessary modifications from the patch
V6 -> V7: - Drop EC platform profile readback after set
- Lock the active_platform_profile mutex unconditionally
- Drop the usage of ACPI_FAILURE in favor of a simpler error check when registering/unregistering the ACPI notifier
- Initialize active_platform_profile in thermal_profile_setup
V7 -> V8: - Pass profile as a value instead of a pointer for
platform_profile_omen_set & platform_profile_victus_set as these functions no longer alter the parameter
- Initialize active_platform_profile during thermal_profile_setup by reading the current platform profile from the embedded controller
- Drop vestigial active_platform_profile initialization code
- Add module dependency (select) to POWER_SUPPLY in Kconfig
- Simplify thermal profile getter check in omen_powersource_event
- Substitute omen_thermal_profile_get/omen_thermal_profile_set with platform_profile_omen_get_ec/platform_profile_omen_set_ec and platform_profile_victus_get_ec/platform_profile_victus_set_ec to simplify thermal_profile_setup
V8 -> V9: - Add missing mutex_lock call in omen_powersource_event read
failure code branch
V9 -> V10: - Use imperative tone and update commit message to conform with the
current revision of the patch
- Use guard(mutex) over mutex_lock/mutex_unlock
- Fix EC <-> user-chosen platform profile comparison in omen_powersource_event
- Remove unregister_acpi_notifier error checking as it is non-fatal for the module unloading
- Make omen_unregister_powersource_event_handler inline to avoid unnecessary function call overhead while still retaining functional symmetry with omen_register_powersource_event_handler

---
 drivers/platform/x86/hp/Kconfig  |   1 +
 drivers/platform/x86/hp/hp-wmi.c | 190 ++++++++++++++++++++++++++++---
 2 files changed, 174 insertions(+), 17 deletions(-)
drivers/platform/x86/hp/Kconfig +1 -0
index 7fef4f12e498..d776761cd5fd 100644
@@ -40,6 +40,7 @@ config HP_WMI
 	depends on ACPI_WMI
 	depends on INPUT
 	depends on RFKILL || RFKILL = n
+	select POWER_SUPPLY
 	select INPUT_SPARSEKMAP
 	select ACPI_PLATFORM_PROFILE
 	select HWMON
drivers/platform/x86/hp/hp-wmi.c +173 -17

287 lines not on this page · raw message

Signature · 1 line
2.45.2
maintainer
#1 lore raw
Quoted 10 lines · Alexis Belmonte

Fix a platform profile option switch/getter bug on some Omen and Victus laptops dismissing userspace choice when selecting performance mode in inadequate conditions (e.g. by being disconnected from the AC power plug) by

- hooking an ACPI notify handler through the omen_register_powersource_event_handler method that listens to AC power source changes (plugging in/out the AC power plug)

[...]

Thank you for your contribution, it has been applied to my local review-ilpo branch. Note it will show up in the public platform-drivers-x86/review-ilpo branch only once I've pushed my local branch there, which might take a while.

The list of commits applied:
[1/1] platform/x86: hp-wmi: Fix platform profile option switch bug on Omen and Victus laptops

      commit: 2282159b33580076235384597df1d62a6a1037ee

--
i.

#2 lore raw

Thanks a lot for your time and suggestions.

Wish you a great evening.

Alexis