Skip to content

Commit 7ca9064

Browse files
committed
Automatically stall if not ready.
1 parent 69fb06b commit 7ca9064

File tree

4 files changed

+21
-37
lines changed

4 files changed

+21
-37
lines changed

SerialPrograms/Source/Controllers/SuperscalarScheduler.cpp

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*
55
*/
66

7-
#include "Common/Cpp/Exceptions.h"
7+
//#include "Common/Cpp/Exceptions.h"
88
#include "Common/Cpp/Time.h"
99
#include "SuperscalarScheduler.h"
1010

@@ -211,21 +211,13 @@ void SuperscalarScheduler::issue_wait_for_resource(
211211
// << ", sent_time = " << std::chrono::duration_cast<Milliseconds>((m_device_sent_time - m_local_start)).count()
212212
// << ", free_time = " << std::chrono::duration_cast<Milliseconds>((resource.m_free_time - m_local_start)).count()
213213
// << endl;
214-
// Resource is not ready yet. Stall until it is.
215214

216-
#if 1
215+
// Resource is not ready yet. Stall until it is.
217216
auto iter = m_live_commands.find(resource_id);
218-
if (iter != m_live_commands.end() && iter->second.free_time > m_device_sent_time){
217+
if (iter != m_live_commands.end() && m_device_sent_time < iter->second.free_time){
219218
m_device_issue_time = iter->second.free_time;
220219
m_local_last_activity = current_time();
221220
}
222-
#else
223-
if (resource.m_free_time > m_device_sent_time){
224-
// cout << "stall = " << std::chrono::duration_cast<Milliseconds>(resource.m_free_time - m_device_sent_time).count() << endl;
225-
m_device_issue_time = resource.m_free_time;
226-
m_local_last_activity = current_time();
227-
}
228-
#endif
229221

230222
process_schedule(cancellable);
231223
}
@@ -238,14 +230,11 @@ void SuperscalarScheduler::issue_to_resource(
238230
clear();
239231
}
240232

241-
// Resource is busy.
233+
// Resource is busy. Stall until it is free.
242234
auto ret = m_live_commands.try_emplace(resource->id);
243-
if (!ret.second && m_device_sent_time < ret.first->second.free_time){
235+
if (!ret.second){
244236
// cout << m_device_sent_time << " : " << ret.first->second.free_time << endl;
245-
throw InternalProgramError(
246-
nullptr, PA_CURRENT_FUNCTION,
247-
"Attempted to issue resource that isn't ready."
248-
);
237+
m_device_issue_time = std::max(m_device_issue_time, ret.first->second.free_time);
249238
}
250239
Command& command = ret.first->second;
251240

SerialPrograms/Source/Controllers/SuperscalarScheduler.h

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,6 @@ class SuperscalarScheduler{
4949
m_pending_clear.store(true, std::memory_order_release);
5050
}
5151

52-
WallClock busy_until(size_t resource_id) const{
53-
auto iter = m_live_commands.find(resource_id);
54-
return iter != m_live_commands.end()
55-
? iter->second.free_time
56-
: WallClock::min();
57-
}
58-
5952

6053
public:
6154
// These are the standard "issue" commands.
@@ -64,6 +57,13 @@ class SuperscalarScheduler{
6457
// These are not thread-safe with each other.
6558
//
6659

60+
WallClock busy_until(size_t resource_id) const{
61+
auto iter = m_live_commands.find(resource_id);
62+
return iter != m_live_commands.end()
63+
? iter->second.free_time
64+
: WallClock::min();
65+
}
66+
6767
// Wait until the pipeline has completely cleared and all resources have
6868
// returned to the ready state.
6969
void issue_wait_for_all(const Cancellable* cancellable);
@@ -80,7 +80,6 @@ class SuperscalarScheduler{
8080
);
8181

8282
// Issue a resource with the specified timing parameters.
83-
// The resource must be ready to be used.
8483
void issue_to_resource(
8584
const Cancellable* cancellable,
8685
std::shared_ptr<const SchedulerResource> resource,
@@ -138,7 +137,7 @@ class SuperscalarScheduler{
138137
// The current timestamp of what has been sent to the device.
139138
WallClock m_device_sent_time;
140139

141-
// Maximum of: m_resources[]->m_free_time
140+
// Maximum of: m_live_commands[]->second.free_time
142141
WallClock m_max_free_time;
143142

144143
// A set of all the scheduled state changes that will happen. Between

SerialPrograms/Source/NintendoSwitch/Controllers/NintendoSwitch_ControllerWithScheduler.cpp

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,6 @@ void ControllerWithScheduler::issue_buttons(
5858
cancellable->throw_if_cancelled();
5959
}
6060

61-
for (size_t c = 0; c < TOTAL_BUTTONS; c++){
62-
ButtonFlagType mask = (ButtonFlagType)1 << c;
63-
if (button & mask){
64-
this->issue_wait_for_resource(cancellable, c);
65-
}
66-
}
6761
for (size_t c = 0; c < TOTAL_BUTTONS; c++){
6862
ButtonFlagType mask = (ButtonFlagType)1 << c;
6963
if (button & mask){
@@ -97,7 +91,6 @@ void ControllerWithScheduler::issue_dpad(
9791
cancellable->throw_if_cancelled();
9892
}
9993

100-
this->issue_wait_for_resource(cancellable, (size_t)SwitchResource::DPAD);
10194
this->issue_to_resource(
10295
cancellable,
10396
std::make_unique<SwitchCommand_Dpad>(position),
@@ -126,7 +119,6 @@ void ControllerWithScheduler::issue_left_joystick(
126119
cancellable->throw_if_cancelled();
127120
}
128121

129-
this->issue_wait_for_resource(cancellable, (size_t)SwitchResource::JOYSTICK_LEFT);
130122
this->issue_to_resource(
131123
cancellable,
132124
std::make_unique<SwitchCommand_LeftJoystick>(x, y),
@@ -154,7 +146,6 @@ void ControllerWithScheduler::issue_right_joystick(
154146
cancellable->throw_if_cancelled();
155147
}
156148

157-
this->issue_wait_for_resource(cancellable, (size_t)SwitchResource::JOYSTICK_RIGHT);
158149
this->issue_to_resource(
159150
cancellable,
160151
std::make_unique<SwitchCommand_RightJoystick>(x, y),
@@ -186,7 +177,6 @@ void ControllerWithScheduler::issue_gyro(
186177
cancellable->throw_if_cancelled();
187178
}
188179

189-
this->issue_wait_for_resource(cancellable, (size_t)id);
190180
this->issue_to_resource(
191181
cancellable,
192182
std::make_unique<SwitchCommand_Gyro>(id, value),
@@ -220,6 +210,7 @@ void ControllerWithScheduler::issue_full_controller_state(
220210
cancellable->throw_if_cancelled();
221211
}
222212

213+
#if 0
223214
for (size_t c = 0; c < TOTAL_BUTTONS; c++){
224215
ButtonFlagType mask = (ButtonFlagType)1 << c;
225216
if (button & mask){
@@ -229,6 +220,9 @@ void ControllerWithScheduler::issue_full_controller_state(
229220
this->issue_wait_for_resource(cancellable, (size_t)SwitchResource::DPAD);
230221
this->issue_wait_for_resource(cancellable, (size_t)SwitchResource::JOYSTICK_LEFT);
231222
this->issue_wait_for_resource(cancellable, (size_t)SwitchResource::JOYSTICK_RIGHT);
223+
#else
224+
this->issue_wait_for_all(cancellable);
225+
#endif
232226

233227
for (size_t c = 0; c < TOTAL_BUTTONS; c++){
234228
ButtonFlagType mask = (ButtonFlagType)1 << c;

SerialPrograms/Source/NintendoSwitch/Controllers/SerialPABotBase/NintendoSwitch_SerialPABotBase_WiredController.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ void SerialPABotBase_WiredController::push_state(
209209
}
210210

211211

212+
#if 0
212213
//
213214
// Given a regularly reported 32-bit counter that wraps around, infer its true
214215
// 64-bit value.
@@ -232,6 +233,7 @@ class ExtendedLengthCounter{
232233
uint32_t m_high_bits;
233234
uint32_t m_last_received;
234235
};
236+
#endif
235237

236238

237239

@@ -270,7 +272,7 @@ void SerialPABotBase_WiredController::status_thread(){
270272
});
271273

272274

273-
ExtendedLengthCounter clock_tracker;
275+
// ExtendedLengthCounter clock_tracker;
274276
// TickRateTracker tick_rate_tracker(m_use_milliseconds ? 1000 : TICKS_PER_SECOND);
275277
WallClock next_ping = current_time();
276278
while (true){

0 commit comments

Comments
 (0)