scheduler.cc (13244:deedec45898f) scheduler.cc (13245:c666c5d4996b)
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

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

31
32#include "base/fiber.hh"
33#include "base/logging.hh"
34#include "sim/eventq.hh"
35#include "systemc/core/kernel.hh"
36#include "systemc/ext/core/sc_main.hh"
37#include "systemc/ext/utils/sc_report.hh"
38#include "systemc/ext/utils/sc_report_handler.hh"
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

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

31
32#include "base/fiber.hh"
33#include "base/logging.hh"
34#include "sim/eventq.hh"
35#include "systemc/core/kernel.hh"
36#include "systemc/ext/core/sc_main.hh"
37#include "systemc/ext/utils/sc_report.hh"
38#include "systemc/ext/utils/sc_report_handler.hh"
39#include "systemc/utils/tracefile.hh"
39
40namespace sc_gem5
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 _elaborationDone(false), _started(false), _stopNow(false),
50 _status(StatusOther), maxTickEvent(this, false, MaxTickPriority),
40
41namespace sc_gem5
42{
43
44Scheduler::Scheduler() :
45 eq(nullptr), readyEvent(this, false, ReadyPriority),
46 pauseEvent(this, false, PausePriority),
47 stopEvent(this, false, StopPriority),
48 scMain(nullptr), _throwToScMain(nullptr),
49 starvationEvent(this, false, StarvationPriority),
50 _elaborationDone(false), _started(false), _stopNow(false),
51 _status(StatusOther), maxTickEvent(this, false, MaxTickPriority),
51 _numCycles(0), _changeStamp(0), _current(nullptr), initDone(false),
52 runOnce(false)
52 timeAdvancesEvent(this, false, TimeAdvancesPriority), _numCycles(0),
53 _changeStamp(0), _current(nullptr), initDone(false), runOnce(false)
53{}
54
55Scheduler::~Scheduler()
56{
57 // Clear out everything that belongs to us to make sure nobody tries to
58 // clear themselves out after the scheduler goes away.
59 clear();
60}

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

81 if (pauseEvent.scheduled())
82 deschedule(&pauseEvent);
83 if (stopEvent.scheduled())
84 deschedule(&stopEvent);
85 if (starvationEvent.scheduled())
86 deschedule(&starvationEvent);
87 if (maxTickEvent.scheduled())
88 deschedule(&maxTickEvent);
54{}
55
56Scheduler::~Scheduler()
57{
58 // Clear out everything that belongs to us to make sure nobody tries to
59 // clear themselves out after the scheduler goes away.
60 clear();
61}

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

82 if (pauseEvent.scheduled())
83 deschedule(&pauseEvent);
84 if (stopEvent.scheduled())
85 deschedule(&stopEvent);
86 if (starvationEvent.scheduled())
87 deschedule(&starvationEvent);
88 if (maxTickEvent.scheduled())
89 deschedule(&maxTickEvent);
90 if (timeAdvancesEvent.scheduled())
91 deschedule(&timeAdvancesEvent);
89
90 Process *p;
91 while ((p = initList.getNext()))
92 p->popListNode();
93 while ((p = readyListMethods.getNext()))
94 p->popListNode();
95 while ((p = readyListThreads.getNext()))
96 p->popListNode();

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

129 if (!runToTime && starved())
130 scheduleStarvationEvent();
131 kernel->status(::sc_core::SC_RUNNING);
132 }
133
134 initDone = true;
135
136 status(StatusOther);
92
93 Process *p;
94 while ((p = initList.getNext()))
95 p->popListNode();
96 while ((p = readyListMethods.getNext()))
97 p->popListNode();
98 while ((p = readyListThreads.getNext()))
99 p->popListNode();

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

