@@ -29,7 +29,7 @@ SuperscalarScheduler::SuperscalarScheduler(
2929
3030
3131void SuperscalarScheduler::clear () noexcept {
32- SpinLockGuard lg (m_lock);
32+ // SpinLockGuard lg(m_lock);
3333 m_logger.log (" Clearing schedule..." );
3434 WallClock now = current_time ();
3535 m_local_start = now;
@@ -54,54 +54,49 @@ void SuperscalarScheduler::clear() noexcept{
5454bool SuperscalarScheduler::iterate_schedule (const Cancellable* cancellable){
5555 cancellable->throw_if_cancelled ();
5656
57- WallDuration duration;
58- {
59- SpinLockGuard lg (m_lock);
60-
61- if (m_state_changes.empty ()){
62- m_device_sent_time = m_device_issue_time;
63- return false ;
64- }
57+ if (m_state_changes.empty ()){
58+ m_device_sent_time = m_device_issue_time;
59+ return false ;
60+ }
6561
66- auto iter = m_state_changes.begin ();
67-
68- WallClock next_state_change;
69- if (m_device_sent_time < *iter){
70- next_state_change = *iter;
71- }else {
72- auto next = iter;
73- ++next;
74- next_state_change = next == m_state_changes.end ()
75- ? m_device_issue_time
76- : *next;
77- }
62+ auto iter = m_state_changes.begin ();
63+
64+ WallClock next_state_change;
65+ if (m_device_sent_time < *iter){
66+ next_state_change = *iter;
67+ }else {
68+ auto next = iter;
69+ ++next;
70+ next_state_change = next == m_state_changes.end ()
71+ ? m_device_issue_time
72+ : *next;
73+ }
7874
79- // Things get complicated if we overshoot the issue time.
80- if (next_state_change > m_device_issue_time){
75+ // Things get complicated if we overshoot the issue time.
76+ if (next_state_change > m_device_issue_time){
8177// m_logger.log("SuperscalarScheduler: Overshoot due to unfinished early return.", COLOR_RED);
82- next_state_change = m_device_issue_time;
83- }
78+ next_state_change = m_device_issue_time;
79+ }
8480
85- duration = next_state_change - m_device_sent_time;
86- if (duration == WallDuration::zero ()){
81+ WallDuration duration = next_state_change - m_device_sent_time;
82+ if (duration == WallDuration::zero ()){
8783// m_logger.log("SuperscalarScheduler: Scheduler is stalled.", COLOR_RED);
88- return false ;
89- }
84+ return false ;
85+ }
9086
91- // Compute the resource state at this timestamp.
92- for (ExecutionResource* resource : m_resources){
93- resource->m_is_busy = resource->m_busy_time <= m_device_sent_time && m_device_sent_time < resource->m_done_time ;
94- }
87+ // Compute the resource state at this timestamp.
88+ for (ExecutionResource* resource : m_resources){
89+ resource->m_is_busy = resource->m_busy_time <= m_device_sent_time && m_device_sent_time < resource->m_done_time ;
90+ }
9591
96- m_device_sent_time = next_state_change;
97- if (next_state_change >= *iter){
98- m_state_changes.erase (iter);
99- }
92+ m_device_sent_time = next_state_change;
93+ if (next_state_change >= *iter){
94+ m_state_changes.erase (iter);
10095 }
10196
10297 this ->push_state (cancellable, duration);
10398
104- SpinLockGuard lg (m_lock);
99+ // SpinLockGuard lg(m_lock);
105100
106101 WallClock now = current_time ();
107102 m_local_last_activity = now;
@@ -142,16 +137,13 @@ void SuperscalarScheduler::issue_wait_for_all(const Cancellable* cancellable){
142137 clear ();
143138 return ;
144139 }
145- {
146- SpinLockGuard lg (m_lock);
147- // cout << "issue_wait_for_all(): " << m_state_changes.size() << endl;
148- // cout << "issue_time = " << std::chrono::duration_cast<Milliseconds>((m_device_issue_time - m_local_start)).count()
149- // << ", sent_time = " << std::chrono::duration_cast<Milliseconds>((m_device_sent_time - m_local_start)).count()
150- // << ", max_free_time = " << std::chrono::duration_cast<Milliseconds>((m_max_free_time - m_local_start)).count()
151- // << endl;
152- m_device_issue_time = std::max (m_device_issue_time, m_max_free_time);
153- m_max_free_time = m_device_issue_time;
154- }
140+ // cout << "issue_wait_for_all(): " << m_state_changes.size() << endl;
141+ // cout << "issue_time = " << std::chrono::duration_cast<Milliseconds>((m_device_issue_time - m_local_start)).count()
142+ // << ", sent_time = " << std::chrono::duration_cast<Milliseconds>((m_device_sent_time - m_local_start)).count()
143+ // << ", max_free_time = " << std::chrono::duration_cast<Milliseconds>((m_max_free_time - m_local_start)).count()
144+ // << endl;
145+ m_device_issue_time = std::max (m_device_issue_time, m_max_free_time);
146+ m_max_free_time = m_device_issue_time;
155147 process_schedule (cancellable);
156148}
157149void SuperscalarScheduler::issue_nop (const Cancellable* cancellable, WallDuration delay){
@@ -161,18 +153,15 @@ void SuperscalarScheduler::issue_nop(const Cancellable* cancellable, WallDuratio
161153 if (m_pending_clear.load (std::memory_order_acquire)){
162154 clear ();
163155 }
164- {
165- SpinLockGuard lg (m_lock);
166- // cout << "issue_nop(): " << m_state_changes.size() << endl;
167- // cout << "issue_time = " << std::chrono::duration_cast<Milliseconds>((m_device_issue_time - m_local_start)).count()
168- // << ", sent_time = " << std::chrono::duration_cast<Milliseconds>((m_device_sent_time - m_local_start)).count()
169- // << ", max_free_time = " << std::chrono::duration_cast<Milliseconds>((m_max_free_time - m_local_start)).count()
170- // << endl;
171- m_state_changes.insert (m_device_issue_time);
172- m_device_issue_time += delay;
173- m_max_free_time = std::max (m_max_free_time, m_device_issue_time);
174- m_local_last_activity = current_time ();
175- }
156+ // cout << "issue_nop(): " << m_state_changes.size() << endl;
157+ // cout << "issue_time = " << std::chrono::duration_cast<Milliseconds>((m_device_issue_time - m_local_start)).count()
158+ // << ", sent_time = " << std::chrono::duration_cast<Milliseconds>((m_device_sent_time - m_local_start)).count()
159+ // << ", max_free_time = " << std::chrono::duration_cast<Milliseconds>((m_max_free_time - m_local_start)).count()
160+ // << endl;
161+ m_state_changes.insert (m_device_issue_time);
162+ m_device_issue_time += delay;
163+ m_max_free_time = std::max (m_max_free_time, m_device_issue_time);
164+ m_local_last_activity = current_time ();
176165 process_schedule (cancellable);
177166}
178167void SuperscalarScheduler::wait_for_resource (const Cancellable* cancellable, ExecutionResource& resource){
@@ -185,14 +174,11 @@ void SuperscalarScheduler::wait_for_resource(const Cancellable* cancellable, Exe
185174// << ", sent_time = " << std::chrono::duration_cast<Milliseconds>((m_device_sent_time - m_local_start)).count()
186175// << ", free_time = " << std::chrono::duration_cast<Milliseconds>((resource.m_free_time - m_local_start)).count()
187176// << endl;
188- {
189- SpinLockGuard lg (m_lock);
190- // Resource is not ready yet. Stall until it is.
191- if (resource.m_free_time > m_device_sent_time){
192- // cout << "stall = " << std::chrono::duration_cast<Milliseconds>(resource.m_free_time - m_device_sent_time).count() << endl;
193- m_device_issue_time = resource.m_free_time ;
194- m_local_last_activity = current_time ();
195- }
177+ // Resource is not ready yet. Stall until it is.
178+ if (resource.m_free_time > m_device_sent_time){
179+ // cout << "stall = " << std::chrono::duration_cast<Milliseconds>(resource.m_free_time - m_device_sent_time).count() << endl;
180+ m_device_issue_time = resource.m_free_time ;
181+ m_local_last_activity = current_time ();
196182 }
197183 process_schedule (cancellable);
198184}
@@ -204,39 +190,36 @@ void SuperscalarScheduler::issue_to_resource(
204190 clear ();
205191 }
206192
207- {
208- SpinLockGuard lg (m_lock);
209- // Resource is busy.
210- if (m_device_sent_time < resource.m_free_time ){
211- throw InternalProgramError (
212- nullptr , PA_CURRENT_FUNCTION,
213- " Attempted to issue resource that isn't ready."
214- );
215- }
193+ // Resource is busy.
194+ if (m_device_sent_time < resource.m_free_time ){
195+ throw InternalProgramError (
196+ nullptr , PA_CURRENT_FUNCTION,
197+ " Attempted to issue resource that isn't ready."
198+ );
199+ }
216200
217- // cout << "issue_to_resource(): delay = " << std::chrono::duration_cast<Milliseconds>(delay).count()
218- // << ", hold = " << std::chrono::duration_cast<Milliseconds>(hold).count()
219- // << ", cooldown = " << std::chrono::duration_cast<Milliseconds>(cooldown).count()
220- // << endl;
221- // cout << "issue_time = " << std::chrono::duration_cast<Milliseconds>((m_device_issue_time - m_local_start)).count()
222- // << ", sent_time = " << std::chrono::duration_cast<Milliseconds>((m_device_sent_time - m_local_start)).count()
223- // << endl;
201+ // cout << "issue_to_resource(): delay = " << std::chrono::duration_cast<Milliseconds>(delay).count()
202+ // << ", hold = " << std::chrono::duration_cast<Milliseconds>(hold).count()
203+ // << ", cooldown = " << std::chrono::duration_cast<Milliseconds>(cooldown).count()
204+ // << endl;
205+ // cout << "issue_time = " << std::chrono::duration_cast<Milliseconds>((m_device_issue_time - m_local_start)).count()
206+ // << ", sent_time = " << std::chrono::duration_cast<Milliseconds>((m_device_sent_time - m_local_start)).count()
207+ // << endl;
224208
225- WallClock release_time = m_device_issue_time + hold;
226- WallClock free_time = release_time + cooldown;
209+ WallClock release_time = m_device_issue_time + hold;
210+ WallClock free_time = release_time + cooldown;
227211
228- m_state_changes.insert (m_device_issue_time);
229- m_state_changes.insert (release_time);
212+ m_state_changes.insert (m_device_issue_time);
213+ m_state_changes.insert (release_time);
230214
231- resource.m_busy_time = m_device_issue_time;
232- resource.m_done_time = release_time;
233- resource.m_free_time = free_time;
215+ resource.m_busy_time = m_device_issue_time;
216+ resource.m_done_time = release_time;
217+ resource.m_free_time = free_time;
234218
235- m_device_issue_time += delay;
236- m_max_free_time = std::max (m_max_free_time, free_time);
237- m_max_free_time = std::max (m_max_free_time, m_device_issue_time);
238- m_local_last_activity = current_time ();
239- }
219+ m_device_issue_time += delay;
220+ m_max_free_time = std::max (m_max_free_time, free_time);
221+ m_max_free_time = std::max (m_max_free_time, m_device_issue_time);
222+ m_local_last_activity = current_time ();
240223
241224 process_schedule (cancellable);
242225}
0 commit comments