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

Fix lv2 sys_lwcond/sys_lwmutex kernel explorer names #7797

Merged
merged 2 commits into from Mar 19, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion rpcs3/Emu/Cell/Modules/sys_lwcond_.cpp
Expand Up @@ -18,7 +18,7 @@ error_code sys_lwcond_create(ppu_thread& ppu, vm::ptr<sys_lwcond_t> lwcond, vm::
attrs->pshared = SYS_SYNC_NOT_PROCESS_SHARED;
attrs->name_u64 = attr->name_u64;

if (auto res = g_cfg.core.hle_lwmutex ? sys_cond_create(ppu, out_id, lwmutex->sleep_queue, attrs) : _sys_lwcond_create(ppu, out_id, lwmutex->sleep_queue, lwcond, attr->name_u64))
if (auto res = g_cfg.core.hle_lwmutex ? sys_cond_create(ppu, out_id, lwmutex->sleep_queue, attrs) : _sys_lwcond_create(ppu, out_id, lwmutex->sleep_queue, lwcond, std::bit_cast<be_t<u64>>(attr->name_u64)))
{
return res;
}
Expand Down
2 changes: 1 addition & 1 deletion rpcs3/Emu/Cell/Modules/sys_lwmutex_.cpp
Expand Up @@ -41,7 +41,7 @@ error_code sys_lwmutex_create(ppu_thread& ppu, vm::ptr<sys_lwmutex_t> lwmutex, v
attrs->flags = 0;
attrs->name_u64 = attr->name_u64;

if (error_code res = g_cfg.core.hle_lwmutex ? sys_mutex_create(ppu, out_id, attrs) : _sys_lwmutex_create(ppu, out_id, protocol, lwmutex, 0x80000001, attr->name_u64))
if (error_code res = g_cfg.core.hle_lwmutex ? sys_mutex_create(ppu, out_id, attrs) : _sys_lwmutex_create(ppu, out_id, protocol, lwmutex, 0x80000001, std::bit_cast<be_t<u64>>(attr->name_u64)))
{
return res;
}
Expand Down
32 changes: 25 additions & 7 deletions rpcs3/Emu/Cell/lv2/lv2.cpp
Expand Up @@ -1162,16 +1162,34 @@ bool lv2_obj::awake_unlocked(cpu_thread* cpu, s32 prio)

if (const auto ppu = g_ppu[i]; ppu == cpu)
{
if (g_ppu[i + 1]->prio != ppu->prio)
std::size_t j = i + 1;

for (; j < g_ppu.size(); j++)
{
if (g_ppu[j]->prio != ppu->prio)
{
break;
}
}

if (j == i + 1)
{
// Empty 'same prio' threads list
return false;
}
else

// Rotate current thread to the last position of the 'same prio' threads list
std::rotate(g_ppu.begin() + i, g_ppu.begin() + i + 1, g_ppu.begin() + j);

if (j <= g_cfg.core.ppu_threads + 0u)
{
g_ppu.erase(g_ppu.cbegin() + i);
ppu->start_time = get_guest_system_time();
break;
// Threads were rotated, but no context switch was made
return false;
}

ppu->start_time = get_guest_system_time();
cpu = nullptr; // Disable current thread enqueing, also enable threads list enqueing
break;
}
}
}
Expand Down Expand Up @@ -1227,9 +1245,9 @@ bool lv2_obj::awake_unlocked(cpu_thread* cpu, s32 prio)
}

// Remove pending if necessary
if (!g_pending.empty() && cpu && cpu == get_current_cpu_thread())
if (!g_pending.empty() && ((cpu && cpu == get_current_cpu_thread()) || prio == yield_cmd))
{
unqueue(g_pending, cpu);
unqueue(g_pending, get_current_cpu_thread());
}

