Skip to content

Commit 7d9739d

Browse files
committed
apu/vp: Make number of voice workers dynamic
Adds a new config option to control number of workers. If the value of the option is 0 (default), then the logical CPU count, as reported by SDL, is used.
1 parent 8881537 commit 7d9739d

File tree

5 files changed

+21
-8
lines changed

5 files changed

+21
-8
lines changed

config_spec.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,10 @@ display:
214214
default: false
215215

216216
audio:
217+
vp:
218+
num_workers:
219+
type: integer
220+
default: 0 # 0 = auto
217221
use_dsp: bool
218222
hrtf:
219223
type: bool

hw/xbox/mcpx/apu/apu_debug.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
#include <stdbool.h>
2424
#include <stdint.h>
2525

26+
#define MAX_VOICE_WORKERS 16
27+
2628
typedef enum McpxApuDebugMonitorPoint {
2729
MCPX_APU_DEBUG_MON_AC97,
2830
MCPX_APU_DEBUG_MON_VP,
@@ -55,10 +57,11 @@ struct McpxApuDebugVoice
5557
struct McpxApuDebugVp
5658
{
5759
struct McpxApuDebugVoice v[256];
60+
int num_workers;
5861
struct {
5962
int num_voices;
6063
int time_us;
61-
} workers[16];
64+
} workers[MAX_VOICE_WORKERS];
6265
int total_worker_time_us;
6366
};
6467

hw/xbox/mcpx/apu/vp/vp.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1717,7 +1717,7 @@ static void voice_work_schedule(MCPXAPUState *d)
17171717

17181718
if (!group) {
17191719
next_worker_to_schedule =
1720-
(next_worker_to_schedule + 1) % NUM_VOICE_WORKERS;
1720+
(next_worker_to_schedule + 1) % vwd->num_workers;
17211721
}
17221722
}
17231723
}
@@ -1761,15 +1761,20 @@ static void voice_work_init(MCPXAPUState *d)
17611761
{
17621762
VoiceWorkDispatch *vwd = &d->vp.voice_work_dispatch;
17631763

1764+
int num_workers = g_config.audio.vp.num_workers ?: SDL_GetCPUCount();
1765+
vwd->num_workers = MAX(1, MIN(num_workers, MAX_VOICE_WORKERS));
1766+
vwd->workers = g_malloc0_n(vwd->num_workers, sizeof(VoiceWorker));
17641767
vwd->workers_should_exit = false;
17651768
vwd->workers_pending = 0;
17661769
vwd->queue_len = 0;
17671770

1771+
g_dbg.vp.num_workers = vwd->num_workers;
1772+
17681773
qemu_mutex_init(&vwd->lock);
17691774
qemu_mutex_lock(&vwd->lock);
17701775
qemu_cond_init(&vwd->work_pending);
17711776
qemu_cond_init(&vwd->work_finished);
1772-
for (int i = 0; i < NUM_VOICE_WORKERS; i++) {
1777+
for (int i = 0; i < vwd->num_workers; i++) {
17731778
vwd->workers_pending |= 1 << i;
17741779
qemu_thread_create(&vwd->workers[i].thread, "mcpx.voice_worker",
17751780
voice_worker_thread, d, QEMU_THREAD_JOINABLE);
@@ -1787,9 +1792,11 @@ static void voice_work_finalize(MCPXAPUState *d)
17871792
vwd->workers_should_exit = true;
17881793
qemu_cond_broadcast(&vwd->work_pending);
17891794
qemu_mutex_unlock(&vwd->lock);
1790-
for (int i = 0; i < NUM_VOICE_WORKERS; i++) {
1795+
for (int i = 0; i < vwd->num_workers; i++) {
17911796
qemu_thread_join(&vwd->workers[i].thread);
17921797
}
1798+
g_free(vwd->workers);
1799+
vwd->workers = NULL;
17931800
}
17941801

17951802
void mcpx_apu_vp_frame(MCPXAPUState *d, float mixbins[NUM_MIXBINS][NUM_SAMPLES_PER_FRAME])

hw/xbox/mcpx/apu/vp/vp.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@
3131
#include "svf.h"
3232
#include "hrtf.h"
3333

34-
#define NUM_VOICE_WORKERS 16
35-
3634
typedef struct MCPXAPUState MCPXAPUState;
3735

3836
typedef struct MCPXAPUVPSSLData {
@@ -65,7 +63,8 @@ typedef struct VoiceWorker {
6563

6664
typedef struct VoiceWorkDispatch {
6765
QemuMutex lock;
68-
VoiceWorker workers[NUM_VOICE_WORKERS];
66+
int num_workers;
67+
VoiceWorker *workers;
6968
bool workers_should_exit;
7069
QemuCond work_pending;
7170
uint64_t workers_pending;

ui/xui/debug.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ void DebugApuWindow::Draw()
233233
ImGui::Text(" W: # us");
234234
ImGui::SameLine();
235235
ImGui::Text(" W: # us");
236-
for (int i = 0; i < 16; i++) {
236+
for (int i = 0; i < dbg->vp.num_workers; i++) {
237237
if (i % 2) ImGui::SameLine();
238238
ImGui::Text("%2d:%2d %3d", i, dbg->vp.workers[i].num_voices,
239239
dbg->vp.workers[i].time_us);

0 commit comments

Comments
 (0)