Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More tuned-ppd adjustments #669

Merged
merged 7 commits into from
Dec 11, 2024
Merged

Conversation

zacikpa
Copy link
Contributor

@zacikpa zacikpa commented Aug 9, 2024

This PR brings another round of tuned-ppd adjustments and bug fixes. The individual commit messages explain why the changes are being made.

The most prominent change is dropping reverse profile mapping, i.e., from TuneD to PPD profiles. Instead, the daemon now keeps track of the currently active profile and the so-called base profile. This improves tuned-ppd in two ways:

  1. Profile mappings now don't have to be injective.
  2. When tuned-ppd is restarted, the initial profile is not the last active profile as inferred from the restored TuneD profile, but the last base profile, as saved into a file by tuned-ppd. The active and the base profile may differ due to profile holds being active before the restart. These should arguably be released when tuned-ppd is restarted.

@zacikpa zacikpa requested a review from yarda August 9, 2024 15:37
@zacikpa
Copy link
Contributor Author

zacikpa commented Aug 12, 2024

CI failures fixed.

@zacikpa
Copy link
Contributor Author

zacikpa commented Aug 20, 2024

Rebased onto master because the issue resolved by the first commit was fixed by c082797.

@zacikpa
Copy link
Contributor Author

zacikpa commented Sep 18, 2024

