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 timestamps in signaling_handler #13551

Merged
merged 2 commits into from
Mar 17, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions rpcs3/Emu/NP/signaling_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,11 @@ bool signaling_handler::validate_signaling_packet(const signaling_packet* sp)
return true;
}

u64 signaling_handler::get_micro_timestamp(const std::chrono::steady_clock::time_point& time_point)
{
return std::chrono::duration_cast<std::chrono::microseconds>(time_point.time_since_epoch()).count();
}

void signaling_handler::process_incoming_messages()
{
auto msgs = get_sign_msgs();
Expand Down Expand Up @@ -249,14 +254,15 @@ void signaling_handler::process_incoming_messages()
}

sent_packet.command = signal_ping;
sent_packet.timestamp_sender = now.time_since_epoch().count();
sent_packet.timestamp_sender = get_micro_timestamp(now);
send_signaling_packet(sent_packet, si->addr, si->port);
queue_signaling_packet(sent_packet, si, now + REPEAT_PING_DELAY);
};

const auto update_rtt = [&](u64 rtt_timestamp)
{
u32 rtt = now.time_since_epoch().count() - rtt_timestamp;
u64 timestamp_now = get_micro_timestamp(now);
u64 rtt = timestamp_now - rtt_timestamp;
si->last_rtts[(si->rtt_counters % 6)] = rtt;
si->rtt_counters++;

Expand All @@ -267,7 +273,7 @@ void signaling_handler::process_incoming_messages()
sum += si->last_rtts[index];
}

si->rtt = (sum / num_rtts) / 1000;
si->rtt = (sum / num_rtts);
};

switch (sp->command)
Expand All @@ -289,7 +295,7 @@ void signaling_handler::process_incoming_messages()
schedule_repeat = true;
sent_packet.command = signal_connect_ack;
sent_packet.timestamp_sender = sp->timestamp_sender;
sent_packet.timestamp_receiver = now.time_since_epoch().count();
sent_packet.timestamp_receiver = get_micro_timestamp(now);
update_si_addr(si, op_addr, op_port);
break;
case signal_connect_ack:
Expand All @@ -298,7 +304,7 @@ void signaling_handler::process_incoming_messages()
schedule_repeat = false;
setup_ping();
sent_packet.command = signal_confirm;
sent_packet.timestamp_receiver = now.time_since_epoch().count();
sent_packet.timestamp_receiver = sp->timestamp_receiver;
retire_packet(si, signal_connect);
update_si_addr(si, op_addr, op_port);
update_si_mapped_addr(si, sp->sent_addr, sp->sent_port);
Expand Down Expand Up @@ -375,10 +381,10 @@ void signaling_handler::operator()()
{
case signal_connect:
case signal_ping:
sig.packet.timestamp_sender = now.time_since_epoch().count();
sig.packet.timestamp_sender = get_micro_timestamp(now);
break;
case signal_connect_ack:
sig.packet.timestamp_receiver = now.time_since_epoch().count();
sig.packet.timestamp_receiver = get_micro_timestamp(now);
break;
default:
break;
Expand Down Expand Up @@ -586,7 +592,7 @@ void signaling_handler::start_sig(u32 conn_id, u32 addr, u16 port)
std::lock_guard lock(data_mutex);
auto& sent_packet = sig_packet;
sent_packet.command = signal_connect;
sent_packet.timestamp_sender = steady_clock::now().time_since_epoch().count();
sent_packet.timestamp_sender = get_micro_timestamp(steady_clock::now());

ensure(sig_peers.contains(conn_id));
std::shared_ptr<signaling_info> si = ::at32(sig_peers, conn_id);
Expand Down
2 changes: 2 additions & 0 deletions rpcs3/Emu/NP/signaling_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ class signaling_handler
vm::ptr<SceNpMatching2SignalingCallback> sig2_cb{};
vm::ptr<void> sig2_cb_arg{};

static u64 get_micro_timestamp(const std::chrono::steady_clock::time_point& time_point);

u32 get_always_conn_id(const SceNpId& npid);
static void update_si_addr(std::shared_ptr<signaling_info>& si, u32 new_addr, u16 new_port);
static void update_si_mapped_addr(std::shared_ptr<signaling_info>& si, u32 new_addr, u16 new_port);
Expand Down