The Sparta Modeling Framework
Loading...
Searching...
No Matches
Rename.cpp
Go to the documentation of this file.
1
8#include <algorithm>
9#include "Rename.hpp"
12#include "sparta/report/DatabaseInterface.hpp"
13#include "simdb/ObjectManager.hpp"
14#include "simdb/ObjectRef.hpp"
15
16namespace core_example
17{
18 const char Rename::name[] = "rename";
19
21 const RenameParameterSet * p) :
22 sparta::Unit(node),
23 uop_queue_("rename_uop_queue", p->rename_queue_depth,
24 node->getClock(), getStatisticSet()),
25 num_to_rename_per_cycle_(p->num_to_rename)
26 {
27 uop_queue_.enableCollection(node);
28
29 // The path into the Rename block
30 // - Instructions are received on the Uop Queue Append port
31 // - Credits arrive on the dispatch queue credits port
32 in_uop_queue_append_.
33 registerConsumerHandler(CREATE_SPARTA_HANDLER_WITH_DATA(Rename, decodedInstructions_, InstGroup));
34 in_dispatch_queue_credits_.
35 registerConsumerHandler(CREATE_SPARTA_HANDLER_WITH_DATA(Rename, creditsDispatchQueue_, uint32_t));
36 in_reorder_flush_.
37 registerConsumerHandler(CREATE_SPARTA_HANDLER_WITH_DATA(Rename, handleFlush_, FlushManager::FlushingCriteria));
38 sparta::StartupEvent(node, CREATE_SPARTA_HANDLER(Rename, sendInitialCredits_));
39 }
40
41 // Send the initial credit count
42 void Rename::sendInitialCredits_()
43 {
44 out_uop_queue_credits_.send(uop_queue_.capacity());
45 }
46
47 void Rename::creditsDispatchQueue_(const uint32_t & credits)
48 {
49 sparta_assert(in_dispatch_queue_credits_.dataReceived());
50
51 credits_dispatch_ += credits;
52 if (uop_queue_.size() > 0) {
53 ev_rename_insts_.schedule();
54 }
55 }
56
57 // Handle incoming flush
58 void Rename::handleFlush_(const FlushManager::FlushingCriteria & criteria)
59 {
61 info_logger_ << "Got a flush call for " << criteria;
62 }
63 out_uop_queue_credits_.send(uop_queue_.size());
64 uop_queue_.clear();
65
66 if (!stop_checking_db_access_) {
67 if (auto container = getContainer()) {
68 if (auto sim = container->getSimulation()) {
69 if (sparta::IsFeatureValueEnabled(sim->getFeatureConfiguration(),
70 "wildcard-components"))
71 {
72 if (auto dbconn = GET_DB_FOR_COMPONENT(Stats, container)) {
73 //Run a simple query against the database just to verify
74 //the connection is open and accepting requests
75 (void) dbconn->findObject("ObjectManagersInDatabase", 1);
76 }
77 }
78 }
79 }
80 stop_checking_db_access_ = true;
81 }
82 }
83
84 void Rename::decodedInstructions_(const InstGroup & insts)
85 {
86 sparta_assert(in_uop_queue_append_.dataReceived());
87
88 for(auto & i : insts) {
89 uop_queue_.push(i);
90 }
91
92 // If we have credits from dispatch, schedule a rename session
93 // this cycle
94 if (credits_dispatch_ > 0) {
95 ev_rename_insts_.schedule();
96 }
97 }
98
99 void Rename::renameInstructions_()
100 {
101
102 uint32_t num_rename = std::min(uop_queue_.size(), num_to_rename_per_cycle_);
103 num_rename = std::min(credits_dispatch_, num_rename);
104
105 if(num_rename > 0)
106 {
107
108 InstGroup insts;
109 for(uint32_t i = 0; i < num_rename; ++i) {
110 insts.emplace_back(uop_queue_.read(0));
112 info_logger_ << ": sending inst to dispatch: " << uop_queue_.read(0);
113 }
114 uop_queue_.pop();
115 }
116 out_dispatch_queue_write_.send(insts);
117 credits_dispatch_ -= num_rename;
118
119 // Replenish credits in the Decode unit
120 out_uop_queue_credits_.send(num_rename);
121 }
122
123 if (credits_dispatch_ > 0 && (uop_queue_.size() > 0)) {
124 ev_rename_insts_.schedule(1);
125 }
126 }
127
128}
#define sparta_assert(...)
Simple variadic assertion that will throw a sparta_exception if the condition fails.
#define SPARTA_EXPECT_FALSE(x)
A macro for hinting to the compiler a particular condition should be considered most likely false.
#define CREATE_SPARTA_HANDLER_WITH_DATA(clname, meth, dataT)
#define CREATE_SPARTA_HANDLER(clname, meth)
File that defines the StartupEvent class.
Parameters for Rename model.
Definition Rename.hpp:33
static const char name[]
Name of this resource. Required by sparta::UnitFactory.
Definition Rename.hpp:53
Rename(sparta::TreeNode *node, const RenameParameterSet *p)
Constructor for Rename.
Definition Rename.cpp:20
bool dataReceived() const
Has this port received data (not timed)
void send(const DataT &dat, sparta::Clock::Cycle rel_time=0)
Send data to bound receivers.
Definition DataPort.hpp:145
size_type size() const
Return the number of valid entries.
Definition Queue.hpp:552
uint32_t capacity() const
Return the fixed size of this queue.
Definition Queue.hpp:544
const value_type & read(uint32_t idx) const
Read and return the data at the given index, const reference.
Definition Queue.hpp:503
iterator push(const value_type &dat)
push data to the Queue.
Definition Queue.hpp:615
void enableCollection(TreeNode *parent)
Request that this queue begin collecting its contents for pipeline collection.
Definition Queue.hpp:603
void clear()
Empty the queue.
Definition Queue.hpp:580
void pop()
Pops the data at the front of the structure (oldest element) After pop iterator always points to the ...
Definition Queue.hpp:636
TreeNode * getContainer()
Gets the TreeNode (container) for this resource (if any)
StartupEvent is a simple class for scheduling a starting event on the Scheduler. It does not support ...
Node in a composite tree representing a sparta Tree item.
Definition TreeNode.hpp:205
void schedule()
Schedule this event with its pre-set delay using the pre-set Clock.
log::MessageSource info_logger_
Default info logger.
Definition Unit.hpp:161
Macros for handling exponential backoff.
std::enable_if< std::is_same< T, app::FeatureConfiguration >::value, bool >::type IsFeatureValueEnabled(const T &cfg, const std::string &feature_name)