scheduler.cc (13182:9e030f636a8c) scheduler.cc (13186:1ebc6c729311)
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

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

41{
42
43Scheduler::Scheduler() :
44 eq(nullptr), readyEvent(this, false, ReadyPriority),
45 pauseEvent(this, false, PausePriority),
46 stopEvent(this, false, StopPriority),
47 scMain(nullptr), _throwToScMain(nullptr),
48 starvationEvent(this, false, StarvationPriority),
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

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

41{
42
43Scheduler::Scheduler() :
44 eq(nullptr), readyEvent(this, false, ReadyPriority),
45 pauseEvent(this, false, PausePriority),
46 stopEvent(this, false, StopPriority),
47 scMain(nullptr), _throwToScMain(nullptr),
48 starvationEvent(this, false, StarvationPriority),
49 _started(false), _paused(false), _stopped(false), _stopNow(false),
49 _started(false), _stopNow(false), _status(StatusOther),
50 maxTickEvent(this, false, MaxTickPriority),
51 _numCycles(0), _changeStamp(0), _current(nullptr), initDone(false),
52 runOnce(false), readyList(nullptr)
53{}
54
55Scheduler::~Scheduler()
56{
57 // Clear out everything that belongs to us to make sure nobody tries to

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

118 }
119
120 for (Process *p = initList.getNext(); p; p = initList.getNext()) {
121 p->finalize();
122 p->popListNode();
123 p->ready();
124 }
125
50 maxTickEvent(this, false, MaxTickPriority),
51 _numCycles(0), _changeStamp(0), _current(nullptr), initDone(false),
52 runOnce(false), readyList(nullptr)
53{}
54
55Scheduler::~Scheduler()
56{
57 // Clear out everything that belongs to us to make sure nobody tries to

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

118 }
119
120 for (Process *p = initList.getNext(); p; p = initList.getNext()) {
121 p->finalize();
122 p->popListNode();
123 p->ready();
124 }
125
126 update();
126 runUpdate();
127 runDelta();
127
128
128 while (!deltas.empty())
129 deltas.front()->run();
130
131 for (auto ets: eventsToSchedule)
132 eq->schedule(ets.first, ets.second);
133 eventsToSchedule.clear();
134
135 if (_started) {
136 if (!runToTime && starved())
137 scheduleStarvationEvent();
138 kernel->status(::sc_core::SC_RUNNING);
139 }
140
141 initDone = true;
129 for (auto ets: eventsToSchedule)
130 eq->schedule(ets.first, ets.second);
131 eventsToSchedule.clear();
132
133 if (_started) {
134 if (!runToTime && starved())
135 scheduleStarvationEvent();
136 kernel->status(::sc_core::SC_RUNNING);
137 }
138
139 initDone = true;
140
141 status(StatusOther);
142}
143
144void
145Scheduler::reg(Process *p)
146{
147 if (initDone) {
148 // If we're past initialization, finalize static sensitivity.
149 p->finalize();

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

306 if (!empty) {
307 _numCycles++;
308 _changeStamp++;
309 }
310
311 if (_stopNow)
312 return;
313
142}
143
144void
145Scheduler::reg(Process *p)
146{
147 if (initDone) {
148 // If we're past initialization, finalize static sensitivity.
149 p->finalize();

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

306 if (!empty) {
307 _numCycles++;
308 _changeStamp++;
309 }
310
311 if (_stopNow)
312 return;
313
314 // The update phase.
315 update();
314 runUpdate();
315 runDelta();
316
316
317 // The delta phase.
318 while (!deltas.empty())
319 deltas.front()->run();
320
321 if (!runToTime && starved())
322 scheduleStarvationEvent();
323
324 if (runOnce)
325 schedulePause();
317 if (!runToTime && starved())
318 scheduleStarvationEvent();
319
320 if (runOnce)
321 schedulePause();
322
323 status(StatusOther);
326}
327
328void
324}
325
326void
329Scheduler::update()
327Scheduler::runUpdate()
330{
328{
329 status(StatusUpdate);
330
331 Channel *channel = updateList.getNext();
332 while (channel) {
333 channel->popListNode();
334 channel->update();
335 channel = updateList.getNext();
336 }
337}
338
339void
331 Channel *channel = updateList.getNext();
332 while (channel) {
333 channel->popListNode();
334 channel->update();
335 channel = updateList.getNext();
336 }
337}
338
339void
340Scheduler::runDelta()
341{
342 status(StatusDelta);
343 while (!deltas.empty())
344 deltas.front()->run();
345}
346
347void
340Scheduler::pause()
341{
348Scheduler::pause()
349{
342 _paused = true;
350 status(StatusPaused);
343 kernel->status(::sc_core::SC_PAUSED);
344 runOnce = false;
345 if (scMain && !scMain->finished())
346 scMain->run();
347}
348
349void
350Scheduler::stop()
351{
351 kernel->status(::sc_core::SC_PAUSED);
352 runOnce = false;
353 if (scMain && !scMain->finished())
354 scMain->run();
355}
356
357void
358Scheduler::stop()
359{
352 _stopped = true;
360 status(StatusStopped);
353 kernel->stop();
354
355 clear();
356
357 runOnce = false;
358 if (scMain && !scMain->finished())
359 scMain->run();
360}
361
362void
363Scheduler::start(Tick max_tick, bool run_to_time)
364{
365 // We should be running from sc_main. Keep track of that Fiber to return
366 // to later.
367 scMain = Fiber::currentFiber();
368
369 _started = true;
361 kernel->stop();
362
363 clear();
364
365 runOnce = false;
366 if (scMain && !scMain->finished())
367 scMain->run();
368}
369
370void
371Scheduler::start(Tick max_tick, bool run_to_time)
372{
373 // We should be running from sc_main. Keep track of that Fiber to return
374 // to later.
375 scMain = Fiber::currentFiber();
376
377 _started = true;
370 _paused = false;
371 _stopped = false;
378 status(StatusOther);
372 runToTime = run_to_time;
373
374 maxTick = max_tick;
375 lastReadyTick = getCurTick();
376
377 if (initDone) {
378 if (!runToTime && starved())
379 scheduleStarvationEvent();

--- 110 unchanged lines hidden ---
379 runToTime = run_to_time;
380
381 maxTick = max_tick;
382 lastReadyTick = getCurTick();
383
384 if (initDone) {
385 if (!runToTime && starved())
386 scheduleStarvationEvent();

--- 110 unchanged lines hidden ---