mirror of
https://github.com/RPCS3/rpcs3.git
synced 2024-11-22 18:53:28 +01:00
SPU: Untangle VM lock to avoid deadlocks
This commit is contained in:
parent
ab31e96385
commit
7698064f5a
@ -323,6 +323,8 @@ void spu_load_exec(const spu_exec_object& elf)
|
||||
spu_thread::g_raw_spu_ctr++;
|
||||
|
||||
auto spu = idm::make_ptr<named_thread<spu_thread>>(nullptr, 0, "test_spu", 0);
|
||||
ensure(vm::get(vm::spu)->falloc(spu->vm_offset(), SPU_LS_SIZE, &spu->shm, vm::page_size_64k));
|
||||
spu->map_ls(*spu->shm, spu->ls);
|
||||
|
||||
for (const auto& prog : elf.progs)
|
||||
{
|
||||
@ -343,6 +345,8 @@ void spu_load_rel_exec(const spu_rel_object& elf)
|
||||
spu_thread::g_raw_spu_ctr++;
|
||||
|
||||
auto spu = idm::make_ptr<named_thread<spu_thread>>(nullptr, 0, "test_spu", 0);
|
||||
ensure(vm::get(vm::spu)->falloc(spu->vm_offset(), SPU_LS_SIZE, &spu->shm, vm::page_size_64k));
|
||||
spu->map_ls(*spu->shm, spu->ls);
|
||||
|
||||
u64 total_memsize = 0;
|
||||
|
||||
|
@ -1656,11 +1656,11 @@ spu_thread::~spu_thread()
|
||||
perf_log.notice("Perf stats for PUTLLC reload: successs %u, failure %u", last_succ, last_fail);
|
||||
}
|
||||
|
||||
u8* spu_thread::map_ls(utils::shm& shm)
|
||||
u8* spu_thread::map_ls(utils::shm& shm, void* ptr)
|
||||
{
|
||||
vm::writer_lock mlock;
|
||||
|
||||
const auto ls = static_cast<u8*>(ensure(utils::memory_reserve(SPU_LS_SIZE * 5, nullptr, true))) + SPU_LS_SIZE * 2;
|
||||
const auto ls = ptr ? static_cast<u8*>(ptr) : static_cast<u8*>(ensure(utils::memory_reserve(SPU_LS_SIZE * 5, nullptr, true))) + SPU_LS_SIZE * 2;
|
||||
ensure(shm.map_critical(ls - SPU_LS_SIZE).first && shm.map_critical(ls).first && shm.map_critical(ls + SPU_LS_SIZE).first);
|
||||
return ls;
|
||||
}
|
||||
@ -1671,7 +1671,7 @@ spu_thread::spu_thread(lv2_spu_group* group, u32 index, std::string_view name, u
|
||||
, index(index)
|
||||
, thread_type(group ? spu_type::threaded : is_isolated ? spu_type::isolated : spu_type::raw)
|
||||
, shm(std::make_shared<utils::shm>(SPU_LS_SIZE))
|
||||
, ls(map_ls(*this->shm))
|
||||
, ls(static_cast<u8*>(utils::memory_reserve(SPU_LS_SIZE * 5, nullptr, true)) + SPU_LS_SIZE * 2)
|
||||
, option(option)
|
||||
, lv2_id(lv2_id)
|
||||
, spu_tname(make_single<std::string>(name))
|
||||
@ -1696,16 +1696,6 @@ spu_thread::spu_thread(lv2_spu_group* group, u32 index, std::string_view name, u
|
||||
utils::memory_commit(vm::g_stat_addr + vm_offset(), SPU_LS_SIZE);
|
||||
}
|
||||
|
||||
if (!group)
|
||||
{
|
||||
ensure(vm::get(vm::spu)->falloc(vm_offset(), SPU_LS_SIZE, &shm, vm::page_size_64k));
|
||||
}
|
||||
else
|
||||
{
|
||||
// alloc_hidden indicates falloc to allocate page with no access rights in base memory
|
||||
ensure(vm::get(vm::spu)->falloc(vm_offset(), SPU_LS_SIZE, &shm, static_cast<u64>(vm::page_size_64k) | static_cast<u64>(vm::alloc_hidden)));
|
||||
}
|
||||
|
||||
if (g_cfg.core.spu_decoder == spu_decoder_type::asmjit || g_cfg.core.spu_decoder == spu_decoder_type::llvm)
|
||||
{
|
||||
if (g_cfg.core.spu_block_size != spu_block_size_type::safe)
|
||||
|
@ -918,7 +918,7 @@ public:
|
||||
return group ? SPU_FAKE_BASE_ADDR + SPU_LS_SIZE * (id & 0xffffff) : RAW_SPU_BASE_ADDR + RAW_SPU_OFFSET * index;
|
||||
}
|
||||
|
||||
static u8* map_ls(utils::shm& shm);
|
||||
static u8* map_ls(utils::shm& shm, void* ptr = nullptr);
|
||||
|
||||
// Returns true if reservation existed but was just discovered to be lost
|
||||
// It is safe to use on any address, even if not directly accessed by SPU (so it's slower)
|
||||
|
@ -707,6 +707,11 @@ error_code sys_spu_thread_initialize(ppu_thread& ppu, vm::ptr<u32> thread, u32 g
|
||||
return spu;
|
||||
}));
|
||||
|
||||
// alloc_hidden indicates falloc to allocate page with no access rights in base memory
|
||||
auto& spu = group->threads[inited];
|
||||
ensure(vm::get(vm::spu)->falloc(spu->vm_offset(), SPU_LS_SIZE, &spu->shm, static_cast<u64>(vm::page_size_64k) | static_cast<u64>(vm::alloc_hidden)));
|
||||
spu->map_ls(*spu->shm, spu->ls);
|
||||
|
||||
*thread = tid;
|
||||
|
||||
group->args[inited] = {arg->arg1, arg->arg2, arg->arg3, arg->arg4};
|
||||
@ -2206,9 +2211,11 @@ error_code sys_raw_spu_create(ppu_thread& ppu, vm::ptr<u32> id, vm::ptr<void> at
|
||||
index = 0;
|
||||
}
|
||||
|
||||
const u32 tid = idm::make<named_thread<spu_thread>>(nullptr, index, "", index);
|
||||
const auto spu = idm::make_ptr<named_thread<spu_thread>>(nullptr, index, "", index);
|
||||
ensure(vm::get(vm::spu)->falloc(spu->vm_offset(), SPU_LS_SIZE, &spu->shm, vm::page_size_64k));
|
||||
spu->map_ls(*spu->shm, spu->ls);
|
||||
|
||||
spu_thread::g_raw_spu_id[index] = (ensure(tid));
|
||||
spu_thread::g_raw_spu_id[index] = idm::last_id();
|
||||
|
||||
*id = index;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user