diff --git a/0001-thread-Fix-preexisting-uncrustify-problem.patch b/0001-thread-Fix-preexisting-uncrustify-problem.patch deleted file mode 100644 index d6bb25f..0000000 --- a/0001-thread-Fix-preexisting-uncrustify-problem.patch +++ /dev/null @@ -1,57 +0,0 @@ -From 372a2ecda4c06170a85936e3b88c7fdd681cdca1 Mon Sep 17 00:00:00 2001 -From: Ray Strode -Date: Tue, 10 Oct 2023 16:24:43 -0400 -Subject: [PATCH 1/4] thread: Fix preexisting uncrustify problem - -uncrustify seems to want a little more indentation, so this -commit gives it what it's asking for. ---- - src/backends/native/meta-thread.h | 6 +++--- - 1 file changed, 3 insertions(+), 3 deletions(-) - -diff --git a/src/backends/native/meta-thread.h b/src/backends/native/meta-thread.h -index f6c5c94f5..9fc3588b9 100644 ---- a/src/backends/native/meta-thread.h -+++ b/src/backends/native/meta-thread.h -@@ -72,35 +72,35 @@ void meta_thread_queue_callback (MetaThread *thread, - - META_EXPORT_TEST - void meta_thread_flush_callbacks (MetaThread *thread); - - META_EXPORT_TEST - gpointer meta_thread_run_impl_task_sync (MetaThread *thread, - MetaThreadTaskFunc func, - gpointer user_data, - GError **error); - - META_EXPORT_TEST - void meta_thread_post_impl_task (MetaThread *thread, - MetaThreadTaskFunc func, - gpointer user_data, - GDestroyNotify user_data_destroy, - MetaThreadTaskFeedbackFunc feedback_func, - gpointer feedback_user_data); - - META_EXPORT_TEST - MetaBackend * meta_thread_get_backend (MetaThread *thread); - - META_EXPORT_TEST - const char * meta_thread_get_name (MetaThread *thread); - - META_EXPORT_TEST - gboolean meta_thread_is_in_impl_task (MetaThread *thread); - - gboolean meta_thread_is_waiting_for_impl_task (MetaThread *thread); - - #define meta_assert_in_thread_impl(thread) \ -- g_assert (meta_thread_is_in_impl_task (thread)) -+ g_assert (meta_thread_is_in_impl_task (thread)) - #define meta_assert_not_in_thread_impl(thread) \ -- g_assert (!meta_thread_is_in_impl_task (thread)) -+ g_assert (!meta_thread_is_in_impl_task (thread)) - #define meta_assert_is_waiting_for_thread_impl_task(thread) \ -- g_assert (meta_thread_is_waiting_for_impl_task (thread)) -+ g_assert (meta_thread_is_waiting_for_impl_task (thread)) --- -2.41.0 - diff --git a/0002-thread-For-consistency-s-real_time-realtime.patch b/0001-thread-For-consistency-s-real_time-realtime.patch similarity index 97% rename from 0002-thread-For-consistency-s-real_time-realtime.patch rename to 0001-thread-For-consistency-s-real_time-realtime.patch index 73a86a8..a26ec8c 100644 --- a/0002-thread-For-consistency-s-real_time-realtime.patch +++ b/0001-thread-For-consistency-s-real_time-realtime.patch @@ -1,7 +1,7 @@ -From 39f55e7af76ee6a6339115a386a4b26f8318fed4 Mon Sep 17 00:00:00 2001 +From 01c01a221a7dabb2382a44b71dcf06649ee193d6 Mon Sep 17 00:00:00 2001 From: Ray Strode Date: Tue, 10 Oct 2023 14:35:46 -0400 -Subject: [PATCH 2/4] thread: For consistency, s/real_time/realtime/ +Subject: [PATCH 1/4] thread: For consistency, s/real_time/realtime/ Most of the code writes "real-time" as "realtime" not "real_time". diff --git a/0002-tests-dbusmock-templates-rtkit-Add-MakeThreadHighPri.patch b/0002-tests-dbusmock-templates-rtkit-Add-MakeThreadHighPri.patch new file mode 100644 index 0000000..6ea63a5 --- /dev/null +++ b/0002-tests-dbusmock-templates-rtkit-Add-MakeThreadHighPri.patch @@ -0,0 +1,65 @@ +From 742316746d50084dda4ebda5ad081e59451e3256 Mon Sep 17 00:00:00 2001 +From: Ray Strode +Date: Wed, 11 Oct 2023 09:37:54 -0400 +Subject: [PATCH 2/4] tests/dbusmock-templates/rtkit: Add + MakeThreadHighPriority + +mutter will soon need to call an additional method in RTKit, +MakeThreadHighPriority. + +In preparation for that, this commit stubs it out in the +dbusmock template. +--- + src/tests/dbusmock-templates/rtkit.py | 4 ++++ + 1 file changed, 4 insertions(+) + +diff --git a/src/tests/dbusmock-templates/rtkit.py b/src/tests/dbusmock-templates/rtkit.py +index 168582de8..766bd681e 100644 +--- a/src/tests/dbusmock-templates/rtkit.py ++++ b/src/tests/dbusmock-templates/rtkit.py +@@ -1,38 +1,42 @@ + # This program is free software; you can redistribute it and/or modify it under + # the terms of the GNU Lesser General Public License as published by the Free + # Software Foundation; either version 3 of the License, or (at your option) any + # later version. See http://www.gnu.org/copyleft/lgpl.html for the full text + # of the license. + + __author__ = 'Jonas Ã…dahl' + __copyright__ = '(c) 2022 Red Hat Inc.' + + import dbus + from dbusmock import MOCK_IFACE, mockobject + + BUS_NAME = 'org.freedesktop.RealtimeKit1' + MAIN_OBJ = '/org/freedesktop/RealtimeKit1' + MAIN_IFACE = 'org.freedesktop.RealtimeKit1' + SYSTEM_BUS = True + + + def load(mock, parameters): + mock.AddProperty(MAIN_IFACE, 'RTTimeUSecMax', dbus.Int64(200000)) + mock.AddProperty(MAIN_IFACE, 'MaxRealtimePriority', dbus.Int32(20)) + mock.AddProperty(MAIN_IFACE, 'MinNiceLevel', dbus.Int32(-15)) + mock.priorities = dict() + + @dbus.service.method(MAIN_IFACE, in_signature='tu') + def MakeThreadRealtime(self, thread, priority): + self.priorities[thread] = priority + ++@dbus.service.method(MAIN_IFACE, in_signature='tu') ++def MakeThreadHighPriority(self, thread, priority): ++ self.priorities[thread] = priority ++ + @dbus.service.method(MOCK_IFACE) + def Reset(self): + self.priorities = dict() + + @dbus.service.method(MOCK_IFACE, in_signature='t', out_signature='u') + def GetThreadPriority(self, thread): + if thread in self.priorities: + return self.priorities[thread] + else: + return 0 +-- +2.41.0 + diff --git a/0003-thread-Allow-turnning-off-rt-scheduling-for-running-.patch b/0003-thread-Allow-turning-off-rt-scheduling-for-running-t.patch similarity index 79% rename from 0003-thread-Allow-turnning-off-rt-scheduling-for-running-.patch rename to 0003-thread-Allow-turning-off-rt-scheduling-for-running-t.patch index c6b11d2..c400c6f 100644 --- a/0003-thread-Allow-turnning-off-rt-scheduling-for-running-.patch +++ b/0003-thread-Allow-turning-off-rt-scheduling-for-running-t.patch @@ -1,7 +1,7 @@ -From c38064c9614b70e92a38e98df3ebd6b232ea2f55 Mon Sep 17 00:00:00 2001 +From a7c0f106b30137e1fc6159eaecee8e61b8dc48a9 Mon Sep 17 00:00:00 2001 From: Ray Strode Date: Tue, 10 Oct 2023 14:39:13 -0400 -Subject: [PATCH 3/4] thread: Allow turnning off rt scheduling for running +Subject: [PATCH 3/4] thread: Allow turning off rt scheduling for running thread At the moment if a thread is made real-time there's no going back, @@ -21,15 +21,15 @@ so that it can be reused by the above apis. A subsequent commit will use the new APIs. --- - src/backends/native/meta-thread.c | 174 ++++++++++++++++++++++++++---- - src/backends/native/meta-thread.h | 6 ++ - 2 files changed, 157 insertions(+), 23 deletions(-) + src/backends/native/meta-thread.c | 189 ++++++++++++++++++++++++++---- + src/backends/native/meta-thread.h | 3 + + 2 files changed, 168 insertions(+), 24 deletions(-) diff --git a/src/backends/native/meta-thread.c b/src/backends/native/meta-thread.c -index 93a84a8a5..f291c0b4a 100644 +index 93a84a8a5..1ed30441d 100644 --- a/src/backends/native/meta-thread.c +++ b/src/backends/native/meta-thread.c -@@ -56,62 +56,65 @@ typedef struct _MetaThreadCallbackSource +@@ -56,62 +56,66 @@ typedef struct _MetaThreadCallbackSource GMutex mutex; GCond cond; @@ -65,6 +65,7 @@ index 93a84a8a5..f291c0b4a 100644 + pid_t thread_id; GMutex init_mutex; + int realtime_inhibit_count; ++ gboolean is_realtime; } kernel; } MetaThreadPrivate; @@ -95,7 +96,7 @@ index 93a84a8a5..f291c0b4a 100644 guint prop_id, GValue *value, GParamSpec *pspec) -@@ -175,181 +178,238 @@ get_rtkit_property (MetaDBusRealtimeKit1 *rtkit_proxy, +@@ -175,181 +179,278 @@ get_rtkit_property (MetaDBusRealtimeKit1 *rtkit_proxy, { GDBusConnection *connection; g_autoptr (GVariant) prop_value = NULL; @@ -265,22 +266,62 @@ index 93a84a8a5..f291c0b4a 100644 +} + +static gboolean -+meta_thread_uses_realtime_scheduling (MetaThread *thread) ++should_use_realtime_scheduling_in_impl (MetaThread *thread) +{ + MetaThreadPrivate *priv = meta_thread_get_instance_private (thread); -+ gboolean uses_realtime_scheduling = FALSE; ++ gboolean should_use_realtime_scheduling = FALSE; + + switch (priv->thread_type) + { + case META_THREAD_TYPE_USER: + break; + case META_THREAD_TYPE_KERNEL: -+ if (priv->kernel.realtime_inhibit_count == 0) -+ uses_realtime_scheduling = TRUE; ++ if (priv->wants_realtime && priv->kernel.realtime_inhibit_count == 0) ++ should_use_realtime_scheduling = TRUE; + break; + } + -+ return uses_realtime_scheduling; ++ return should_use_realtime_scheduling; ++} ++ ++static void ++sync_realtime_scheduling_in_impl (MetaThread *thread) ++{ ++ MetaThreadPrivate *priv = meta_thread_get_instance_private (thread); ++ g_autoptr (GError) error = NULL; ++ gboolean should_be_realtime; ++ ++ should_be_realtime = should_use_realtime_scheduling_in_impl (thread); ++ ++ if (should_be_realtime == priv->kernel.is_realtime) ++ return; ++ ++ if (should_be_realtime) ++ { ++ if (!request_realtime_scheduling (thread, &error)) ++ { ++ g_warning ("Failed to make thread '%s' realtime scheduled: %s", ++ priv->name, error->message); ++ } ++ else ++ { ++ meta_topic (META_DEBUG_BACKEND, "Made thread '%s' real-time scheduled", priv->name); ++ priv->kernel.is_realtime = TRUE; ++ } ++ } ++ else ++ { ++ if (!request_normal_scheduling (thread, &error)) ++ { ++ g_warning ("Failed to make thread '%s' normally scheduled: %s", ++ priv->name, error->message); ++ } ++ else ++ { ++ meta_topic (META_DEBUG_BACKEND, "Made thread '%s' normally scheduled", priv->name); ++ priv->kernel.is_realtime = FALSE; ++ } ++ } +} + static gpointer @@ -305,13 +346,12 @@ index 93a84a8a5..f291c0b4a 100644 meta_profiler_register_thread (profiler, thread_context, priv->name); #endif -+ priv->kernel.thread_id = gettid (); -+ priv->kernel.realtime_inhibit_count = 1; -+ - if (priv->wants_realtime) +- if (priv->wants_realtime) - { - g_autoptr (GError) error = NULL; -+ meta_thread_uninhibit_realtime_in_impl (thread); ++ priv->kernel.thread_id = gettid (); ++ priv->kernel.realtime_inhibit_count = 0; ++ priv->kernel.is_realtime = FALSE; - if (!request_realtime_scheduling (thread, &error)) - { @@ -323,7 +363,9 @@ index 93a84a8a5..f291c0b4a 100644 - g_message ("Made thread '%s' realtime scheduled", priv->name); - run_flags |= META_THREAD_IMPL_RUN_FLAG_REALTIME; - } -+ if (meta_thread_uses_realtime_scheduling (thread)) ++ sync_realtime_scheduling_in_impl (thread); ++ ++ if (priv->kernel.is_realtime) + { + g_message ("Made thread '%s' realtime scheduled", priv->name); + run_flags |= META_THREAD_IMPL_RUN_FLAG_REALTIME; @@ -357,7 +399,7 @@ index 93a84a8a5..f291c0b4a 100644 int *timeout) { WrapperSource *wrapper_source = (WrapperSource *) source; -@@ -522,60 +582,66 @@ meta_thread_initable_init (GInitable *initable, +@@ -522,60 +623,64 @@ meta_thread_initable_init (GInitable *initable, start_thread (thread); @@ -390,8 +432,6 @@ index 93a84a8a5..f291c0b4a 100644 priv->kernel.thread = NULL; + priv->kernel.thread_id = 0; + -+ priv->kernel.realtime_inhibit_count = -1; -+ + g_clear_object (&priv->kernel.rtkit_proxy); + g_mutex_clear (&priv->kernel.init_mutex); @@ -424,70 +464,7 @@ index 93a84a8a5..f291c0b4a 100644 tear_down_thread (thread); meta_thread_unregister_callback_context (thread, priv->main_context); -@@ -618,60 +684,62 @@ meta_thread_class_init (MetaThreadClass *klass) - - obj_props[PROP_THREAD_TYPE] = - g_param_spec_enum ("thread-type", - "thread-type", - "Type of thread", - META_TYPE_THREAD_TYPE, - META_THREAD_TYPE_KERNEL, - G_PARAM_READWRITE | - G_PARAM_CONSTRUCT_ONLY | - G_PARAM_STATIC_STRINGS); - - obj_props[PROP_WANTS_REALTIME] = - g_param_spec_boolean ("wants-realtime", - "wants-realtime", - "Wants real-time thread scheduling", - FALSE, - G_PARAM_READWRITE | - G_PARAM_CONSTRUCT_ONLY | - G_PARAM_STATIC_STRINGS); - - g_object_class_install_properties (object_class, N_PROPS, obj_props); - } - - static void - meta_thread_init (MetaThread *thread) - { - MetaThreadPrivate *priv = meta_thread_get_instance_private (thread); - - g_mutex_init (&priv->callbacks_mutex); - priv->main_thread = g_thread_self (); -+ -+ priv->kernel.realtime_inhibit_count = -1; - } - - void - meta_thread_class_register_impl_type (MetaThreadClass *thread_class, - GType impl_type) - { - MetaThreadClassPrivate *class_priv = - G_TYPE_CLASS_GET_PRIVATE (thread_class, META_TYPE_THREAD, - MetaThreadClassPrivate); - - g_assert (class_priv->impl_type == G_TYPE_INVALID); - class_priv->impl_type = impl_type; - } - - void - meta_thread_reset_thread_type (MetaThread *thread, - MetaThreadType thread_type) - { - MetaThreadPrivate *priv = meta_thread_get_instance_private (thread); - g_autoptr (GMainContext) thread_context = NULL; - - if (priv->thread_type == thread_type) - return; - - tear_down_thread (thread); - g_assert (!priv->wrapper_source); - - priv->thread_type = thread_type; - - start_thread (thread); -@@ -1134,30 +1202,90 @@ meta_thread_get_thread_type (MetaThread *thread) +@@ -1134,30 +1239,66 @@ meta_thread_get_thread_type (MetaThread *thread) MetaThreadPrivate *priv = meta_thread_get_instance_private (thread); return priv->thread_type; @@ -523,7 +500,6 @@ index 93a84a8a5..f291c0b4a 100644 +meta_thread_inhibit_realtime_in_impl (MetaThread *thread) +{ + MetaThreadPrivate *priv = meta_thread_get_instance_private (thread); -+ g_autoptr (GError) error = NULL; + + switch (priv->thread_type) + { @@ -531,18 +507,7 @@ index 93a84a8a5..f291c0b4a 100644 + priv->kernel.realtime_inhibit_count++; + + if (priv->kernel.realtime_inhibit_count == 1) -+ { -+ if (!request_normal_scheduling (thread, &error)) -+ { -+ g_warning ("Failed to make thread '%s' normally scheduled: %s", -+ priv->name, error->message); -+ priv->kernel.realtime_inhibit_count--; -+ } -+ else -+ { -+ meta_topic (META_DEBUG_BACKEND, "Made thread '%s' normally scheduled", priv->name); -+ } -+ } ++ sync_realtime_scheduling_in_impl (thread); + break; + case META_THREAD_TYPE_USER: + break; @@ -553,7 +518,6 @@ index 93a84a8a5..f291c0b4a 100644 +meta_thread_uninhibit_realtime_in_impl (MetaThread *thread) +{ + MetaThreadPrivate *priv = meta_thread_get_instance_private (thread); -+ g_autoptr (GError) error = NULL; + + switch (priv->thread_type) + { @@ -561,28 +525,17 @@ index 93a84a8a5..f291c0b4a 100644 + priv->kernel.realtime_inhibit_count--; + + if (priv->kernel.realtime_inhibit_count == 0) -+ { -+ if (!request_realtime_scheduling (thread, &error)) -+ { -+ g_warning ("Failed to make thread '%s' realtime scheduled: %s", -+ priv->name, error->message); -+ priv->kernel.realtime_inhibit_count++; -+ } -+ else -+ { -+ meta_topic (META_DEBUG_BACKEND, "Made thread '%s' realtime scheduled", priv->name); -+ } -+ } ++ sync_realtime_scheduling_in_impl (thread); + break; + case META_THREAD_TYPE_USER: + break; + } +} diff --git a/src/backends/native/meta-thread.h b/src/backends/native/meta-thread.h -index 9fc3588b9..96b79b586 100644 +index f6c5c94f5..4765719ec 100644 --- a/src/backends/native/meta-thread.h +++ b/src/backends/native/meta-thread.h -@@ -71,36 +71,42 @@ void meta_thread_queue_callback (MetaThread *thread, +@@ -71,36 +71,39 @@ void meta_thread_queue_callback (MetaThread *thread, GDestroyNotify user_data_destroy); META_EXPORT_TEST @@ -613,18 +566,15 @@ index 9fc3588b9..96b79b586 100644 gboolean meta_thread_is_waiting_for_impl_task (MetaThread *thread); -+META_EXPORT_TEST +void meta_thread_inhibit_realtime_in_impl (MetaThread *thread); -+ -+META_EXPORT_TEST +void meta_thread_uninhibit_realtime_in_impl (MetaThread *thread); + #define meta_assert_in_thread_impl(thread) \ - g_assert (meta_thread_is_in_impl_task (thread)) + g_assert (meta_thread_is_in_impl_task (thread)) #define meta_assert_not_in_thread_impl(thread) \ - g_assert (!meta_thread_is_in_impl_task (thread)) + g_assert (!meta_thread_is_in_impl_task (thread)) #define meta_assert_is_waiting_for_thread_impl_task(thread) \ - g_assert (meta_thread_is_waiting_for_impl_task (thread)) + g_assert (meta_thread_is_waiting_for_impl_task (thread)) -- 2.41.0 diff --git a/0004-kms-impl-device-Inhibit-real-time-scheduling-when-mo.patch b/0004-kms-impl-device-Inhibit-real-time-scheduling-when-mo.patch index 6ef06d8..fa9c1d2 100644 --- a/0004-kms-impl-device-Inhibit-real-time-scheduling-when-mo.patch +++ b/0004-kms-impl-device-Inhibit-real-time-scheduling-when-mo.patch @@ -1,4 +1,4 @@ -From 99be4ed7c3be19969930ce826f48c444e5e9da41 Mon Sep 17 00:00:00 2001 +From 105a3d60df5df74fd7ea78cacc0d9ca30607b45a Mon Sep 17 00:00:00 2001 From: Ray Strode Date: Tue, 10 Oct 2023 14:48:55 -0400 Subject: [PATCH 4/4] kms/impl-device: Inhibit real-time scheduling when mode diff --git a/mutter.spec b/mutter.spec index af955f9..df2d9c9 100644 --- a/mutter.spec +++ b/mutter.spec @@ -45,11 +45,12 @@ Patch: 3306.patch Patch: 0001-Revert-x11-Use-input-region-from-frame-window-for-de.patch # https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3324 -Patch: 0001-thread-Fix-preexisting-uncrustify-problem.patch -Patch: 0002-thread-For-consistency-s-real_time-realtime.patch -Patch: 0003-thread-Allow-turnning-off-rt-scheduling-for-running-.patch +Patch: 0001-thread-For-consistency-s-real_time-realtime.patch +Patch: 0002-tests-dbusmock-templates-rtkit-Add-MakeThreadHighPri.patch +Patch: 0003-thread-Allow-turning-off-rt-scheduling-for-running-t.patch Patch: 0004-kms-impl-device-Inhibit-real-time-scheduling-when-mo.patch + BuildRequires: pkgconfig(gobject-introspection-1.0) >= 1.41.0 BuildRequires: pkgconfig(sm) BuildRequires: pkgconfig(libwacom)