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

sys_event: Save ID of self event queue #10252

Merged
merged 4 commits into from
May 9, 2021
Merged
Show file tree
Hide file tree
Changes from 3 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
13 changes: 11 additions & 2 deletions rpcs3/Emu/Cell/lv2/sys_event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@

LOG_CHANNEL(sys_event);

lv2_event_queue::lv2_event_queue(u32 protocol, s32 type, u64 name, u64 ipc_key, s32 size) noexcept
: protocol{protocol}
, id(idm::last_id())
, type(type)
, name(name)
, key(ipc_key)
, size(size)
{
}

std::shared_ptr<lv2_event_queue> lv2_event_queue::find(u64 ipc_key)
{
if (ipc_key == SYS_EVENT_QUEUE_LOCAL)
Expand Down Expand Up @@ -112,7 +122,7 @@ error_code sys_event_queue_create(cpu_thread& cpu, vm::ptr<u32> equeue_id, vm::p
}

const u32 pshared = ipc_key == SYS_EVENT_QUEUE_LOCAL ? SYS_SYNC_NOT_PROCESS_SHARED : SYS_SYNC_PROCESS_SHARED;
constexpr u32 flags = SYS_SYNC_NEWLY_CREATED; // NOTE: This is inaccurate for multi-process
constexpr u32 flags = SYS_SYNC_NEWLY_CREATED;
const u64 name = attr->name_u64;

if (const auto error = lv2_obj::create<lv2_event_queue>(pshared, ipc_key, flags, [&]()
Expand Down Expand Up @@ -409,7 +419,6 @@ error_code sys_event_port_connect_local(cpu_thread& cpu, u32 eport_id, u32 equeu
}

port->queue = idm::get_unlocked<lv2_obj, lv2_event_queue>(equeue_id);
port->queue_id = equeue_id;

return CELL_OK;
}
Expand Down
11 changes: 2 additions & 9 deletions rpcs3/Emu/Cell/lv2/sys_event.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ struct lv2_event_queue final : public lv2_obj
static const u32 id_base = 0x8d000000;

const lv2_protocol protocol;
const u32 id;
const s32 type;
const u64 name;
const u64 key;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const lv2_protocol protocol;
const u32 id;
const s32 type;
const u64 name;
const u64 key;
const lv2_protocol protocol;
const u32 id;
const s16 type;
const s16 size;
const u64 name;
const u64 key;

Something like this

Expand All @@ -90,14 +91,7 @@ struct lv2_event_queue final : public lv2_obj
std::deque<lv2_event> events;
std::deque<cpu_thread*> sq;

lv2_event_queue(u32 protocol, s32 type, u64 name, u64 ipc_key, s32 size)
: protocol{protocol}
, type(type)
, name(name)
, key(ipc_key)
, size(size)
{
}
lv2_event_queue(u32 protocol, s32 type, u64 name, u64 ipc_key, s32 size) noexcept;

CellError send(lv2_event);

Expand All @@ -120,7 +114,6 @@ struct lv2_event_port final : lv2_obj

const s32 type; // Port type, either IPC or local
const u64 name; // Event source (generated from id and process id if not set)
u32 queue_id = 0; // Event queue ID (if IPC is used this value is meaningless)

std::shared_ptr<lv2_event_queue> queue; // Event queue this port is connected to

Expand Down
13 changes: 13 additions & 0 deletions rpcs3/Emu/Cell/lv2/sys_interrupt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,19 @@

LOG_CHANNEL(sys_interrupt);

lv2_int_tag::lv2_int_tag() noexcept
: id(idm::last_id())
{
}

lv2_int_serv::lv2_int_serv(const std::shared_ptr<named_thread<ppu_thread>>& thread, u64 arg1, u64 arg2) noexcept
: id(idm::last_id())
, thread(thread)
, arg1(arg1)
, arg2(arg2)
{
}

void lv2_int_serv::exec() const
{
thread->cmd_list
Expand Down
11 changes: 5 additions & 6 deletions rpcs3/Emu/Cell/lv2/sys_interrupt.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,22 @@ struct lv2_int_tag final : lv2_obj
{
static const u32 id_base = 0x0a000000;

const u32 id;
std::weak_ptr<struct lv2_int_serv> handler;

lv2_int_tag() noexcept;
};

struct lv2_int_serv final : lv2_obj
{
static const u32 id_base = 0x0b000000;

const u32 id;
const std::shared_ptr<named_thread<ppu_thread>> thread;
const u64 arg1;
const u64 arg2;

lv2_int_serv(const std::shared_ptr<named_thread<ppu_thread>>& thread, u64 arg1, u64 arg2)
: thread(thread)
, arg1(arg1)
, arg2(arg2)
{
}
lv2_int_serv(const std::shared_ptr<named_thread<ppu_thread>>& thread, u64 arg1, u64 arg2) noexcept;

void exec() const;
void join() const;
Expand Down
16 changes: 2 additions & 14 deletions rpcs3/Emu/Cell/lv2/sys_spu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1948,25 +1948,13 @@ error_code raw_spu_destroy(ppu_thread& ppu, u32 id)
// SLEEP
lv2_obj::sleep(ppu);
handler->join();
to_remove.emplace_back(std::move(handler), 0);
to_remove.emplace_back(std::move(handler), +handler->id);
}

to_remove.emplace_back(std::move(tag), 0);
to_remove.emplace_back(std::move(tag), +tag->id);
}
}

// Scan all kernel objects to determine IDs
idm::select<lv2_obj>([&](u32 id, lv2_obj& obj)
{
for (auto& pair : to_remove)
{
if (pair.first.get() == std::addressof(obj))
{
pair.second = id;
}
}
});

// Remove IDs
for (auto&& pair : to_remove)
{
Expand Down
4 changes: 2 additions & 2 deletions rpcs3/Emu/Cell/lv2/sys_sync.h
Original file line number Diff line number Diff line change
Expand Up @@ -224,13 +224,13 @@ struct lv2_obj
default: return CELL_EINVAL;
}

std::shared_ptr<T> result = make();

// EAGAIN for IDM IDs shortage
CellError error = CELL_EAGAIN;

if (!idm::import<lv2_obj, T>([&]() -> std::shared_ptr<T>
{
std::shared_ptr<T> result = make();

auto finalize_construct = [&]() -> std::shared_ptr<T>
{
if ((error = result->on_id_create()))
Expand Down
26 changes: 16 additions & 10 deletions rpcs3/rpcs3qt/kernel_explorer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "Emu/Cell/lv2/sys_vm.h"
#include "Emu/Cell/lv2/sys_net.h"
#include "Emu/Cell/lv2/sys_fs.h"
#include "Emu/Cell/lv2/sys_interrupt.h"
#include "Emu/Cell/Modules/cellSpurs.h"

#include "Emu/RSX/RSXThread.h"
Expand Down Expand Up @@ -348,14 +349,22 @@ void kernel_explorer::Update()
}
case SYS_INTR_TAG_OBJECT:
{
// auto& tag = static_cast<lv2_int_tag&>(obj);
add_leaf(node, qstr(fmt::format("Intr Tag 0x%08x", id)));
auto& tag = static_cast<lv2_int_tag&>(obj);
auto handler = tag.handler.lock();

if (handler && handler.get() == idm::check_unlocked<lv2_obj, lv2_int_serv>(handler->id))
{
add_leaf(node, qstr(fmt::format("Intr Tag 0x%08x, Handler: 0x%08x", id, handler->id)));
break;
}

add_leaf(node, qstr(fmt::format("Intr Tag 0x%08x, Handler: Unbound", id)));
break;
}
case SYS_INTR_SERVICE_HANDLE_OBJECT:
{
// auto& serv = static_cast<lv2_int_serv&>(obj);
add_leaf(node, qstr(fmt::format("Intr Svc 0x%08x", id)));
auto& serv = static_cast<lv2_int_serv&>(obj);
add_leaf(node, qstr(fmt::format("Intr Svc 0x%08x, PPU: 0x%07x, arg1: 0x%x, arg2: 0x%x", id, serv.thread->id, serv.arg1, serv.arg2)));
break;
}
case SYS_EVENT_QUEUE_OBJECT:
Expand All @@ -372,18 +381,15 @@ void kernel_explorer::Update()

if (const auto queue = ep.queue.get(); queue && queue->exists)
{
if (queue == idm::check_unlocked<lv2_obj, lv2_event_queue>(ep.queue_id))
if (queue == idm::check_unlocked<lv2_obj, lv2_event_queue>(queue->id))
{
// Type must be LOCAL here, but refer to the note below for why it is showed
add_leaf(node, qstr(fmt::format("Event Port 0x%08x: %s, Name: %#llx, Event Queue (ID): 0x%08x", id, type, ep.name, ep.queue_id)));
add_leaf(node, qstr(fmt::format("Event Port 0x%08x: %s, Name: %#llx, Event Queue (ID): 0x%08x", id, type, ep.name, queue->id)));
break;
}

// This code is unused until multi-process is implemented
if (queue == lv2_event_queue::find(queue->key).get())
{
// There are cases in which the attached queue by ID also has an IPC
// And the ID was destroyed but another was created for that same IPC
// So show event port type as well here because it not guaranteed to be IPC
add_leaf(node, qstr(fmt::format("Event Port 0x%08x: %s, Name: %#llx, Event Queue (IPC): %s", id, type, ep.name, queue->key)));
break;
}
Expand Down