Skip to content

Commit 161ccba

Browse files
committed
MOD Audio specific optimizations
Signed-off-by: falkTX <falktx@falktx.com>
1 parent d5dd20d commit 161ccba

File tree

7 files changed

+64
-7
lines changed

7 files changed

+64
-7
lines changed

common/JackClient.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,37 @@ namespace Jack
4141

4242
#define IsRealTime() ((fProcess != NULL) | (fThreadFun != NULL) | (fSync != NULL) | (fTimebase != NULL))
4343

44+
/* Disables denormal numbers in floating point calculation. Denormal numbers
45+
* happens often in IIR filters, and it can be very slow.
46+
*/
47+
/* Taken from cras/src/dsp/dsp_util.c in Chromium OS code.
48+
* Copyright (c) 2013 The Chromium OS Authors. */
49+
static void dsp_enable_flush_denormal_to_zero()
50+
{
51+
#if defined(__i386__) || defined(__x86_64__)
52+
unsigned int mxcsr;
53+
mxcsr = __builtin_ia32_stmxcsr();
54+
__builtin_ia32_ldmxcsr(mxcsr | 0x8040);
55+
#elif defined(__aarch64__)
56+
uint64_t cw;
57+
__asm__ __volatile__ (
58+
"mrs %0, fpcr \n"
59+
"orr %0, %0, #0x1000000 \n"
60+
"msr fpcr, %0 \n"
61+
"isb \n"
62+
: "=r"(cw) :: "memory");
63+
#elif defined(__arm__)
64+
uint32_t cw;
65+
__asm__ __volatile__ (
66+
"vmrs %0, fpscr \n"
67+
"orr %0, %0, #0x1000000 \n"
68+
"vmsr fpscr, %0 \n"
69+
: "=r"(cw) :: "memory");
70+
#else
71+
#warning "Don't know how to disable denorms. Performace may suffer."
72+
#endif
73+
}
74+
4475
JackClient::JackClient(JackSynchro* table):fThread(this)
4576
{
4677
fSynchroTable = table;

common/JackEngine.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@ extern const char* JACK_METADATA_PRETTY_NAME;
4040
namespace Jack
4141
{
4242

43+
static bool areFutexesOptimizedForInternalClients()
44+
{
45+
static bool ret = (getenv("JACK_NO_OPTIMIZATIONS") == NULL);
46+
return ret;
47+
}
48+
4349
JackEngine::JackEngine(JackGraphManager* manager,
4450
JackSynchro* table,
4551
JackEngineControl* control,
@@ -635,7 +641,7 @@ int JackEngine::ClientExternalOpen(const char* name, int pid, jack_uuid_t uuid,
635641

636642
JackExternalClient* client = new JackExternalClient();
637643

638-
if (!fSynchroTable[refnum].Allocate(real_name, fEngineControl->fServerName, 0)) {
644+
if (!fSynchroTable[refnum].Allocate(real_name, fEngineControl->fServerName, 0, false)) {
639645
jack_error("Cannot allocate synchro");
640646
goto error;
641647
}
@@ -685,7 +691,7 @@ int JackEngine::ClientInternalOpen(const char* name, int* ref, JackEngineControl
685691
goto error;
686692
}
687693

688-
if (!fSynchroTable[refnum].Allocate(name, fEngineControl->fServerName, 0)) {
694+
if (!fSynchroTable[refnum].Allocate(name, fEngineControl->fServerName, 0, areFutexesOptimizedForInternalClients())) {
689695
jack_error("Cannot allocate synchro");
690696
goto error;
691697
}

common/JackMidiAsyncWaitQueue.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,17 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
2525

2626
using Jack::JackMidiAsyncWaitQueue;
2727

28+
static bool areFutexesOptimizedForInternalClients()
29+
{
30+
static bool ret = (getenv("JACK_NO_OPTIMIZATIONS") == NULL);
31+
return ret;
32+
}
33+
2834
JackMidiAsyncWaitQueue::JackMidiAsyncWaitQueue(size_t max_bytes,
2935
size_t max_messages):
3036
JackMidiAsyncQueue(max_bytes, max_messages)
3137
{
32-
if (semaphore.Allocate("JackMidiAsyncWaitQueue", "midi-thread", 0)) {
38+
if (semaphore.Allocate("JackMidiAsyncWaitQueue", "midi-thread", 0, areFutexesOptimizedForInternalClients())) {
3339
throw std::bad_alloc();
3440
}
3541
}

linux/JackLinuxFutex.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,15 @@ void JackLinuxFutex::BuildName(const char* client_name, const char* server_name,
4848
{
4949
char ext_client_name[SYNC_MAX_NAME_SIZE + 1];
5050
JackTools::RewriteName(client_name, ext_client_name);
51+
#ifdef __MOD_DEVICES__
52+
snprintf(res, size, "jack_sem.%s", ext_client_name);
53+
#else
5154
if (fPromiscuous) {
5255
snprintf(res, size, "jack_sem.%s_%s", server_name, ext_client_name);
5356
} else {
5457
snprintf(res, size, "jack_sem.%d_%s_%s", JackTools::GetUID(), server_name, ext_client_name);
5558
}
59+
#endif
5660
}
5761

5862
bool JackLinuxFutex::Signal()
@@ -78,7 +82,17 @@ bool JackLinuxFutex::Signal()
7882

7983
bool JackLinuxFutex::SignalAll()
8084
{
81-
return Signal();
85+
if (!fFutex) {
86+
jack_error("JackLinuxFutex::Signal name = %s already deallocated!!", fName);
87+
return false;
88+
}
89+
90+
if (fFlush) {
91+
return true;
92+
}
93+
94+
::syscall(SYS_futex, fFutex, fFutex->internal ? FUTEX_WAKE_PRIVATE : FUTEX_WAKE, INT32_MAX, NULL, NULL, 0);
95+
return true;
8296
}
8397

8498
bool JackLinuxFutex::Wait()

linux/JackLinuxFutex.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class SERVER_EXPORT JackLinuxFutex : public detail::JackSynchro
6969
bool Wait();
7070
bool TimedWait(long usec);
7171

72-
bool Allocate(const char* name, const char* server_name, int value, bool internal = false);
72+
bool Allocate(const char* name, const char* server_name, int value, bool internal);
7373
bool Connect(const char* name, const char* server_name);
7474
bool ConnectInput(const char* name, const char* server_name);
7575
bool ConnectOutput(const char* name, const char* server_name);

windows/JackWinSemaphore.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ bool JackWinSemaphore::Disconnect()
129129
}
130130
}
131131

132-
bool JackWinSemaphore::Allocate(const char* name, const char* server_name, int value)
132+
bool JackWinSemaphore::Allocate(const char* name, const char* server_name, int value, bool)
133133
{
134134
BuildName(name, server_name, fName, sizeof(fName));
135135
jack_log("JackWinSemaphore::Allocate name = %s val = %ld", fName, value);

windows/JackWinSemaphore.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class JackWinSemaphore : public detail::JackSynchro
5656
bool Wait();
5757
bool TimedWait(long usec);
5858

59-
bool Allocate(const char* name, const char* server_name, int value);
59+
bool Allocate(const char* name, const char* server_name, int value, bool internal = false);
6060
bool Connect(const char* name, const char* server_name);
6161
bool ConnectInput(const char* name, const char* server_name);
6262
bool ConnectOutput(const char* name, const char* server_name);

0 commit comments

Comments
 (0)