[2] | 1 | #ifndef CACHE_MULTILEVEL_H |
---|
| 2 | #define CACHE_MULTILEVEL_H |
---|
| 3 | |
---|
| 4 | #include <stdint.h> |
---|
| 5 | #include <stdarg.h> |
---|
| 6 | #include <iostream> |
---|
| 7 | #include "cache_onelevel.h" |
---|
| 8 | #include "type_req_cache.h" |
---|
| 9 | #include "type_rsp_cache.h" |
---|
| 10 | |
---|
| 11 | using namespace std; |
---|
| 12 | using namespace hierarchy_memory::cache::cache_multilevel::cache_onelevel; |
---|
| 13 | |
---|
| 14 | namespace hierarchy_memory { |
---|
| 15 | namespace cache { |
---|
| 16 | namespace cache_multilevel { |
---|
| 17 | |
---|
| 18 | class param_t |
---|
| 19 | { |
---|
| 20 | public : const char * name ; |
---|
| 21 | public : uint32_t nb_level ; |
---|
| 22 | public : uint32_t nb_port ; |
---|
| 23 | public : param_cache_t * param_cache ; |
---|
| 24 | |
---|
| 25 | public : param_t () {}; |
---|
| 26 | |
---|
| 27 | public : param_t (const char * name , |
---|
| 28 | uint32_t nb_level , |
---|
| 29 | uint32_t nb_port , |
---|
| 30 | param_cache_t * param_cache ) : |
---|
| 31 | name (name) |
---|
| 32 | { |
---|
| 33 | //this->name = name ; |
---|
| 34 | this->nb_level = nb_level ; |
---|
| 35 | this->nb_port = nb_port ; |
---|
| 36 | this->param_cache = param_cache ; |
---|
| 37 | } |
---|
| 38 | |
---|
| 39 | friend ostream& operator<< (ostream& output_stream, const param_t & x) |
---|
| 40 | { |
---|
| 41 | output_stream << "<" << x.name << "> " |
---|
| 42 | << x.nb_level << " " |
---|
| 43 | << x.nb_port; |
---|
| 44 | |
---|
| 45 | for (uint32_t it = 0; it < x.nb_level; it ++) |
---|
| 46 | output_stream << endl << x.param_cache [it]; |
---|
| 47 | return output_stream; |
---|
| 48 | } |
---|
| 49 | |
---|
| 50 | };//end param_t |
---|
| 51 | |
---|
| 52 | class access_t |
---|
| 53 | { |
---|
| 54 | public : uint32_t num_port ; |
---|
| 55 | public : type_rsp_cache_t hit ; // result of access |
---|
| 56 | public : uint32_t latence ; // Latence of access |
---|
| 57 | public : uint32_t last_nb_level; // if access is not a hit : last level of cache before a error |
---|
| 58 | |
---|
| 59 | public : access_t (uint32_t num_port , |
---|
| 60 | type_rsp_cache_t hit , |
---|
| 61 | uint32_t latence , |
---|
| 62 | uint32_t last_nb_level) |
---|
| 63 | { |
---|
| 64 | this->num_port = num_port ; |
---|
| 65 | this->hit = hit ; |
---|
| 66 | this->latence = latence ; |
---|
| 67 | this->last_nb_level = last_nb_level; |
---|
| 68 | } |
---|
| 69 | |
---|
| 70 | friend ostream& operator<< (ostream& output_stream, const access_t & x) |
---|
| 71 | { |
---|
| 72 | output_stream << "[" |
---|
| 73 | << x.num_port << "] " |
---|
| 74 | << x.hit << " " |
---|
| 75 | << x.latence << " " |
---|
| 76 | << x.last_nb_level; |
---|
| 77 | return output_stream; |
---|
| 78 | } |
---|
| 79 | };//access_t |
---|
| 80 | |
---|
| 81 | class Cache_Multilevel |
---|
| 82 | { |
---|
| 83 | private : char * name; |
---|
| 84 | protected : Cache_OneLevel ** hierarchy_cache; |
---|
| 85 | public : const uint32_t nb_level; |
---|
| 86 | public : const uint32_t nb_port ; |
---|
| 87 | |
---|
| 88 | //*****[ constructor ]***** |
---|
| 89 | public : Cache_Multilevel (param_t param) : |
---|
| 90 | nb_level (param.nb_level), |
---|
| 91 | nb_port (param.nb_port ) |
---|
| 92 | { |
---|
| 93 | uint32_t size_name = strlen(param.name)+1; |
---|
| 94 | name = new char [size_name]; |
---|
| 95 | strncpy(name,param.name,size_name); |
---|
| 96 | |
---|
| 97 | hierarchy_cache = new Cache_OneLevel * [nb_level]; |
---|
| 98 | |
---|
| 99 | // Creation of Cache hierarchy |
---|
| 100 | for (uint32_t it = 0; it < nb_level; it ++) |
---|
| 101 | hierarchy_cache [it] = new Cache_OneLevel (cache_onelevel::param_t(param.nb_port , |
---|
| 102 | param.param_cache [it])); |
---|
| 103 | } |
---|
| 104 | |
---|
| 105 | //*****[ destructor ]***** |
---|
| 106 | public : ~Cache_Multilevel () |
---|
| 107 | { |
---|
| 108 | for (uint32_t it = 0; it < nb_level; it ++) |
---|
| 109 | delete hierarchy_cache [it]; |
---|
| 110 | }; |
---|
| 111 | //*****[ reset ]***** |
---|
| 112 | public : void reset () |
---|
| 113 | { |
---|
| 114 | for (uint32_t it = 0; it < nb_level; it ++) |
---|
| 115 | hierarchy_cache [it]->reset(); |
---|
| 116 | } |
---|
| 117 | |
---|
| 118 | //*****[ transition ]***** |
---|
| 119 | public : void transition () |
---|
| 120 | { |
---|
| 121 | for (uint32_t it = 0; it < nb_level; it ++) |
---|
| 122 | hierarchy_cache [it]->transition(); |
---|
| 123 | } |
---|
| 124 | |
---|
| 125 | //*****[ access ]***** |
---|
| 126 | public : access_t access (uint32_t num_port, uint32_t address, uint32_t trdid, type_req_cache_t type, direction_req_cache_t dir) |
---|
| 127 | { |
---|
| 128 | uint32_t time = 0; |
---|
| 129 | uint32_t last_nb_level = (nb_level==0)?0:(nb_level-1); |
---|
| 130 | type_rsp_cache_t hit = MISS; |
---|
| 131 | |
---|
| 132 | for (uint32_t it_nb_level = 0; it_nb_level < nb_level; it_nb_level ++) |
---|
| 133 | { |
---|
| 134 | hit = hierarchy_cache[it_nb_level]->access(num_port,address,trdid,type,dir); |
---|
| 135 | time += hierarchy_cache [it_nb_level]->latence (num_port); |
---|
| 136 | |
---|
| 137 | if ( (hit == HIT_CACHE) || |
---|
| 138 | (hit == HIT_WRITE_BUFFER) || |
---|
| 139 | (hit == HIT_BYPASS) ) |
---|
| 140 | { |
---|
| 141 | last_nb_level = it_nb_level; |
---|
| 142 | break; |
---|
| 143 | } |
---|
| 144 | } |
---|
| 145 | return access_t (num_port,hit,time,last_nb_level); |
---|
| 146 | } |
---|
| 147 | |
---|
| 148 | //*****[ update_access ]***** |
---|
| 149 | public : uint32_t update_access (access_t cur_access) |
---|
| 150 | { |
---|
| 151 | for (uint32_t it = 0; it < cur_access.last_nb_level; it ++) |
---|
| 152 | hierarchy_cache [it]->update_latence (cur_access.num_port,cur_access.latence); |
---|
| 153 | |
---|
| 154 | return cur_access.latence; |
---|
| 155 | } |
---|
| 156 | |
---|
| 157 | //*****[ latence ]***** |
---|
| 158 | // Return the time to have the data |
---|
| 159 | // latence is call on the same port in a single cycle, only the last access is save |
---|
| 160 | public : uint32_t latence (uint32_t num_port, uint32_t address, uint32_t trdid, type_req_cache_t type, direction_req_cache_t dir) |
---|
| 161 | { |
---|
| 162 | return update_access (access (num_port, address, trdid, type, dir)); |
---|
| 163 | } |
---|
| 164 | |
---|
| 165 | //*****[ information ]***** |
---|
| 166 | public : void information (void) |
---|
| 167 | { |
---|
| 168 | cout << "<" << name << ">" << endl; |
---|
| 169 | for (uint32_t it = 0; it < nb_level; it ++) |
---|
| 170 | hierarchy_cache [it]->information(); |
---|
| 171 | } |
---|
| 172 | |
---|
| 173 | friend ostream& operator<< (ostream& output_stream, const Cache_Multilevel & x) |
---|
| 174 | { |
---|
| 175 | output_stream << "<" << x.name << ">" << endl; |
---|
| 176 | |
---|
| 177 | for (uint32_t it = 0; it < x.nb_level; it ++) |
---|
| 178 | output_stream << *x.hierarchy_cache [it] << endl; |
---|
| 179 | |
---|
| 180 | return output_stream; |
---|
| 181 | } |
---|
| 182 | }; |
---|
| 183 | |
---|
| 184 | };};}; |
---|
| 185 | #endif //!CACHE_MULTILEVEL_H |
---|
| 186 | |
---|