// Suspend threads if necessary
Expand Down
2 changes: 1 addition & 1 deletion rpcs3/Emu/Cell/lv2/sys_lwcond.cpp
Expand Up @@ -13,7 +13,7 @@ error_code _sys_lwcond_create(ppu_thread& ppu, vm::ptr<u32> lwcond_id, u32 lwmut
{
vm::temporary_unlock(ppu);

sys_lwcond.warning(u8"_sys_lwcond_create(lwcond_id=*0x%x, lwmutex_id=0x%x, control=*0x%x, name=0x%llx (“%s”))", lwcond_id, lwmutex_id, control, name, lv2_obj::name64(name));
sys_lwcond.warning(u8"_sys_lwcond_create(lwcond_id=*0x%x, lwmutex_id=0x%x, control=*0x%x, name=0x%llx (“%s”))", lwcond_id, lwmutex_id, control, name, lv2_obj::name64(std::bit_cast<be_t<u64>>(name)));

u32 protocol;

Expand Down
4 changes: 2 additions & 2 deletions rpcs3/Emu/Cell/lv2/sys_lwcond.h
Expand Up @@ -25,7 +25,7 @@ struct lv2_lwcond final : lv2_obj
{
static const u32 id_base = 0x97000000;

const u64 name;
const be_t<u64> name;
const u32 lwid;
const u32 protocol;
vm::ptr<sys_lwcond_t> control;
Expand All @@ -35,7 +35,7 @@ struct lv2_lwcond final : lv2_obj
std::deque<cpu_thread*> sq;

lv2_lwcond(u64 name, u32 lwid, u32 protocol, vm::ptr<sys_lwcond_t> control)
: name(name)
: name(std::bit_cast<be_t<u64>>(name))
, lwid(lwid)
, protocol(protocol)
, control(control)
Expand Down
2 changes: 1 addition & 1 deletion rpcs3/Emu/Cell/lv2/sys_lwmutex.cpp
Expand Up @@ -12,7 +12,7 @@ error_code _sys_lwmutex_create(ppu_thread& ppu, vm::ptr<u32> lwmutex_id, u32 pro
{
vm::temporary_unlock(ppu);

sys_lwmutex.warning(u8"_sys_lwmutex_create(lwmutex_id=*0x%x, protocol=0x%x, control=*0x%x, has_name=0x%x, name=0x%llx (“%s”))", lwmutex_id, protocol, control, has_name, name, lv2_obj::name64(name));
sys_lwmutex.warning(u8"_sys_lwmutex_create(lwmutex_id=*0x%x, protocol=0x%x, control=*0x%x, has_name=0x%x, name=0x%llx (“%s”))", lwmutex_id, protocol, control, has_name, name, lv2_obj::name64(std::bit_cast<be_t<u64>>(name)));

if (protocol != SYS_SYNC_FIFO && protocol != SYS_SYNC_RETRY && protocol != SYS_SYNC_PRIORITY)
{
Expand Down
4 changes: 2 additions & 2 deletions rpcs3/Emu/Cell/lv2/sys_lwmutex.h
Expand Up @@ -57,7 +57,7 @@ struct lv2_lwmutex final : lv2_obj

const u32 protocol;
const vm::ptr<sys_lwmutex_t> control;
const u64 name;
const be_t<u64> name;

shared_mutex mutex;
atomic_t<s32> signaled{0};
Expand All @@ -66,7 +66,7 @@ struct lv2_lwmutex final : lv2_obj
lv2_lwmutex(u32 protocol, vm::ptr<sys_lwmutex_t> control, u64 name)
: protocol(protocol)
, control(control)
, name(name)
, name(std::bit_cast<be_t<u64>>(name))
{
}
};
Expand Down
2 changes: 1 addition & 1 deletion rpcs3/Emu/Cell/lv2/sys_ppu_thread.cpp
Expand Up @@ -82,7 +82,7 @@ s32 sys_ppu_thread_yield(ppu_thread& ppu)
{
sys_ppu_thread.trace("sys_ppu_thread_yield()");

// Return 1 on no-op, 0 on successful context switch
// Return 0 on successful context switch, 1 otherwise
return +!lv2_obj::yield(ppu);
}

Expand Down
2 changes: 1 addition & 1 deletion rpcs3/Emu/Cell/lv2/sys_sync.h
Expand Up @@ -159,7 +159,7 @@ struct lv2_obj
return awake_unlocked(thread, prio);
}

// Returns true and success, false if did nothing
// Returns true on successful context switch, false otherwise
static bool yield(cpu_thread& thread)
{
vm::temporary_unlock(thread);
Expand Down