gem5 v24.0.0.0
Loading...
Searching...
No Matches
mem_ctrl.hh
Go to the documentation of this file.
1/*
2 * Copyright (c) 2020 ARM Limited
3 * All rights reserved
4 *
5 * The license below extends only to copyright in the software and shall
6 * not be construed as granting a license to any other intellectual
7 * property including but not limited to intellectual property relating
8 * to a hardware implementation of the functionality of the software
9 * licensed hereunder. You may use the software subject to the license
10 * terms below provided that you ensure that this notice is replicated
11 * unmodified and in its entirety in all distributions of the software,
12 * modified or unmodified, in source code or in binary form.
13 *
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions are
16 * met: redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer;
18 * redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution;
21 * neither the name of the copyright holders nor the names of its
22 * contributors may be used to endorse or promote products derived from
23 * this software without specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 */
37
38#ifndef __MEM_QOS_MEM_CTRL_HH__
39#define __MEM_QOS_MEM_CTRL_HH__
40
41#include <cstdint>
42#include <deque>
43#include <memory>
44#include <unordered_map>
45#include <utility>
46#include <vector>
47
48#include "base/compiler.hh"
49#include "base/logging.hh"
50#include "base/statistics.hh"
51#include "base/trace.hh"
52#include "base/types.hh"
53#include "debug/QOS.hh"
54#include "mem/packet.hh"
55#include "mem/request.hh"
56#include "params/QoSMemCtrl.hh"
57#include "sim/clocked_object.hh"
58#include "sim/cur_tick.hh"
59#include "sim/system.hh"
60
61namespace gem5
62{
63
64namespace memory
65{
66
67namespace qos
68{
69
70class Policy;
71class QueuePolicy;
72class TurnaroundPolicy;
73
79class MemCtrl : public ClockedObject
80{
81 public:
83 enum BusState { READ, WRITE };
84
85 protected:
87 const std::unique_ptr<Policy> policy;
88
90 const std::unique_ptr<TurnaroundPolicy> turnPolicy;
91
93 const std::unique_ptr<QueuePolicy> queuePolicy;
94
96 const uint8_t _numPriorities;
97
100
106
108 std::unordered_map<RequestorID, const std::string> requestors;
109
111 std::unordered_map<RequestorID, std::vector<uint64_t> > packetPriorities;
112
114 std::unordered_map<RequestorID,
115 std::unordered_map<uint64_t, std::deque<uint64_t>> > requestTimes;
116
122
125
128
131
134
140
143
173
176
183 void addRequestor(const RequestorID id);
184
195 void logRequest(BusState dir, RequestorID id, uint8_t _qos,
196 Addr addr, uint64_t entries);
197
209 void logResponse(BusState dir, RequestorID id, uint8_t _qos,
210 Addr addr, uint64_t entries, double delay);
211
221 template<typename Queues>
222 uint8_t qosSchedule(std::initializer_list<Queues*> queues_ptr,
223 uint64_t queue_entry_size, const PacketPtr pkt);
224
226 uint8_t schedule(RequestorID id, uint64_t data);
227 uint8_t schedule(const PacketPtr pkt);
228
234
240
246
257 template<typename Queues>
258 void escalate(std::initializer_list<Queues*> queues,
259 uint64_t queue_entry_size,
260 RequestorID id, uint8_t tgt_prio);
261
277 template<typename Queues>
278 void escalateQueues(Queues& queues, uint64_t queue_entry_size,
279 RequestorID id, uint8_t curr_prio, uint8_t tgt_prio);
280
281 public:
287 MemCtrl(const QoSMemCtrlParams &);
288
289 virtual ~MemCtrl();
290
296 BusState getBusState() const { return busState; }
297
304
316 {
317 return requestors.find(id) != requestors.end();
318 }
319
326 uint64_t getReadQueueSize(const uint8_t prio) const
327 { return readQueueSizes[prio]; }
328
335 uint64_t getWriteQueueSize(const uint8_t prio) const
336 { return writeQueueSizes[prio]; }
337
343 uint64_t getTotalReadQueueSize() const { return totalReadQueueSize; }
344
350 uint64_t getTotalWriteQueueSize() const { return totalWriteQueueSize; }
351
358 Tick getServiceTick(const uint8_t prio) const { return serviceTick[prio]; }
359
366 uint8_t numPriorities() const { return _numPriorities; }
367
370 System* system() const { return _system; }
371};
372
373template<typename Queues>
374void
375MemCtrl::escalateQueues(Queues& queues, uint64_t queue_entry_size,
376 RequestorID id, uint8_t curr_prio, uint8_t tgt_prio)
377{
378 auto it = queues[curr_prio].begin();
379 while (it != queues[curr_prio].end()) {
380 // No packets left to move
381 if (packetPriorities[id][curr_prio] == 0)
382 break;
383
384 auto pkt = *it;
385
386 DPRINTF(QOS,
387 "qos::MemCtrl::escalateQueues checking priority %d packet "
388 "id %d address %d\n", curr_prio,
389 pkt->requestorId(), pkt->getAddr());
390
391 // Found a packet to move
392 if (pkt->requestorId() == id) {
393
394 uint64_t moved_entries = divCeil(pkt->getSize(),
395 queue_entry_size);
396
397 DPRINTF(QOS,
398 "qos::MemCtrl::escalateQueues Requestor %s [id %d] moving "
399 "packet addr %d size %d (p size %d) from priority %d "
400 "to priority %d - "
401 "this requestor packets %d (entries to move %d)\n",
402 requestors[id], id, pkt->getAddr(),
403 pkt->getSize(),
404 queue_entry_size, curr_prio, tgt_prio,
405 packetPriorities[id][curr_prio], moved_entries);
406
407
408 if (pkt->isRead()) {
409 panic_if(readQueueSizes[curr_prio] < moved_entries,
410 "qos::MemCtrl::escalateQueues requestor %s negative "
411 "READ packets for priority %d",
412 requestors[id], tgt_prio);
413 readQueueSizes[curr_prio] -= moved_entries;
414 readQueueSizes[tgt_prio] += moved_entries;
415 } else if (pkt->isWrite()) {
416 panic_if(writeQueueSizes[curr_prio] < moved_entries,
417 "qos::MemCtrl::escalateQueues requestor %s negative "
418 "WRITE packets for priority %d",
419 requestors[id], tgt_prio);
420 writeQueueSizes[curr_prio] -= moved_entries;
421 writeQueueSizes[tgt_prio] += moved_entries;
422 }
423
424 // Change QoS priority and move packet
425 pkt->qosValue(tgt_prio);
426 queues[tgt_prio].push_back(pkt);
427
428 // Erase element from source packet queue, this will
429 // increment the iterator
430 it = queues[curr_prio].erase(it);
431 panic_if(packetPriorities[id][curr_prio] < moved_entries,
432 "qos::MemCtrl::escalateQueues requestor %s negative "
433 "packets for priority %d",
434 requestors[id], tgt_prio);
435
436 packetPriorities[id][curr_prio] -= moved_entries;
437 packetPriorities[id][tgt_prio] += moved_entries;
438 } else {
439 // Increment iterator to next location in the queue
440 it++;
441 }
442 }
443}
444
445template<typename Queues>
446void
447MemCtrl::escalate(std::initializer_list<Queues*> queues,
448 uint64_t queue_entry_size,
449 RequestorID id, uint8_t tgt_prio)
450{
451 // If needed, initialize all counters and statistics
452 // for this requestor
453 addRequestor(id);
454
455 DPRINTF(QOS,
456 "qos::MemCtrl::escalate Requestor %s [id %d] to priority "
457 "%d (currently %d packets)\n",requestors[id], id, tgt_prio,
458 packetPriorities[id][tgt_prio]);
459
460 for (uint8_t curr_prio = 0; curr_prio < numPriorities(); ++curr_prio) {
461 // Skip target priority
462 if (curr_prio == tgt_prio)
463 continue;
464
465 // Process other priority packet
466 while (packetPriorities[id][curr_prio] > 0) {
467 DPRINTF(QOS,
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",
472 id, curr_prio, packetPriorities[id][curr_prio],
473 tgt_prio, packetPriorities[id][tgt_prio],
474 readQueueSizes[curr_prio],
475 writeQueueSizes[curr_prio], readQueueSizes[tgt_prio],
476 writeQueueSizes[tgt_prio]);
477
478 // Check both read and write queue
479 for (auto q : queues) {
480 escalateQueues(*q, queue_entry_size, id,
481 curr_prio, tgt_prio);
482 }
483 }
484 }
485
486 DPRINTF(QOS,
487 "qos::MemCtrl::escalate Completed requestor %s [id %d] to "
488 "priority %d (now %d packets)\n\t(total read %d, total write %d)"
489 "\n", requestors[id], id, tgt_prio, packetPriorities[id][tgt_prio],
490 readQueueSizes[tgt_prio], writeQueueSizes[tgt_prio]);
491}
492
493template<typename Queues>
494uint8_t
495MemCtrl::qosSchedule(std::initializer_list<Queues*> queues,
496 const uint64_t queue_entry_size,
497 const PacketPtr pkt)
498{
499 // Schedule packet.
500 uint8_t pkt_priority = schedule(pkt);
501
502 assert(pkt_priority < numPriorities());
503
504 pkt->qosValue(pkt_priority);
505
506 if (qosSyncroScheduler) {
507 // Call the scheduling function on all other requestors.
508 for (const auto& requestor : requestors) {
509
510 if (requestor.first == pkt->requestorId())
511 continue;
512
513 uint8_t prio = schedule(requestor.first, 0);
514
516 DPRINTF(QOS,
517 "qos::MemCtrl::qosSchedule: (syncro) escalating "
518 "REQUESTOR %s to assigned priority %d\n",
519 _system->getRequestorName(requestor.first),
520 prio);
521 escalate(queues, queue_entry_size, requestor.first, prio);
522 }
523 }
524 }
525
527 DPRINTF(QOS,
528 "qos::MemCtrl::qosSchedule: escalating "
529 "REQUESTOR %s to assigned priority %d\n",
531 pkt_priority);
532 escalate(queues, queue_entry_size, pkt->requestorId(), pkt_priority);
533 }
534
535 // Update last service tick for selected priority
536 serviceTick[pkt_priority] = curTick();
537
538 return pkt_priority;
539}
540
541} // namespace qos
542} // namespace memory
543} // namespace gem5
544
545#endif /* __MEM_QOS_MEM_CTRL_HH__ */
#define DPRINTF(x,...)
Definition trace.hh:210
Defines global host-dependent types: Counter, Tick, and (indirectly) {int,uint}{8,...
const char data[]
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....
Definition packet.hh:295
RequestorID requestorId() const
Definition packet.hh:780
uint8_t qosValue() const
QoS Value getter Returns 0 if QoS value was never set (constructor default).
Definition packet.hh:769
std::string getRequestorName(RequestorID requestor_id)
Get the name of an object for a given request id.
Definition system.cc:526
The qos::MemCtrl is a base class for Memory objects which support QoS - it provides access to a set o...
Definition mem_ctrl.hh:80
BusState getBusState() const
Gets the current bus state.
Definition mem_ctrl.hh:296
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.
Definition mem_ctrl.cc:148
std::vector< uint64_t > writeQueueSizes
Write request packets queue length in #packets, per QoS priority.
Definition mem_ctrl.hh:127
uint64_t getReadQueueSize(const uint8_t prio) const
Gets a READ queue size.
Definition mem_ctrl.hh:326
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.
Definition mem_ctrl.hh:495
uint64_t totalWriteQueueSize
Total write request packets queue length in #packets.
Definition mem_ctrl.hh:133
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...
Definition mem_ctrl.hh:375
const bool qosPriorityEscalation
Enables QoS priority escalation.
Definition mem_ctrl.hh:99
void recordTurnaroundStats(BusState busState, BusState busStateNext)
Record statistics on turnarounds based on busStateNext and busState values.
Definition mem_ctrl.cc:358
std::vector< Tick > serviceTick
Vector of QoS priorities/last service time.
Definition mem_ctrl.hh:121
void setCurrentBusState()
Set current bus direction (READ or WRITE) from next selected one.
Definition mem_ctrl.hh:239
std::unordered_map< RequestorID, std::vector< uint64_t > > packetPriorities
Hash of requestors - number of packets queued per priority.
Definition mem_ctrl.hh:111
std::vector< uint64_t > readQueueSizes
Read request packets queue length in #packets, per QoS priority.
Definition mem_ctrl.hh:124
const std::unique_ptr< Policy > policy
QoS Policy, assigns QoS priority to the incoming packets.
Definition mem_ctrl.hh:87
const std::unique_ptr< QueuePolicy > queuePolicy
QoS Queue Policy: selects packet among same-priority queue.
Definition mem_ctrl.hh:93
BusState getBusStateNext() const
Gets the next bus state.
Definition mem_ctrl.hh:303
Tick getServiceTick(const uint8_t prio) const
Gets the last service tick related to a QoS Priority.
Definition mem_ctrl.hh:358
MemCtrl(const QoSMemCtrlParams &)
QoS Memory base class.
Definition mem_ctrl.cc:54
BusState selectNextBusState()
Returns next bus direction (READ or WRITE) based on configured policy.
Definition mem_ctrl.cc:246
const std::unique_ptr< TurnaroundPolicy > turnPolicy
QoS Bus Turnaround Policy: selects the bus direction (READ/WRITE)
Definition mem_ctrl.hh:90
const bool qosSyncroScheduler
Enables QoS synchronized scheduling invokes the QoS scheduler on all requestors, at every packet arri...
Definition mem_ctrl.hh:105
bool hasRequestor(RequestorID id) const
hasRequestor returns true if the selected requestor(ID) has been registered in the memory controller,...
Definition mem_ctrl.hh:315
uint8_t numPriorities() const
Gets the total number of priority levels in the QoS memory controller.
Definition mem_ctrl.hh:366
uint64_t getTotalWriteQueueSize() const
Gets the total combined WRITE queues size.
Definition mem_ctrl.hh:350
const uint8_t _numPriorities
Number of configured QoS priorities.
Definition mem_ctrl.hh:96
void addRequestor(const RequestorID id)
Initializes dynamically counters and statistics for a given Requestor.
Definition mem_ctrl.cc:274
BusState busState
Bus state used to control the read/write switching and drive the scheduling of the next request.
Definition mem_ctrl.hh:139
System * _system
Pointer to the System object.
Definition mem_ctrl.hh:175
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.
Definition mem_ctrl.hh:447
uint64_t totalReadQueueSize
Total read request packets queue length in #packets.
Definition mem_ctrl.hh:130
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.
Definition mem_ctrl.hh:115
uint64_t getWriteQueueSize(const uint8_t prio) const
Gets a WRITE queue size.
Definition mem_ctrl.hh:335
gem5::memory::qos::MemCtrl::MemCtrlStats stats
System * system() const
read the system pointer
Definition mem_ctrl.hh:370
BusState busStateNext
bus state for next request event triggered
Definition mem_ctrl.hh:142
uint8_t schedule(RequestorID id, uint64_t data)
Definition mem_ctrl.cc:217
uint64_t getTotalReadQueueSize() const
Gets the total combined READ queues size.
Definition mem_ctrl.hh:343
std::unordered_map< RequestorID, const std::string > requestors
Hash of requestor ID - requestor name.
Definition mem_ctrl.hh:108
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.
Definition mem_ctrl.cc:91
Statistics container.
Definition group.hh:93
This is a simple scalar statistic, like a counter.
This is a vector of StandardDeviation stats.
A vector of scalar stats.
STL vector class.
Definition stl.hh:37
ClockedObject declaration and implementation.
static constexpr T divCeil(const T &a, const U &b)
Definition intmath.hh:110
void schedule(Event &event, Tick when)
Definition eventq.hh:1012
#define panic_if(cond,...)
Conditional panic macro that checks the supplied condition and only panics if the condition is true a...
Definition logging.hh:214
Bitfield< 27 > q
Definition misc_types.hh:55
Bitfield< 33 > id
Bitfield< 3 > addr
Definition types.hh:84
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
Definition binary32.hh:36
Tick curTick()
The universal simulation clock.
Definition cur_tick.hh:46
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition types.hh:147
uint64_t Tick
Tick count type.
Definition types.hh:58
uint16_t RequestorID
Definition request.hh:95
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
Definition mem_ctrl.hh:158
statistics::VectorStandardDeviation avgPriority
per-requestor average QoS priority
Definition mem_ctrl.hh:153
statistics::Vector priorityMaxLatency
per-priority maximum latency
Definition mem_ctrl.hh:163
statistics::Vector priorityMinLatency
per-priority minimum latency
Definition mem_ctrl.hh:161
statistics::Scalar numStayReadState
Count the number of times bus staying in READ state.
Definition mem_ctrl.hh:169
statistics::Scalar numReadWriteTurnArounds
Count the number of turnarounds READ to WRITE.
Definition mem_ctrl.hh:165
void regStats() override
Callback to set stat parameters.
Definition mem_ctrl.cc:313
statistics::Scalar numStayWriteState
Count the number of times bus staying in WRITE state.
Definition mem_ctrl.hh:171
statistics::Scalar numWriteReadTurnArounds
Count the number of turnarounds WRITE to READ.
Definition mem_ctrl.hh:167
Definition mem.h:38

Generated on Tue Jun 18 2024 16:24:05 for gem5 by doxygen 1.11.0