SPU: Improve SPURS Task limit algorithm

This commit is contained in:
Elad 2024-09-26 20:24:24 +03:00
parent 9dd0b055d0
commit 10dece1c80

View File

@ -4894,15 +4894,11 @@ bool spu_thread::process_mfc_cmd()
// Avoid logging useless commands if there is no reservation // Avoid logging useless commands if there is no reservation
const bool dump = g_cfg.core.mfc_debug && raddr; const bool dump = g_cfg.core.mfc_debug && raddr;
const bool is_spurs_task_wait = pc == 0x11e4 && group->max_run != group->max_num && spurs_addr != 0u - 0x80 && !spurs_waited; const bool is_spurs_task_wait = pc == 0x11e4 && spurs_addr == raddr && group->max_run != group->max_num && !spurs_waited;
if (is_spurs_task_wait) if (is_spurs_task_wait)
{ {
const u32 prev_running = group->spurs_running;
// Wait for other threads to complete their tasks (temporarily) // Wait for other threads to complete their tasks (temporarily)
if (!is_stopped())
{
const u32 max_run = group->max_run; const u32 max_run = group->max_run;
u32 prev_running = group->spurs_running; u32 prev_running = group->spurs_running;
@ -4910,18 +4906,17 @@ bool spu_thread::process_mfc_cmd()
if (prev_running > max_run) if (prev_running > max_run)
{ {
const u64 before = get_system_time(); const u64 before = get_system_time();
u64 current = before;
spurs_waited = true;
while (true) while (true)
{ {
thread_ctrl::wait_on(group->spurs_running, prev_running, 10000);
if (is_stopped()) if (is_stopped())
{ {
break; break;
} }
thread_ctrl::wait_on(group->spurs_running, prev_running, 20000 - (current - before));
prev_running = group->spurs_running; prev_running = group->spurs_running;
if (prev_running <= max_run) if (prev_running <= max_run)
@ -4929,7 +4924,9 @@ bool spu_thread::process_mfc_cmd()
break; break;
} }
if (get_system_time() - before >= 4000) current = get_system_time();
if (current - before >= 18000u)
{ {
// Timed-out // Timed-out
break; break;
@ -4937,7 +4934,6 @@ bool spu_thread::process_mfc_cmd()
} }
} }
} }
}
if (do_putllc(ch_mfc_cmd)) if (do_putllc(ch_mfc_cmd))
@ -5539,7 +5535,7 @@ s64 spu_thread::get_ch_value(u32 ch)
case SPU_RdEventStat: case SPU_RdEventStat:
{ {
const bool is_spurs_task_wait = pc == 0x11a8 && group->max_run != group->max_num && spurs_addr == raddr && !spurs_waited; const bool is_spurs_task_wait = pc == 0x11a8 && spurs_addr == raddr && group->max_run != group->max_num && !spurs_waited;
if (is_spurs_task_wait) if (is_spurs_task_wait)
{ {
@ -5556,7 +5552,7 @@ s64 spu_thread::get_ch_value(u32 ch)
if (prev_running == group->max_run) if (prev_running == group->max_run)
{ {
group->spurs_running.notify_all(); group->spurs_running.notify_one();
} }
} }
@ -5573,9 +5569,9 @@ s64 spu_thread::get_ch_value(u32 ch)
{ {
const u32 max_run = group->max_run; const u32 max_run = group->max_run;
u32 prev_running = group->spurs_running.fetch_op([max = max_run](u32& x) u32 prev_running = group->spurs_running.fetch_op([max_run](u32& x)
{ {
if (x < max) if (x < max_run)
{ {
x++; x++;
return true; return true;
@ -5587,18 +5583,19 @@ s64 spu_thread::get_ch_value(u32 ch)
if (prev_running >= max_run) if (prev_running >= max_run)
{ {
const u64 before = get_system_time(); const u64 before = get_system_time();
u64 current = before;
spurs_waited = true; spurs_waited = true;
while (true) while (true)
{ {
thread_ctrl::wait_on(group->spurs_running, prev_running, 10000);
if (is_stopped()) if (is_stopped())
{ {
break; break;
} }
thread_ctrl::wait_on(group->spurs_running, prev_running, 20000 - (current - before));
prev_running = group->spurs_running.fetch_op([max_run](u32& x) prev_running = group->spurs_running.fetch_op([max_run](u32& x)
{ {
if (x < max_run) if (x < max_run)
@ -5615,7 +5612,9 @@ s64 spu_thread::get_ch_value(u32 ch)
break; break;
} }
if (get_system_time() - before >= 4000) current = get_system_time();
if (current - before >= 18000u)
{ {
// Timed-out // Timed-out
group->spurs_running++; group->spurs_running++;