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

[X1] Turn off the display when system is suspended #740

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

vunnyso
Copy link
Contributor

@vunnyso vunnyso commented Aug 15, 2024

  • Addresses SP-4844 - Display turns on in sleep mode when the lid is closed.

Description of changes

Checklist for things done

  • Summary of the proposed changes in the PR description
  • More detailed description in the commit message(s)
  • Commits are squashed into relevant entities - avoid a lot of minimal dev time commits in the PR
  • Contribution guidelines followed
  • Ghaf documentation updated with the commit - https://tiiuae.github.io/ghaf/
  • PR linked to architecture documentation and requirement(s) (ticket id)
  • Test procedure described (or includes tests). Select one or more:
    • Tested on Lenovo X1 x86_64
    • Tested on Jetson Orin NX or AGX aarch64
    • Tested on Polarfire riscv64
  • Author has run nix flake check --accept-flake-config and it passes
  • All automatic Github Action checks pass - see actions
  • Author has added reviewers and removed PR draft status

Testing

  • Display will get turn off automatically when lid is closed.
  • Display will get turn off automatically when we run sudo systsemctl suspend on ghaf-host

Known issues with Qemu

  1. As persistent Storage is enabled in gui-vm due to which gui-vm fails to suspend as virtio filesystem doesn't support suspend, details here.
gui-vm kernel: virtio-fs: suspend/resume not yet supported
gui-vm kernel: virtio-pci 0000:00:04.0: PM: pci_pm_suspend(): virtio_pci_freeze+0x0/0x50 [virtio_pci] returns -95
gui-vm kernel: virtio-pci 0000:00:04.0: PM: dpm_run_callback(): pci_pm_suspend+0x0/0x170 returns -95
gui-vm kernel: virtio-pci 0000:00:04.0: PM: failed to suspend async: error -95
  1. If someway we can managed to solve problem 1, then gui-vm cannot be resume on keyboard press, way to resume is from qemu monitor socket.

  2. If someway we can managed to solve problem 2, then qemu freezes after resume, more details here

So considering above qemu issues, I think better to turn off display.

Power improvements

Check With PR Without PR
Battery Drainage ~2 % per hour ~8 % per hour

Approx 4 times improvement in battery life when lid is closed.

Next Steps

Try to replicate with givc service if feasible.

@vunnyso vunnyso temporarily deployed to internal-build-workflow August 15, 2024 13:44 — with GitHub Actions Inactive
@nesteroff
Copy link
Contributor

I was thinking that maybe we don’t need to suspend the GUIVM at all. Instead, we can simply turn off the display before suspending and turn it back on after resuming using the wlopm command.
These commands can be added to a oneshot systemd service that runs before and after the sleep.target target on the host. We can use SSH to execute them in the GUIVM from the host, or better yet add them to the RPC service.
This way, we don’t need to take care of the QEMU and virtiofs suspend/resume issues. Also, we will be able to remove the -device button from here.
Here’s an example of how to turn the display on and off from the host (pkgs.wlopm needs to be added to the GUIVM):

ssh -t ghaf@gui-vm-debug 'WAYLAND_DISPLAY=/run/user/1000/wayland-0 wlopm --off \*’
ssh -t ghaf@gui-vm-debug 'WAYLAND_DISPLAY=/run/user/1000/wayland-0 wlopm --on \*’

@vunnyso what do you think?

@vunnyso
Copy link
Contributor Author

vunnyso commented Sep 10, 2024

I was thinking that maybe we don’t need to suspend the GUIVM at all. Instead, we can simply turn off the display before suspending and turn it back on after resuming using the wlopm command. These commands can be added to a oneshot systemd service that runs before and after the sleep.target target on the host. We can use SSH to execute them in the GUIVM from the host, or better yet add them to the RPC service. This way, we don’t need to take care of the QEMU and virtiofs suspend/resume issues. Also, we will be able to remove the -device button from here. Here’s an example of how to turn the display on and off from the host (pkgs.wlopm needs to be added to the GUIVM):

ssh -t ghaf@gui-vm-debug 'WAYLAND_DISPLAY=/run/user/1000/wayland-0 wlopm --off \*’
ssh -t ghaf@gui-vm-debug 'WAYLAND_DISPLAY=/run/user/1000/wayland-0 wlopm --on \*’

@vunnyso what do you think?

Thanks @nesteroff for suggestion, I think its good idea to start with, as I am still struggling to find proper fix from qemu

@vunnyso vunnyso temporarily deployed to internal-build-workflow September 11, 2024 09:06 — with GitHub Actions Inactive
@vunnyso vunnyso changed the title gui-vm: support system suspend on lid close [X1]: Turn off the display when system is suspended on lid close Sep 11, 2024
This patch is adding two systemd services.
On suspend we turn off the display of gui-vm and on
resume we turn on the display back. This will help to
save system power when system system is suspended or lid
is closed.

Signed-off-by: Vunny Sodhi <vunny.sodhi@unikie.com>
@vunnyso vunnyso changed the title [X1]: Turn off the display when system is suspended on lid close [X1] Turn off the display when system is suspended Sep 11, 2024
@vunnyso vunnyso temporarily deployed to internal-build-workflow September 11, 2024 09:19 — with GitHub Actions Inactive
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.

2 participants