38#ifndef __MEM_QOS_MEM_CTRL_HH__
39#define __MEM_QOS_MEM_CTRL_HH__
44#include <unordered_map>
53#include "debug/QOS.hh"
56#include "params/QoSMemCtrl.hh"
72class TurnaroundPolicy;
87 const std::unique_ptr<Policy>
policy;
108 std::unordered_map<RequestorID, const std::string>
requestors;
210 Addr addr, uint64_t entries,
double delay);
221 template<
typename Queues>
222 uint8_t
qosSchedule(std::initializer_list<Queues*> queues_ptr,
223 uint64_t queue_entry_size,
const PacketPtr pkt);
257 template<
typename Queues>
258 void escalate(std::initializer_list<Queues*> queues,
259 uint64_t queue_entry_size,
277 template<
typename Queues>
279 RequestorID id, uint8_t curr_prio, uint8_t tgt_prio);
287 MemCtrl(
const QoSMemCtrlParams &);
373template<
typename Queues>
376 RequestorID id, uint8_t curr_prio, uint8_t tgt_prio)
378 auto it = queues[curr_prio].begin();
379 while (it != queues[curr_prio].end()) {
387 "qos::MemCtrl::escalateQueues checking priority %d packet "
388 "id %d address %d\n", curr_prio,
389 pkt->requestorId(), pkt->getAddr());
392 if (pkt->requestorId() ==
id) {
394 uint64_t moved_entries =
divCeil(pkt->getSize(),
398 "qos::MemCtrl::escalateQueues Requestor %s [id %d] moving "
399 "packet addr %d size %d (p size %d) from priority %d "
401 "this requestor packets %d (entries to move %d)\n",
404 queue_entry_size, curr_prio, tgt_prio,
410 "qos::MemCtrl::escalateQueues requestor %s negative "
411 "READ packets for priority %d",
415 }
else if (pkt->isWrite()) {
417 "qos::MemCtrl::escalateQueues requestor %s negative "
418 "WRITE packets for priority %d",
425 pkt->qosValue(tgt_prio);
426 queues[tgt_prio].push_back(pkt);
430 it = queues[curr_prio].erase(it);
432 "qos::MemCtrl::escalateQueues requestor %s negative "
433 "packets for priority %d",
445template<
typename Queues>
448 uint64_t queue_entry_size,
456 "qos::MemCtrl::escalate Requestor %s [id %d] to priority "
457 "%d (currently %d packets)\n",
requestors[
id],
id, tgt_prio,
460 for (uint8_t curr_prio = 0; curr_prio <
numPriorities(); ++curr_prio) {
462 if (curr_prio == tgt_prio)
468 "qos::MemCtrl::escalate MID %d checking priority %d "
469 "(packets %d)- current packets in prio %d: %d\n"
470 "\t(source read %d source write %d target read %d, "
471 "target write %d)\n",
479 for (
auto q : queues) {
481 curr_prio, tgt_prio);
487 "qos::MemCtrl::escalate Completed requestor %s [id %d] to "
488 "priority %d (now %d packets)\n\t(total read %d, total write %d)"
493template<
typename Queues>
496 const uint64_t queue_entry_size,
500 uint8_t pkt_priority =
schedule(pkt);
513 uint8_t prio =
schedule(requestor.first, 0);
517 "qos::MemCtrl::qosSchedule: (syncro) escalating "
518 "REQUESTOR %s to assigned priority %d\n",
521 escalate(queues, queue_entry_size, requestor.first, prio);
528 "qos::MemCtrl::qosSchedule: escalating "
529 "REQUESTOR %s to assigned priority %d\n",
Defines global host-dependent types: Counter, Tick, and (indirectly) {int,uint}{8,...
The ClockedObject class extends the SimObject with a clock and accessor functions to relate ticks to ...
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
RequestorID requestorId() const
uint8_t qosValue() const
QoS Value getter Returns 0 if QoS value was never set (constructor default).
std::string getRequestorName(RequestorID requestor_id)
Get the name of an object for a given request id.
The qos::MemCtrl is a base class for Memory objects which support QoS - it provides access to a set o...
BusState getBusState() const
Gets the current bus state.
void logResponse(BusState dir, RequestorID id, uint8_t _qos, Addr addr, uint64_t entries, double delay)
Called upon receiving a response, updates statistics and updates queues status.
std::vector< uint64_t > writeQueueSizes
Write request packets queue length in #packets, per QoS priority.
uint64_t getReadQueueSize(const uint8_t prio) const
Gets a READ queue size.
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.
uint64_t totalWriteQueueSize
Total write request packets queue length in #packets.
void escalateQueues(Queues &queues, uint64_t queue_entry_size, RequestorID id, uint8_t curr_prio, uint8_t tgt_prio)
Escalates/demotes priority of all packets belonging to the passed requestor to given priority value i...
const bool qosPriorityEscalation
Enables QoS priority escalation.
void recordTurnaroundStats(BusState busState, BusState busStateNext)
Record statistics on turnarounds based on busStateNext and busState values.
std::vector< Tick > serviceTick
Vector of QoS priorities/last service time.
void setCurrentBusState()
Set current bus direction (READ or WRITE) from next selected one.
std::unordered_map< RequestorID, std::vector< uint64_t > > packetPriorities
Hash of requestors - number of packets queued per priority.
std::vector< uint64_t > readQueueSizes
Read request packets queue length in #packets, per QoS priority.
const std::unique_ptr< Policy > policy
QoS Policy, assigns QoS priority to the incoming packets.
const std::unique_ptr< QueuePolicy > queuePolicy
QoS Queue Policy: selects packet among same-priority queue.
BusState getBusStateNext() const
Gets the next bus state.
Tick getServiceTick(const uint8_t prio) const
Gets the last service tick related to a QoS Priority.
MemCtrl(const QoSMemCtrlParams &)
QoS Memory base class.
BusState selectNextBusState()
Returns next bus direction (READ or WRITE) based on configured policy.
const std::unique_ptr< TurnaroundPolicy > turnPolicy
QoS Bus Turnaround Policy: selects the bus direction (READ/WRITE)
const bool qosSyncroScheduler
Enables QoS synchronized scheduling invokes the QoS scheduler on all requestors, at every packet arri...
bool hasRequestor(RequestorID id) const
hasRequestor returns true if the selected requestor(ID) has been registered in the memory controller,...
uint8_t numPriorities() const
Gets the total number of priority levels in the QoS memory controller.
uint64_t getTotalWriteQueueSize() const
Gets the total combined WRITE queues size.
const uint8_t _numPriorities
Number of configured QoS priorities.
void addRequestor(const RequestorID id)
Initializes dynamically counters and statistics for a given Requestor.
BusState busState
Bus state used to control the read/write switching and drive the scheduling of the next request.
System * _system
Pointer to the System object.
void escalate(std::initializer_list< Queues * > queues, uint64_t queue_entry_size, RequestorID id, uint8_t tgt_prio)
Escalates/demotes priority of all packets belonging to the passed requestor to given priority value.
uint64_t totalReadQueueSize
Total read request packets queue length in #packets.
std::unordered_map< RequestorID, std::unordered_map< uint64_t, std::deque< uint64_t > > > requestTimes
Hash of requestors - address of request - queue of times of request.
uint64_t getWriteQueueSize(const uint8_t prio) const
Gets a WRITE queue size.
gem5::memory::qos::MemCtrl::MemCtrlStats stats
System * system() const
read the system pointer
BusState busStateNext
bus state for next request event triggered
uint8_t schedule(RequestorID id, uint64_t data)
uint64_t getTotalReadQueueSize() const
Gets the total combined READ queues size.
std::unordered_map< RequestorID, const std::string > requestors
Hash of requestor ID - requestor name.
void logRequest(BusState dir, RequestorID id, uint8_t _qos, Addr addr, uint64_t entries)
Called upon receiving a request or updates statistics and updates queues status.
This is a simple scalar statistic, like a counter.
This is a vector of StandardDeviation stats.
A vector of scalar stats.
ClockedObject declaration and implementation.
static constexpr T divCeil(const T &a, const U &b)
void schedule(Event &event, Tick when)
#define panic_if(cond,...)
Conditional panic macro that checks the supplied condition and only panics if the condition is true a...
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
Tick curTick()
The universal simulation clock.
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
uint64_t Tick
Tick count type.
Declaration of the Packet class.
Declaration of a request, the overall memory request consisting of the parts of the request that are ...
Declaration of Statistics objects.
statistics::VectorStandardDeviation avgPriorityDistance
per-requestor average QoS distance between assigned and queued values
statistics::VectorStandardDeviation avgPriority
per-requestor average QoS priority
statistics::Vector priorityMaxLatency
per-priority maximum latency
statistics::Vector priorityMinLatency
per-priority minimum latency
statistics::Scalar numStayReadState
Count the number of times bus staying in READ state.
MemCtrlStats(MemCtrl &mc)
statistics::Scalar numReadWriteTurnArounds
Count the number of turnarounds READ to WRITE.
void regStats() override
Callback to set stat parameters.
statistics::Scalar numStayWriteState
Count the number of times bus staying in WRITE state.
statistics::Scalar numWriteReadTurnArounds
Count the number of turnarounds WRITE to READ.