2 * Copyright (c) 2012-2020 ARM Limited
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.
14 * Copyright (c) 2013 Amin Farmahini-Farahani
15 * All rights reserved.
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.
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.
43 * MemInterface declaration
46 #ifndef __MEM_INTERFACE_HH__
47 #define __MEM_INTERFACE_HH__
51 #include <unordered_set>
55 #include "base/statistics.hh"
56 #include "enums/AddrMap.hh"
57 #include "enums/PageManage.hh"
58 #include "mem/abstract_mem.hh"
59 #include "mem/drampower.hh"
60 #include "mem/mem_ctrl.hh"
61 #include "params/DRAMInterface.hh"
62 #include "params/MemInterface.hh"
63 #include "params/NVMInterface.hh"
64 #include "sim/eventq.hh"
67 * General interface to memory device
68 * Includes functions and parameters shared across media types
70 class MemInterface : public AbstractMemory
74 * A basic class to track the bank state, i.e. what row is
75 * currently open (if any), when is the bank free to accept a new
76 * column (read/write) command, when can it be precharged, and
77 * when can it be activated.
79 * The bank also keeps track of how many bytes have been accessed
80 * in the open row since it was opened.
87 static const uint32_t NO_ROW = -1;
99 uint32_t bytesAccessed;
102 openRow(NO_ROW), bank(0), bankgr(0),
103 rdAllowedAt(0), wrAllowedAt(0), preAllowedAt(0), actAllowedAt(0),
104 rowAccesses(0), bytesAccessed(0)
109 * A pointer to the parent MemCtrl instance
114 * Number of commands that can issue in the defined controller
115 * command window, used to verify command bandwidth
117 unsigned int maxCommandsPerWindow;
120 * Memory controller configuration initialized based on parameter
123 Enums::AddrMap addrMapping;
126 * General device and channel characteristics
127 * The rowsPerBank is determined based on the capacity, number of
128 * ranks and banks, the burst size, and the row buffer size.
130 const uint32_t burstSize;
131 const uint32_t deviceSize;
132 const uint32_t deviceRowBufferSize;
133 const uint32_t devicesPerRank;
134 const uint32_t rowBufferSize;
135 const uint32_t burstsPerRowBuffer;
136 const uint32_t burstsPerStripe;
137 const uint32_t ranksPerChannel;
138 const uint32_t banksPerRank;
139 uint32_t rowsPerBank;
142 * General timing requirements
144 const Tick M5_CLASS_VAR_USED tCK;
151 * @return delay between write and read commands
153 virtual Tick writeToReadDelay() const { return tBURST + tWTR; }
156 * @return delay between write and read commands
158 Tick readToWriteDelay() const { return tBURST + tRTW; }
161 * @return delay between accesses to different ranks
163 Tick rankToRankDelay() const { return tBURST + tCS; }
169 * Buffer sizes for read and write queues in the controller
170 * These are passed to the controller on instantiation
171 * Defining them here allows for buffers to be resized based
172 * on memory type / configuration.
174 const uint32_t readBufferSize;
175 const uint32_t writeBufferSize;
177 /** Set a pointer to the controller and initialize
178 * interface based on controller parameters
179 * @param _ctrl pointer to the parent controller
180 * @param command_window size of command window used to
181 * check command bandwidth
183 void setCtrl(MemCtrl* _ctrl, unsigned int command_window);
186 * Get an address in a dense range which starts from 0. The input
187 * address is the physical address of the request in an address
188 * space that contains other SimObjects apart from this
191 * @param addr The intput address which should be in the addrRange
192 * @return An address in the continues range [0, max)
194 Addr getCtrlAddr(Addr addr) { return range.getOffset(addr); }
197 * Setup the rank based on packet received
199 * @param integer value of rank to be setup. used to index ranks vector
200 * @param are we setting up rank for read or write packet?
202 virtual void setupRank(const uint8_t rank, const bool is_read) = 0;
205 * Check drain state of interface
207 * @return true if all ranks are drained and idle
210 virtual bool allRanksDrained() const = 0;
213 * For FR-FCFS policy, find first command that can issue
214 * Function will be overriden by interface to select based
215 * on media characteristics, used to determine when read
216 * or write can issue.
218 * @param queue Queued requests to consider
219 * @param min_col_at Minimum tick for 'seamless' issue
220 * @return an iterator to the selected packet, else queue.end()
221 * @return the tick when the packet selected will issue
223 virtual std::pair<MemPacketQueue::iterator, Tick>
224 chooseNextFRFCFS(MemPacketQueue& queue, Tick min_col_at) const = 0;
227 * Function to calulate unloaded latency
229 virtual Tick accessLatency() const = 0;
232 * @return number of bytes in a burst for this interface
234 uint32_t bytesPerBurst() const { return burstSize; }
237 * @return time to offset next command
239 virtual Tick commandOffset() const = 0;
242 * Check if a burst operation can be issued to the interface
244 * @param Return true if RD/WR can issue
246 virtual bool burstReady(MemPacket* pkt) const = 0;
249 * Determine the required delay for an access to a different rank
251 * @return required rank to rank delay
253 Tick rankDelay() const { return tCS; }
257 * @return minimum additional bus turnaround required for read-to-write
259 Tick minReadToWriteDataGap() const { return std::min(tRTW, tCS); }
263 * @return minimum additional bus turnaround required for write-to-read
265 Tick minWriteToReadDataGap() const { return std::min(tWTR, tCS); }
268 * Address decoder to figure out physical mapping onto ranks,
269 * banks, and rows. This function is called multiple times on the same
270 * system packet if the pakcet is larger than burst of the memory. The
271 * pkt_addr is used for the offset within the packet.
273 * @param pkt The packet from the outside world
274 * @param pkt_addr The starting address of the packet
275 * @param size The size of the packet in bytes
276 * @param is_read Is the request for a read or a write to memory
277 * @param is_dram Is the request to a DRAM interface
278 * @return A MemPacket pointer with the decoded information
280 MemPacket* decodePacket(const PacketPtr pkt, Addr pkt_addr,
281 unsigned int size, bool is_read, bool is_dram);
284 * Add rank to rank delay to bus timing to all banks in all ranks
285 * when access to an alternate interface is issued
287 * param cmd_at Time of current command used as starting point for
288 * addition of rank-to-rank delay
290 virtual void addRankToRankDelay(Tick cmd_at) = 0;
292 typedef MemInterfaceParams Params;
293 MemInterface(const Params* _p);
297 * Interface to DRAM devices with media specific parameters,
298 * statistics, and functions.
299 * The DRAMInterface includes a class for individual ranks
300 * and per rank functions.
302 class DRAMInterface : public MemInterface
306 * Simple structure to hold the values needed to keep track of
307 * commands for DRAMPower
311 Data::MemCommand::cmds type;
315 constexpr Command(Data::MemCommand::cmds _type, uint8_t _bank,
317 : type(_type), bank(_bank), timeStamp(time_stamp)
322 * The power state captures the different operational states of
323 * the DRAM and interacts with the bus read/write state machine,
324 * and the refresh state machine.
326 * PWR_IDLE : The idle state in which all banks are closed
327 * From here can transition to: PWR_REF, PWR_ACT,
330 * PWR_REF : Auto-refresh state. Will transition when refresh is
331 * complete based on power state prior to PWR_REF
332 * From here can transition to: PWR_IDLE, PWR_PRE_PDN,
335 * PWR_SREF : Self-refresh state. Entered after refresh if
336 * previous state was PWR_PRE_PDN
337 * From here can transition to: PWR_IDLE
339 * PWR_PRE_PDN : Precharge power down state
340 * From here can transition to: PWR_REF, PWR_IDLE
342 * PWR_ACT : Activate state in which one or more banks are open
343 * From here can transition to: PWR_IDLE, PWR_ACT_PDN
345 * PWR_ACT_PDN : Activate power down state
346 * From here can transition to: PWR_ACT
359 * The refresh state is used to control the progress of the
360 * refresh scheduling. When normal operation is in progress the
361 * refresh state is idle. Once tREFI has elasped, a refresh event
362 * is triggered to start the following STM transitions which are
363 * used to issue a refresh and return back to normal operation
365 * REF_IDLE : IDLE state used during normal operation
366 * From here can transition to: REF_DRAIN
368 * REF_SREF_EXIT : Exiting a self-refresh; refresh event scheduled
369 * after self-refresh exit completes
370 * From here can transition to: REF_DRAIN
372 * REF_DRAIN : Drain state in which on going accesses complete.
373 * From here can transition to: REF_PD_EXIT
375 * REF_PD_EXIT : Evaluate pwrState and issue wakeup if needed
376 * Next state dependent on whether banks are open
377 * From here can transition to: REF_PRE, REF_START
379 * REF_PRE : Close (precharge) all open banks
380 * From here can transition to: REF_START
382 * REF_START : Issue refresh command and update DRAMPower stats
383 * From here can transition to: REF_RUN
385 * REF_RUN : Refresh running, waiting for tRFC to expire
386 * From here can transition to: REF_IDLE, REF_SREF_EXIT
400 struct RankStats : public Stats::Group
402 RankStats(DRAMInterface &dram, Rank &rank);
404 void regStats() override;
405 void resetStats() override;
406 void preDumpStats() override;
413 Stats::Scalar actEnergy;
414 Stats::Scalar preEnergy;
415 Stats::Scalar readEnergy;
416 Stats::Scalar writeEnergy;
417 Stats::Scalar refreshEnergy;
420 * Active Background Energy
422 Stats::Scalar actBackEnergy;
425 * Precharge Background Energy
427 Stats::Scalar preBackEnergy;
430 * Active Power-Down Energy
432 Stats::Scalar actPowerDownEnergy;
435 * Precharge Power-Down Energy
437 Stats::Scalar prePowerDownEnergy;
440 * self Refresh Energy
442 Stats::Scalar selfRefreshEnergy;
444 Stats::Scalar totalEnergy;
445 Stats::Scalar averagePower;
448 * Stat to track total DRAM idle time
451 Stats::Scalar totalIdleTime;
454 * Track time spent in each power state.
456 Stats::Vector pwrStateTime;
460 * Rank class includes a vector of banks. Refresh and Power state
461 * machines are defined per rank. Events required to change the
462 * state of the refresh and power state machine are scheduled per
463 * rank. This class allows the implementation of rank-wise refresh
464 * and rank-wise power-down.
466 class Rank : public EventManager
471 * A reference to the parent DRAMInterface instance
476 * Since we are taking decisions out of order, we need to keep
477 * track of what power transition is happening at what time
479 PowerState pwrStateTrans;
482 * Previous low-power state, which will be re-entered after refresh.
484 PowerState pwrStatePostRefresh;
487 * Track when we transitioned to the current power state
492 * Keep track of when a refresh is due.
497 * Function to update Power Stats
499 void updatePowerStats();
502 * Schedule a power state transition in the future, and
503 * potentially override an already scheduled transition.
505 * @param pwr_state Power state to transition to
506 * @param tick Tick when transition should take place
508 void schedulePowerEvent(PowerState pwr_state, Tick tick);
513 * Current power state.
518 * current refresh state
520 RefreshState refreshState;
523 * rank is in or transitioning to power-down or self-refresh
525 bool inLowPowerState;
533 * Track number of packets in read queue going to this rank
535 uint32_t readEntries;
538 * Track number of packets in write queue going to this rank
540 uint32_t writeEntries;
543 * Number of ACT, RD, and WR events currently scheduled
544 * Incremented when a refresh event is started as well
545 * Used to determine when a low-power state can be entered
547 uint8_t outstandingEvents;
550 * delay low-power exit until this requirement is met
552 Tick wakeUpAllowedAt;
555 * One DRAMPower instance per rank
560 * List of commands issued, to be sent to DRAMPpower at refresh
561 * and stats dump. Keep commands here since commands to different
562 * banks are added out of order. Will only pass commands up to
563 * curTick() to DRAMPower after sorting.
565 std::vector<Command> cmdList;
568 * Vector of Banks. Each rank is made of several devices which in
569 * term are made from several banks.
571 std::vector<Bank> banks;
574 * To track number of banks which are currently active for
577 unsigned int numBanksActive;
579 /** List to keep track of activate ticks */
580 std::deque<Tick> actTicks;
583 * Track when we issued the last read/write burst
587 Rank(const DRAMInterfaceParams* _p, int _rank,
588 DRAMInterface& _dram);
590 const std::string name() const { return csprintf("%d", rank); }
593 * Kick off accounting for power and refresh states and
594 * schedule initial refresh.
596 * @param ref_tick Tick for first refresh
598 void startup(Tick ref_tick);
601 * Stop the refresh events.
606 * Check if there is no refresh and no preparation of refresh ongoing
607 * i.e. the refresh state machine is in idle
609 * @param Return true if the rank is idle from a refresh point of view
611 bool inRefIdleState() const { return refreshState == REF_IDLE; }
614 * Check if the current rank has all banks closed and is not
615 * in a low power state
617 * @param Return true if the rank is idle from a bank
618 * and power point of view
620 bool inPwrIdleState() const { return pwrState == PWR_IDLE; }
623 * Trigger a self-refresh exit if there are entries enqueued
624 * Exit if there are any read entries regardless of the bus state.
625 * If we are currently issuing write commands, exit if we have any
626 * write commands enqueued as well.
627 * Could expand this in the future to analyze state of entire queue
630 * @return boolean indicating self-refresh exit should be scheduled
632 bool forceSelfRefreshExit() const;
635 * Check if the command queue of current rank is idle
637 * @param Return true if the there are no commands in Q.
638 * Bus direction determines queue checked.
640 bool isQueueEmpty() const;
643 * Let the rank check if it was waiting for requests to drain
644 * to allow it to transition states.
646 void checkDrainDone();
649 * Push command out of cmdList queue that are scheduled at
650 * or before curTick() to DRAMPower library
651 * All commands before curTick are guaranteed to be complete
652 * and can safely be flushed.
657 * Computes stats just prior to dump event
662 * Reset stats on a stats event
667 * Schedule a transition to power-down (sleep)
669 * @param pwr_state Power state to transition to
670 * @param tick Absolute tick when transition should take place
672 void powerDownSleep(PowerState pwr_state, Tick tick);
675 * schedule and event to wake-up from power-down or self-refresh
676 * and update bank timing parameters
678 * @param exit_delay Relative tick defining the delay required between
679 * low-power exit and the next command
681 void scheduleWakeUpEvent(Tick exit_delay);
683 void processWriteDoneEvent();
684 EventFunctionWrapper writeDoneEvent;
686 void processActivateEvent();
687 EventFunctionWrapper activateEvent;
689 void processPrechargeEvent();
690 EventFunctionWrapper prechargeEvent;
692 void processRefreshEvent();
693 EventFunctionWrapper refreshEvent;
695 void processPowerEvent();
696 EventFunctionWrapper powerEvent;
698 void processWakeUpEvent();
699 EventFunctionWrapper wakeUpEvent;
706 * Function for sorting Command structures based on timeStamp
708 * @param a Memory Command
709 * @param next Memory Command
710 * @return true if timeStamp of Command 1 < timeStamp of Command 2
713 sortTime(const Command& cmd, const Command& cmd_next)
715 return cmd.timeStamp < cmd_next.timeStamp;
719 * DRAM specific device characteristics
721 const uint32_t bankGroupsPerRank;
722 const bool bankGroupArch;
725 * DRAM specific timing requirements
728 const Tick tBURST_MIN;
729 const Tick tBURST_MAX;
730 const Tick tCCD_L_WR;
746 const Tick clkResyncDelay;
747 const bool dataClockSync;
748 const bool burstInterleave;
749 const uint8_t twoCycleActivate;
750 const uint32_t activationLimit;
751 const Tick wrToRdDlySameBG;
752 const Tick rdToWrDlySameBG;
754 Enums::PageManage pageMgmt;
756 * Max column accesses (read and write) per row, before forefully
759 const uint32_t maxAccessesPerRow;
762 uint64_t timeStampOffset;
764 // Holds the value of the DRAM rank of burst issued
767 /** Enable or disable DRAM powerdown states. */
768 bool enableDRAMPowerdown;
770 /** The time when stats were last reset used to calculate average power */
771 Tick lastStatsResetTick;
774 * Keep track of when row activations happen, in order to enforce
775 * the maximum number of activations in the activation window. The
776 * method updates the time that the banks become available based
777 * on the current limits.
779 * @param rank_ref Reference to the rank
780 * @param bank_ref Reference to the bank
781 * @param act_tick Time when the activation takes place
782 * @param row Index of the row
784 void activateBank(Rank& rank_ref, Bank& bank_ref, Tick act_tick,
788 * Precharge a given bank and also update when the precharge is
789 * done. This will also deal with any stats related to the
790 * accesses to the open page.
792 * @param rank_ref The rank to precharge
793 * @param bank_ref The bank to precharge
794 * @param pre_tick Time when the precharge takes place
795 * @param auto_or_preall Is this an auto-precharge or precharge all command
796 * @param trace Is this an auto precharge then do not add to trace
798 void prechargeBank(Rank& rank_ref, Bank& bank_ref,
799 Tick pre_tick, bool auto_or_preall = false,
802 struct DRAMStats : public Stats::Group
804 DRAMStats(DRAMInterface &dram);
806 void regStats() override;
807 void resetStats() override;
811 /** total number of DRAM bursts serviced */
812 Stats::Scalar readBursts;
813 Stats::Scalar writeBursts;
815 /** DRAM per bank stats */
816 Stats::Vector perBankRdBursts;
817 Stats::Vector perBankWrBursts;
819 // Latencies summed over all requests
820 Stats::Scalar totQLat;
821 Stats::Scalar totBusLat;
822 Stats::Scalar totMemAccLat;
824 // Average latencies per request
825 Stats::Formula avgQLat;
826 Stats::Formula avgBusLat;
827 Stats::Formula avgMemAccLat;
829 // Row hit count and rate
830 Stats::Scalar readRowHits;
831 Stats::Scalar writeRowHits;
832 Stats::Formula readRowHitRate;
833 Stats::Formula writeRowHitRate;
834 Stats::Histogram bytesPerActivate;
835 // Number of bytes transferred to/from DRAM
836 Stats::Scalar bytesRead;
837 Stats::Scalar bytesWritten;
840 Stats::Formula avgRdBW;
841 Stats::Formula avgWrBW;
842 Stats::Formula peakBW;
844 Stats::Formula busUtil;
845 Stats::Formula busUtilRead;
846 Stats::Formula busUtilWrite;
847 Stats::Formula pageHitRate;
853 * Vector of dram ranks
855 std::vector<Rank*> ranks;
858 * @return delay between write and read commands
860 Tick writeToReadDelay() const override { return tBURST + tWTR + tCL; }
863 * Find which are the earliest banks ready to issue an activate
864 * for the enqueued requests. Assumes maximum of 32 banks per rank
865 * Also checks if the bank is already prepped.
867 * @param queue Queued requests to consider
868 * @param min_col_at time of seamless burst command
869 * @return One-hot encoded mask of bank indices
870 * @return boolean indicating burst can issue seamlessly, with no gaps
872 std::pair<std::vector<uint32_t>, bool>
873 minBankPrep(const MemPacketQueue& queue, Tick min_col_at) const;
876 * @return time to send a burst of data without gaps
881 return (burstInterleave ? tBURST_MAX / 2 : tBURST);
886 * Initialize the DRAM interface and verify parameters
888 void init() override;
891 * Iterate through dram ranks and instantiate per rank startup routine
893 void startup() override;
896 * Setup the rank based on packet received
898 * @param integer value of rank to be setup. used to index ranks vector
899 * @param are we setting up rank for read or write packet?
901 void setupRank(const uint8_t rank, const bool is_read) override;
904 * Iterate through dram ranks to exit self-refresh in order to drain
909 * Return true once refresh is complete for all ranks and there are no
910 * additional commands enqueued. (only evaluated when draining)
911 * This will ensure that all banks are closed, power state is IDLE, and
912 * power stats have been updated
914 * @return true if all ranks have refreshed, with no commands enqueued
917 bool allRanksDrained() const override;
920 * Iterate through DRAM ranks and suspend them
925 * @return time to offset next command
927 Tick commandOffset() const override { return (tRP + tRCD); }
930 * Function to calulate unloaded, closed bank access latency
932 Tick accessLatency() const override { return (tRP + tRCD + tCL); }
935 * For FR-FCFS policy, find first DRAM command that can issue
937 * @param queue Queued requests to consider
938 * @param min_col_at Minimum tick for 'seamless' issue
939 * @return an iterator to the selected packet, else queue.end()
940 * @return the tick when the packet selected will issue
942 std::pair<MemPacketQueue::iterator, Tick>
943 chooseNextFRFCFS(MemPacketQueue& queue, Tick min_col_at) const override;
946 * Actually do the burst - figure out the latency it
947 * will take to service the req based on bank state, channel state etc
948 * and then update those states to account for this request. Based
949 * on this, update the packet's "readyTime" and move it to the
950 * response q from where it will eventually go back to the outside
953 * @param mem_pkt The packet created from the outside world pkt
954 * @param next_burst_at Minimum bus timing requirement from controller
955 * @param queue Reference to the read or write queue with the packet
956 * @return pair, tick when current burst is issued and
957 * tick when next burst can issue
959 std::pair<Tick, Tick>
960 doBurstAccess(MemPacket* mem_pkt, Tick next_burst_at,
961 const std::vector<MemPacketQueue>& queue);
964 * Check if a burst operation can be issued to the DRAM
966 * @param Return true if RD/WR can issue
967 * This requires the DRAM to be in the
971 burstReady(MemPacket* pkt) const override
973 return ranks[pkt->rank]->inRefIdleState();
977 * This function checks if ranks are actively refreshing and
978 * therefore busy. The function also checks if ranks are in
979 * the self-refresh state, in which case, a self-refresh exit
982 * return boolean if all ranks are in refresh and therefore busy
987 * Add rank to rank delay to bus timing to all DRAM banks in alli ranks
988 * when access to an alternate interface is issued
990 * param cmd_at Time of current command used as starting point for
991 * addition of rank-to-rank delay
993 void addRankToRankDelay(Tick cmd_at) override;
996 * Complete response process for DRAM when read burst is complete
997 * This will update the counters and check if a power down state
1000 * @param rank Specifies rank associated with read burst
1002 void respondEvent(uint8_t rank);
1005 * Check the refresh state to determine if refresh needs
1006 * to be kicked back into action after a read response
1008 * @param rank Specifies rank associated with read burst
1010 void checkRefreshState(uint8_t rank);
1012 DRAMInterface(const DRAMInterfaceParams* _p);
1016 * Interface to NVM devices with media specific parameters,
1017 * statistics, and functions.
1018 * The NVMInterface includes a class for individual ranks
1019 * and per rank functions.
1021 class NVMInterface : public MemInterface
1025 * NVM rank class simply includes a vector of banks.
1027 class Rank : public EventManager
1032 * A reference to the parent NVMInterface instance
1039 * Current Rank index
1044 * Vector of NVM banks. Each rank is made of several banks
1045 * that can be accessed in parallel.
1047 std::vector<Bank> banks;
1049 Rank(const NVMInterfaceParams* _p, int _rank,
1050 NVMInterface& _nvm);
1054 * NVM specific device and channel characteristics
1056 const uint32_t maxPendingWrites;
1057 const uint32_t maxPendingReads;
1058 const bool twoCycleRdWr;
1061 * NVM specific timing requirements
1067 struct NVMStats : public Stats::Group
1069 NVMStats(NVMInterface &nvm);
1071 void regStats() override;
1076 Stats::Scalar readBursts;
1077 Stats::Scalar writeBursts;
1079 Stats::Vector perBankRdBursts;
1080 Stats::Vector perBankWrBursts;
1082 // Latencies summed over all requests
1083 Stats::Scalar totQLat;
1084 Stats::Scalar totBusLat;
1085 Stats::Scalar totMemAccLat;
1087 // Average latencies per request
1088 Stats::Formula avgQLat;
1089 Stats::Formula avgBusLat;
1090 Stats::Formula avgMemAccLat;
1092 Stats::Scalar bytesRead;
1093 Stats::Scalar bytesWritten;
1095 // Average bandwidth
1096 Stats::Formula avgRdBW;
1097 Stats::Formula avgWrBW;
1098 Stats::Formula peakBW;
1099 Stats::Formula busUtil;
1100 Stats::Formula busUtilRead;
1101 Stats::Formula busUtilWrite;
1104 Stats::Histogram pendingReads;
1105 Stats::Histogram pendingWrites;
1106 Stats::Histogram bytesPerBank;
1111 void processWriteRespondEvent();
1112 EventFunctionWrapper writeRespondEvent;
1114 void processReadReadyEvent();
1115 EventFunctionWrapper readReadyEvent;
1118 * Vector of nvm ranks
1120 std::vector<Rank*> ranks;
1123 * Holding queue for non-deterministic write commands, which
1124 * maintains writes that have been issued but have not completed
1125 * Stored seperately mostly to keep the code clean and help with
1126 * events scheduling.
1127 * This mimics a buffer on the media controller and therefore is
1128 * not added to the main write queue for sizing
1130 std::list<Tick> writeRespQueue;
1132 std::deque<Tick> readReadyQueue;
1135 * Check if the write response queue is empty
1137 * @param Return true if empty
1139 bool writeRespQueueEmpty() const { return writeRespQueue.empty(); }
1142 * Till when must we wait before issuing next read command?
1146 // keep track of reads that have issued for which data is either
1147 // not yet ready or has not yet been transferred to the ctrl
1148 uint16_t numPendingReads;
1149 uint16_t numReadDataReady;
1152 // keep track of the number of reads that have yet to be issued
1153 uint16_t numReadsToIssue;
1155 // number of writes in the writeQueue for the NVM interface
1156 uint32_t numWritesQueued;
1159 * Initialize the NVM interface and verify parameters
1161 void init() override;
1164 * Setup the rank based on packet received
1166 * @param integer value of rank to be setup. used to index ranks vector
1167 * @param are we setting up rank for read or write packet?
1169 void setupRank(const uint8_t rank, const bool is_read) override;
1172 * Check drain state of NVM interface
1174 * @return true if write response queue is empty
1177 bool allRanksDrained() const override { return writeRespQueueEmpty(); }
1180 * @return time to offset next command
1182 Tick commandOffset() const override { return tBURST; }
1185 * Check if a burst operation can be issued to the NVM
1187 * @param Return true if RD/WR can issue
1188 * for reads, also verfy that ready count
1189 * has been updated to a non-zero value to
1190 * account for race conditions between events
1192 bool burstReady(MemPacket* pkt) const override;
1195 * This function checks if ranks are busy.
1196 * This state is true when either:
1197 * 1) There is no command with read data ready to transmit or
1198 * 2) The NVM inteface has reached the maximum number of outstanding
1200 * @param read_queue_empty There are no read queued
1201 * @param all_writes_nvm All writes in queue are for NVM interface
1202 * @return true of NVM is busy
1205 bool isBusy(bool read_queue_empty, bool all_writes_nvm);
1207 * For FR-FCFS policy, find first NVM command that can issue
1208 * default to first command to prepped region
1210 * @param queue Queued requests to consider
1211 * @param min_col_at Minimum tick for 'seamless' issue
1212 * @return an iterator to the selected packet, else queue.end()
1213 * @return the tick when the packet selected will issue
1215 std::pair<MemPacketQueue::iterator, Tick>
1216 chooseNextFRFCFS(MemPacketQueue& queue, Tick min_col_at) const override;
1219 * Add rank to rank delay to bus timing to all NVM banks in alli ranks
1220 * when access to an alternate interface is issued
1222 * param cmd_at Time of current command used as starting point for
1223 * addition of rank-to-rank delay
1225 void addRankToRankDelay(Tick cmd_at) override;
1229 * Select read command to issue asynchronously
1231 void chooseRead(MemPacketQueue& queue);
1234 * Function to calulate unloaded access latency
1236 Tick accessLatency() const override { return (tREAD + tSEND); }
1239 * Check if the write response queue has reached defined threshold
1241 * @param Return true if full
1244 writeRespQueueFull() const
1246 return writeRespQueue.size() == maxPendingWrites;
1250 readsWaitingToIssue() const
1252 return ((numReadsToIssue != 0) &&
1253 (numPendingReads < maxPendingReads));
1257 * Actually do the burst and update stats.
1259 * @param pkt The packet created from the outside world pkt
1260 * @param next_burst_at Minimum bus timing requirement from controller
1261 * @return pair, tick when current burst is issued and
1262 * tick when next burst can issue
1264 std::pair<Tick, Tick>
1265 doBurstAccess(MemPacket* pkt, Tick next_burst_at);
1267 NVMInterface(const NVMInterfaceParams* _p);
1270 #endif //__MEM_INTERFACE_HH__