40 #include "debug/QOS.hh" 44 #include "params/QoSMemCtrl.hh" 47 #include <unordered_map> 51 #ifndef __MEM_QOS_MEM_CTRL_HH__ 52 #define __MEM_QOS_MEM_CTRL_HH__ 69 const std::unique_ptr<Policy>
policy;
90 std::unordered_map<MasterID, const std::string>
masters;
189 Addr addr, uint64_t entries,
double delay);
200 template<
typename Queues>
201 uint8_t
qosSchedule(std::initializer_list<Queues*> queues_ptr,
202 uint64_t queue_entry_size,
const PacketPtr pkt);
236 template<
typename Queues>
237 void escalate(std::initializer_list<Queues*> queues,
238 uint64_t queue_entry_size,
239 MasterID m_id, uint8_t tgt_prio);
256 template<
typename Queues>
258 MasterID m_id, uint8_t curr_prio, uint8_t tgt_prio);
266 MemCtrl(
const QoSMemCtrlParams*);
273 void init()
override;
301 return masters.find(m_id) != masters.end();
311 {
return readQueueSizes[prio]; }
320 {
return writeQueueSizes[prio]; }
353 template<
typename Queues>
356 MasterID m_id, uint8_t curr_prio, uint8_t tgt_prio)
358 auto it = queues[curr_prio].begin();
359 while (it != queues[curr_prio].end()) {
367 "QoSMemCtrl::escalate checking priority %d packet " 368 "m_id %d address %d\n", curr_prio,
369 pkt->masterId(), pkt->getAddr());
372 if (pkt->masterId() == m_id) {
374 uint64_t moved_entries =
divCeil(pkt->getSize(),
378 "QoSMemCtrl::escalate Master %s [id %d] moving " 379 "packet addr %d size %d (p size %d) from priority %d " 381 "this master packets %d (entries to move %d)\n",
382 masters[m_id], m_id, pkt->getAddr(),
384 queue_entry_size, curr_prio, tgt_prio,
390 "QoSMemCtrl::escalate master %s negative READ " 391 "packets for priority %d",
395 }
else if (pkt->isWrite()) {
397 "QoSMemCtrl::escalate master %s negative WRITE " 398 "packets for priority %d",
405 pkt->qosValue(tgt_prio);
406 queues[tgt_prio].push_back(pkt);
410 it = queues[curr_prio].erase(it);
411 panic_if(packetPriorities[m_id][curr_prio] < moved_entries,
412 "QoSMemCtrl::escalate master %s negative packets " 416 packetPriorities[m_id][curr_prio] -= moved_entries;
417 packetPriorities[m_id][tgt_prio] += moved_entries;
425 template<
typename Queues>
428 uint64_t queue_entry_size,
436 "QoSMemCtrl::escalate Master %s [id %d] to priority " 437 "%d (currently %d packets)\n",
masters[m_id], m_id, tgt_prio,
440 for (uint8_t curr_prio = 0; curr_prio <
numPriorities(); ++curr_prio) {
442 if (curr_prio == tgt_prio)
448 "QoSMemCtrl::escalate MID %d checking priority %d " 449 "(packets %d)- current packets in prio %d: %d\n" 450 "\t(source read %d source write %d target read %d, " 451 "target write %d)\n",
459 for (
auto q : queues) {
461 curr_prio, tgt_prio);
467 "QoSMemCtrl::escalate Completed master %s [id %d] to priority %d " 468 "(now %d packets)\n\t(total read %d, total write %d)\n",
473 template<
typename Queues>
476 const uint64_t queue_entry_size,
480 uint8_t pkt_priority =
schedule(pkt);
497 "QoSMemCtrl::qosSchedule: (syncro) escalating " 498 "MASTER %s to assigned priority %d\n",
501 escalate(queues, queue_entry_size,
m.first, prio);
508 "QoSMemCtrl::qosSchedule: escalating " 509 "MASTER %s to assigned priority %d\n",
void logResponse(BusState dir, MasterID m_id, uint8_t qos, Addr addr, uint64_t entries, double delay)
Called upon receiving a response, updates statistics and updates queues status.
BusState busStateNext
bus state for next request event triggered
std::string getMasterName(MasterID master_id)
Get the name of an object for a given request id.
const std::unique_ptr< QueuePolicy > queuePolicy
QoS Queue Policy: selects packet among same-priority queue.
uint64_t totalReadQueueSize
Total read request packets queue length in #packets.
Stats::Scalar numWriteReadTurnArounds
Count the number of turnarounds WRITE to READ.
Stats::Vector priorityMinLatency
per-priority minimum latency
void addMaster(const MasterID m_id)
Initializes dynamically counters and statistics for a given Master.
Stats::Scalar numStayReadState
Count the number of times bus staying in READ state.
A vector of scalar stats.
void escalate(std::initializer_list< Queues *> queues, uint64_t queue_entry_size, MasterID m_id, uint8_t tgt_prio)
Escalates/demotes priority of all packets belonging to the passed master to given priority value...
std::vector< Tick > serviceTick
Vector of QoS priorities/last service time.
uint8_t numPriorities() const
Gets the total number of priority levels in the QoS memory controller.
uint8_t qosSchedule(std::initializer_list< Queues *> queues_ptr, uint64_t queue_entry_size, const PacketPtr pkt)
Assign priority to a packet by executing the configured QoS policy.
This is a simple scalar statistic, like a counter.
const std::unique_ptr< TurnaroundPolicy > turnPolicy
QoS Bus Turnaround Policy: selects the bus direction (READ/WRITE)
std::unordered_map< MasterID, const std::string > masters
Hash of master ID - master name.
MemCtrl(const QoSMemCtrlParams *)
QoS Memory base class.
AbstractMemory declaration.
Tick curTick()
The current simulated tick.
Stats::Scalar numStayWriteState
Count the number of times bus staying in WRITE state.
Stats::VectorStandardDeviation avgPriorityDistance
per-master average QoS distance between assigned and queued values
MemCtrlStats(MemCtrl &mc)
uint64_t getWriteQueueSize(const uint8_t prio) const
Gets a WRITE queue size.
std::vector< uint64_t > readQueueSizes
Read request packets queue length in #packets, per QoS priority.
uint64_t Tick
Tick count type.
uint8_t qosValue() const
QoS Value getter Returns 0 if QoS value was never set (constructor default).
void escalateQueues(Queues &queues, uint64_t queue_entry_size, MasterID m_id, uint8_t curr_prio, uint8_t tgt_prio)
Escalates/demotes priority of all packets belonging to the passed master to given priority value in a...
MasterID masterId() const
BusState busState
Bus state used to control the read/write switching and drive the scheduling of the next request...
void recordTurnaroundStats()
Record statistics on turnarounds based on busStateNext and busState values.
uint64_t getTotalWriteQueueSize() const
Gets the total combined WRITE queues size.
BusState getBusStateNext() const
Gets the next bus state.
uint64_t totalWriteQueueSize
Total write request packets queue length in #packets.
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
const bool qosSyncroScheduler
Enables QoS synchronized scheduling invokes the QoS scheduler on all masters, at every packet arrival...
bool hasMaster(MasterID m_id) const
hasMaster returns true if the selected master(ID) has been registered in the memory controller...
void setCurrentBusState()
Set current bus direction (READ or WRITE) from next selected one.
const uint8_t _numPriorities
Number of configured QoS priorities.
A Packet is used to encapsulate a transfer between two objects in the memory system (e...
void regStats() override
Callback to set stat parameters.
uint64_t getReadQueueSize(const uint8_t prio) const
Gets a READ queue size.
const std::unique_ptr< Policy > policy
QoS Policy, assigns QoS priority to the incoming packets.
Stats::VectorStandardDeviation avgPriority
per-master average QoS priority
uint64_t getTotalReadQueueSize() const
Gets the total combined READ queues size.
void logRequest(BusState dir, MasterID m_id, uint8_t qos, Addr addr, uint64_t entries)
Called upon receiving a request or updates statistics and updates queues status.
System * _system
Pointer to the System object.
std::unordered_map< MasterID, std::unordered_map< uint64_t, std::deque< uint64_t > > > requestTimes
Hash of masters - address of request - queue of times of request.
T divCeil(const T &a, const U &b)
Stats::Scalar numReadWriteTurnArounds
Count the number of turnarounds READ to WRITE.
void schedule(Event &event, Tick when)
Stats::Vector priorityMaxLatency
per-priority maximum latency
BusState getBusState() const
Gets the current bus state.
const bool qosPriorityEscalation
Enables QoS priority escalation.
An abstract memory represents a contiguous block of physical memory, with an associated address range...
Tick getServiceTick(const uint8_t prio) const
Gets the last service tick related to a QoS Priority.
void init() override
Initializes this object.
std::unordered_map< MasterID, std::vector< uint64_t > > packetPriorities
Hash of masters - number of packets queued per priority.
std::vector< uint64_t > writeQueueSizes
Write request packets queue length in #packets, per QoS priority.
This is a vector of StandardDeviation stats.
#define panic_if(cond,...)
Conditional panic macro that checks the supplied condition and only panics if the condition is true a...
std::vector< Info * > stats
The QoS::MemCtrl is a base class for Memory objects which support QoS - it provides access to a set o...
uint8_t schedule(MasterID m_id, uint64_t data)
BusState selectNextBusState()
Returns next bus direction (READ or WRITE) based on configured policy.