From 68af2bee016dc4ea2bd977d5262bbc8d0133bffd Mon Sep 17 00:00:00 2001
From: Caleb Connolly <caleb@postmarketos.org>
Date: Wed, 6 Mar 2024 23:52:02 +0000
Subject: [PATCH] systemd/gnome-shell-mobile: add uclamp hack

This is a hack to configure utilisation clamping for gnome-shell. It
works by telling the scheduler that the gnome-shell process should run
with a much higher performance level. This improve animation performance
and general UI smoothness. A proper solution to have gnome-shell manage
this itself is in the works upstream.

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
---
 systemd/gnome-shell-mobile/APKBUILD              | 8 ++++++++
 systemd/gnome-shell-mobile/gnome-shell-uclamp.sh | 6 ++++++
 systemd/gnome-shell-mobile/uclamp-override.conf  | 2 ++
 3 files changed, 16 insertions(+)
 create mode 100644 systemd/gnome-shell-mobile/gnome-shell-uclamp.sh
 create mode 100644 systemd/gnome-shell-mobile/uclamp-override.conf

diff --git a/systemd/gnome-shell-mobile/APKBUILD b/systemd/gnome-shell-mobile/APKBUILD
index 63dfd5ac5b8..5d33b2f927e 100644
--- a/systemd/gnome-shell-mobile/APKBUILD
+++ b/systemd/gnome-shell-mobile/APKBUILD
@@ -71,6 +71,8 @@ source="mobile-shell-$_commit.tar.gz::https://gitlab.gnome.org/verdre/mobile-she
 	libgnome-volume-control-$_gvc_commit.tar.gz::https://gitlab.gnome.org/GNOME/libgnome-volume-control/-/archive/$_gvc_commit/gnome-shell-$_gvc_commit.tar.gz
 	disable-telepathy-integration.patch
 	gsh.patch
+	gnome-shell-uclamp.sh
+	uclamp-override.conf
 	"
 builddir="$srcdir/mobile-shell-$_commit"
 options="!check" # Tests have circular dependency 'gnome-shell <-> gdm'
@@ -117,6 +119,10 @@ package() {
 
 	# owned by postmarketos-hidden-desktop-entries
 	rm $pkgdir/usr/share/applications/org.gnome.Extensions.desktop
+
+	install -Dm755 "$srcdir/gnome-shell-uclamp.sh" "$pkgdir/usr/libexec/gnome-shell-uclamp"
+	install -Dm644 "$srcdir/uclamp-override.conf" \
+		"$pkgdir/etc/systemd/user/org.gnome.Shell@.service.d/override.conf"
 }
 
 sha512sums="
@@ -124,4 +130,6 @@ f7445d29006496865f9ea9d70efd1e2f1be1886b97bdd09bb5b000db6b576200d076178050527e92
 ebc6985afbda5ddebcda44d8b6732a9abc2d7249aff3adf7a76a90aa681590f830dcf2e5f3534a624adc32d1f0445e261ee149d65c221f733e0c33e0690a004d  libgnome-volume-control-8e7a5a4c3e51007ce6579292642517e3d3eb9c50.tar.gz
 2ca70115fab957fdf276b7f0772786e1afd56b0b22bcfd92f5b5f1d29676dc97c19cfb079434d0dbf7b459f1d133dbd8d1faa0d88f7b94846040a23856f951f8  disable-telepathy-integration.patch
 dba79b94ab4bcf0db51aa4a19c5fb52f9dae05909fe13531fe9dc06d9db334ac3328bd4040484eac8ef851057ee471a28d86800aa2ae82eec7274f5f79b9146a  gsh.patch
+545d584307ee90894525a75b7c2b99c4e05d7f903dd2181509ca0c04c5711b50a539c2f1263a8dfe26380cf121817ff2eaecac38f4fc2d0bdde5629d73f7ee0c  gnome-shell-uclamp.sh
+71ac6a8694ddcda211ff4060a55c374ae5b8eb7c3cd2a057b6eccac2c83b87bac18e09fda1d572054357d7f2e6e57b79f80a6a3cebeca75335931e1676011055  uclamp-override.conf
 "
diff --git a/systemd/gnome-shell-mobile/gnome-shell-uclamp.sh b/systemd/gnome-shell-mobile/gnome-shell-uclamp.sh
new file mode 100644
index 00000000000..42c87580eb6
--- /dev/null
+++ b/systemd/gnome-shell-mobile/gnome-shell-uclamp.sh
@@ -0,0 +1,6 @@
+#!/usr/bin/sh
+
+sleep 5
+uclampset --pid $(pidof gnome-shell) -m 900 2>&1 >/dev/null || true
+
+echo "Configured gnome-shell uclamp..."
diff --git a/systemd/gnome-shell-mobile/uclamp-override.conf b/systemd/gnome-shell-mobile/uclamp-override.conf
new file mode 100644
index 00000000000..2d164839e13
--- /dev/null
+++ b/systemd/gnome-shell-mobile/uclamp-override.conf
@@ -0,0 +1,2 @@
+[Service]
+ExecStartPost=-/usr/libexec/gnome-shell-uclamp
-- 
GitLab