sys_spu: Untangle IDM mutex from sys_spu's
Some checks are pending
Generate Translation Template / Generate Translation Template (push) Waiting to run
Build RPCS3 / RPCS3 Linux ${{ matrix.os }} ${{ matrix.compiler }} (/rpcs3/.ci/build-linux-aarch64.sh, gcc, rpcs3/rpcs3-ci-jammy-aarch64:1.6, ubuntu-24.04-arm) (push) Waiting to run
Build RPCS3 / RPCS3 Linux ${{ matrix.os }} ${{ matrix.compiler }} (/rpcs3/.ci/build-linux.sh, gcc, rpcs3/rpcs3-ci-jammy:1.6, ubuntu-24.04) (push) Waiting to run
Build RPCS3 / RPCS3 Linux ${{ matrix.os }} ${{ matrix.compiler }} (a1d35836e8d45bfc6f63c26f0a3e5d46ef622fe1, rpcs3/rpcs3-binaries-linux-arm64, /rpcs3/.ci/build-linux-aarch64.sh, clang, rpcs3/rpcs3-ci-jammy-aarch64:1.6, ubuntu-24.04-arm) (push) Waiting to run
Build RPCS3 / RPCS3 Linux ${{ matrix.os }} ${{ matrix.compiler }} (d812f1254a1157c80fd402f94446310560f54e5f, rpcs3/rpcs3-binaries-linux, /rpcs3/.ci/build-linux.sh, clang, rpcs3/rpcs3-ci-jammy:1.6, ubuntu-24.04) (push) Waiting to run
Build RPCS3 / RPCS3 Mac ${{ matrix.name }} (51ae32f468089a8169aaf1567de355ff4a3e0842, rpcs3/rpcs3-binaries-mac, arch -X86_64 .ci/build-mac.sh, Intel) (push) Waiting to run
Build RPCS3 / RPCS3 Mac ${{ matrix.name }} (8e21bdbc40711a3fccd18fbf17b742348b0f4281, rpcs3/rpcs3-binaries-mac-arm64, .ci/build-mac-arm64.sh, Apple Silicon) (push) Waiting to run
Build RPCS3 / RPCS3 Windows (push) Waiting to run
Build RPCS3 / RPCS3 Windows Clang (win64, clang, clang64) (push) Waiting to run
Build RPCS3 / RPCS3 FreeBSD (push) Waiting to run

This commit is contained in:
Elad 2025-09-21 17:48:09 +03:00
parent 9d020a3e59
commit 9524211b9a
3 changed files with 41 additions and 11 deletions

View File

@ -1899,6 +1899,12 @@ void spu_thread::cpu_task()
return fmt::format("%sSPU[0x%07x] Thread (%s) [0x%05x]", type >= spu_type::raw ? type == spu_type::isolated ? "Iso" : "Raw" : "", cpu->lv2_id, *name_cache.get(), cpu->pc);
};
if (get_type() == spu_type::threaded)
{
// Update thread name (spu_thread::lv2_id update)
thread_ctrl::set_name(*group->threads[group->threads_map[index]], thread_name);
}
constexpr u32 invalid_spurs = 0u - 0x80;
if (spurs_addr == 0)

View File

@ -768,7 +768,7 @@ public:
std::shared_ptr<utils::shm> shm; // SPU memory
const std::add_pointer_t<u8> ls; // SPU LS pointer
const u32 option; // sys_spu_thread_initialize option
const u32 lv2_id; // The actual id that is used by syscalls
u32 lv2_id; // The actual id that is used by syscalls
u32 spurs_addr = 0;
bool spurs_waited = false;
bool spurs_entered_wait = false;

View File

@ -776,8 +776,6 @@ error_code sys_spu_thread_initialize(ppu_thread& ppu, vm::ptr<u32> thread, u32 g
return CELL_ESRCH;
}
std::unique_lock lock(group->mutex);
if (auto state = +group->run_state; state != SPU_THREAD_GROUP_STATUS_NOT_INITIALIZED)
{
if (state == SPU_THREAD_GROUP_STATUS_DESTROYED)
@ -793,6 +791,34 @@ error_code sys_spu_thread_initialize(ppu_thread& ppu, vm::ptr<u32> thread, u32 g
return CELL_EBUSY;
}
const u32 inited_before_lock = group->init;
u32 tid = (inited_before_lock << 24) | (group_id & 0xffffff);
const auto spu_ptr = ensure(idm::make_ptr<named_thread<spu_thread>>(group.get(), spu_num, thread_name, tid, false, option));
std::unique_lock lock(group->mutex);
if (auto state = +group->run_state; state != SPU_THREAD_GROUP_STATUS_NOT_INITIALIZED)
{
lock.unlock();
idm::remove<named_thread<spu_thread>>(idm::last_id());
if (state == SPU_THREAD_GROUP_STATUS_DESTROYED)
{
return CELL_ESRCH;
}
return CELL_EBUSY;
}
if (group->threads_map[spu_num] != -1)
{
lock.unlock();
idm::remove<named_thread<spu_thread>>(idm::last_id());
return CELL_EBUSY;
}
if (option & SYS_SPU_THREAD_OPTION_ASYNC_INTR_ENABLE)
{
sys_spu.warning("Unimplemented SPU Thread options (0x%x)", option);
@ -800,15 +826,13 @@ error_code sys_spu_thread_initialize(ppu_thread& ppu, vm::ptr<u32> thread, u32 g
const u32 inited = group->init;
const u32 tid = (inited << 24) | (group_id & 0xffffff);
tid = (inited << 24) | (group_id & 0xffffff);
ensure(idm::import<named_thread<spu_thread>>([&]()
{
const auto spu = stx::make_shared<named_thread<spu_thread>>(group.get(), spu_num, thread_name, tid, false, option);
group->threads[inited] = spu;
group->threads_map[spu_num] = static_cast<s8>(inited);
return spu;
}));
// Update lv2_id (potentially changed after locking)
spu_ptr->lv2_id = tid;
group->threads[inited] = spu_ptr;
group->threads_map[spu_num] = static_cast<s8>(inited);
// alloc_hidden indicates falloc to allocate page with no access rights in base memory
auto& spu = group->threads[inited];