The Sparta Modeling Framework
Loading...
Searching...
No Matches
Dispatch.hpp
1// <Dispatch.h> -*- C++ -*-
2
3
4#pragma once
5
6#include <string>
7#include <array>
8#include <cinttypes>
9
16#include "sparta/log/MessageSource.hpp"
17#include "sparta/statistics/Counter.hpp"
18#include "sparta/statistics/ContextCounter.hpp"
19#include "sparta/statistics/WeightedContextCounter.hpp"
20
21#include "CoreTypes.hpp"
22#include "FlushManager.hpp"
23
24namespace core_example
25{
26
35 class Dispatch : public sparta::Unit
36 {
37 public:
40 {
41 public:
44 { }
45
46 PARAMETER(uint32_t, num_to_dispatch, 3, "Number of instructions to dispatch")
47 PARAMETER(uint32_t, dispatch_queue_depth, 10, "Depth of the dispatch buffer")
48 PARAMETER(std::vector<double>, context_weights, std::vector<double>(1,1),
49 "Relative weight of each context")
50 };
51
63 const DispatchParameterSet * p);
64
66 static const char name[];
67
68 private:
69 InstQueue dispatch_queue_;
70
71 // Ports
72 sparta::DataInPort<InstGroup> in_dispatch_queue_write_ {&unit_port_set_, "in_dispatch_queue_write", 1};
73 sparta::DataOutPort<uint32_t> out_dispatch_queue_credits_{&unit_port_set_, "out_dispatch_queue_credits"};
74 sparta::DataOutPort<InstQueue::value_type> out_fpu_write_ {&unit_port_set_, "out_fpu_write"};
75 sparta::DataOutPort<InstQueue::value_type> out_alu0_write_ {&unit_port_set_, "out_alu0_write", false}; // Do not assume zero-cycle delay
76 sparta::DataOutPort<InstQueue::value_type> out_alu1_write_ {&unit_port_set_, "out_alu1_write", false}; // Do not assume zero-cycle delay
77 sparta::DataOutPort<InstQueue::value_type> out_br_write_ {&unit_port_set_, "out_br_write", false}; // Do not assume zero-cycle delay
78 sparta::DataOutPort<InstQueue::value_type> out_lsu_write_ {&unit_port_set_, "out_lsu_write", false};
79 sparta::DataOutPort<InstGroup> out_reorder_write_ {&unit_port_set_, "out_reorder_buffer_write"};
80
81 sparta::DataInPort<uint32_t> in_fpu_credits_ {&unit_port_set_, "in_fpu_credits", sparta::SchedulingPhase::Tick, 0};
82 sparta::DataInPort<uint32_t> in_alu0_credits_ {&unit_port_set_, "in_alu0_credits", sparta::SchedulingPhase::Tick, 0};
83 sparta::DataInPort<uint32_t> in_alu1_credits_ {&unit_port_set_, "in_alu1_credits", sparta::SchedulingPhase::Tick, 0};
85 sparta::DataInPort<uint32_t> in_lsu_credits_ {&unit_port_set_, "in_lsu_credits", sparta::SchedulingPhase::Tick, 0};
86 sparta::DataInPort<uint32_t> in_reorder_credits_{&unit_port_set_, "in_reorder_buffer_credits", sparta::SchedulingPhase::Tick, 0};
87
88 // For flush
90 {&unit_port_set_, "in_reorder_flush", sparta::SchedulingPhase::Flush, 1};
91
92 // Tick events
93 sparta::SingleCycleUniqueEvent<> ev_dispatch_insts_{&unit_event_set_, "dispatch_event", CREATE_SPARTA_HANDLER(Dispatch, dispatchInstructions_)};
94
95 const uint32_t num_to_dispatch_;
96 uint32_t credits_rob_ = 0;
97 uint32_t credits_fpu_ = 0;
98 uint32_t credits_alu0_ = 0;
99 uint32_t credits_alu1_ = 0;
100 uint32_t credits_br_ = 0;
101 uint32_t credits_lsu_ = 0;
102
103 // Send rename initial credits
104 void sendInitialCredits_();
105
106 // Tick callbacks assigned to Ports -- zero cycle
107 void fpuCredits_ (const uint32_t&);
108 void alu0Credits_(const uint32_t&);
109 void alu1Credits_(const uint32_t&);
110 void brCredits_(const uint32_t&);
111 void lsuCredits_ (const uint32_t&);
112 void robCredits_(const uint32_t&);
113
114 // Dispatch instructions
115 void dispatchQueueAppended_(const InstGroup &);
116 void dispatchInstructions_();
117
118 // Flush notifications
119 void handleFlush_(const FlushManager::FlushingCriteria & criteria);
120
122 // Stall counters
123 enum StallReason {
124 NOT_STALLED, // Made forward progress (dipatched all instructions or no instructions)
125 NO_ROB_CREDITS, // No credits from the ROB
126 ALU0_BUSY, // Could not send any or all instructions -- ALU0 busy
127 ALU1_BUSY, // Could not send any or all instructions -- ALU1 busy
128 FPU_BUSY, // Could not send any or all instructions -- FPU busy
129 LSU_BUSY,
130 BR_BUSY, // Could not send any or all instructions -- BR busy
131 N_STALL_REASONS
132 };
133
134 StallReason current_stall_ = NOT_STALLED;
135
136 // Counters -- this is only supported in C++11 -- uses
137 // Counter's move semantics
138 std::array<sparta::CycleCounter, N_STALL_REASONS> stall_counters_{{
139 sparta::CycleCounter(getStatisticSet(), "stall_not_stalled",
140 "Dispatch not stalled, all instructions dispatched",
142 sparta::CycleCounter(getStatisticSet(), "stall_no_rob_credits",
143 "No credits from ROB",
145 sparta::CycleCounter(getStatisticSet(), "stall_alu0_busy",
146 "ALU0 busy",
148 sparta::CycleCounter(getStatisticSet(), "stall_alu1_busy",
149 "ALU1 busy",
151 sparta::CycleCounter(getStatisticSet(), "stall_fpu_busy",
152 "FPU busy",
154 sparta::CycleCounter(getStatisticSet(), "stall_lsu_busy",
155 "LSU busy",
157 sparta::CycleCounter(getStatisticSet(), "stall_br_busy",
158 "BR busy",
160 }};
161
162 std::array<sparta::Counter,
163 static_cast<uint32_t>(ExampleInst::TargetUnit::N_TARGET_UNITS)>
164 unit_distribution_ {{
165 sparta::Counter(getStatisticSet(), "count_alu0_insts",
166 "Total ALU0 insts", sparta::Counter::COUNT_NORMAL),
167 sparta::Counter(getStatisticSet(), "count_alu1_insts",
168 "Total ALU1 insts", sparta::Counter::COUNT_NORMAL),
169 sparta::Counter(getStatisticSet(), "count_fpu_insts",
170 "Total FPU insts", sparta::Counter::COUNT_NORMAL),
171 sparta::Counter(getStatisticSet(), "count_br_insts",
172 "Total BR insts", sparta::Counter::COUNT_NORMAL),
173 sparta::Counter(getStatisticSet(), "count_lsu_insts",
174 "Total LSU insts", sparta::Counter::COUNT_NORMAL),
175 sparta::Counter(getStatisticSet(), "count_rob_insts",
176 "Total ROB insts", sparta::Counter::COUNT_NORMAL)
177 }};
178
179 // As an example, this is a context counter that does the same
180 // thing as the unit_distribution counter, albeit a little
181 // ambiguous as to the relation of the context and the unit.
182 sparta::ContextCounter<sparta::Counter> unit_distribution_context_
184 "count_insts_per_unit",
185 "Unit distributions",
186 static_cast<uint32_t>(ExampleInst::TargetUnit::N_TARGET_UNITS),
187 "dispatch_inst_count",
190
191 // As another example, this is a weighted context counter. It does
192 // the same thing as a regular sparta::ContextCounter with the addition
193 // of being able to specify weights to the various contexts. Calling
194 // the "calculatedWeightedAverage()" method will compute the weighted
195 // average of the internal context counter values.
196 sparta::WeightedContextCounter<sparta::Counter> weighted_unit_distribution_context_ {
198 "weighted_count_insts_per_unit",
199 "Weighted unit distributions",
200 static_cast<uint32_t>(ExampleInst::TargetUnit::N_TARGET_UNITS),
203 };
204
205 // ContextCounter with only one context. These are handled differently
206 // than other ContextCounters; they are not automatically expanded to
207 // include per-context information in reports, since that is redundant
208 // information.
211 "context_count_alu0_insts",
212 "ALU0 instruction count",
213 1,
214 "dispatch_alu0_inst_count",
217 };
218
219 sparta::StatisticDef total_insts_{
220 getStatisticSet(), "count_total_insts_dispatched",
221 "Total number of instructions dispatched",
222 getStatisticSet(), "count_alu0_insts + count_alu1_insts + count_fpu_insts + count_lsu_insts"
223 };
224 };
225}
File that defines Data[In,Out]Port<DataT>
A set of sparta::Parameters per sparta::ResourceTreeNode.
#define PARAMETER(type, name, def, doc)
Parameter declaration.
File that defines the SignalInPort.
File that defines the SingleCycleUniqueEvent class.
#define CREATE_SPARTA_HANDLER(clname, meth)
Basic Node framework in sparta device tree composite pattern.
File that defines the Unit class, a common grouping of sets and loggers.
Parameters for Dispatch model.
Definition Dispatch.hpp:40
static const char name[]
Name of this resource. Required by sparta::UnitFactory.
Definition Dispatch.hpp:66
A container type that allows a modeler to build, store, and charge counts to a specific context.
@ COUNT_NORMAL
Counter counts the number of times something happens like one would expect. This is a weakly monotoni...
Represents a counter of type counter_type (uint64_t). 2 and greater than 0 with a ceiling specified....
Definition Counter.hpp:27
Represents a cycle counter.
DataInPort receives data from sender using a DataOutPort.
Definition DataPort.hpp:289
DataOutPort is used for transferring any data to another module.
Definition DataPort.hpp:77
@ VIS_NORMAL
Normal visibility (default)
Generic container of Parameters.
const Clock * getClock() const
An event that can only be schedule one cycle into the future.
Contains a statistic definition (some useful information which can be computed)
Node in a composite tree representing a sparta Tree item.
Definition TreeNode.hpp:205
The is the base class for user defined blocks in simulation.
Definition Unit.hpp:38
sparta::EventSet unit_event_set_
The Unit's event set.
Definition Unit.hpp:114
sparta::PortSet unit_port_set_
The Unit's Ports.
Definition Unit.hpp:111
StatisticSet * getStatisticSet()
Return the stat set.
Definition Unit.hpp:105
This is an example context counter subclass used to show how users may supply their own "aggregated v...
@ Tick
Most operations (combinational logic) occurs in this phase.
@ Flush
Phase where flushing of pipelines, etc can occur.