Added another change - a new Version DBus property, which signifies the level of compatibility with power-profiles-daemon (as suggested in #684 (comment)).

@zacikpa
Copy link
Contributor Author

zacikpa commented Oct 14, 2024

Moved the first commit into a separate PR: #697. That one should ideally land in Fedora 41 before the final freeze. The rest are more complex and will likely require some discussion.

@velsinki
Copy link

velsinki commented Nov 26, 2024

Just chiming in here to say that technically this is api-incompatible still with PPD. The original PPD cannot return an "unknown" active profile, whereas tuned-ppd can.

This can cause a crash in gnome-control-center: see https://bugzilla.redhat.com/show_bug.cgi?id=2324518.

Now, I don't really see a way around this, but it would be good to document this.

Source: I'm the upstream (co)maintainer of gnome-control-center.

@zacikpa
Copy link
Contributor Author

zacikpa commented Nov 27, 2024

Thanks, @velsinki. I'll adjust the code not to perform this check.

@velsinki
Copy link

Thanks for the reply.

I'm not sure that's ideal either, as it would mean tuned-ppd is lying about which profile is active? We'll anyways fix the crash in gnome-control-center, not against keeping "unknown". I don't know what other consumers of PPD are doing though, GNOME Shell should have a similar issue.

@zacikpa
Copy link
Contributor Author

zacikpa commented Nov 27, 2024

I'm not sure that's ideal either, as it would mean tuned-ppd is lying about which profile is active?

Exactly. I agree it's not ideal, but it shifts the responsibility to the users when they mess with the TuneD profiles via multiple methods.

What's your proposed behavior of gnome-control-center if tuned-ppd returns "unknown"? It would certainly be nicer if we could keep the implementation as it is now. I would check with the other users of PPD to see whether they would be able to deal with it too.

@velsinki
Copy link

What's your proposed behavior of gnome-control-center if tuned-ppd returns "unknown"?

We currently show three radio buttons (performance, balanced, power-saver). If tuned-ppd would lie about a profile, we would start the UI with that radio button enabled, as we don't know anything else. That would mean that radio button can't actually be clicked anymore, as it's already active. If however we get "unknown", we can start the UI with no radio buttons selected instead.

Currently we don't handle "unknown", and crash, but that's not hard to support.

@zacikpa
Copy link
Contributor Author

zacikpa commented Nov 27, 2024

If however we get "unknown", we can start the UI with no radio buttons selected instead.

This sounds like very reasonable behavior.

Currently we don't handle "unknown", and crash, but that's not hard to support.

In that case, I'd prefer to keep this as is and check in with the other consumers.

Sorry for the troubles and thanks for looking into this!

@velsinki
Copy link

It would also be nice if the tuned profile is tracked, and if it changes, tuned-ppd anounces an ActiveProfile property change. That would resolve #689.

@zacikpa zacikpa marked this pull request as draft November 29, 2024 13:41
@zacikpa zacikpa force-pushed the ppd-adjustments branch 11 times, most recently from 9768c01 to 734cb53 Compare December 3, 2024 14:04
Make sure that we only initialize the UPower signal
handler only if such a handler is not already running.

This also reorders the order of operations in the initialization
procedure, skipping redundant initial TuneD profile changes.
@zacikpa zacikpa marked this pull request as ready for review December 3, 2024 14:30
Instead of querying TuneD each time we want to determine the active
TuneD profile, remember its value. Also watch for signals from TuneD,
updating the value when the TuneD profile changes (resolves redhat-performance#689).

The daemon now also keeps track of the "base" PPD profile, which is
restored when all profile holds are released or when tuned-ppd is
restarted. For the latter purpose, this profile is also saved in a file.

Direct access via two dictionaries (one for AC, one for DC)
was clumsy, this commit replaces it with a new class - ProfileMap.
This makes tuned-ppd fully API-compatible with
the latest power-profiles-daemon. The property
will signify the level of API compatibility with
power-profiles-daemon.
To be consistent and make sure tuned-ppd works well with
its users no matter the configuration, the balanced profile
must be required in the configuration file, similarly to
the power-saver and performance profiles.

If no default profile is specified in the configuration,
this also sets the default profile to balanced, not raising
any exceptions like before.
Instead of actively polling for changes in the relevant files,
set up inotify handlers which are invoked when the files change.
On some Thinkpad laptops, it is possible to change the ACPI
platform profile using function keys (e.g., Fn+L). This can
now trigger a complete profile change if the functionality
is enabled.

Resolves redhat-performance#710.
@zacikpa
Copy link
Contributor Author

zacikpa commented Dec 3, 2024

Major update pushed now:

  • After user feedback, I decided to stick with enforcing bijective PPD-to-TuneD profile mapping. We can thus translate TuneD profiles back to PPD profiles if the TuneD profile changes, e.g., via tuned-adm. This resolves Gnome-shell - doesn't change Power Mode indicator #689. If users wish to simulate non-injective profile mapping, they'll have to create TuneD profile copies.
  • Instead of actively polling for changes in the files related to performance degradation, the daemon now uses inotify to handle the changes.
  • inotify is also used to watch the ACPI platform profile, which can optionally serve as an alternative way of switching PPD profiles on Thinkpad machines which support Fn+L/M/H function keys. This resolves tuned should track firmware initiated changes to the platform_profiles #710.

gnomesysadmins pushed a commit to GNOME/gnome-control-center that referenced this pull request Dec 11, 2024
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.

(cherry picked from commit 131c559)
gnomesysadmins pushed a commit to GNOME/gnome-control-center that referenced this pull request Dec 11, 2024
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.
Copy link
Contributor

@yarda yarda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, the code looks good. I didn't run functionality tests, I don't own specific HW to test all the supported features.

@yarda yarda merged commit d9293d7 into redhat-performance:master Dec 11, 2024
14 checks passed
zacikpa pushed a commit to zacikpa/budgie-control-center that referenced this pull request Jan 24, 2025
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.
zacikpa added a commit to zacikpa/cosmic-applets that referenced this pull request Jan 24, 2025
TuneD provides a compatibility daemon (tuned-ppd) which replaces
power-profiles-daemon in Fedora 41 [1]. However, the new daemon
can report an "unknown" profile in case the user manipulates with
underlying TuneD profiles directly; see [2].

Before this change, the "unknown" profile makes the battery applet
panic. With this change, the applet reports the balanced profile.
This is in line with the behavior of cosmic-settings [3].

[1] https://pagure.io/fesco/issue/3222
[2] redhat-performance/tuned#669
[3] https://github.com/pop-os/cosmic-settings/blob/6f05e9e/cosmic-settings/src/pages/power/backend/mod.rs#L65
mmstick pushed a commit to pop-os/cosmic-applets that referenced this pull request Jan 24, 2025
TuneD provides a compatibility daemon (tuned-ppd) which replaces
power-profiles-daemon in Fedora 41 [1]. However, the new daemon
can report an "unknown" profile in case the user manipulates with
underlying TuneD profiles directly; see [2].

Before this change, the "unknown" profile makes the battery applet
panic. With this change, the applet reports the balanced profile.
This is in line with the behavior of cosmic-settings [3].

[1] https://pagure.io/fesco/issue/3222
[2] redhat-performance/tuned#669
[3] https://github.com/pop-os/cosmic-settings/blob/6f05e9e/cosmic-settings/src/pages/power/backend/mod.rs#L65
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants