scheduler.cc (12959:33d9a39e40a3) scheduler.cc (12961:9bd3a469fd11)
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

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

32#include "base/fiber.hh"
33#include "base/logging.hh"
34#include "sim/eventq.hh"
35
36namespace sc_gem5
37{
38
39Scheduler::Scheduler() :
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

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

32#include "base/fiber.hh"
33#include "base/logging.hh"
34#include "sim/eventq.hh"
35
36namespace sc_gem5
37{
38
39Scheduler::Scheduler() :
40 eq(nullptr), readyEvent(this, false, EventBase::Default_Pri + 1),
40 eq(nullptr), _pendingCurr(0), _pendingFuture(0),
41 readyEvent(this, false, ReadyPriority),
42 pauseEvent(this, false, PausePriority),
43 stopEvent(this, false, StopPriority),
44 scMain(nullptr), _started(false), _paused(false), _stopped(false),
45 maxTickEvent(this, false, MaxTickPriority),
41 _numCycles(0), _current(nullptr), initReady(false)
42{}
43
44void
45Scheduler::prepareForInit()
46{
47 for (Process *p = toFinalize.getNext(); p; p = toFinalize.getNext()) {
48 p->finalize();
49 p->popListNode();
50 }
51
52 for (Process *p = initList.getNext(); p; p = initList.getNext()) {
53 p->finalize();
54 p->ready();
55 }
56
46 _numCycles(0), _current(nullptr), initReady(false)
47{}
48
49void
50Scheduler::prepareForInit()
51{
52 for (Process *p = toFinalize.getNext(); p; p = toFinalize.getNext()) {
53 p->finalize();
54 p->popListNode();
55 }
56
57 for (Process *p = initList.getNext(); p; p = initList.getNext()) {
58 p->finalize();
59 p->ready();
60 }
61
62 if (_started)
63 eq->schedule(&maxTickEvent, maxTick);
64
57 initReady = true;
58}
59
60void
61Scheduler::reg(Process *p)
62{
63 if (initReady) {
64 // If we're past initialization, finalize static sensitivity.

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

93 if (!_current) {
94 // There are no more processes, so return control to evaluate.
95 Fiber::primaryFiber()->run();
96 } else {
97 _current->popListNode();
98 // Switch to whatever Fiber is supposed to run this process. All
99 // Fibers which aren't running should be parked at this line.
100 _current->fiber()->run();
65 initReady = true;
66}
67
68void
69Scheduler::reg(Process *p)
70{
71 if (initReady) {
72 // If we're past initialization, finalize static sensitivity.

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

101 if (!_current) {
102 // There are no more processes, so return control to evaluate.
103 Fiber::primaryFiber()->run();
104 } else {
105 _current->popListNode();
106 // Switch to whatever Fiber is supposed to run this process. All
107 // Fibers which aren't running should be parked at this line.
108 _current->fiber()->run();
101 // If the current process hasn't been started yet, start it. This
102 // should always be true for methods, but may not be true for threads.
103 if (_current && !_current->running())
109 // If the current process needs to be manually started, start it.
110 if (_current && _current->needsStart())
104 _current->run();
105 }
106}
107
108void
109Scheduler::ready(Process *p)
110{
111 // Clump methods together to minimize context switching.

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

159 Channel *channel = updateList.getNext();
160 while (channel) {
161 channel->popListNode();
162 channel->update();
163 channel = updateList.getNext();
164 }
165}
166
111 _current->run();
112 }
113}
114
115void
116Scheduler::ready(Process *p)
117{
118 // Clump methods together to minimize context switching.

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

166 Channel *channel = updateList.getNext();
167 while (channel) {
168 channel->popListNode();
169 channel->update();
170 channel = updateList.getNext();
171 }
172}
173
174void
175Scheduler::pause()
176{
177 _paused = true;
178 scMain->run();
179}
180
181void
182Scheduler::stop()
183{
184 _stopped = true;
185 scMain->run();
186}
187
188void
189Scheduler::start(Tick max_tick, bool run_to_time)
190{
191 // We should be running from sc_main. Keep track of that Fiber to return
192 // to later.
193 scMain = Fiber::currentFiber();
194
195 _started = true;
196 _paused = false;
197 _stopped = false;
198
199 maxTick = max_tick;
200
201 if (initReady)
202 eq->schedule(&maxTickEvent, maxTick);
203
204 // Return to gem5 to let it run events, etc.
205 Fiber::primaryFiber()->run();
206
207 if (pauseEvent.scheduled())
208 eq->deschedule(&pauseEvent);
209 if (stopEvent.scheduled())
210 eq->deschedule(&stopEvent);
211 if (maxTickEvent.scheduled())
212 eq->deschedule(&maxTickEvent);
213}
214
215void
216Scheduler::schedulePause()
217{
218 if (pauseEvent.scheduled())
219 return;
220
221 eq->schedule(&pauseEvent, eq->getCurTick());
222}
223
224void
225Scheduler::scheduleStop(bool finish_delta)
226{
227 if (stopEvent.scheduled())
228 return;
229
230 if (!finish_delta) {
231 // If we're not supposed to finish the delta cycle, flush the list
232 // of ready processes and scheduled updates.
233 Process *p;
234 while ((p = readyList.getNext()))
235 p->popListNode();
236 Channel *c;
237 while ((c = updateList.getNext()))
238 c->popListNode();
239 }
240 eq->schedule(&stopEvent, eq->getCurTick());
241}
242
167Scheduler scheduler;
168
169} // namespace sc_gem5
243Scheduler scheduler;
244
245} // namespace sc_gem5