-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path0002-server-Fallback-to-RTKIT-for-thread-priorities.mypatch
151 lines (144 loc) · 5.42 KB
/
0002-server-Fallback-to-RTKIT-for-thread-priorities.mypatch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
commit ebf411c1e5f20c6db7962cea587d6169246078e0
Author: Rémi Bernon <[email protected]>
Date: Wed Jul 3 10:54:06 2019 +0200
Subject: [PATCH 2/2] server: Fallback to RTKIT for thread priorities.
sched_setscheduler and setpriority usually require elevated privileges
to succeed and most Linux distributions ship rtkit daemon with a dbus
interface to enable unprivileged control of some scheduling parameters.
diff --git a/configure.ac b/configure.ac
index 59a8668b609..9457ed3103f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1395,7 +1395,7 @@ dnl **** Check for libdbus ****
if test "x$with_dbus" != "xno"
then
WINE_PACKAGE_FLAGS(DBUS,[dbus-1],,,,
- [AC_CHECK_HEADER([dbus/dbus.h],
+ [AC_CHECK_HEADERS([dbus/dbus.h],
[WINE_CHECK_SONAME(dbus-1, dbus_connection_close,,[DBUS_CFLAGS=""],[$DBUS_LIBS])],
[DBUS_CFLAGS=""])])
fi
diff --git a/server/Makefile.in b/server/Makefile.in
index 4264e3db108..43be2fe3ddb 100644
--- a/server/Makefile.in
+++ b/server/Makefile.in
@@ -49,6 +49,7 @@ MANPAGES = \
wineserver.fr.UTF-8.man.in \
wineserver.man.in
-EXTRALIBS = $(LDEXECFLAGS) $(RT_LIBS) $(INOTIFY_LIBS) $(PROCSTAT_LIBS)
+EXTRAINCL = $(DBUS_CFLAGS)
+EXTRALIBS = $(LDEXECFLAGS) $(RT_LIBS) $(INOTIFY_LIBS) $(PROCSTAT_LIBS) $(DBUS_LIBS)
unicode_EXTRADEFS = -DNLSDIR="\"${nlsdir}\"" -DBIN_TO_NLSDIR=\"`$(MAKEDEP) -R ${bindir} ${nlsdir}`\"
diff --git a/server/thread.c b/server/thread.c
index 6b53b518d98..cbabf9c7070 100644
--- a/server/thread.c
+++ b/server/thread.c
@@ -58,6 +58,77 @@
#include "user.h"
#include "security.h"
+#ifdef HAVE_DBUS_DBUS_H
+#include <dbus/dbus.h>
+
+static int rtkit_set_realtime( dbus_uint64_t process, dbus_uint64_t thread, dbus_uint32_t priority )
+{
+ DBusConnection* dbus;
+ DBusMessage *msg;
+ int ret = -1;
+
+ if ((dbus = dbus_bus_get(DBUS_BUS_SYSTEM, NULL)))
+ {
+ dbus_connection_set_exit_on_disconnect(dbus, 0);
+
+ if ((msg = dbus_message_new_method_call("org.freedesktop.RealtimeKit1",
+ "/org/freedesktop/RealtimeKit1",
+ "org.freedesktop.RealtimeKit1",
+ "MakeThreadRealtimeWithPID")))
+ {
+ dbus_message_set_no_reply(msg, 1);
+
+ if (dbus_message_append_args(msg,
+ DBUS_TYPE_UINT64, &process,
+ DBUS_TYPE_UINT64, &thread,
+ DBUS_TYPE_UINT32, &priority,
+ DBUS_TYPE_INVALID) &&
+ dbus_connection_send(dbus, msg, NULL))
+ ret = 0;
+
+ dbus_message_unref(msg);
+ }
+
+ dbus_connection_unref(dbus);
+ }
+
+ return ret;
+}
+
+static int rtkit_set_niceness( dbus_uint64_t process, dbus_uint64_t thread, dbus_int32_t niceness )
+{
+ DBusConnection* dbus;
+ DBusMessage *msg;
+ int ret = -1;
+
+ if ((dbus = dbus_bus_get(DBUS_BUS_SYSTEM, NULL)))
+ {
+ dbus_connection_set_exit_on_disconnect(dbus, 0);
+
+ if ((msg = dbus_message_new_method_call("org.freedesktop.RealtimeKit1",
+ "/org/freedesktop/RealtimeKit1",
+ "org.freedesktop.RealtimeKit1",
+ "MakeThreadHighPriorityWithPID")))
+ {
+ dbus_message_set_no_reply(msg, 1);
+
+ if (dbus_message_append_args(msg,
+ DBUS_TYPE_UINT64, &process,
+ DBUS_TYPE_UINT64, &thread,
+ DBUS_TYPE_INT32, &niceness,
+ DBUS_TYPE_INVALID) &&
+ dbus_connection_send(dbus, msg, NULL))
+ ret = 0;
+
+ dbus_message_unref(msg);
+ }
+
+ dbus_connection_unref(dbus);
+ }
+
+ return ret;
+}
+#endif
#ifdef __i386__
static const unsigned int supported_cpus = CPU_FLAG(CPU_x86);
@@ -598,7 +670,8 @@ affinity_t get_thread_affinity( struct thread *thread )
return mask;
}
-#if defined(HAVE_SCHED_SETSCHEDULER) || defined(HAVE_SETPRIORITY)
+#if defined(HAVE_SCHED_SETSCHEDULER) || defined(HAVE_SETPRIORITY) || \
+ defined(HAVE_DBUS_DBUS_H)
static int get_unix_priority( int priority_class, int priority )
{
switch (priority_class) {
@@ -718,6 +797,11 @@ int set_thread_priority( struct thread* thread, int priority_class, int priority
param.sched_priority = get_unix_priority( priority_class, priority );
if (sched_setscheduler( thread->unix_tid, SCHED_RR|SCHED_RESET_ON_FORK, ¶m ) == 0)
return 0;
+#endif
+#ifdef HAVE_DBUS_DBUS_H
+ if (rtkit_set_realtime( thread->unix_pid, thread->unix_tid,
+ get_unix_priority( priority_class, priority ) ) == 0)
+ return 0;
#endif
}
else
@@ -726,6 +809,11 @@ int set_thread_priority( struct thread* thread, int priority_class, int priority
if (setpriority( PRIO_PROCESS, thread->unix_tid,
get_unix_priority( priority_class, priority ) ) == 0)
return 0;
+#endif
+#ifdef HAVE_DBUS_DBUS_H
+ if (rtkit_set_niceness( thread->unix_pid, thread->unix_tid,
+ get_unix_priority( priority_class, priority ) ) == 0)
+ return 0;
#endif
}
#endif