Port yuzu-emu/yuzu#4437: "core_timing: Make use of uintptr_t to represent user_data" (#5499)

Co-authored-by: LC <lioncash@users.noreply.github.com>
This commit is contained in:
Tobias 2022-11-06 02:24:45 +01:00 committed by GitHub
parent 7801907288
commit 3201943423
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 62 additions and 58 deletions

View file

@ -102,7 +102,7 @@ void CheatEngine::LoadCheatFile() {
} }
} }
void CheatEngine::RunCallback([[maybe_unused]] u64 userdata, s64 cycles_late) { void CheatEngine::RunCallback([[maybe_unused]] std::uintptr_t user_data, s64 cycles_late) {
{ {
std::shared_lock<std::shared_mutex> lock(cheats_list_mutex); std::shared_lock<std::shared_mutex> lock(cheats_list_mutex);
for (auto& cheat : cheats_list) { for (auto& cheat : cheats_list) {

View file

@ -35,7 +35,7 @@ public:
private: private:
void LoadCheatFile(); void LoadCheatFile();
void RunCallback(u64 userdata, s64 cycles_late); void RunCallback(std::uintptr_t user_data, s64 cycles_late);
std::vector<std::shared_ptr<CheatBase>> cheats_list; std::vector<std::shared_ptr<CheatBase>> cheats_list;
mutable std::shared_mutex cheats_list_mutex; mutable std::shared_mutex cheats_list_mutex;
Core::TimingEventType* event; Core::TimingEventType* event;

View file

@ -47,8 +47,8 @@ TimingEventType* Timing::RegisterEvent(const std::string& name, TimedCallback ca
return event_type; return event_type;
} }
void Timing::ScheduleEvent(s64 cycles_into_future, const TimingEventType* event_type, u64 userdata, void Timing::ScheduleEvent(s64 cycles_into_future, const TimingEventType* event_type,
std::size_t core_id) { std::uintptr_t user_data, std::size_t core_id) {
if (event_queue_locked) { if (event_queue_locked) {
return; return;
} }
@ -69,22 +69,22 @@ void Timing::ScheduleEvent(s64 cycles_into_future, const TimingEventType* event_
timer->ForceExceptionCheck(cycles_into_future); timer->ForceExceptionCheck(cycles_into_future);
timer->event_queue.emplace_back( timer->event_queue.emplace_back(
Event{timeout, timer->event_fifo_id++, userdata, event_type}); Event{timeout, timer->event_fifo_id++, user_data, event_type});
std::push_heap(timer->event_queue.begin(), timer->event_queue.end(), std::greater<>()); std::push_heap(timer->event_queue.begin(), timer->event_queue.end(), std::greater<>());
} else { } else {
timer->ts_queue.Push(Event{static_cast<s64>(timer->GetTicks() + cycles_into_future), 0, timer->ts_queue.Push(Event{static_cast<s64>(timer->GetTicks() + cycles_into_future), 0,
userdata, event_type}); user_data, event_type});
} }
} }
void Timing::UnscheduleEvent(const TimingEventType* event_type, u64 userdata) { void Timing::UnscheduleEvent(const TimingEventType* event_type, std::uintptr_t user_data) {
if (event_queue_locked) { if (event_queue_locked) {
return; return;
} }
for (auto timer : timers) { for (auto timer : timers) {
auto itr = std::remove_if( auto itr = std::remove_if(
timer->event_queue.begin(), timer->event_queue.end(), timer->event_queue.begin(), timer->event_queue.end(),
[&](const Event& e) { return e.type == event_type && e.userdata == userdata; }); [&](const Event& e) { return e.type == event_type && e.user_data == user_data; });
// Removing random items breaks the invariant so we have to re-establish it. // Removing random items breaks the invariant so we have to re-establish it.
if (itr != timer->event_queue.end()) { if (itr != timer->event_queue.end()) {
@ -215,7 +215,7 @@ void Timing::Timer::Advance() {
std::pop_heap(event_queue.begin(), event_queue.end(), std::greater<>()); std::pop_heap(event_queue.begin(), event_queue.end(), std::greater<>());
event_queue.pop_back(); event_queue.pop_back();
if (evt.type->callback != nullptr) { if (evt.type->callback != nullptr) {
evt.type->callback(evt.userdata, static_cast<int>(executed_ticks - evt.time)); evt.type->callback(evt.user_data, static_cast<int>(executed_ticks - evt.time));
} else { } else {
LOG_ERROR(Core, "Event '{}' has no callback", *evt.type->name); LOG_ERROR(Core, "Event '{}' has no callback", *evt.type->name);
} }

View file

@ -128,7 +128,7 @@ constexpr u64 cyclesToMs(s64 cycles) {
namespace Core { namespace Core {
using TimedCallback = std::function<void(u64 userdata, int cycles_late)>; using TimedCallback = std::function<void(std::uintptr_t user_data, int cycles_late)>;
struct TimingEventType { struct TimingEventType {
TimedCallback callback; TimedCallback callback;
@ -141,7 +141,7 @@ public:
struct Event { struct Event {
s64 time; s64 time;
u64 fifo_order; u64 fifo_order;
u64 userdata; std::uintptr_t user_data;
const TimingEventType* type; const TimingEventType* type;
bool operator>(const Event& right) const; bool operator>(const Event& right) const;
@ -152,7 +152,7 @@ public:
void save(Archive& ar, const unsigned int) const { void save(Archive& ar, const unsigned int) const {
ar& time; ar& time;
ar& fifo_order; ar& fifo_order;
ar& userdata; ar& user_data;
std::string name = *(type->name); std::string name = *(type->name);
ar << name; ar << name;
} }
@ -161,7 +161,7 @@ public:
void load(Archive& ar, const unsigned int) { void load(Archive& ar, const unsigned int) {
ar& time; ar& time;
ar& fifo_order; ar& fifo_order;
ar& userdata; ar& user_data;
std::string name; std::string name;
ar >> name; ar >> name;
type = Global<Timing>().RegisterEvent(name, nullptr); type = Global<Timing>().RegisterEvent(name, nullptr);
@ -265,10 +265,11 @@ public:
*/ */
TimingEventType* RegisterEvent(const std::string& name, TimedCallback callback); TimingEventType* RegisterEvent(const std::string& name, TimedCallback callback);
void ScheduleEvent(s64 cycles_into_future, const TimingEventType* event_type, u64 userdata = 0, void ScheduleEvent(s64 cycles_into_future, const TimingEventType* event_type,
std::uintptr_t user_data = 0,
std::size_t core_id = std::numeric_limits<std::size_t>::max()); std::size_t core_id = std::numeric_limits<std::size_t>::max());
void UnscheduleEvent(const TimingEventType* event_type, u64 userdata); void UnscheduleEvent(const TimingEventType* event_type, std::uintptr_t user_data);
/// We only permit one event of each type in the queue at a time. /// We only permit one event of each type in the queue at a time.
void RemoveEvent(const TimingEventType* event_type); void RemoveEvent(const TimingEventType* event_type);

View file

@ -108,7 +108,7 @@ u64 Handler::GetSystemTime() const {
return console_time; return console_time;
} }
void Handler::UpdateTimeCallback(u64 userdata, int cycles_late) { void Handler::UpdateTimeCallback(std::uintptr_t user_data, int cycles_late) {
DateTime& date_time = DateTime& date_time =
shared_page.date_time_counter % 2 ? shared_page.date_time_0 : shared_page.date_time_1; shared_page.date_time_counter % 2 ? shared_page.date_time_0 : shared_page.date_time_1;

View file

@ -114,7 +114,7 @@ public:
private: private:
u64 GetSystemTime() const; u64 GetSystemTime() const;
void UpdateTimeCallback(u64 userdata, int cycles_late); void UpdateTimeCallback(std::uintptr_t user_data, int cycles_late);
Core::Timing& timing; Core::Timing& timing;
Core::TimingEventType* update_time_event; Core::TimingEventType* update_time_event;
std::chrono::seconds init_time; std::chrono::seconds init_time;

View file

@ -1118,11 +1118,12 @@ Module::Module(Core::System& system) : system(system) {
system.Kernel().CreateEvent(ResetType::OneShot, "CAM::vsync_interrupt_event"); system.Kernel().CreateEvent(ResetType::OneShot, "CAM::vsync_interrupt_event");
} }
completion_event_callback = system.CoreTiming().RegisterEvent( completion_event_callback = system.CoreTiming().RegisterEvent(
"CAM::CompletionEventCallBack", "CAM::CompletionEventCallBack", [this](std::uintptr_t user_data, s64 cycles_late) {
[this](u64 userdata, s64 cycles_late) { CompletionEventCallBack(userdata, cycles_late); }); CompletionEventCallBack(user_data, cycles_late);
});
vsync_interrupt_event_callback = system.CoreTiming().RegisterEvent( vsync_interrupt_event_callback = system.CoreTiming().RegisterEvent(
"CAM::VsyncInterruptEventCallBack", [this](u64 userdata, s64 cycles_late) { "CAM::VsyncInterruptEventCallBack", [this](std::uintptr_t user_data, s64 cycles_late) {
VsyncInterruptEventCallBack(userdata, cycles_late); VsyncInterruptEventCallBack(user_data, cycles_late);
}); });
} }

View file

@ -105,7 +105,7 @@ void Module::LoadInputDevices() {
} }
} }
void Module::UpdatePadCallback(u64 userdata, s64 cycles_late) { void Module::UpdatePadCallback(std::uintptr_t user_data, s64 cycles_late) {
SharedMem* mem = reinterpret_cast<SharedMem*>(shared_mem->GetPointer()); SharedMem* mem = reinterpret_cast<SharedMem*>(shared_mem->GetPointer());
if (is_device_reload_pending.exchange(false)) if (is_device_reload_pending.exchange(false))
@ -225,7 +225,7 @@ void Module::UpdatePadCallback(u64 userdata, s64 cycles_late) {
system.CoreTiming().ScheduleEvent(pad_update_ticks - cycles_late, pad_update_event); system.CoreTiming().ScheduleEvent(pad_update_ticks - cycles_late, pad_update_event);
} }
void Module::UpdateAccelerometerCallback(u64 userdata, s64 cycles_late) { void Module::UpdateAccelerometerCallback(std::uintptr_t user_data, s64 cycles_late) {
SharedMem* mem = reinterpret_cast<SharedMem*>(shared_mem->GetPointer()); SharedMem* mem = reinterpret_cast<SharedMem*>(shared_mem->GetPointer());
mem->accelerometer.index = next_accelerometer_index; mem->accelerometer.index = next_accelerometer_index;
@ -270,7 +270,7 @@ void Module::UpdateAccelerometerCallback(u64 userdata, s64 cycles_late) {
accelerometer_update_event); accelerometer_update_event);
} }
void Module::UpdateGyroscopeCallback(u64 userdata, s64 cycles_late) { void Module::UpdateGyroscopeCallback(std::uintptr_t user_data, s64 cycles_late) {
SharedMem* mem = reinterpret_cast<SharedMem*>(shared_mem->GetPointer()); SharedMem* mem = reinterpret_cast<SharedMem*>(shared_mem->GetPointer());
mem->gyroscope.index = next_gyroscope_index; mem->gyroscope.index = next_gyroscope_index;
@ -438,17 +438,17 @@ Module::Module(Core::System& system) : system(system) {
// Register update callbacks // Register update callbacks
Core::Timing& timing = system.CoreTiming(); Core::Timing& timing = system.CoreTiming();
pad_update_event = pad_update_event = timing.RegisterEvent("HID::UpdatePadCallback",
timing.RegisterEvent("HID::UpdatePadCallback", [this](u64 userdata, s64 cycles_late) { [this](std::uintptr_t user_data, s64 cycles_late) {
UpdatePadCallback(userdata, cycles_late); UpdatePadCallback(user_data, cycles_late);
}); });
accelerometer_update_event = timing.RegisterEvent( accelerometer_update_event = timing.RegisterEvent(
"HID::UpdateAccelerometerCallback", [this](u64 userdata, s64 cycles_late) { "HID::UpdateAccelerometerCallback", [this](std::uintptr_t user_data, s64 cycles_late) {
UpdateAccelerometerCallback(userdata, cycles_late); UpdateAccelerometerCallback(user_data, cycles_late);
}); });
gyroscope_update_event = gyroscope_update_event = timing.RegisterEvent(
timing.RegisterEvent("HID::UpdateGyroscopeCallback", [this](u64 userdata, s64 cycles_late) { "HID::UpdateGyroscopeCallback", [this](std::uintptr_t user_data, s64 cycles_late) {
UpdateGyroscopeCallback(userdata, cycles_late); UpdateGyroscopeCallback(user_data, cycles_late);
}); });
timing.ScheduleEvent(pad_update_ticks, pad_update_event); timing.ScheduleEvent(pad_update_ticks, pad_update_event);

View file

@ -307,9 +307,9 @@ public:
private: private:
void LoadInputDevices(); void LoadInputDevices();
void UpdatePadCallback(u64 userdata, s64 cycles_late); void UpdatePadCallback(std::uintptr_t user_data, s64 cycles_late);
void UpdateAccelerometerCallback(u64 userdata, s64 cycles_late); void UpdateAccelerometerCallback(std::uintptr_t user_data, s64 cycles_late);
void UpdateGyroscopeCallback(u64 userdata, s64 cycles_late); void UpdateGyroscopeCallback(std::uintptr_t user_data, s64 cycles_late);
Core::System& system; Core::System& system;

View file

@ -66,7 +66,7 @@ void IR_RST::UnloadInputDevices() {
c_stick = nullptr; c_stick = nullptr;
} }
void IR_RST::UpdateCallback(u64 userdata, s64 cycles_late) { void IR_RST::UpdateCallback(std::uintptr_t user_data, s64 cycles_late) {
SharedMem* mem = reinterpret_cast<SharedMem*>(shared_memory->GetPointer()); SharedMem* mem = reinterpret_cast<SharedMem*>(shared_memory->GetPointer());
if (is_device_reload_pending.exchange(false)) if (is_device_reload_pending.exchange(false))
@ -175,8 +175,9 @@ IR_RST::IR_RST(Core::System& system) : ServiceFramework("ir:rst", 1), system(sys
update_event = system.Kernel().CreateEvent(ResetType::OneShot, "IRRST:UpdateEvent"); update_event = system.Kernel().CreateEvent(ResetType::OneShot, "IRRST:UpdateEvent");
update_callback_id = system.CoreTiming().RegisterEvent( update_callback_id = system.CoreTiming().RegisterEvent(
"IRRST:UpdateCallBack", "IRRST:UpdateCallBack", [this](std::uintptr_t user_data, s64 cycles_late) {
[this](u64 userdata, s64 cycles_late) { UpdateCallback(userdata, cycles_late); }); UpdateCallback(user_data, cycles_late);
});
static const FunctionInfo functions[] = { static const FunctionInfo functions[] = {
{0x00010000, &IR_RST::GetHandles, "GetHandles"}, {0x00010000, &IR_RST::GetHandles, "GetHandles"},

View file

@ -74,7 +74,7 @@ private:
void LoadInputDevices(); void LoadInputDevices();
void UnloadInputDevices(); void UnloadInputDevices();
void UpdateCallback(u64 userdata, s64 cycles_late); void UpdateCallback(std::uintptr_t user_data, s64 cycles_late);
Core::System& system; Core::System& system;
std::shared_ptr<Kernel::Event> update_event; std::shared_ptr<Kernel::Event> update_event;

View file

@ -126,9 +126,9 @@ struct MIC_U::Impl {
explicit Impl(Core::System& system) : timing(system.CoreTiming()) { explicit Impl(Core::System& system) : timing(system.CoreTiming()) {
buffer_full_event = buffer_full_event =
system.Kernel().CreateEvent(Kernel::ResetType::OneShot, "MIC_U::buffer_full_event"); system.Kernel().CreateEvent(Kernel::ResetType::OneShot, "MIC_U::buffer_full_event");
buffer_write_event = buffer_write_event = timing.RegisterEvent(
timing.RegisterEvent("MIC_U::UpdateBuffer", [this](u64 userdata, s64 cycles_late) { "MIC_U::UpdateBuffer", [this](std::uintptr_t user_data, s64 cycles_late) {
UpdateSharedMemBuffer(userdata, cycles_late); UpdateSharedMemBuffer(user_data, cycles_late);
}); });
} }
@ -158,7 +158,7 @@ struct MIC_U::Impl {
LOG_TRACE(Service_MIC, "called"); LOG_TRACE(Service_MIC, "called");
} }
void UpdateSharedMemBuffer(u64 userdata, s64 cycles_late) { void UpdateSharedMemBuffer(std::uintptr_t user_data, s64 cycles_late) {
if (change_mic_impl_requested.exchange(false)) { if (change_mic_impl_requested.exchange(false)) {
CreateMic(); CreateMic();
} }

View file

@ -1443,7 +1443,7 @@ void NWM_UDS::DecryptBeaconData(Kernel::HLERequestContext& ctx) {
} }
// Sends a 802.11 beacon frame with information about the current network. // Sends a 802.11 beacon frame with information about the current network.
void NWM_UDS::BeaconBroadcastCallback(u64 userdata, s64 cycles_late) { void NWM_UDS::BeaconBroadcastCallback(std::uintptr_t user_data, s64 cycles_late) {
// Don't do anything if we're not actually hosting a network // Don't do anything if we're not actually hosting a network
if (connection_status.status != static_cast<u32>(NetworkStatus::ConnectedAsHost)) if (connection_status.status != static_cast<u32>(NetworkStatus::ConnectedAsHost))
return; return;
@ -1503,8 +1503,9 @@ NWM_UDS::NWM_UDS(Core::System& system) : ServiceFramework("nwm::UDS"), system(sy
RegisterHandlers(functions); RegisterHandlers(functions);
beacon_broadcast_event = system.CoreTiming().RegisterEvent( beacon_broadcast_event = system.CoreTiming().RegisterEvent(
"UDS::BeaconBroadcastCallback", "UDS::BeaconBroadcastCallback", [this](std::uintptr_t user_data, s64 cycles_late) {
[this](u64 userdata, s64 cycles_late) { BeaconBroadcastCallback(userdata, cycles_late); }); BeaconBroadcastCallback(user_data, cycles_late);
});
CryptoPP::AutoSeededRandomPool rng; CryptoPP::AutoSeededRandomPool rng;
auto mac = SharedPage::DefaultMac; auto mac = SharedPage::DefaultMac;

View file

@ -459,7 +459,7 @@ private:
const u8* network_info_buffer, std::size_t network_info_size, const u8* network_info_buffer, std::size_t network_info_size,
u8 connection_type, std::vector<u8> passphrase); u8 connection_type, std::vector<u8> passphrase);
void BeaconBroadcastCallback(u64 userdata, s64 cycles_late); void BeaconBroadcastCallback(std::uintptr_t user_data, s64 cycles_late);
/** /**
* Returns a list of received 802.11 beacon frames from the specified sender since the last * Returns a list of received 802.11 beacon frames from the specified sender since the last

View file

@ -503,7 +503,7 @@ template void Write<u16>(u32 addr, const u16 data);
template void Write<u8>(u32 addr, const u8 data); template void Write<u8>(u32 addr, const u8 data);
/// Update hardware /// Update hardware
static void VBlankCallback(u64 userdata, s64 cycles_late) { static void VBlankCallback(std::uintptr_t user_data, s64 cycles_late) {
VideoCore::g_renderer->SwapBuffers(); VideoCore::g_renderer->SwapBuffers();
// Signal to GSP that GPU interrupt has occurred // Signal to GSP that GPU interrupt has occurred

View file

@ -21,10 +21,10 @@ static u64 expected_callback = 0;
static s64 lateness = 0; static s64 lateness = 0;
template <unsigned int IDX> template <unsigned int IDX>
void CallbackTemplate(u64 userdata, s64 cycles_late) { void CallbackTemplate(std::uintptr_t user_data, s64 cycles_late) {
static_assert(IDX < CB_IDS.size(), "IDX out of range"); static_assert(IDX < CB_IDS.size(), "IDX out of range");
callbacks_ran_flags.set(IDX); callbacks_ran_flags.set(IDX);
REQUIRE(CB_IDS[IDX] == userdata); REQUIRE(CB_IDS[IDX] == user_data);
REQUIRE(CB_IDS[IDX] == expected_callback); REQUIRE(CB_IDS[IDX] == expected_callback);
REQUIRE(lateness == cycles_late); REQUIRE(lateness == cycles_late);
} }
@ -81,10 +81,10 @@ namespace SharedSlotTest {
static unsigned int counter = 0; static unsigned int counter = 0;
template <unsigned int ID> template <unsigned int ID>
void FifoCallback(u64 userdata, s64 cycles_late) { void FifoCallback(std::uintptr_t user_data, s64 cycles_late) {
static_assert(ID < CB_IDS.size(), "ID out of range"); static_assert(ID < CB_IDS.size(), "ID out of range");
callbacks_ran_flags.set(ID); callbacks_ran_flags.set(ID);
REQUIRE(CB_IDS[ID] == userdata); REQUIRE(CB_IDS[ID] == user_data);
REQUIRE(ID == counter); REQUIRE(ID == counter);
REQUIRE(lateness == cycles_late); REQUIRE(lateness == cycles_late);
++counter; ++counter;
@ -143,13 +143,13 @@ TEST_CASE("CoreTiming[PredictableLateness]", "[core]") {
namespace ChainSchedulingTest { namespace ChainSchedulingTest {
static int reschedules = 0; static int reschedules = 0;
static void RescheduleCallback(Core::Timing& timing, u64 userdata, s64 cycles_late) { static void RescheduleCallback(Core::Timing& timing, std::uintptr_t user_data, s64 cycles_late) {
--reschedules; --reschedules;
REQUIRE(reschedules >= 0); REQUIRE(reschedules >= 0);
REQUIRE(lateness == cycles_late); REQUIRE(lateness == cycles_late);
if (reschedules > 0) if (reschedules > 0)
timing.ScheduleEvent(1000, reinterpret_cast<Core::TimingEventType*>(userdata), userdata); timing.ScheduleEvent(1000, reinterpret_cast<Core::TimingEventType*>(user_data), user_data);
} }
} // namespace ChainSchedulingTest } // namespace ChainSchedulingTest
@ -161,9 +161,9 @@ TEST_CASE("CoreTiming[ChainScheduling]", "[core]") {
Core::TimingEventType* cb_a = timing.RegisterEvent("callbackA", CallbackTemplate<0>); Core::TimingEventType* cb_a = timing.RegisterEvent("callbackA", CallbackTemplate<0>);
Core::TimingEventType* cb_b = timing.RegisterEvent("callbackB", CallbackTemplate<1>); Core::TimingEventType* cb_b = timing.RegisterEvent("callbackB", CallbackTemplate<1>);
Core::TimingEventType* cb_c = timing.RegisterEvent("callbackC", CallbackTemplate<2>); Core::TimingEventType* cb_c = timing.RegisterEvent("callbackC", CallbackTemplate<2>);
Core::TimingEventType* cb_rs = Core::TimingEventType* cb_rs = timing.RegisterEvent(
timing.RegisterEvent("callbackReschedule", [&timing](u64 userdata, s64 cycles_late) { "callbackReschedule", [&timing](std::uintptr_t user_data, s64 cycles_late) {
RescheduleCallback(timing, userdata, cycles_late); RescheduleCallback(timing, user_data, cycles_late);
}); });
// Enter slice 0 // Enter slice 0