CommandAnalysis.h revision 11555
1/* 2 * Copyright (c) 2012-2014, TU Delft 3 * Copyright (c) 2012-2014, TU Eindhoven 4 * Copyright (c) 2012-2014, TU Kaiserslautern 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions are 9 * met: 10 * 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 14 * 2. Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in the 16 * documentation and/or other materials provided with the distribution. 17 * 18 * 3. Neither the name of the copyright holder nor the names of its 19 * contributors may be used to endorse or promote products derived from 20 * this software without specific prior written permission. 21 * 22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 23 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 24 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 25 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 26 * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 27 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 28 * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 29 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 30 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 31 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 32 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 * 34 * Authors: Karthik Chandrasekar, Matthias Jung, Omar Naji 35 * 36 */ 37 38#ifndef COMMAND_TIMINGS_H 39#define COMMAND_TIMINGS_H 40 41#include <stdint.h> 42 43#include <vector> 44#include <iostream> 45#include <deque> 46#include <string> 47 48#include "MemCommand.h" 49#include "MemorySpecification.h" 50#include "Utils.h" 51 52namespace Data { 53class CommandAnalysis { 54 public: 55 // Power-Down and Self-refresh related memory states 56 enum memstate { 57 MS_PDN_F_ACT = 10, MS_PDN_S_ACT = 11, MS_PDN_F_PRE = 12, 58 MS_PDN_S_PRE = 13, MS_SREF = 14 59 }; 60 61 // Returns number of reads, writes, acts, pres and refs in the trace 62 CommandAnalysis(const int64_t nbrofBanks); 63 64 // Number of activate commands 65 int64_t numberofacts; 66 // Number of precharge commands 67 int64_t numberofpres; 68 // Number of reads commands 69 int64_t numberofreads; 70 // Number of writes commands 71 int64_t numberofwrites; 72 // Number of refresh commands 73 int64_t numberofrefs; 74 // Number of precharge cycles 75 int64_t precycles; 76 // Number of active cycles 77 int64_t actcycles; 78 // Number of Idle cycles in the active state 79 int64_t idlecycles_act; 80 // Number of Idle cycles in the precharge state 81 int64_t idlecycles_pre; 82 // Number of fast-exit activate power-downs 83 int64_t f_act_pdns; 84 // Number of slow-exit activate power-downs 85 int64_t s_act_pdns; 86 // Number of fast-exit precharged power-downs 87 int64_t f_pre_pdns; 88 // Number of slow-exit activate power-downs 89 int64_t s_pre_pdns; 90 // Number of self-refresh commands 91 int64_t numberofsrefs; 92 // Number of clock cycles in fast-exit activate power-down mode 93 int64_t f_act_pdcycles; 94 // Number of clock cycles in slow-exit activate power-down mode 95 int64_t s_act_pdcycles; 96 // Number of clock cycles in fast-exit precharged power-down mode 97 int64_t f_pre_pdcycles; 98 // Number of clock cycles in slow-exit precharged power-down mode 99 int64_t s_pre_pdcycles; 100 // Number of clock cycles in self-refresh mode 101 int64_t sref_cycles; 102 // Number of clock cycles in activate power-up mode 103 int64_t pup_act_cycles; 104 // Number of clock cycles in precharged power-up mode 105 int64_t pup_pre_cycles; 106 // Number of clock cycles in self-refresh power-up mode 107 int64_t spup_cycles; 108 109 // Number of active auto-refresh cycles in self-refresh mode 110 int64_t sref_ref_act_cycles; 111 // Number of precharged auto-refresh cycles in self-refresh mode 112 int64_t sref_ref_pre_cycles; 113 // Number of active auto-refresh cycles during self-refresh exit 114 int64_t spup_ref_act_cycles; 115 // Number of precharged auto-refresh cycles during self-refresh exit 116 int64_t spup_ref_pre_cycles; 117 118 // function for clearing counters 119 void clearStats(const int64_t timestamp); 120 121 // function for clearing arrays 122 void clear(); 123 124 // To identify auto-precharges 125 void getCommands(const MemorySpecification& memSpec, 126 std::vector<MemCommand>& list, 127 bool lastupdate); 128 129 private: 130 int64_t zero; 131 // Cached last read command from the file 132 std::vector<MemCommand> cached_cmd; 133 134 // Stores the memory commands for analysis 135 std::vector<MemCommand> cmd_list; 136 137 // To save states of the different banks, before entering active 138 // power-down mode (slow/fast-exit). 139 std::vector<int> last_states; 140 // Bank state vector 141 std::vector<int> bankstate; 142 143 std::vector<int64_t> activation_cycle; 144 // To keep track of the last ACT cycle 145 int64_t latest_act_cycle; 146 // To keep track of the last PRE cycle 147 int64_t latest_pre_cycle; 148 // To keep track of the last READ cycle 149 int64_t latest_read_cycle; 150 // To keep track of the last WRITE cycle 151 int64_t latest_write_cycle; 152 153 // To calculate end of READ operation 154 int64_t end_read_op; 155 // To calculate end of WRITE operation 156 int64_t end_write_op; 157 // To calculate end of ACT operation 158 int64_t end_act_op; 159 160 // Clock cycle when self-refresh was issued 161 int64_t sref_cycle; 162 163 // Clock cycle when the latest power-down was issued 164 int64_t pdn_cycle; 165 166 // Memory State 167 unsigned mem_state; 168 unsigned num_active_banks; 169 170 // Clock cycle of first activate command when memory state changes to ACT 171 int64_t first_act_cycle; 172 173 // Clock cycle of last precharge command when memory state changes to PRE 174 int64_t last_pre_cycle; 175 176 // To perform timing analysis of a given set of commands and update command counters 177 void evaluate(const MemorySpecification& memSpec, 178 std::vector<MemCommand>& cmd_list); 179 180 // To calculate time of completion of any issued command 181 int64_t timeToCompletion(const MemorySpecification& memSpec, 182 MemCommand::cmds type); 183 184 // To update idle period information whenever active cycles may be idle 185 void idle_act_update(const MemorySpecification& memSpec, 186 int64_t latest_read_cycle, 187 int64_t latest_write_cycle, 188 int64_t latest_act_cycle, 189 int64_t timestamp); 190 191 // To update idle period information whenever precharged cycles may be idle 192 void idle_pre_update(const MemorySpecification& memSpec, 193 int64_t timestamp, 194 int64_t latest_pre_cycle); 195 196 void printWarningIfActive(const std::string& warning, int type, int64_t timestamp, int bank); 197 void printWarningIfNotActive(const std::string& warning, int type, int64_t timestamp, int bank); 198 void printWarningIfPoweredDown(const std::string& warning, int type, int64_t timestamp, int bank); 199 void printWarning(const std::string& warning, int type, int64_t timestamp, int bank); 200}; 201} 202#endif // ifndef COMMAND_TIMINGS_H 203