CommandAnalysis.h revision 10428:0caf62b57dfd
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 CommandAnalysis(); 62 63 // Returns number of reads, writes, acts, pres and refs in the trace 64 CommandAnalysis(const int nbrofBanks); 65 66 // Number of activate commands 67 int64_t numberofacts; 68 // Number of precharge commands 69 int64_t numberofpres; 70 // Number of reads commands 71 int64_t numberofreads; 72 // Number of writes commands 73 int64_t numberofwrites; 74 // Number of refresh commands 75 int64_t numberofrefs; 76 // Number of precharge cycles 77 int64_t precycles; 78 // Number of active cycles 79 int64_t actcycles; 80 // Number of Idle cycles in the active state 81 int64_t idlecycles_act; 82 // Number of Idle cycles in the precharge state 83 int64_t idlecycles_pre; 84 // Number of fast-exit activate power-downs 85 int64_t f_act_pdns; 86 // Number of slow-exit activate power-downs 87 int64_t s_act_pdns; 88 // Number of fast-exit precharged power-downs 89 int64_t f_pre_pdns; 90 // Number of slow-exit activate power-downs 91 int64_t s_pre_pdns; 92 // Number of self-refresh commands 93 int64_t numberofsrefs; 94 // Number of clock cycles in fast-exit activate power-down mode 95 int64_t f_act_pdcycles; 96 // Number of clock cycles in slow-exit activate power-down mode 97 int64_t s_act_pdcycles; 98 // Number of clock cycles in fast-exit precharged power-down mode 99 int64_t f_pre_pdcycles; 100 // Number of clock cycles in slow-exit precharged power-down mode 101 int64_t s_pre_pdcycles; 102 // Number of clock cycles in self-refresh mode 103 int64_t sref_cycles; 104 // Number of clock cycles in activate power-up mode 105 int64_t pup_act_cycles; 106 // Number of clock cycles in precharged power-up mode 107 int64_t pup_pre_cycles; 108 // Number of clock cycles in self-refresh power-up mode 109 int64_t spup_cycles; 110 111 // Number of active auto-refresh cycles in self-refresh mode 112 int64_t sref_ref_act_cycles; 113 // Number of precharged auto-refresh cycles in self-refresh mode 114 int64_t sref_ref_pre_cycles; 115 // Number of active auto-refresh cycles during self-refresh exit 116 int64_t spup_ref_act_cycles; 117 // Number of precharged auto-refresh cycles during self-refresh exit 118 int64_t spup_ref_pre_cycles; 119 120 // function for clearing arrays 121 void clear(); 122 123 // To identify auto-precharges 124 void getCommands(const MemorySpecification& memSpec, 125 const int 126 nbrofBanks, 127 std::vector<MemCommand>& list, 128 bool lastupdate); 129 130 private: 131 unsigned init; 132 int64_t zero; 133 unsigned pop; 134 // Cached last read command from the file 135 std::vector<MemCommand> cached_cmd; 136 137 // Stores the memory commands for analysis 138 std::vector<MemCommand> cmd_list; 139 140 // Stores all memory commands for analysis 141 std::vector<MemCommand> full_cmd_list; 142 143 // To save states of the different banks, before entering active 144 // power-down mode (slow/fast-exit). 145 std::vector<int> last_states; 146 // Bank state vector 147 std::vector<int> bankstate; 148 149 std::vector<int64_t> activation_cycle; 150 // To keep track of the last ACT cycle 151 int64_t latest_act_cycle; 152 // To keep track of the last PRE cycle 153 int64_t latest_pre_cycle; 154 // To keep track of the last READ cycle 155 int64_t latest_read_cycle; 156 // To keep track of the last WRITE cycle 157 int64_t latest_write_cycle; 158 159 // To calculate end of READ operation 160 int64_t end_read_op; 161 // To calculate end of WRITE operation 162 int64_t end_write_op; 163 // To calculate end of ACT operation 164 int64_t end_act_op; 165 166 // Clock cycle when self-refresh was issued 167 int64_t sref_cycle; 168 169 // Clock cycle when the latest power-down was issued 170 int64_t pdn_cycle; 171 172 // Memory State 173 unsigned mem_state; 174 175 // Clock cycle of first activate command when memory state changes to ACT 176 int64_t first_act_cycle; 177 178 // Clock cycle of last precharge command when memory state changes to PRE 179 int64_t last_pre_cycle; 180 // To collect and analyse all commands including auto-precharges 181 void analyse_commands(const int nbrofBanks, 182 Data::MemorySpecification 183 memSpec, 184 int64_t nCommands, 185 int64_t nCached, 186 bool lastupdate); 187 // To perform timing analysis of a given set of commands and update command counters 188 void evaluate(const MemorySpecification& memSpec, 189 std::vector<MemCommand>& cmd_list, 190 int nbrofBanks); 191 192 // To calculate time of completion of any issued command 193 int timeToCompletion(const MemorySpecification& memSpec, 194 MemCommand::cmds type); 195 196 // To update idle period information whenever active cycles may be idle 197 void idle_act_update(const MemorySpecification& memSpec, 198 int64_t latest_read_cycle, 199 int64_t latest_write_cycle, 200 int64_t latest_act_cycle, 201 int64_t timestamp); 202 203 // To update idle period information whenever precharged cycles may be idle 204 void idle_pre_update(const MemorySpecification& memSpec, 205 int64_t timestamp, 206 int64_t latest_pre_cycle); 207 208 void printWarningIfActive(const std::string& warning, int type, int64_t timestamp, int bank); 209 void printWarningIfNotActive(const std::string& warning, int type, int64_t timestamp, int bank); 210 void printWarning(const std::string& warning, int type, int64_t timestamp, int bank); 211}; 212} 213#endif // ifndef COMMAND_TIMINGS_H 214