gem5  v22.1.0.0
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 
53 namespace gem5
54 {
55 
56 namespace 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 
112  {
113  PWR_IDLE = 0,
119  };
120 
152  {
153  REF_IDLE = 0,
159  REF_RUN
160  };
161 
162  class Rank;
163  struct RankStats : public statistics::Group
164  {
165  RankStats(DRAMInterface &dram, Rank &rank);
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 name() const { return csprintf("%d", rank); }
354 
361  void startup(Tick ref_tick);
362 
366  void suspend();
367 
374  bool inRefIdleState() const { return refreshState == REF_IDLE; }
375 
383  bool inPwrIdleState() const { return pwrState == PWR_IDLE; }
384 
395  bool forceSelfRefreshExit() const;
396 
403  bool isQueueEmpty() const;
404 
409  void checkDrainDone();
410 
417  void flushCmdList();
418 
422  void computeStats();
423 
427  void resetStats();
428 
435  void powerDownSleep(PowerState pwr_state, Tick tick);
436 
444  void scheduleWakeUpEvent(Tick exit_delay);
445 
446  void processWriteDoneEvent();
448 
449  void processActivateEvent();
451 
452  void processPrechargeEvent();
454 
455  void processRefreshEvent();
457 
458  void processPowerEvent();
460 
461  void processWakeUpEvent();
463 
464  protected:
466  };
467 
475  static bool
476  sortTime(const Command& cmd, const Command& cmd_next)
477  {
478  return cmd.timeStamp < cmd_next.timeStamp;
479  }
480 
484  const uint32_t bankGroupsPerRank;
485  const bool bankGroupArch;
486 
490  const Tick tRL;
491  const Tick tWL;
495  const Tick tCCD_L;
496  const Tick tRCD_RD;
497  const Tick tRCD_WR;
498  const Tick tRP;
499  const Tick tRAS;
500  const Tick tWR;
501  const Tick tRTP;
502  const Tick tRFC;
503  const Tick tREFI;
504  const Tick tRRD;
505  const Tick tRRD_L;
506  const Tick tPPD;
507  const Tick tAAD;
508  const Tick tXAW;
509  const Tick tXP;
510  const Tick tXS;
512  const bool dataClockSync;
513  const bool burstInterleave;
514  const uint8_t twoCycleActivate;
515  const uint32_t activationLimit;
518 
519 
520  enums::PageManage pageMgmt;
525  const uint32_t maxAccessesPerRow;
526 
527  // timestamp offset
528  uint64_t timeStampOffset;
529 
530  // Holds the value of the DRAM rank of burst issued
531  uint8_t activeRank;
532 
535 
538 
550  void activateBank(Rank& rank_ref, Bank& bank_ref, Tick act_tick,
551  uint32_t row);
552 
564  void prechargeBank(Rank& rank_ref, Bank& bank_ref,
565  Tick pre_tick, bool auto_or_preall = false,
566  bool trace = true);
567 
568  struct DRAMStats : public statistics::Group
569  {
571 
572  void regStats() override;
573  void resetStats() override;
574 
576 
580 
584 
585  // Latencies summed over all requests
589 
590  // Average latencies per request
594 
595  // Row hit count and rate
601  // Number of bytes transferred to/from DRAM
604 
605  // Average bandwidth
609  // bus utilization
614  };
615 
617 
622 
623  /*
624  * @return delay between write and read commands
625  */
626  Tick writeToReadDelay() const override { return tBURST + tWTR + tWL; }
627 
639  minBankPrep(const MemPacketQueue& queue, Tick min_col_at) const;
640 
641  /*
642  * @return time to send a burst of data without gaps
643  */
644  Tick
645  burstDelay() const
646  {
647  return (burstInterleave ? tBURST_MAX / 2 : tBURST);
648  }
649 
650  public:
654  void init() override;
655 
659  void startup() override;
660 
667  void setupRank(const uint8_t rank, const bool is_read) override;
668 
669  MemPacket* decodePacket(const PacketPtr pkt, Addr pkt_addr,
670  unsigned int size, bool is_read,
671  uint8_t pseudo_channel = 0) override;
672 
676  void drainRanks() override;
677 
687  bool allRanksDrained() const override;
688 
692  void suspend() override;
693 
694  /*
695  * @return time to offset next command
696  */
697  Tick commandOffset() const override
698  {
699  return (tRP + std::max(tRCD_RD, tRCD_WR));
700  }
701 
702  /*
703  * Function to calulate unloaded, closed bank access latency
704  */
705  Tick accessLatency() const override { return (tRP + tRCD_RD + tRL); }
706 
716  chooseNextFRFCFS(MemPacketQueue& queue, Tick min_col_at) const override;
717 
733  doBurstAccess(MemPacket* mem_pkt, Tick next_burst_at,
734  const std::vector<MemPacketQueue>& queue) override;
735 
743  bool
744  burstReady(MemPacket* pkt) const override
745  {
746  return ranks[pkt->rank]->inRefIdleState();
747  }
748 
757  bool isBusy(bool read_queue_empty, bool all_writes_nvm) override;
758 
766  void addRankToRankDelay(Tick cmd_at) override;
767 
775  void respondEvent(uint8_t rank) override;
776 
783  void checkRefreshState(uint8_t rank) override;
784 
788  bool readsWaitingToIssue() const override { return false;}
789  void chooseRead(MemPacketQueue& queue) override { }
790  bool writeRespQueueFull() const override { return false;}
791 
792  DRAMInterface(const DRAMInterfaceParams &_p);
793 };
794 
795 } // namespace memory
796 } // namespace gem5
797 
798 #endif //__DRAM_INTERFACE_HH__
DRAMPower is a standalone tool which calculates the power consumed by a DRAM in the system.
Definition: drampower.hh:57
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition: packet.hh:294
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.
EventFunctionWrapper activateEvent
std::deque< Tick > actTicks
List to keep track of activate ticks.
bool inLowPowerState
rank is in or transitioning to power-down or self-refresh
EventFunctionWrapper prechargeEvent
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.
void startup(Tick ref_tick)
Kick off accounting for power and refresh states and schedule initial refresh.
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.
EventFunctionWrapper writeDoneEvent
bool isQueueEmpty() const
Check if the command queue of current rank is idle.
Rank(const DRAMInterfaceParams &_p, int _rank, DRAMInterface &_dram)
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.
DRAMInterface(const DRAMInterfaceParams &_p)
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.
Definition: statistics.hh:2540
Statistics container.
Definition: group.hh:94
A simple histogram stat.
Definition: statistics.hh:2127
This is a simple scalar statistic, like a counter.
Definition: statistics.hh:1931
A vector of scalar stats.
Definition: statistics.hh:2007
STL pair class.
Definition: stl.hh:58
STL vector class.
Definition: stl.hh:37
DRAMPower declaration.
MemInterface declaration.
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
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.
RankStats(DRAMInterface &dram, Rank &rank)
Definition: mem.h:38

Generated on Wed Dec 21 2022 10:22:37 for gem5 by doxygen 1.9.1