scheduler.hh (12957:e54f9890363d) | scheduler.hh (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 --- 18 unchanged lines hidden (view full) --- 27 * Authors: Gabe Black 28 */ 29 30#ifndef __SYSTEMC_CORE_SCHEDULER_HH__ 31#define __SYSTEMC_CORE_SCHEDULER_HH__ 32 33#include <vector> 34 | 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 --- 18 unchanged lines hidden (view full) --- 27 * Authors: Gabe Black 28 */ 29 30#ifndef __SYSTEMC_CORE_SCHEDULER_HH__ 31#define __SYSTEMC_CORE_SCHEDULER_HH__ 32 33#include <vector> 34 |
35#include "base/logging.hh" |
|
35#include "sim/eventq.hh" 36#include "systemc/core/channel.hh" 37#include "systemc/core/list.hh" 38#include "systemc/core/process.hh" 39 | 36#include "sim/eventq.hh" 37#include "systemc/core/channel.hh" 38#include "systemc/core/list.hh" 39#include "systemc/core/process.hh" 40 |
41class Fiber; 42 |
|
40namespace sc_gem5 41{ 42 43typedef NodeList<Process> ProcessList; 44typedef NodeList<Channel> ChannelList; 45 46/* 47 * The scheduler supports three different mechanisms, the initialization phase, --- 52 unchanged lines hidden (view full) --- 100 * TIMED NOTIFICATION PHASE 101 * 102 * If no processes became runnable, the event queue will continue to process 103 * events until it comes across a timed notification, aka a notification 104 * scheduled to happen in the future. Like delta notification events, those 105 * will all happen together since the readyEvent priority is lower, 106 * potentially marking new processes as ready. Once these events finish, the 107 * readyEvent may run, starting the next delta cycle. | 43namespace sc_gem5 44{ 45 46typedef NodeList<Process> ProcessList; 47typedef NodeList<Channel> ChannelList; 48 49/* 50 * The scheduler supports three different mechanisms, the initialization phase, --- 52 unchanged lines hidden (view full) --- 103 * TIMED NOTIFICATION PHASE 104 * 105 * If no processes became runnable, the event queue will continue to process 106 * events until it comes across a timed notification, aka a notification 107 * scheduled to happen in the future. Like delta notification events, those 108 * will all happen together since the readyEvent priority is lower, 109 * potentially marking new processes as ready. Once these events finish, the 110 * readyEvent may run, starting the next delta cycle. |
111 * 112 * PAUSE/STOP 113 * 114 * To inject a pause from sc_pause which should happen after the current delta 115 * cycle's delta notification phase, an event is scheduled with a lower than 116 * normal priority, but higher than the readyEvent. That ensures that any 117 * delta notifications which are scheduled with normal priority will happen 118 * first, since those are part of the current delta cycle. Then the pause 119 * event will happen before the next readyEvent which would start the next 120 * delta cycle. All of these events are scheduled for the current time, and so 121 * would happen before any timed notifications went off. 122 * 123 * To inject a stop from sc_stop, the delta cycles should stop before even the 124 * delta notifications have happened, but after the evaluate and update phases. 125 * For that, a stop event with slightly higher than normal priority will be 126 * scheduled so that it happens before any of the delta notification events 127 * which are at normal priority. 128 * 129 * MAX RUN TIME 130 * 131 * When sc_start is called, it's possible to pass in a maximum time the 132 * simulation should run to, at which point sc_pause is implicitly called. 133 * That's implemented by scheduling an event at the max time with a priority 134 * which is lower than all the others so that it happens only if time would 135 * advance. When that event triggers, it calls the same function as the pause 136 * event. |
|
108 */ 109 110class Scheduler 111{ 112 public: 113 Scheduler(); 114 115 const std::string name() const { return "systemc_scheduler"; } --- 35 unchanged lines hidden (view full) --- 151 void setEventQueue(EventQueue *_eq) { eq = _eq; } 152 153 // Retrieve the event queue. 154 EventQueue &eventQueue() const { return *eq; } 155 156 // Run scheduled channel updates. 157 void update(); 158 | 137 */ 138 139class Scheduler 140{ 141 public: 142 Scheduler(); 143 144 const std::string name() const { return "systemc_scheduler"; } --- 35 unchanged lines hidden (view full) --- 180 void setEventQueue(EventQueue *_eq) { eq = _eq; } 181 182 // Retrieve the event queue. 183 EventQueue &eventQueue() const { return *eq; } 184 185 // Run scheduled channel updates. 186 void update(); 187 |
188 void setScMainFiber(Fiber *sc_main) { scMain = sc_main; } 189 190 void start(Tick max_tick, bool run_to_time); 191 192 void schedulePause(); 193 void scheduleStop(bool finish_delta); 194 195 bool paused() { return _paused; } 196 bool stopped() { return _stopped; } 197 |
|
159 private: | 198 private: |
199 typedef const EventBase::Priority Priority; 200 static Priority DefaultPriority = EventBase::Default_Pri; 201 202 static Priority StopPriority = DefaultPriority - 1; 203 static Priority PausePriority = DefaultPriority + 1; 204 static Priority ReadyPriority = DefaultPriority + 2; 205 static Priority MaxTickPriority = DefaultPriority + 3; 206 |
|
160 EventQueue *eq; 161 162 void runReady(); 163 EventWrapper<Scheduler, &Scheduler::runReady> readyEvent; 164 void scheduleReadyEvent(); 165 | 207 EventQueue *eq; 208 209 void runReady(); 210 EventWrapper<Scheduler, &Scheduler::runReady> readyEvent; 211 void scheduleReadyEvent(); 212 |
213 void pause(); 214 void stop(); 215 EventWrapper<Scheduler, &Scheduler::pause> pauseEvent; 216 EventWrapper<Scheduler, &Scheduler::stop> stopEvent; 217 Fiber *scMain; 218 219 bool _started; 220 bool _paused; 221 bool _stopped; 222 223 Tick maxTick; 224 EventWrapper<Scheduler, &Scheduler::pause> maxTickEvent; 225 |
|
166 uint64_t _numCycles; 167 168 Process *_current; 169 170 bool initReady; 171 172 ProcessList initList; 173 ProcessList toFinalize; 174 ProcessList readyList; 175 176 ChannelList updateList; 177}; 178 179extern Scheduler scheduler; 180 181} // namespace sc_gem5 182 183#endif // __SYSTEMC_CORE_SCHEDULER_H__ | 226 uint64_t _numCycles; 227 228 Process *_current; 229 230 bool initReady; 231 232 ProcessList initList; 233 ProcessList toFinalize; 234 ProcessList readyList; 235 236 ChannelList updateList; 237}; 238 239extern Scheduler scheduler; 240 241} // namespace sc_gem5 242 243#endif // __SYSTEMC_CORE_SCHEDULER_H__ |