scheduler.hh (13140:ecd8a58f3884) scheduler.hh (13144:61e0f3230787)
1/*
2 * Copyright 2018 Google, Inc.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met: redistributions of source code must retain the above copyright
7 * notice, this list of conditions and the following disclaimer;
8 * redistributions in binary form must reproduce the above copyright

--- 131 unchanged lines hidden (view full) ---

140 * priority which is lower than all the others except the ready event. Timed
141 * notifications will happen before it fires, but it will override any ready
142 * event and prevent the evaluate phase from starting.
143 */
144
145class Scheduler
146{
147 public:
1/*
2 * Copyright 2018 Google, Inc.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met: redistributions of source code must retain the above copyright
7 * notice, this list of conditions and the following disclaimer;
8 * redistributions in binary form must reproduce the above copyright

--- 131 unchanged lines hidden (view full) ---

140 * priority which is lower than all the others except the ready event. Timed
141 * notifications will happen before it fires, but it will override any ready
142 * event and prevent the evaluate phase from starting.
143 */
144
145class Scheduler
146{
147 public:
148 typedef std::set<ScEvent *> ScEvents;
148 typedef std::list<ScEvent *> ScEvents;
149
150 class TimeSlot : public ::Event
151 {
152 public:
153 TimeSlot() : ::Event(Default_Pri, AutoDelete) {}
154
155 ScEvents events;
156 void process();

--- 64 unchanged lines hidden (view full) ---

221 // For scheduling delayed/timed notifications/timeouts.
222 void
223 schedule(ScEvent *event, const ::sc_core::sc_time &delay)
224 {
225 Tick tick = delayed(delay);
226 if (tick < getCurTick())
227 tick = getCurTick();
228
149
150 class TimeSlot : public ::Event
151 {
152 public:
153 TimeSlot() : ::Event(Default_Pri, AutoDelete) {}
154
155 ScEvents events;
156 void process();

--- 64 unchanged lines hidden (view full) ---

221 // For scheduling delayed/timed notifications/timeouts.
222 void
223 schedule(ScEvent *event, const ::sc_core::sc_time &delay)
224 {
225 Tick tick = delayed(delay);
226 if (tick < getCurTick())
227 tick = getCurTick();
228
229 event->schedule(tick);
230
231 // Delta notification/timeout.
232 if (delay.value() == 0) {
229 // Delta notification/timeout.
230 if (delay.value() == 0) {
233 deltas.insert(event);
231 event->schedule(deltas, tick);
234 scheduleReadyEvent();
235 return;
236 }
237
238 // Timed notification/timeout.
239 TimeSlot *&ts = timeSlots[tick];
240 if (!ts) {
241 ts = new TimeSlot;
242 schedule(ts, tick);
243 }
232 scheduleReadyEvent();
233 return;
234 }
235
236 // Timed notification/timeout.
237 TimeSlot *&ts = timeSlots[tick];
238 if (!ts) {
239 ts = new TimeSlot;
240 schedule(ts, tick);
241 }
244 ts->events.insert(event);
242 event->schedule(ts->events, tick);
245 }
246
247 // For descheduling delayed/timed notifications/timeouts.
248 void
249 deschedule(ScEvent *event)
250 {
243 }
244
245 // For descheduling delayed/timed notifications/timeouts.
246 void
247 deschedule(ScEvent *event)
248 {
251 if (event->when() == getCurTick()) {
252 // Attempt to remove from delta notifications.
253 if (deltas.erase(event) == 1) {
254 event->deschedule();
255 return;
256 }
249 ScEvents *on = event->scheduledOn();
250
251 if (on == &deltas) {
252 event->deschedule();
253 return;
257 }
258
259 // Timed notification/timeout.
260 auto tsit = timeSlots.find(event->when());
261 panic_if(tsit == timeSlots.end(),
262 "Descheduling event at time with no events.");
263 TimeSlot *ts = tsit->second;
264 ScEvents &events = ts->events;
254 }
255
256 // Timed notification/timeout.
257 auto tsit = timeSlots.find(event->when());
258 panic_if(tsit == timeSlots.end(),
259 "Descheduling event at time with no events.");
260 TimeSlot *ts = tsit->second;
261 ScEvents &events = ts->events;
265 assert(events.erase(event));
262 assert(on == &events);
266 event->deschedule();
267
268 // If no more events are happening at this time slot, get rid of it.
269 if (events.empty()) {
270 deschedule(ts);
271 timeSlots.erase(tsit);
272 }
273 }

--- 145 unchanged lines hidden (view full) ---

419 std::map<::Event *, Tick> eventsToSchedule;
420};
421
422extern Scheduler scheduler;
423
424inline void
425Scheduler::TimeSlot::process()
426{
263 event->deschedule();
264
265 // If no more events are happening at this time slot, get rid of it.
266 if (events.empty()) {
267 deschedule(ts);
268 timeSlots.erase(tsit);
269 }
270 }

--- 145 unchanged lines hidden (view full) ---

416 std::map<::Event *, Tick> eventsToSchedule;
417};
418
419extern Scheduler scheduler;
420
421inline void
422Scheduler::TimeSlot::process()
423{
427 for (auto &e: events)
428 e->run();
424 while (!events.empty())
425 events.front()->run();
429 scheduler.completeTimeSlot(this);
430}
431
432} // namespace sc_gem5
433
434#endif // __SYSTEMC_CORE_SCHEDULER_H__
426 scheduler.completeTimeSlot(this);
427}
428
429} // namespace sc_gem5
430
431#endif // __SYSTEMC_CORE_SCHEDULER_H__