Skip to content

Commit

Permalink
power: Handle "unknown" power profiles from tuned-ppd
Browse files Browse the repository at this point in the history
Tuned has become the new default in Fedora 41, replacing PPD. Tuned does
offer the same DBus interface with tuned-ppd. However, because tuned
supports much more profiles, the tuned-ppd api is slightly incompatible
as it can return an "unknown" active profile. Some discussion here:
redhat-performance/tuned#669.

This crashes the Power panel. Instead, let's handle this by not doing
anything when we get that profile. This means no radio buttons will end
up getting selected, but that's better than showing an active profile
that isn't really active. Note that tuned-ppd currently does not
actively announce an ActiveProfile change if the change came from tuned,
but it might start to in the future, so

We do this by adding a new enum value, outside of the range of actual
profiles, as we don't want to handle it as a real profile anywhere. This
also removes the manual enum counting, there's no reason for that as
enums are guaranteed to start at 0 and increment by 1.

Note that tuned-ppd currently does not actively announce an
ActiveProfile change if the change came from tuned, but it might start
to in the future, so also reset all radio buttons if we get an unknown
profile, just in case someone has the Power panel open and changes the
active profile via tuned.
  • Loading branch information
velsinki authored and felipeborges committed Dec 5, 2024
1 parent 1c8acbd commit 131c559
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
9 changes: 9 additions & 0 deletions panels/power/cc-power-panel.c
Original file line number Diff line number Diff line change
Expand Up @@ -834,6 +834,10 @@ performance_profile_set_active (CcPowerPanel *self,
CcPowerProfile profile = cc_power_profile_from_str (profile_str);
GtkCheckButton *button;

/* FIXME: We don't know what to do with unknown profiles */
if (profile == CC_POWER_PROFILE_UNKNOWN)
return;

button = cc_power_profile_row_get_radio_button (CC_POWER_PROFILE_ROW (self->power_profiles_row[profile]));
if (!button) {
g_warning ("Not setting profile '%s' as it doesn't have a widget", profile_str);
Expand Down Expand Up @@ -1144,6 +1148,11 @@ setup_power_profiles (CcPowerPanel *self)
name, variant_lookup_string (profile_variant, "Driver"));

profile = cc_power_profile_from_str (name);

/* FIXME: We don't know what to do with unknown profiles */
if (profile == CC_POWER_PROFILE_UNKNOWN)
continue;

row = cc_power_profile_row_new (cc_power_profile_from_str (name));
g_signal_connect_object (G_OBJECT (row), "button-toggled",
G_CALLBACK (power_profile_button_toggled_cb), self,
Expand Down
4 changes: 3 additions & 1 deletion panels/power/cc-power-profile-row.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,9 @@ cc_power_profile_from_str (const char *profile)
if (g_strcmp0 (profile, "performance") == 0)
return CC_POWER_PROFILE_PERFORMANCE;

g_assert_not_reached ();
g_warning ("Unknown power profile: %s", profile);

return CC_POWER_PROFILE_UNKNOWN;
}

const char *
Expand Down
10 changes: 6 additions & 4 deletions panels/power/cc-power-profile-row.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,12 @@ G_BEGIN_DECLS

typedef enum
{
CC_POWER_PROFILE_PERFORMANCE = 0,
CC_POWER_PROFILE_BALANCED = 1,
CC_POWER_PROFILE_POWER_SAVER = 2,
NUM_CC_POWER_PROFILES
CC_POWER_PROFILE_PERFORMANCE,
CC_POWER_PROFILE_BALANCED,
CC_POWER_PROFILE_POWER_SAVER,
NUM_CC_POWER_PROFILES,
/* The unknown profile is intentionally not counted as a profile. It exists to handle unsupported profiles. */
CC_POWER_PROFILE_UNKNOWN
} CcPowerProfile;

#define CC_TYPE_POWER_PROFILE_ROW (cc_power_profile_row_get_type())
Expand Down

0 comments on commit 131c559

Please sign in to comment.