git: 2ff9ebccfa41 - 2023Q3 - x11-wm/kwinft: support mac_priority(4) on Wayland

From: Jan Beich <jbeich_at_FreeBSD.org>
Date: Sun, 23 Jul 2023 19:27:24 UTC
The branch 2023Q3 has been updated by jbeich:

URL: https://cgit.FreeBSD.org/ports/commit/?id=2ff9ebccfa41712c5d4498a08a510e22d977fe24

commit 2ff9ebccfa41712c5d4498a08a510e22d977fe24
Author:     Jan Beich <jbeich@FreeBSD.org>
AuthorDate: 2023-07-15 08:31:14 +0000
Commit:     Jan Beich <jbeich@FreeBSD.org>
CommitDate: 2023-07-23 19:26:10 +0000

    x11-wm/kwinft: support mac_priority(4) on Wayland
    
    https://blog.martin-graesslin.com/blog/2017/09/kwinwayland-goes-real-time/
    (cherry picked from commit 9bb1dbe677724f5a7a6bb29e6978842468387670)
---
 x11-wm/kwinft/Makefile                      |  2 +-
 x11-wm/kwinft/files/patch-main__wayland.cpp | 36 +++++++++++++++++++++++++++++
 x11-wm/kwinft/pkg-message                   |  7 ++++++
 3 files changed, 44 insertions(+), 1 deletion(-)

diff --git a/x11-wm/kwinft/Makefile b/x11-wm/kwinft/Makefile
index 4c84f53db734..7ff6452443dd 100644
--- a/x11-wm/kwinft/Makefile
+++ b/x11-wm/kwinft/Makefile
@@ -1,7 +1,7 @@
 PORTNAME=	kwinft
 DISTVERSIONPREFIX=	${PORTNAME}@
 DISTVERSION=	5.27.0
-PORTREVISION=	1
+PORTREVISION=	2
 CATEGORIES=	x11-wm wayland
 
 MAINTAINER=	jbeich@FreeBSD.org
diff --git a/x11-wm/kwinft/files/patch-main__wayland.cpp b/x11-wm/kwinft/files/patch-main__wayland.cpp
new file mode 100644
index 000000000000..df6a92432f05
--- /dev/null
+++ b/x11-wm/kwinft/files/patch-main__wayland.cpp
@@ -0,0 +1,36 @@
+- Emulate SCHED_RESET_ON_FORK via pthread_atfork
+- Switch to pthread_setschedparam as Linux sched_setscheduler
+  operates on threads contrary to POSIX
+
+--- main_wayland.cpp.orig	2023-02-17 14:50:58 UTC
++++ main_wayland.cpp
+@@ -58,7 +58,7 @@ along with this program.  If not, see <http://www.gnu.
+ #include <QDebug>
+ #include <QWindow>
+ 
+-#include <sched.h>
++#include <pthread.h>
+ #include <sys/resource.h>
+ 
+ #include <iostream>
+@@ -122,12 +122,17 @@ void gainRealTime()
+ namespace {
+ void gainRealTime()
+ {
+-#if HAVE_SCHED_RESET_ON_FORK
+     const int minPriority = sched_get_priority_min(SCHED_RR);
+     sched_param sp;
+     sp.sched_priority = minPriority;
+-    sched_setscheduler(0, SCHED_RR | SCHED_RESET_ON_FORK, &sp);
+-#endif
++    if (pthread_setschedparam(pthread_self(), SCHED_RR, &sp))
++        return;
++
++    pthread_atfork(NULL, NULL, []() {
++        sched_param sp;
++        sp.sched_priority = 0;
++        pthread_setschedparam(pthread_self(), SCHED_OTHER, &sp);
++    });
+ }
+ }
+ 
diff --git a/x11-wm/kwinft/pkg-message b/x11-wm/kwinft/pkg-message
index 68e3a0e9b0dd..969f9444a619 100644
--- a/x11-wm/kwinft/pkg-message
+++ b/x11-wm/kwinft/pkg-message
@@ -36,6 +36,13 @@ Replace KWin in Plasma Desktop:
   $ pkg set -o x11-wm/plasma5-kwin:x11-wm/kwinft
   $ pkg upgrade -f kwinft
   $ pkg lock kwinft
+
+Improve Wayland responsiveness under high load:
+
+  $ sysrc kld_list+=mac_priority
+  $ service kld restart
+  $ pw groupmod realtime -m <user>
+  $ exit # log out to refresh group permissions
 EOM
 }
 ]