Browse Source

Only use Engine::yieldWorkers() when we know it's needed in Core Audio. Use _mm_pause() in spinlocks.

tags/v1.0.0
Andrew Belt 5 years ago
parent
commit
269f9aca9b
5 changed files with 12 additions and 9 deletions
  1. +2
    -1
      Makefile
  2. +1
    -1
      include/simd/sse_mathfun.h
  3. +1
    -1
      include/simd/vector.hpp
  4. +3
    -3
      src/Core/AudioInterface.cpp
  5. +5
    -3
      src/engine/Engine.cpp

+ 2
- 1
Makefile View File

@@ -72,7 +72,8 @@ perf: $(TARGET)
# Requires gperftools # Requires gperftools
perf record --call-graph dwarf -o perf.data ./$< -d perf record --call-graph dwarf -o perf.data ./$< -d
# Analyze with hotspot (https://github.com/KDAB/hotspot) for example # Analyze with hotspot (https://github.com/KDAB/hotspot) for example
# hotspot perf.data
hotspot perf.data
rm perf.data


valgrind: $(TARGET) valgrind: $(TARGET)
# --gen-suppressions=yes # --gen-suppressions=yes


+ 1
- 1
include/simd/sse_mathfun.h View File

@@ -45,7 +45,7 @@ This derived source file is released under the zlib license.
*/ */




#include <emmintrin.h>
#include <x86intrin.h>




/** Generate 1.f without accessing memory */ /** Generate 1.f without accessing memory */


+ 1
- 1
include/simd/vector.hpp View File

@@ -1,6 +1,6 @@
#pragma once #pragma once
#include <cstring> #include <cstring>
#include <emmintrin.h>
#include <x86intrin.h>




namespace rack { namespace rack {


+ 3
- 3
src/Core/AudioInterface.cpp View File

@@ -132,7 +132,6 @@ struct AudioInterface : Module {
if (port.active && port.numInputs > 0) { if (port.active && port.numInputs > 0) {
// Wait until inputs are present // Wait until inputs are present
// Give up after a timeout in case the audio device is being unresponsive. // Give up after a timeout in case the audio device is being unresponsive.
APP->engine->yieldWorkers();
std::unique_lock<std::mutex> lock(port.engineMutex); std::unique_lock<std::mutex> lock(port.engineMutex);
auto cond = [&] { auto cond = [&] {
return (!port.inputBuffer.empty()); return (!port.inputBuffer.empty());
@@ -182,11 +181,12 @@ struct AudioInterface : Module {
if (outputBuffer.full()) { if (outputBuffer.full()) {
// Wait until enough outputs are consumed // Wait until enough outputs are consumed
// Give up after a timeout in case the audio device is being unresponsive. // Give up after a timeout in case the audio device is being unresponsive.
APP->engine->yieldWorkers();
std::unique_lock<std::mutex> lock(port.engineMutex);
auto cond = [&] { auto cond = [&] {
return (port.outputBuffer.size() < (size_t) port.blockSize); return (port.outputBuffer.size() < (size_t) port.blockSize);
}; };
if (!cond())
APP->engine->yieldWorkers();
std::unique_lock<std::mutex> lock(port.engineMutex);
auto timeout = std::chrono::milliseconds(200); auto timeout = std::chrono::milliseconds(200);
if (port.engineCv.wait_for(lock, timeout, cond)) { if (port.engineCv.wait_for(lock, timeout, cond)) {
// Push converted output // Push converted output


+ 5
- 3
src/engine/Engine.cpp View File

@@ -9,8 +9,7 @@
#include <condition_variable> #include <condition_variable>
#include <mutex> #include <mutex>
#include <atomic> #include <atomic>
#include <xmmintrin.h>
#include <pmmintrin.h>
#include <x86intrin.h>




namespace rack { namespace rack {
@@ -90,7 +89,9 @@ struct SpinBarrier {
count = 0; count = 0;
} }
else { else {
while (count != 0);
while (count != 0) {
_mm_pause();
}
} }
} }
}; };
@@ -127,6 +128,7 @@ struct HybridBarrier {
while (!yield) { while (!yield) {
if (count == 0) if (count == 0)
return; return;
_mm_pause();
} }


// Wait on mutex // Wait on mutex


Loading…
Cancel
Save