Deleted Added
sdiff udiff text old ( 12953:ddfd5e4643a9 ) new ( 12954:8ea3a185354c )
full compact
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

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

25 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 *
27 * Authors: Gabe Black
28 */
29
30#ifndef __SYSTEMC_CORE_SCHEDULER_HH__
31#define __SYSTEMC_CORE_SCHEDULER_HH__
32
33#include "systemc/core/list.hh"
34#include "systemc/core/process.hh"
35
36namespace sc_gem5
37{
38
39typedef NodeList<Process> ProcessList;
40
41class Scheduler
42{
43 public:
44 Scheduler();
45
46 uint64_t numCycles() { return _numCycles; }
47 Process *current() { return _current; }
48
49 // Run the initialization phase.
50 void initialize();
51
52 // Run delta cycles until time needs to advance.
53 void runCycles();
54
55 // Put a process on the list of processes to be initialized.
56 void init(Process *p) { initList.pushLast(p); }
57
58 // Run the next process, if there is one.
59 void yield();
60
61 // Put a process on the ready list.
62 void
63 ready(Process *p)
64 {
65 // Clump methods together to minimize context switching.
66 if (p->procKind() == ::sc_core::SC_METHOD_PROC_)
67 readyList.pushFirst(p);
68 else
69 readyList.pushLast(p);
70 }
71
72 // Run the given process immediately, preempting whatever may be running.
73 void
74 runNow(Process *p)
75 {
76 // If a process is running, schedule it/us to run again.
77 if (_current)
78 readyList.pushFirst(_current);
79 // Schedule p to run first.
80 readyList.pushFirst(p);
81 yield();
82 }
83
84 private:
85 uint64_t _numCycles;
86
87 Process *_current;
88
89 ProcessList initList;
90 ProcessList readyList;
91
92 void evaluate();
93 void update();
94 void delta();
95};
96
97extern Scheduler scheduler;
98
99} // namespace sc_gem5
100
101#endif // __SYSTEMC_CORE_SCHEDULER_H__