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 --- 28 unchanged lines hidden (view full) --- 37 38namespace sc_gem5 39{ 40 41Scheduler::Scheduler() : 42 eq(nullptr), readyEvent(this, false, ReadyPriority), 43 pauseEvent(this, false, PausePriority), 44 stopEvent(this, false, StopPriority), |
45 scMain(nullptr), 46 starvationEvent(this, false, StarvationPriority), 47 _started(false), _paused(false), _stopped(false), |
48 maxTickEvent(this, false, MaxTickPriority), 49 _numCycles(0), _current(nullptr), initReady(false) 50{} 51 52void 53Scheduler::prepareForInit() 54{ 55 for (Process *p = toFinalize.getNext(); p; p = toFinalize.getNext()) { --- 84 unchanged lines hidden (view full) --- 140 141void 142Scheduler::scheduleReadyEvent() 143{ 144 // Schedule the evaluate and update phases. 145 if (!readyEvent.scheduled()) { 146 panic_if(!eq, "Need to schedule ready, but no event manager.\n"); 147 eq->schedule(&readyEvent, eq->getCurTick()); |
148 if (starvationEvent.scheduled()) 149 eq->deschedule(&starvationEvent); |
150 } 151} 152 153void |
154Scheduler::scheduleStarvationEvent() 155{ 156 if (!starvationEvent.scheduled()) { 157 panic_if(!eq, "Need to schedule starvation event, " 158 "but no event manager.\n"); 159 eq->schedule(&starvationEvent, eq->getCurTick()); 160 if (readyEvent.scheduled()) 161 eq->deschedule(&readyEvent); 162 } 163} 164 165void |
166Scheduler::runReady() 167{ 168 bool empty = readyList.empty(); 169 170 // The evaluation phase. 171 do { 172 yield(); 173 } while (!readyList.empty()); 174 175 if (!empty) 176 _numCycles++; 177 178 // The update phase. 179 update(); 180 |
181 if (starved() && !runToTime) 182 scheduleStarvationEvent(); 183 |
184 // The delta phase will happen naturally through the event queue. 185} 186 187void 188Scheduler::update() 189{ 190 Channel *channel = updateList.getNext(); 191 while (channel) { --- 24 unchanged lines hidden (view full) --- 216{ 217 // We should be running from sc_main. Keep track of that Fiber to return 218 // to later. 219 scMain = Fiber::currentFiber(); 220 221 _started = true; 222 _paused = false; 223 _stopped = false; |
224 runToTime = run_to_time; |
225 226 maxTick = max_tick; 227 |
228 if (starved() && !runToTime) 229 return; 230 |
231 if (initReady) { 232 kernel->status(::sc_core::SC_RUNNING); 233 eq->schedule(&maxTickEvent, maxTick); 234 } 235 236 // Return to gem5 to let it run events, etc. 237 Fiber::primaryFiber()->run(); 238 239 if (pauseEvent.scheduled()) 240 eq->deschedule(&pauseEvent); 241 if (stopEvent.scheduled()) 242 eq->deschedule(&stopEvent); 243 if (maxTickEvent.scheduled()) 244 eq->deschedule(&maxTickEvent); |
245 if (starvationEvent.scheduled()) 246 eq->deschedule(&starvationEvent); |
247} 248 249void 250Scheduler::schedulePause() 251{ 252 if (pauseEvent.scheduled()) 253 return; 254 --- 25 unchanged lines hidden --- |