132 if (!runToTime && starved())
133 scheduleStarvationEvent();
134 kernel->status(::sc_core::SC_RUNNING);
135 }
136
137 initDone = true;
138
139 status(StatusOther);
140
141 scheduleTimeAdvancesEvent();
137}
138
139void
140Scheduler::reg(Process *p)
141{
142 if (initDone) {
143 // If not marked as dontInitialize, mark as ready.
144 if (!p->dontInitialize())

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

258 if (readyEvent.scheduled())
259 deschedule(&readyEvent);
260 }
261}
262
263void
264Scheduler::runReady()
265{
142}
143
144void
145Scheduler::reg(Process *p)
146{
147 if (initDone) {
148 // If not marked as dontInitialize, mark as ready.
149 if (!p->dontInitialize())

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

263 if (readyEvent.scheduled())
264 deschedule(&readyEvent);
265 }
266}
267
268void
269Scheduler::runReady()
270{
271 scheduleTimeAdvancesEvent();
272
266 bool empty = readyListMethods.empty() && readyListThreads.empty();
267 lastReadyTick = getCurTick();
268
269 // The evaluation phase.
273 bool empty = readyListMethods.empty() && readyListThreads.empty();
274 lastReadyTick = getCurTick();
275
276 // The evaluation phase.
277 status(StatusEvaluate);
270 do {
271 yield();
272 } while (getNextReady());
273
274 if (!empty) {
275 _numCycles++;
276 _changeStamp++;
277 }
278
279 if (_stopNow) {
280 status(StatusOther);
281 return;
282 }
283
284 runUpdate();
278 do {
279 yield();
280 } while (getNextReady());
281
282 if (!empty) {
283 _numCycles++;
284 _changeStamp++;
285 }
286
287 if (_stopNow) {
288 status(StatusOther);
289 return;
290 }
291
292 runUpdate();
293 if (!traceFiles.empty())
294 trace(true);
285 runDelta();
286
287 if (!runToTime && starved())
288 scheduleStarvationEvent();
289
290 if (runOnce)
291 schedulePause();
292

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

362
363 if (initDone) {
364 if (!runToTime && starved())
365 scheduleStarvationEvent();
366 kernel->status(::sc_core::SC_RUNNING);
367 }
368
369 schedule(&maxTickEvent, maxTick);
295 runDelta();
296
297 if (!runToTime && starved())
298 scheduleStarvationEvent();
299
300 if (runOnce)
301 schedulePause();
302

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

372
373 if (initDone) {
374 if (!runToTime && starved())
375 scheduleStarvationEvent();
376 kernel->status(::sc_core::SC_RUNNING);
377 }
378
379 schedule(&maxTickEvent, maxTick);
380 scheduleTimeAdvancesEvent();
370
371 // Return to gem5 to let it run events, etc.
372 Fiber::primaryFiber()->run();
373
374 if (pauseEvent.scheduled())
375 deschedule(&pauseEvent);
376 if (stopEvent.scheduled())
377 deschedule(&stopEvent);

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

424 _stopNow = true;
425 // If we're not supposed to finish the delta cycle, flush all
426 // pending activity.
427 clear();
428 }
429 schedule(&stopEvent);
430}
431
381
382 // Return to gem5 to let it run events, etc.
383 Fiber::primaryFiber()->run();
384
385 if (pauseEvent.scheduled())
386 deschedule(&pauseEvent);
387 if (stopEvent.scheduled())
388 deschedule(&stopEvent);

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

435 _stopNow = true;
436 // If we're not supposed to finish the delta cycle, flush all
437 // pending activity.
438 clear();
439 }
440 schedule(&stopEvent);
441}
442
443void
444Scheduler::trace(bool delta)
445{
446 for (auto tf: traceFiles)
447 tf->trace(delta);
448}
449
432Scheduler scheduler;
433
434namespace {
435
436void
437throwingReportHandler(const ::sc_core::sc_report &r,
438 const ::sc_core::sc_actions &)
439{

--- 37 unchanged lines hidden ---
450Scheduler scheduler;
451
452namespace {
453
454void
455throwingReportHandler(const ::sc_core::sc_report &r,
456 const ::sc_core::sc_actions &)
457{

--- 37 unchanged lines hidden ---