[670] | 1 | #ifndef UPDATE_TAB_H_ |
---|
| 2 | #define UPDATE_TAB_H_ |
---|
| 3 | |
---|
| 4 | #include <inttypes.h> |
---|
| 5 | #include <systemc> |
---|
| 6 | #include <cassert> |
---|
| 7 | #include "arithmetics.h" |
---|
| 8 | |
---|
| 9 | //////////////////////////////////////////////////////////////////////// |
---|
| 10 | // An update tab entry |
---|
| 11 | //////////////////////////////////////////////////////////////////////// |
---|
| 12 | class UpdateTabEntry { |
---|
| 13 | |
---|
| 14 | typedef uint32_t size_t; |
---|
| 15 | typedef sc_dt::sc_uint<40> addr_t; |
---|
| 16 | |
---|
| 17 | public: |
---|
| 18 | |
---|
| 19 | bool valid; // It is a valid pending transaction |
---|
| 20 | bool update; // It is an update transaction |
---|
| 21 | bool brdcast; // It is a broadcast invalidate |
---|
| 22 | bool rsp; // Response to the initiator required |
---|
| 23 | bool ack; // Acknowledge to the CONFIG FSM required |
---|
| 24 | size_t srcid; // The srcid of the initiator which wrote the data |
---|
| 25 | size_t trdid; // The trdid of the initiator which wrote the data |
---|
| 26 | size_t pktid; // The pktid of the initiator which wrote the data |
---|
| 27 | addr_t nline; // The identifier of the cache line |
---|
| 28 | size_t count; // The number of acknowledge responses to receive |
---|
[680] | 29 | bool type; // for a command read or write |
---|
| 30 | bool is_changed; // multi ack miss req sends this bit to 1 |
---|
[670] | 31 | |
---|
| 32 | UpdateTabEntry() |
---|
| 33 | { |
---|
[677] | 34 | valid = false; |
---|
| 35 | update = false; |
---|
| 36 | brdcast = false; |
---|
| 37 | rsp = false; |
---|
| 38 | ack = false; |
---|
| 39 | srcid = 0; |
---|
| 40 | trdid = 0; |
---|
| 41 | pktid = 0; |
---|
| 42 | nline = 0; |
---|
| 43 | count = 0; |
---|
[680] | 44 | type = 0; |
---|
| 45 | is_changed = 0; |
---|
[670] | 46 | } |
---|
| 47 | |
---|
| 48 | UpdateTabEntry(bool i_valid, |
---|
| 49 | bool i_update, |
---|
| 50 | bool i_brdcast, |
---|
| 51 | bool i_rsp, |
---|
| 52 | bool i_ack, |
---|
| 53 | size_t i_srcid, |
---|
| 54 | size_t i_trdid, |
---|
| 55 | size_t i_pktid, |
---|
| 56 | addr_t i_nline, |
---|
[677] | 57 | size_t i_count, |
---|
[680] | 58 | bool i_type, |
---|
| 59 | bool i_is_changed) |
---|
[670] | 60 | { |
---|
[677] | 61 | valid = i_valid; |
---|
| 62 | update = i_update; |
---|
| 63 | brdcast = i_brdcast; |
---|
| 64 | rsp = i_rsp; |
---|
| 65 | ack = i_ack; |
---|
| 66 | srcid = i_srcid; |
---|
| 67 | trdid = i_trdid; |
---|
| 68 | pktid = i_pktid; |
---|
| 69 | nline = i_nline; |
---|
| 70 | count = i_count; |
---|
[680] | 71 | type = i_type; |
---|
| 72 | is_changed = i_is_changed; |
---|
[670] | 73 | } |
---|
| 74 | |
---|
| 75 | UpdateTabEntry(const UpdateTabEntry &source) |
---|
| 76 | { |
---|
[677] | 77 | valid = source.valid; |
---|
| 78 | update = source.update; |
---|
| 79 | brdcast = source.brdcast; |
---|
| 80 | rsp = source.rsp; |
---|
| 81 | ack = source.ack; |
---|
| 82 | srcid = source.srcid; |
---|
| 83 | trdid = source.trdid; |
---|
| 84 | pktid = source.pktid; |
---|
| 85 | nline = source.nline; |
---|
| 86 | count = source.count; |
---|
[680] | 87 | type = source.type; |
---|
| 88 | is_changed = source.is_changed; |
---|
[670] | 89 | } |
---|
| 90 | |
---|
| 91 | //////////////////////////////////////////////////// |
---|
| 92 | // The init() function initializes the entry |
---|
| 93 | /////////////////////////////////////////////////// |
---|
| 94 | void init() |
---|
| 95 | { |
---|
[677] | 96 | valid = false; |
---|
| 97 | update = false; |
---|
| 98 | brdcast = false; |
---|
| 99 | rsp = false; |
---|
| 100 | ack = false; |
---|
| 101 | srcid = 0; |
---|
| 102 | trdid = 0; |
---|
| 103 | pktid = 0; |
---|
| 104 | nline = 0; |
---|
| 105 | count = 0; |
---|
[680] | 106 | type = 0; |
---|
| 107 | is_changed = 0; |
---|
[670] | 108 | } |
---|
| 109 | |
---|
| 110 | //////////////////////////////////////////////////////////////////// |
---|
| 111 | // The copy() function copies an existing entry |
---|
| 112 | // Its arguments are : |
---|
| 113 | // - source : the update tab entry to copy |
---|
| 114 | //////////////////////////////////////////////////////////////////// |
---|
| 115 | void copy(const UpdateTabEntry &source) |
---|
| 116 | { |
---|
[677] | 117 | valid = source.valid; |
---|
| 118 | update = source.update; |
---|
| 119 | brdcast = source.brdcast; |
---|
| 120 | rsp = source.rsp; |
---|
| 121 | ack = source.ack; |
---|
| 122 | srcid = source.srcid; |
---|
| 123 | trdid = source.trdid; |
---|
| 124 | pktid = source.pktid; |
---|
| 125 | nline = source.nline; |
---|
| 126 | count = source.count; |
---|
[680] | 127 | type = source.type; |
---|
| 128 | is_changed = source.is_changed; |
---|
[670] | 129 | } |
---|
| 130 | |
---|
| 131 | //////////////////////////////////////////////////////////////////// |
---|
| 132 | // The print() function prints the entry |
---|
| 133 | //////////////////////////////////////////////////////////////////// |
---|
| 134 | void print() |
---|
| 135 | { |
---|
| 136 | std::cout << " val = " << std::dec << valid |
---|
| 137 | << " / updt = " << update |
---|
| 138 | << " / bc = " << brdcast |
---|
| 139 | << " / rsp = " << rsp |
---|
| 140 | << " / ack = " << ack |
---|
| 141 | << " / count = " << count |
---|
| 142 | << " / srcid = " << std::hex << srcid |
---|
| 143 | << " / trdid = " << trdid |
---|
| 144 | << " / pktid = " << pktid |
---|
[680] | 145 | << " / type = " << type |
---|
| 146 | << " / is_changed = " << is_changed |
---|
[670] | 147 | << " / nline = " << nline << std::endl; |
---|
| 148 | } |
---|
| 149 | }; |
---|
| 150 | |
---|
| 151 | //////////////////////////////////////////////////////////////////////// |
---|
| 152 | // The update tab |
---|
| 153 | //////////////////////////////////////////////////////////////////////// |
---|
| 154 | class UpdateTab{ |
---|
| 155 | |
---|
| 156 | typedef uint64_t addr_t; |
---|
| 157 | |
---|
| 158 | private: |
---|
| 159 | size_t size_tab; |
---|
| 160 | std::vector<UpdateTabEntry> tab; |
---|
| 161 | |
---|
| 162 | public: |
---|
| 163 | |
---|
| 164 | UpdateTab() |
---|
| 165 | : tab(0) |
---|
| 166 | { |
---|
| 167 | size_tab=0; |
---|
| 168 | } |
---|
| 169 | |
---|
| 170 | UpdateTab(size_t size_tab_i) |
---|
| 171 | : tab(size_tab_i) |
---|
| 172 | { |
---|
| 173 | size_tab=size_tab_i; |
---|
| 174 | } |
---|
| 175 | |
---|
| 176 | //////////////////////////////////////////////////////////////////// |
---|
| 177 | // The size() function returns the size of the tab |
---|
| 178 | //////////////////////////////////////////////////////////////////// |
---|
| 179 | const size_t size() |
---|
| 180 | { |
---|
| 181 | return size_tab; |
---|
| 182 | } |
---|
| 183 | |
---|
| 184 | //////////////////////////////////////////////////////////////////// |
---|
| 185 | // The print() function diplays the tab content |
---|
| 186 | //////////////////////////////////////////////////////////////////// |
---|
| 187 | void print() |
---|
| 188 | { |
---|
| 189 | std::cout << "UPDATE TABLE Content" << std::endl; |
---|
| 190 | for(size_t i=0; i<size_tab; i++) |
---|
| 191 | { |
---|
| 192 | std::cout << "[" << std::dec << i << "] "; |
---|
| 193 | tab[i].print(); |
---|
| 194 | } |
---|
| 195 | return; |
---|
| 196 | } |
---|
| 197 | |
---|
| 198 | ///////////////////////////////////////////////////////////////////// |
---|
| 199 | // The init() function initializes the tab |
---|
| 200 | ///////////////////////////////////////////////////////////////////// |
---|
| 201 | void init() |
---|
| 202 | { |
---|
| 203 | for ( size_t i=0; i<size_tab; i++) tab[i].init(); |
---|
| 204 | } |
---|
| 205 | |
---|
| 206 | ///////////////////////////////////////////////////////////////////// |
---|
| 207 | // The reads() function reads an entry |
---|
| 208 | // Arguments : |
---|
| 209 | // - entry : the entry to read |
---|
| 210 | // This function returns a copy of the entry. |
---|
| 211 | ///////////////////////////////////////////////////////////////////// |
---|
| 212 | UpdateTabEntry read (size_t entry) |
---|
| 213 | { |
---|
| 214 | assert(entry<size_tab && "Bad Update Tab Entry"); |
---|
| 215 | return UpdateTabEntry(tab[entry]); |
---|
| 216 | } |
---|
| 217 | |
---|
| 218 | /////////////////////////////////////////////////////////////////////////// |
---|
| 219 | // The set() function writes an entry in the Update Table |
---|
| 220 | // Arguments : |
---|
| 221 | // - update : transaction type (bool) |
---|
| 222 | // - srcid : srcid of the initiator |
---|
| 223 | // - trdid : trdid of the initiator |
---|
| 224 | // - pktid : pktid of the initiator |
---|
| 225 | // - count : number of expected responses |
---|
| 226 | // - index : (return argument) index of the selected entry |
---|
| 227 | // This function returns true if the write successed (an entry was empty). |
---|
| 228 | /////////////////////////////////////////////////////////////////////////// |
---|
| 229 | bool set(const bool update, |
---|
| 230 | const bool brdcast, |
---|
| 231 | const bool rsp, |
---|
| 232 | const bool ack, |
---|
| 233 | const size_t srcid, |
---|
| 234 | const size_t trdid, |
---|
| 235 | const size_t pktid, |
---|
| 236 | const addr_t nline, |
---|
| 237 | const size_t count, |
---|
[680] | 238 | const bool type, |
---|
[677] | 239 | size_t &index, |
---|
[680] | 240 | const bool is_changed=false) |
---|
[670] | 241 | { |
---|
| 242 | for ( size_t i=0 ; i<size_tab ; i++ ) |
---|
| 243 | { |
---|
| 244 | if( !tab[i].valid ) |
---|
| 245 | { |
---|
| 246 | tab[i].valid = true; |
---|
| 247 | tab[i].update = update; |
---|
| 248 | tab[i].brdcast = brdcast; |
---|
| 249 | tab[i].rsp = rsp; |
---|
| 250 | tab[i].ack = ack; |
---|
| 251 | tab[i].srcid = (size_t) srcid; |
---|
| 252 | tab[i].trdid = (size_t) trdid; |
---|
| 253 | tab[i].pktid = (size_t) pktid; |
---|
| 254 | tab[i].nline = (addr_t) nline; |
---|
| 255 | tab[i].count = (size_t) count; |
---|
[680] | 256 | tab[i].type = type; |
---|
| 257 | tab[i].is_changed = is_changed; |
---|
[670] | 258 | index = i; |
---|
| 259 | return true; |
---|
| 260 | } |
---|
| 261 | } |
---|
| 262 | return false; |
---|
| 263 | } // end set() |
---|
| 264 | |
---|
| 265 | ///////////////////////////////////////////////////////////////////// |
---|
| 266 | // The decrement() function decrements the counter for a given entry. |
---|
| 267 | // Arguments : |
---|
| 268 | // - index : the index of the entry |
---|
| 269 | // - counter : (return argument) value of the counter after decrement |
---|
| 270 | // This function returns true if the entry is valid. |
---|
| 271 | ///////////////////////////////////////////////////////////////////// |
---|
| 272 | bool decrement( const size_t index, |
---|
| 273 | size_t &counter ) |
---|
| 274 | { |
---|
| 275 | assert((index<size_tab) && "Bad Update Tab Entry"); |
---|
| 276 | if ( tab[index].valid ) |
---|
| 277 | { |
---|
| 278 | tab[index].count--; |
---|
| 279 | counter = tab[index].count; |
---|
| 280 | return true; |
---|
| 281 | } |
---|
| 282 | else |
---|
| 283 | { |
---|
| 284 | return false; |
---|
| 285 | } |
---|
| 286 | } |
---|
| 287 | |
---|
| 288 | ///////////////////////////////////////////////////////////////////// |
---|
| 289 | // The is_full() function returns true if the table is full |
---|
| 290 | ///////////////////////////////////////////////////////////////////// |
---|
| 291 | bool is_full() |
---|
| 292 | { |
---|
| 293 | for(size_t i = 0 ; i < size_tab ; i++) |
---|
| 294 | { |
---|
| 295 | if(!tab[i].valid) return false; |
---|
| 296 | } |
---|
| 297 | return true; |
---|
| 298 | } |
---|
| 299 | |
---|
| 300 | ///////////////////////////////////////////////////////////////////// |
---|
| 301 | // The is_not_empty() function returns true if the table is not empty |
---|
| 302 | ///////////////////////////////////////////////////////////////////// |
---|
| 303 | bool is_not_empty() |
---|
| 304 | { |
---|
| 305 | for(size_t i = 0 ; i < size_tab ; i++) |
---|
| 306 | { |
---|
| 307 | if(tab[i].valid) return true; |
---|
| 308 | } |
---|
| 309 | return false; |
---|
| 310 | } |
---|
| 311 | |
---|
| 312 | ///////////////////////////////////////////////////////////////////// |
---|
| 313 | // The need_rsp() function returns the need of a response |
---|
| 314 | // Arguments : |
---|
| 315 | // - index : the index of the entry |
---|
| 316 | ///////////////////////////////////////////////////////////////////// |
---|
| 317 | bool need_rsp(const size_t index) |
---|
| 318 | { |
---|
| 319 | assert(index<size_tab && "Bad Update Tab Entry"); |
---|
| 320 | return tab[index].rsp; |
---|
| 321 | } |
---|
| 322 | |
---|
| 323 | ///////////////////////////////////////////////////////////////////// |
---|
| 324 | // The need_ack() function returns the need of an acknowledge |
---|
| 325 | // Arguments : |
---|
| 326 | // - index : the index of the entry |
---|
| 327 | ///////////////////////////////////////////////////////////////////// |
---|
| 328 | bool need_ack(const size_t index) |
---|
| 329 | { |
---|
| 330 | assert(index<size_tab && "Bad Update Tab Entry"); |
---|
| 331 | return tab[index].ack; |
---|
| 332 | } |
---|
| 333 | |
---|
| 334 | ///////////////////////////////////////////////////////////////////// |
---|
| 335 | // The is_brdcast() function returns the transaction type |
---|
| 336 | // Arguments : |
---|
| 337 | // - index : the index of the entry |
---|
| 338 | ///////////////////////////////////////////////////////////////////// |
---|
| 339 | bool is_brdcast(const size_t index) |
---|
| 340 | { |
---|
| 341 | assert(index<size_tab && "Bad Update Tab Entry"); |
---|
| 342 | return tab[index].brdcast; |
---|
| 343 | } |
---|
| 344 | |
---|
| 345 | ///////////////////////////////////////////////////////////////////// |
---|
| 346 | // The is_update() function returns the transaction type |
---|
| 347 | // Arguments : |
---|
| 348 | // - index : the index of the entry |
---|
| 349 | ///////////////////////////////////////////////////////////////////// |
---|
| 350 | bool is_update(const size_t index) |
---|
| 351 | { |
---|
| 352 | assert(index<size_tab && tab[index].valid && "Bad Update Tab Entry"); |
---|
| 353 | return tab[index].update; |
---|
| 354 | } |
---|
| 355 | ///////////////////////////////////////////////////////////////////// |
---|
| 356 | // The is_update() function returns the valid bit |
---|
| 357 | // Arguments : |
---|
| 358 | // - index : the index of the entry |
---|
| 359 | ///////////////////////////////////////////////////////////////////// |
---|
| 360 | bool is_valid(const size_t index) |
---|
| 361 | { |
---|
| 362 | assert(index<size_tab && "Bad Update Tab Entry"); |
---|
| 363 | return tab[index].valid; |
---|
| 364 | } |
---|
| 365 | |
---|
| 366 | ///////////////////////////////////////////////////////////////////// |
---|
| 367 | // The srcid() function returns the srcid value |
---|
| 368 | // Arguments : |
---|
| 369 | // - index : the index of the entry |
---|
| 370 | ///////////////////////////////////////////////////////////////////// |
---|
| 371 | size_t srcid(const size_t index) |
---|
| 372 | { |
---|
| 373 | assert(index<size_tab && "Bad Update Tab Entry"); |
---|
| 374 | return tab[index].srcid; |
---|
| 375 | } |
---|
| 376 | |
---|
| 377 | ///////////////////////////////////////////////////////////////////// |
---|
| 378 | // The count() function returns the count value |
---|
| 379 | // Arguments : |
---|
| 380 | // - index : the index of the entry |
---|
| 381 | ///////////////////////////////////////////////////////////////////// |
---|
| 382 | size_t count(const size_t index) |
---|
| 383 | { |
---|
| 384 | assert(index<size_tab && "Bad Update Tab Entry"); |
---|
| 385 | return tab[index].count; |
---|
| 386 | } |
---|
| 387 | |
---|
| 388 | ///////////////////////////////////////////////////////////////////// |
---|
| 389 | // The trdid() function returns the trdid value |
---|
| 390 | // Arguments : |
---|
| 391 | // - index : the index of the entry |
---|
| 392 | ///////////////////////////////////////////////////////////////////// |
---|
| 393 | size_t trdid(const size_t index) |
---|
| 394 | { |
---|
| 395 | assert(index<size_tab && "Bad Update Tab Entry"); |
---|
| 396 | return tab[index].trdid; |
---|
| 397 | } |
---|
| 398 | |
---|
| 399 | ///////////////////////////////////////////////////////////////////// |
---|
| 400 | // The pktid() function returns the pktid value |
---|
| 401 | // Arguments : |
---|
| 402 | // - index : the index of the entry |
---|
| 403 | ///////////////////////////////////////////////////////////////////// |
---|
| 404 | size_t pktid(const size_t index) |
---|
| 405 | { |
---|
| 406 | assert(index<size_tab && "Bad Update Tab Entry"); |
---|
| 407 | return tab[index].pktid; |
---|
| 408 | } |
---|
| 409 | |
---|
| 410 | ///////////////////////////////////////////////////////////////////// |
---|
| 411 | // The nline() function returns the nline value |
---|
| 412 | // Arguments : |
---|
| 413 | // - index : the index of the entry |
---|
| 414 | ///////////////////////////////////////////////////////////////////// |
---|
| 415 | addr_t nline(const size_t index) |
---|
| 416 | { |
---|
| 417 | assert(index<size_tab && "Bad Update Tab Entry"); |
---|
| 418 | return tab[index].nline; |
---|
| 419 | } |
---|
| 420 | |
---|
| 421 | ///////////////////////////////////////////////////////////////////// |
---|
| 422 | // The search_inval() function returns the index of the entry in UPT |
---|
| 423 | // Arguments : |
---|
| 424 | // - nline : the line number of the entry in the directory |
---|
| 425 | ///////////////////////////////////////////////////////////////////// |
---|
| 426 | bool search_inval(const addr_t nline,size_t &index) |
---|
| 427 | { |
---|
| 428 | size_t i ; |
---|
| 429 | |
---|
| 430 | for (i = 0 ; i < size_tab ; i++) |
---|
| 431 | { |
---|
| 432 | //if ( (tab[i].nline == nline) and tab[i].valid and not tab[i].update ) |
---|
| 433 | if ( (tab[i].nline == nline) and tab[i].valid ) |
---|
| 434 | { |
---|
| 435 | index = i ; |
---|
| 436 | return true; |
---|
| 437 | } |
---|
| 438 | } |
---|
| 439 | return false; |
---|
| 440 | } |
---|
| 441 | |
---|
| 442 | ///////////////////////////////////////////////////////////////////// |
---|
| 443 | // The read_nline() function returns the index of the entry in UPT |
---|
| 444 | // Arguments : |
---|
| 445 | // - nline : the line number of the entry in the directory |
---|
| 446 | ///////////////////////////////////////////////////////////////////// |
---|
| 447 | bool read_nline(const addr_t nline,size_t &index) |
---|
| 448 | { |
---|
| 449 | size_t i ; |
---|
| 450 | |
---|
| 451 | for (i = 0 ; i < size_tab ; i++) |
---|
| 452 | { |
---|
| 453 | if ( (tab[i].nline == nline) and tab[i].valid ) |
---|
| 454 | { |
---|
| 455 | index = i ; |
---|
| 456 | return true; |
---|
| 457 | } |
---|
| 458 | } |
---|
| 459 | return false; |
---|
| 460 | } |
---|
| 461 | |
---|
| 462 | ///////////////////////////////////////////////////////////////////// |
---|
| 463 | // The clear() function erases an entry of the tab |
---|
| 464 | // Arguments : |
---|
| 465 | // - index : the index of the entry |
---|
| 466 | ///////////////////////////////////////////////////////////////////// |
---|
| 467 | void clear(const size_t index) |
---|
| 468 | { |
---|
| 469 | assert(index<size_tab && "Bad Update Tab Entry"); |
---|
| 470 | tab[index].valid=false; |
---|
| 471 | return; |
---|
| 472 | } |
---|
| 473 | |
---|
[677] | 474 | void change(const size_t index) |
---|
| 475 | { |
---|
| 476 | assert(index<size_tab && "Bad Update Tab Entry"); |
---|
[680] | 477 | tab[index].is_changed = true; |
---|
[677] | 478 | } |
---|
| 479 | |
---|
[680] | 480 | bool is_changed(const size_t index) |
---|
[677] | 481 | { |
---|
| 482 | assert(index<size_tab && "Bad Update Tab Entry"); |
---|
[680] | 483 | return tab[index].is_changed; |
---|
[677] | 484 | } |
---|
[680] | 485 | |
---|
| 486 | bool is_read(const size_t index) |
---|
| 487 | { |
---|
| 488 | assert(index<size_tab && "Bad Update Tab Entry"); |
---|
| 489 | return tab[index].type; |
---|
| 490 | } |
---|
[670] | 491 | }; |
---|
| 492 | |
---|
| 493 | #endif |
---|
| 494 | |
---|
| 495 | // Local Variables: |
---|
| 496 | // tab-width: 4 |
---|
| 497 | // c-basic-offset: 4 |
---|
| 498 | // c-file-offsets:((innamespace . 0)(inline-open . 0)) |
---|
| 499 | // indent-tabs-mode: nil |
---|
| 500 | // End: |
---|
| 501 | |
---|
| 502 | // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 |
---|
| 503 | |
---|