Skip to content

Commit 5d76ba8

Browse files
committed
Anagram: Use cores 4-8 for RT, 0-3 for non-RT
Signed-off-by: falkTX <[email protected]>
1 parent 161ccba commit 5d76ba8

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

posix/JackPosixThread.cpp

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,17 @@ int JackPosixThread::StartImp(jack_native_thread_t* thread, int priority, int re
103103
struct sched_param rt_param;
104104
pthread_attr_init(&attributes);
105105
int res;
106+
#ifdef _DARKGLASS_DEVICE_PABLITO
107+
cpu_set_t cpuset;
108+
CPU_ZERO(&cpuset);
109+
if (realtime) {
110+
for (int i = 4; i < 8; ++i)
111+
CPU_SET(i, &cpuset);
112+
} else {
113+
for (int i = 0; i < 4; ++i)
114+
CPU_SET(i, &cpuset);
115+
}
116+
#endif
106117

107118
if ((res = pthread_attr_setdetachstate(&attributes, PTHREAD_CREATE_JOINABLE))) {
108119
jack_error("Cannot request joinable thread creation for thread res = %d", res);
@@ -143,6 +154,13 @@ int JackPosixThread::StartImp(jack_native_thread_t* thread, int priority, int re
143154
}
144155
}
145156

157+
#ifdef _DARKGLASS_DEVICE_PABLITO
158+
if ((res = pthread_attr_setaffinity_np(&attributes, sizeof(cpuset), &cpuset))) {
159+
jack_error("Cannot set thread affinity res = %d", res);
160+
return -1;
161+
}
162+
#endif
163+
146164
if ((res = pthread_attr_setstacksize(&attributes, THREAD_STACK))) {
147165
jack_error("Cannot set thread stack size res = %d", res);
148166
return -1;
@@ -238,9 +256,20 @@ int JackPosixThread::AcquireRealTimeImp(jack_native_thread_t thread, int priorit
238256
int res;
239257
memset(&rtparam, 0, sizeof(rtparam));
240258
rtparam.sched_priority = priority;
259+
#ifdef _DARKGLASS_DEVICE_PABLITO
260+
cpu_set_t cpuset;
261+
CPU_ZERO(&cpuset);
262+
for (int i = 4; i < 8; ++i)
263+
CPU_SET(i, &cpuset);
264+
#endif
241265

242266
jack_log("JackPosixThread::AcquireRealTimeImp priority = %d", priority);
243267

268+
#ifdef _DARKGLASS_DEVICE_PABLITO
269+
if ((res = pthread_setaffinity_np(thread, sizeof(cpuset), &cpuset)))
270+
jack_error("Cannot set thread affinity (%d: %s)", res, strerror(res));
271+
#endif
272+
244273
if ((res = pthread_setschedparam(thread, JACK_SCHED_POLICY, &rtparam)) == 0)
245274
return 0;
246275

@@ -272,11 +301,23 @@ int JackPosixThread::DropRealTimeImp(jack_native_thread_t thread)
272301
int res;
273302
memset(&rtparam, 0, sizeof(rtparam));
274303
rtparam.sched_priority = 0;
304+
#ifdef _DARKGLASS_DEVICE_PABLITO
305+
cpu_set_t cpuset;
306+
CPU_ZERO(&cpuset);
307+
for (int i = 0; i < 4; ++i)
308+
CPU_SET(i, &cpuset);
309+
#endif
275310

276311
if ((res = pthread_setschedparam(thread, SCHED_OTHER, &rtparam)) != 0) {
277312
jack_error("Cannot switch to normal scheduling priority(%s)", strerror(errno));
278313
return -1;
279314
}
315+
316+
#ifdef _DARKGLASS_DEVICE_PABLITO
317+
if ((res = pthread_setaffinity_np(thread, sizeof(cpuset), &cpuset)))
318+
jack_error("Cannot set thread affinity (%d: %s)", res, strerror(res));
319+
#endif
320+
280321
return 0;
281322
}
282323

0 commit comments

Comments
 (0)