gem5 v24.1.0.1
Loading...
Searching...
No Matches
dram_interface.hh
Go to the documentation of this file.
1/*
2 * Copyright (c) 2012-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 * Copyright (c) 2013 Amin Farmahini-Farahani
15 * All rights reserved.
16 *
17 * Redistribution and use in source and binary forms, with or without
18 * modification, are permitted provided that the following conditions are
19 * met: redistributions of source code must retain the above copyright
20 * notice, this list of conditions and the following disclaimer;
21 * redistributions in binary form must reproduce the above copyright
22 * notice, this list of conditions and the following disclaimer in the
23 * documentation and/or other materials provided with the distribution;
24 * neither the name of the copyright holders nor the names of its
25 * contributors may be used to endorse or promote products derived from
26 * this software without specific prior written permission.
27 *
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
31 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 */
40
46#ifndef __DRAM_INTERFACE_HH__
47#define __DRAM_INTERFACE_HH__
48
49#include "mem/drampower.hh"
50#include "mem/mem_interface.hh"
51#include "params/DRAMInterface.hh"
52
53namespace gem5
54{
55
56namespace memory
57{
58
66{
67 private:
72 struct Command
73 {
74 Data::MemCommand::cmds type;
75 uint8_t bank;
77
78 constexpr Command(Data::MemCommand::cmds _type, uint8_t _bank,
79 Tick time_stamp)
80 : type(_type), bank(_bank), timeStamp(time_stamp)
81 { }
82 };
83
120
161
162 class Rank;
164 {
166
167 void regStats() override;
168 void resetStats() override;
169 void preDumpStats() override;
170
172
173 /*
174 * Command energies
175 */
181
182 /*
183 * Active Background Energy
184 */
186
187 /*
188 * Precharge Background Energy
189 */
191
192 /*
193 * Active Power-Down Energy
194 */
196
197 /*
198 * Precharge Power-Down Energy
199 */
201
202 /*
203 * self Refresh Energy
204 */
206
209
215
220 };
221
229 class Rank : public EventManager
230 {
231 private:
232
237
243
248
253
258
262 void updatePowerStats();
263
271 void schedulePowerEvent(PowerState pwr_state, Tick tick);
272
273 public:
274
279
284
289
293 uint8_t rank;
294
298 uint32_t readEntries;
299
303 uint32_t writeEntries;
304
311
316
321
329
335
340 unsigned int numBanksActive;
341
344
349
350 Rank(const DRAMInterfaceParams &_p, int _rank,
351 DRAMInterface& _dram);
352
353 const std::string
354 name() const
355 {
356 return csprintf("%s.rank%d", dram.name(), rank);
357 }
358
365 void startup(Tick ref_tick);
366
370 void suspend();
371
378 bool inRefIdleState() const { return refreshState == REF_IDLE; }
379
387 bool
389 {
390 // If powerdown is not enabled, then the ranks never go to idle
391 // states. In that case return true here to prevent checkpointing
392 // from getting stuck waiting for DRAM to be idle.
394 return true;
395 }
396
397 return pwrState == PWR_IDLE;
398 }
399
410 bool forceSelfRefreshExit() const;
411
418 bool isQueueEmpty() const;
419
424 void checkDrainDone();
425
432 void flushCmdList();
433
437 void computeStats();
438
442 void resetStats();
443
450 void powerDownSleep(PowerState pwr_state, Tick tick);
451
459 void scheduleWakeUpEvent(Tick exit_delay);
460
463
466
469
470 void processRefreshEvent();
472
473 void processPowerEvent();
475
476 void processWakeUpEvent();
478
479 protected:
481 };
482
490 static bool
491 sortTime(const Command& cmd, const Command& cmd_next)
492 {
493 return cmd.timeStamp < cmd_next.timeStamp;
494 }
495
499 const uint32_t bankGroupsPerRank;
500 const bool bankGroupArch;
501
505 const Tick tRL;
506 const Tick tWL;
513 const Tick tRP;
514 const Tick tRAS;
515 const Tick tWR;
516 const Tick tRTP;
517 const Tick tRFC;
518 const Tick tREFI;
519 const Tick tRRD;
521 const Tick tPPD;
522 const Tick tAAD;
523 const Tick tXAW;
524 const Tick tXP;
525 const Tick tXS;
527 const bool dataClockSync;
528 const bool burstInterleave;
529 const uint8_t twoCycleActivate;
530 const uint32_t activationLimit;
533
534
535 enums::PageManage pageMgmt;
540 const uint32_t maxAccessesPerRow;
541
542 // timestamp offset
544
545 // Holds the value of the DRAM rank of burst issued
546 uint8_t activeRank;
547
550
553
565 void activateBank(Rank& rank_ref, Bank& bank_ref, Tick act_tick,
566 uint32_t row);
567
579 void prechargeBank(Rank& rank_ref, Bank& bank_ref,
580 Tick pre_tick, bool auto_or_preall = false,
581 bool trace = true);
582
630
632
637
638 /*
639 * @return delay between write and read commands
640 */
641 Tick writeToReadDelay() const override { return tBURST + tWTR + tWL; }
642
654 minBankPrep(const MemPacketQueue& queue, Tick min_col_at) const;
655
656 /*
657 * @return time to send a burst of data without gaps
658 */
659 Tick
661 {
662 return (burstInterleave ? tBURST_MAX / 2 : tBURST);
663 }
664
665 public:
669 void init() override;
670
674 void startup() override;
675
682 void setupRank(const uint8_t rank, const bool is_read) override;
683
684 MemPacket* decodePacket(const PacketPtr pkt, Addr pkt_addr,
685 unsigned int size, bool is_read,
686 uint8_t pseudo_channel = 0) override;
687
691 void drainRanks() override;
692
702 bool allRanksDrained() const override;
703
707 void suspend() override;
708
709 /*
710 * @return time to offset next command
711 */
712 Tick commandOffset() const override
713 {
714 return (tRP + std::max(tRCD_RD, tRCD_WR));
715 }
716
717 /*
718 * Function to calulate unloaded, closed bank access latency
719 */
720 Tick accessLatency() const override { return (tRP + tRCD_RD + tRL); }
721
731 chooseNextFRFCFS(MemPacketQueue& queue, Tick min_col_at) const override;
732
748 doBurstAccess(MemPacket* mem_pkt, Tick next_burst_at,
749 const std::vector<MemPacketQueue>& queue) override;
750
758 bool
759 burstReady(MemPacket* pkt) const override
760 {
761 return ranks[pkt->rank]->inRefIdleState();
762 }
763
772 bool isBusy(bool read_queue_empty, bool all_writes_nvm) override;
773
781 void addRankToRankDelay(Tick cmd_at) override;
782
790 void respondEvent(uint8_t rank) override;
791
798 void checkRefreshState(uint8_t rank) override;
799
803 bool readsWaitingToIssue() const override { return false;}
804 void chooseRead(MemPacketQueue& queue) override { }
805 bool writeRespQueueFull() const override { return false;}
806
807 DRAMInterface(const DRAMInterfaceParams &_p);
808};
809
810} // namespace memory
811} // namespace gem5
812
813#endif //__DRAM_INTERFACE_HH__
DRAMPower is a standalone tool which calculates the power consumed by a DRAM in the system.
Definition drampower.hh:57
virtual std::string name() const
Definition named.hh:47
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition packet.hh:295
uint64_t size() const
Get the memory size.
Rank class includes a vector of banks.
void computeStats()
Computes stats just prior to dump event.
void powerDownSleep(PowerState pwr_state, Tick tick)
Schedule a transition to power-down (sleep)
void checkDrainDone()
Let the rank check if it was waiting for requests to drain to allow it to transition states.
DRAMInterface & dram
A reference to the parent DRAMInterface instance.
void resetStats()
Reset stats on a stats event.
DRAMPower power
One DRAMPower instance per rank.
bool inPwrIdleState() const
Check if the current rank has all banks closed and is not in a low power state.
uint8_t outstandingEvents
Number of ACT, RD, and WR events currently scheduled Incremented when a refresh event is started as w...
bool inRefIdleState() const
Check if there is no refresh and no preparation of refresh ongoing i.e.
PowerState pwrState
Current power state.
std::deque< Tick > actTicks
List to keep track of activate ticks.
bool inLowPowerState
rank is in or transitioning to power-down or self-refresh
uint32_t readEntries
Track number of packets in read queue going to this rank.
RefreshState refreshState
current refresh state
Tick pwrStateTick
Track when we transitioned to the current power state.
PowerState pwrStatePostRefresh
Previous low-power state, which will be re-entered after refresh.
PowerState pwrStateTrans
Since we are taking decisions out of order, we need to keep track of what power transition is happeni...
unsigned int numBanksActive
To track number of banks which are currently active for this rank.
std::vector< Command > cmdList
List of commands issued, to be sent to DRAMPpower at refresh and stats dump.
std::vector< Bank > banks
Vector of Banks.
Tick lastBurstTick
Track when we issued the last read/write burst.
void scheduleWakeUpEvent(Tick exit_delay)
schedule and event to wake-up from power-down or self-refresh and update bank timing parameters
Tick wakeUpAllowedAt
delay low-power exit until this requirement is met
Tick refreshDueAt
Keep track of when a refresh is due.
const std::string name() const
void schedulePowerEvent(PowerState pwr_state, Tick tick)
Schedule a power state transition in the future, and potentially override an already scheduled transi...
uint8_t rank
Current Rank index.
void suspend()
Stop the refresh events.
void updatePowerStats()
Function to update Power Stats.
bool isQueueEmpty() const
Check if the command queue of current rank is idle.
bool forceSelfRefreshExit() const
Trigger a self-refresh exit if there are entries enqueued Exit if there are any read entries regardle...
uint32_t writeEntries
Track number of packets in write queue going to this rank.
void flushCmdList()
Push command out of cmdList queue that are scheduled at or before curTick() to DRAMPower library All ...
Interface to DRAM devices with media specific parameters, statistics, and functions.
std::vector< Rank * > ranks
Vector of dram ranks.
Tick commandOffset() const override
void checkRefreshState(uint8_t rank) override
Check the refresh state to determine if refresh needs to be kicked back into action after a read resp...
void respondEvent(uint8_t rank) override
Complete response process for DRAM when read burst is complete This will update the counters and chec...
const uint32_t maxAccessesPerRow
Max column accesses (read and write) per row, before forefully closing it.
Tick lastStatsResetTick
The time when stats were last reset used to calculate average power.
bool allRanksDrained() const override
Return true once refresh is complete for all ranks and there are no additional commands enqueued.
void addRankToRankDelay(Tick cmd_at) override
Add rank to rank delay to bus timing to all DRAM banks in alli ranks when access to an alternate inte...
std::pair< Tick, Tick > doBurstAccess(MemPacket *mem_pkt, Tick next_burst_at, const std::vector< MemPacketQueue > &queue) override
Actually do the burst - figure out the latency it will take to service the req based on bank state,...
void drainRanks() override
Iterate through dram ranks to exit self-refresh in order to drain.
bool isBusy(bool read_queue_empty, bool all_writes_nvm) override
This function checks if ranks are actively refreshing and therefore busy.
void prechargeBank(Rank &rank_ref, Bank &bank_ref, Tick pre_tick, bool auto_or_preall=false, bool trace=true)
Precharge a given bank and also update when the precharge is done.
const uint32_t bankGroupsPerRank
DRAM specific device characteristics.
void activateBank(Rank &rank_ref, Bank &bank_ref, Tick act_tick, uint32_t row)
Keep track of when row activations happen, in order to enforce the maximum number of activations in t...
std::pair< MemPacketQueue::iterator, Tick > chooseNextFRFCFS(MemPacketQueue &queue, Tick min_col_at) const override
For FR-FCFS policy, find first DRAM command that can issue.
bool writeRespQueueFull() const override
This function is NVM specific.
PowerState
The power state captures the different operational states of the DRAM and interacts with the bus read...
MemPacket * decodePacket(const PacketPtr pkt, Addr pkt_addr, unsigned int size, bool is_read, uint8_t pseudo_channel=0) override
Address decoder to figure out physical mapping onto ranks, banks, and rows.
const Tick tRL
DRAM specific timing requirements.
RefreshState
The refresh state is used to control the progress of the refresh scheduling.
void startup() override
Iterate through dram ranks and instantiate per rank startup routine.
bool enableDRAMPowerdown
Enable or disable DRAM powerdown states.
Tick writeToReadDelay() const override
Tick accessLatency() const override
std::pair< std::vector< uint32_t >, bool > minBankPrep(const MemPacketQueue &queue, Tick min_col_at) const
Find which are the earliest banks ready to issue an activate for the enqueued requests.
static bool sortTime(const Command &cmd, const Command &cmd_next)
Function for sorting Command structures based on timeStamp.
void chooseRead(MemPacketQueue &queue) override
This function is NVM specific.
void init() override
Initialize the DRAM interface and verify parameters.
bool readsWaitingToIssue() const override
The next three functions are NVM-specific and will be ignored by DRAM.
void suspend() override
Iterate through DRAM ranks and suspend them.
void setupRank(const uint8_t rank, const bool is_read) override
Setup the rank based on packet received.
bool burstReady(MemPacket *pkt) const override
Check if a burst operation can be issued to the DRAM.
A basic class to track the bank state, i.e.
General interface to memory device Includes functions and parameters shared across media types.
A memory packet stores packets along with the timestamp of when the packet entered the queue,...
Definition mem_ctrl.hh:99
const uint8_t rank
Will be populated by address decoder.
Definition mem_ctrl.hh:123
A formula for statistics that is calculated when printed.
Statistics container.
Definition group.hh:93
A simple histogram stat.
This is a simple scalar statistic, like a counter.
A vector of scalar stats.
STL deque class.
Definition stl.hh:44
STL pair class.
Definition stl.hh:58
STL vector class.
Definition stl.hh:37
DRAMPower declaration.
MemInterface declaration.
Copyright (c) 2024 Arm Limited All rights reserved.
Definition binary32.hh:36
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
std::string csprintf(const char *format, const Args &...args)
Definition cprintf.hh:161
Simple structure to hold the values needed to keep track of commands for DRAMPower.
constexpr Command(Data::MemCommand::cmds _type, uint8_t _bank, Tick time_stamp)
statistics::Vector perBankRdBursts
DRAM per bank stats.
void resetStats() override
Callback to reset stats.
void regStats() override
Callback to set stat parameters.
statistics::Scalar readBursts
total number of DRAM bursts serviced
void resetStats() override
Callback to reset stats.
void preDumpStats() override
Callback before stats are dumped.
statistics::Vector pwrStateTime
Track time spent in each power state.
void regStats() override
Callback to set stat parameters.
statistics::Scalar totalIdleTime
Stat to track total DRAM idle time.
Definition mem.h:38

Generated on Mon Jan 13 2025 04:28:38 for gem5 by doxygen 1.9.8