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

Enable soft real time for gnome shell #71390

Merged
merged 3 commits into from Nov 12, 2019

Conversation

hedning
Copy link
Contributor

@hedning hedning commented Oct 19, 2019

Motivation for this change

Make gnome-shell wayland run with cap_sys_nice to improve performance.

closes #71381

Things done

Patched mutter to drop cap_sys_nice=i on startup, which prevents the ambient set leaking into processes gnome-shell spawns.

Overrode gnome-shell-wayland.service to launch through an added capability wrapper. (This proved a bit fiddly as NixOS provides a rather bad default environment for user services). Thought this was cleaner than mucking about in the gnome-shell derivation.

Running this at the moment, and it seems to work:
image

  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nix-review --run "nix-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Ensured that relevant documentation is up to date
  • Fits CONTRIBUTING.md.
Notify maintainers

cc @

Mutter have shipped its own `clutter` for ages, we need json-glib however which
clutter propagated.
In NixOS extra capabilities are provided through the ambient set which provides
real inheritability to user run processes [0].

We don't want gome-shell to spawn processes with cap_sys_nice however (apart
from the obvious this also breaks eg. flatpaks). So we drop inheritable when
starting to prevent further inheritance (the ambient set is only propagated
if inherit is set).

[0] torvalds/linux@5831905
We create a wrapper which launches gnome-shell with the correct environment and
cap_sys_nice.

We can then override gnome-shell-wayland.service to use this wrapper.

NOTE: We need to force clear the environment, because the defaults aren't good
for user services. That should probably be fixed.
@hedning
Copy link
Contributor Author

hedning commented Oct 19, 2019

Note we could simplify the drop-inheritable patch, as there's a bunch of stuff we don't really need to support (eg. having a meson option, and ifdefs in the code etc.).

@worldofpeace
Copy link
Contributor

@hedning Could it be possible to do similar without security wrappers and systemd?
Or is that not supported well in nixos?

I also believe this is an experimental feature, so I don't think it's on by default.
So perhaps we should respect this and just make it easily configurable for the user.

Could you add an option services.gnome3.core-shell.realtimeScheduling (not sure how we feel about camel case there), and optional gsettings override?

[org.gnome.mutter]
experimental-features=['rt-scheduler']

@hedning
Copy link
Contributor Author

hedning commented Oct 19, 2019

Could it be possible to do similar without security wrappers and systemd?

You basically need an executable with cap_sys_nice=ep or a security wrapper. It's possible to copy the gnome-shell executable somewhere and setting cap_sys_nice=ep, but there's really no precedence or infrastructure to do that (I tested this by hardcoding this in the security wrapper setup, and it does work).

To actually launch sessions with the capability it just seemed cleanest to do it as a service override. That keeps the separation between NixOS and nixpkgs, and the security wrapper code can live together with the override.

I also believe this is an experimental feature, so I don't think it's on by default.

Right, totally forgot that (I apparently turned it on a long time ago 😂 ).

Could you add an option services.gnome3.core-shell.realtimeScheduling

Yep, that makes sense 👍 The gsettings override only acts as a default right? It doesn't override anything if the option is set in the users database?

Fedora sets cap_sys_nice by default (https://src.fedoraproject.org/rpms/gnome-shell/blob/f31/f/gnome-shell.spec#_173), so I think that's fine to launch through the wrapper by default (that way it's possible to enable it through dconf-editor etc. too).

@worldofpeace
Copy link
Contributor

You basically need an executable with cap_sys_nice=ep or a security wrapper. It's possible to copy the gnome-shell executable somewhere and setting cap_sys_nice=ep, but there's really no precedence or infrastructure to do that (I tested this by hardcoding this in the security wrapper setup, and it does work).

To actually launch sessions with the capability it just seemed cleanest to do it as a service override. That keeps the separation between NixOS and nixpkgs, and the security wrapper code can live together with the override.

Umm, by using systemd I meant a service override. But with

@jtojnar
Copy link
Contributor

jtojnar commented Oct 19, 2019

The gsettings override only acts as a default right? It doesn't override anything if the option is set in the users database?

Yup. And worst of all, GSettings list do not have merging semantics like Nix modules have, so if we wanted to add another experimental feature, we would need to remember to do it all in single place.

@hedning
Copy link
Contributor Author

hedning commented Oct 19, 2019

https://www.freedesktop.org/software/systemd/man/systemd.exec.html#Capabilities

Ah, right, that only works for system services unfortunately. I think it would be fairly difficult to integrate it with the display-managers etc. (Also looks like the capabilities are passed through the ambient set, so we'd still need the mutter patch).

@worldofpeace worldofpeace added this to In Progress in GNOME Oct 31, 2019
@worldofpeace
Copy link
Contributor

I'm thinking it might make more sense in nixos to not launch through the wrapper default, but to add the option services.gnome3.core-shell.realtimeScheduling to enable this. Thoughts?

@worldofpeace
Copy link
Contributor

I'm thinking it might make more sense in nixos to not launch through the wrapper default, but to add the option services.gnome3.core-shell.realtimeScheduling to enable this. Thoughts?

Actually, after thinking about it I don't think there's much point without #54150, as we can only influence default values. Which isn't much use, it doesn't enable it. I would only enables support. So it's more of an implementation detail, and it's pretty harmless capability anyways.

Copy link
Contributor

@worldofpeace worldofpeace left a comment

Choose a reason for hiding this comment

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

LGTM, tested and it works.

@worldofpeace worldofpeace merged commit b252047 into NixOS:master Nov 12, 2019
GNOME automation moved this from In Progress to Done Nov 12, 2019
@hedning hedning deleted the enable-gnome-shell-RT branch March 1, 2020 11:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
GNOME
  
Done
Development

Successfully merging this pull request may close these issues.

Support launching gnome-shell with RT scheduling
3 participants