Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PPU: Sleep after returning from thread entry function #13966

Merged
merged 2 commits into from
Jun 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions rpcs3/Emu/Cell/PPUThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2055,12 +2055,7 @@ void ppu_thread::fast_call(u32 addr, u64 rtoc)

auto at_ret = [&]()
{
if (std::uncaught_exceptions())
{
cpu_on_stop();
current_function = old_func;
}
else if (old_cia)
if (old_cia)
{
if (state & cpu_flag::again)
{
Expand All @@ -2071,6 +2066,18 @@ void ppu_thread::fast_call(u32 addr, u64 rtoc)
gpr[2] = old_rtoc;
lr = old_lr;
}
else if (state & cpu_flag::ret && cia == g_fxo->get<ppu_function_manager>().func_addr(1, true) + 4)
{
std::string ret;
dump_all(ret);

ppu_log.error("Returning from the thread entry function! (func=0x%x)", entry_func.addr);
ppu_log.notice("Thread context: %s", ret);

lv2_obj::sleep(*this);

state += cpu_flag::again; // For savestates
}

current_function = old_func;
g_tls_log_prefix = old_fmt;
Expand Down
17 changes: 7 additions & 10 deletions rpcs3/Emu/Cell/lv2/sys_ppu_thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,10 +201,6 @@ error_code sys_ppu_thread_join(ppu_thread& ppu, u32 thread_id, vm::ptr<u64> vptr
lv2_obj::prepare_for_sleep(ppu);
lv2_obj::sleep(ppu);
}
else if (result == CELL_EAGAIN)
{
thread.joiner.notify_one();
}

notify.cleanup();
return result;
Expand All @@ -220,6 +216,12 @@ error_code sys_ppu_thread_join(ppu_thread& ppu, u32 thread_id, vm::ptr<u64> vptr
return thread.ret;
}

if (thread.ret == CELL_EAGAIN)
{
// Notify thread if waiting for a joiner
thread->joiner.notify_one();
}

// Wait for cleanup
(*thread.ptr)();

Expand Down Expand Up @@ -287,11 +289,6 @@ error_code sys_ppu_thread_detach(ppu_thread& ppu, u32 thread_id)
return {};
});

if (result == CELL_EAGAIN)
{
thread.joiner.notify_one();
}

// Remove ID on EAGAIN
return result != CELL_EAGAIN;
});
Expand All @@ -300,7 +297,7 @@ error_code sys_ppu_thread_detach(ppu_thread& ppu, u32 thread_id)
{
if (result == CELL_EAGAIN)
{
// Join thread (it is detached from IDM now so it must be done explicitly now)
// Join and notify thread (it is detached from IDM now so it must be done explicitly now)
*ptr = thread_state::finished;
}

Expand Down