Changeset 527 for trunk/lib/generic_llsc_global_table/include
- Timestamp:
- Sep 18, 2013, 1:44:37 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/generic_llsc_global_table/include/generic_llsc_global_table.h
r524 r527 28 28 #define SOCLIB_GENERIC_LLSC_GLOBAL_TABLE_H 29 29 30 #include <systemc>31 #include <arithmetics.h>32 30 #include <cassert> 33 31 #include <cstring> … … 35 33 #include <iostream> 36 34 #include <iomanip> 35 #include <stdint.h> 37 36 38 37 namespace soclib … … 70 69 71 70 uint32_t r_next_key ; // value of the next key 72 sc_dt::sc_uint<nb_slots>r_block_mask ; // mask for the slots blocks73 sc_dt::sc_uint<nb_slots>r_last_counter ; // mask for the slots blocks71 uint64_t r_block_mask ; // mask for the slots blocks 72 uint64_t r_last_counter ; // mask for the slots blocks 74 73 size_t r_write_ptr ; // index of next slot to replace 75 74 size_t r_last_empty ; // index of last empty slot used 76 75 77 uint32_t m_cpt_evic ; // number of eviction in the table 78 uint32_t m_cpt_ll ; // number of ll accesses to the table 79 uint32_t m_cpt_ll_update ; // number of ll accesses to the table that trigger an update TODO check that 80 uint32_t m_cpt_sc ; // number of sc accesses to the table 81 uint32_t m_cpt_sc_success ; // number of sc accesses to the table that are successful 82 uint32_t m_cpt_sw ; // number of sw accesses to the table 76 mutable uint32_t m_cpt_evic ; // number of eviction in the table 77 mutable uint32_t m_cpt_ll ; // number of ll accesses to the table 78 mutable uint32_t m_cpt_ll_update ; // number of ll accesses to the table that trigger an update TODO check that 79 mutable uint32_t m_cpt_sc ; // number of sc accesses to the table 80 mutable uint32_t m_cpt_sc_success ; // number of sc accesses to the table that are successful 81 mutable uint32_t m_cpt_check ; // number of check accesses to the table 82 mutable uint32_t m_cpt_sw ; // number of sw accesses to the table 83 83 84 84 //////////////////////////////////////////////////////////////////////////// … … 121 121 // This is done by updating the value of r_write_ptr 122 122 { 123 sc_dt::sc_uint<nb_slots>new_counter;124 sc_dt::sc_uint<nb_slots>xor_counter;123 uint64_t new_counter; 124 uint64_t xor_counter; 125 125 126 126 new_counter = newCounter(r_block_mask, r_last_counter); … … 129 129 for (size_t i = nb_slots - 1; i >= 0; --i) 130 130 { 131 if(xor_counter [i])131 if(xor_counter & (1 << i)) 132 132 { 133 133 r_write_ptr = i; … … 140 140 141 141 //////////////////////////////////////////////////////////////////////////// 142 inline sc_dt::sc_uint<nb_slots> newCounter(const sc_dt::sc_uint<nb_slots>& mask,143 const sc_dt::sc_uint<nb_slots>& counter)142 inline uint64_t newCounter(const uint64_t& mask, 143 const uint64_t& counter) const 144 144 // This function generates the new counter //TODO comment more 145 145 { 146 //147 146 return ((((~counter) & (counter << 1)) & mask) | (counter + 1)); 148 147 } … … 164 163 { 165 164 case 12: 166 r_block_mask = sc_dt::sc_uint<nb_slots>("0x000");165 r_block_mask = (uint64_t)0x000ULL; 167 166 break; 168 167 case 16 : 169 r_block_mask = sc_dt::sc_uint<nb_slots>("0xA800");168 r_block_mask = (uint64_t)0xA800ULL; 170 169 break; 171 170 case 20 : 172 r_block_mask = sc_dt::sc_uint<nb_slots>("0xD5500");171 r_block_mask = (uint64_t)0xD5500ULL; 173 172 break; 174 173 case 24 : 175 r_block_mask = sc_dt::sc_uint<nb_slots>("0xDB5540");174 r_block_mask = (uint64_t)0xDB5540ULL; 176 175 break; 177 176 case 28 : 178 r_block_mask = sc_dt::sc_uint<nb_slots>("0xEEDAAA0");177 r_block_mask = (uint64_t)0xEEDAAA0ULL; 179 178 break; 180 179 case 32 : 181 r_block_mask = sc_dt::sc_uint<nb_slots>("0xF776D550");180 r_block_mask = (uint64_t)0xF776D550ULL; 182 181 break; 183 182 case 36 : 184 r_block_mask = sc_dt::sc_uint<nb_slots>("0xFBDDDB550");183 r_block_mask = (uint64_t)0xFBDDDB550ULL; 185 184 break; 186 185 case 40 : 187 r_block_mask = sc_dt::sc_uint<nb_slots>("0xFDF7BB6D50");186 r_block_mask = (uint64_t)0xFDF7BB6D50ULL; 188 187 break; 189 188 case 44 : 190 r_block_mask = sc_dt::sc_uint<nb_slots>("0xFEFBDEEDAA8");189 r_block_mask = (uint64_t)0xFEFBDEEDAA8ULL; 191 190 break; 192 191 case 48 : 193 r_block_mask = sc_dt::sc_uint<nb_slots>("0xFF7EFBDDDAA8");192 r_block_mask = (uint64_t)0xFF7EFBDDDAA8ULL; 194 193 break; 195 194 case 52 : 196 r_block_mask = sc_dt::sc_uint<nb_slots>("0xFFBFBF7BBB6A8");195 r_block_mask = (uint64_t)0xFFBFBF7BBB6A8ULL; 197 196 break; 198 197 case 56 : 199 r_block_mask = sc_dt::sc_uint<nb_slots>("0xFFDFEFDF7BB6A8");198 r_block_mask = (uint64_t)0xFFDFEFDF7BB6A8ULL; 200 199 break; 201 200 case 60 : 202 r_block_mask = sc_dt::sc_uint<nb_slots>("0xFFF7FDFDF7BB6A8");201 r_block_mask = (uint64_t)0xFFF7FDFDF7BB6A8ULL; 203 202 break; 204 203 case 64 : 205 r_block_mask = sc_dt::sc_uint<nb_slots>("0xFFFBFF7FBF7BB6A8");204 r_block_mask = (uint64_t)0xFFFBFF7FBF7BB6A8ULL; 206 205 break; 207 206 default: … … 211 210 212 211 //////////////////////////////////////////////////////////////////////////// 213 inline int nextEmptySlot() 212 inline int nextEmptySlot() const 214 213 // This function returns : 215 214 // - the position of the first next empty slot in the table … … 218 217 // - -1 if the table is full 219 218 { 220 size_t i = r_last_empty; 221 do 222 { 223 // checking if current slot is empty 224 if(!r_val[i]) 225 { 226 // updating last empty slot and returning its position 227 r_last_empty = i; 228 return i; 229 } 230 // selecting next slot 231 i = (i+1) % nb_slots; 232 } 233 // stop if all slots have been tested 234 while(i != r_last_empty); 235 236 // the table is full 219 uint64_t i; 220 for(i = 0; i < nb_slots; i++) 221 { 222 if (!r_val[i]) return i; 223 } 224 237 225 return -1; 238 226 } 239 227 240 228 //////////////////////////////////////////////////////////////////////////// 241 inline int hitAddr(const addr_t ad) 229 inline int hitAddr(const addr_t ad) const 242 230 // HIT on the address only 243 231 // This function takes an addr_t ad … … 259 247 260 248 //////////////////////////////////////////////////////////////////////////// 261 inline int hitAddrKey(const addr_t ad, const uint32_t key) 249 inline int hitAddrKey(const addr_t ad, const uint32_t key) const 262 250 // HIT on the address AND the on the signature 263 251 // This function takes an addr_t ad and a uint32_t key … … 291 279 m_cpt_sc = 0; 292 280 m_cpt_sc_success = 0; 281 m_cpt_check = 0; 293 282 m_cpt_sw = 0; 294 283 } … … 301 290 : name(n) 302 291 { 303 #define L2 soclib::common::uint32_log2304 292 assert(nb_procs > 1); 305 assert((int)nb_slots >= L2(nb_procs));306 #undef L2307 293 init(); 308 294 init_block_mask(); … … 362 348 if (pos >= 0) 363 349 { 364 if(r_key[pos] - r_next_key > life_span) 365 return r_key[pos]; 350 uint32_t absdiff = ( r_key[pos] > r_next_key) ? 351 r_key[pos] - r_next_key : 352 r_next_key - r_key[pos]; 353 354 if(absdiff < life_span) return r_key[pos]; 355 366 356 r_key[pos] = r_next_key; 367 357 upNextKey(); 368 358 m_cpt_ll_update++; 359 369 360 return r_key[pos]; 370 361 } … … 377 368 if (pos == -1) 378 369 { 370 // update the victim slot for the next eviction 371 updateVictimSlot(); 372 379 373 // get the position of the evicted registration 380 374 pos = r_write_ptr; 381 // update the victim slot for the next eviction 382 updateVictimSlot(); 375 383 376 // increment the eviction counter (for stats) 384 377 m_cpt_evic++; … … 434 427 435 428 //////////////////////////////////////////////////////////////////////////// 429 inline bool check(const addr_t ad, const uint32_t key) const 430 // This method checks if there is a valid registration for the SC (ad && 431 // key) 432 // The return value can be used to tell if the SC is atomic 433 { 434 // increment the check access counter (for stats) 435 m_cpt_check++; 436 437 return (hitAddrKey(ad, key) >= 0); 438 } 439 440 //////////////////////////////////////////////////////////////////////////// 436 441 /* 437 442 inline void sw(const addr_t ad) … … 489 494 inline void print_trace(std::ostream& out = std::cout) 490 495 { 491 out << " ___________________________________" << std::endl492 << "| " << std::setw(33) << "generic_llsc_global_table" << " |" << std::endl493 << "| " << std::setw(33) << name << " |" << std::endl494 << " ===================================" << std::endl495 << "| "496 << std::setw(11) << "addr" << " | "497 << std::setw(11) << "key" << " | "498 << std::setw(5) << "val"499 << " |" << std::endl500 << " -----------------------------------" << std::endl;501 496 for ( size_t i = 0; i < nb_slots ; i++ ) 502 497 { 503 out << "| " 504 << std::showbase 505 << std::setw(11) << std::setfill('0') << std::hex << r_addr[i] << " | " 498 out << std::setw(3) << std::setfill(' ') << std::dec << i 506 499 << std::noshowbase 507 << std::setw(11) << std::setfill('0') << std::dec << r_key[i] << " | " 508 << std::setw(5) << std::setfill(' ') << std::boolalpha << r_val[i] << " |" << std::endl ; 509 } 510 out << " -----------------------------------" << std::endl 511 << std::noshowbase << std::dec << std::endl ; 500 << " VLD_RX = " << r_val[i] 501 << std::uppercase 502 << " ADR_RX = 0x" << std::setw(8) << std::setfill('0') << std::hex << (r_addr[i] >> 2) 503 << " SGN_RX = 0x" << std::setw(8) << std::setfill('0') << std::hex << r_key[i] 504 << std::endl; 505 } 506 out << "NEXT_SGN_RX = 0x" << std::setw(8) << std::setfill('0') << std::hex << r_next_key << std::endl 507 << "CNT_RX = 0x" << std::setw(8) << std::setfill('0') << std::hex << r_last_counter << std::endl; 512 508 } 513 509
Note: See TracChangeset
for help on using the changeset viewer.