- Timestamp:
- Sep 24, 2014, 3:48:50 PM (10 years ago)
- Location:
- branches/RWT/modules/vci_mem_cache
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/RWT/modules/vci_mem_cache
- Property svn:mergeinfo changed
/trunk/modules/vci_mem_cache (added) merged: 597,599,601,603,605,617
- Property svn:mergeinfo changed
-
branches/RWT/modules/vci_mem_cache/caba/source/include
- Property svn:mergeinfo changed
/trunk/modules/vci_mem_cache/caba/source/include (added) merged: 597,599,601,605
- Property svn:mergeinfo changed
-
branches/RWT/modules/vci_mem_cache/caba/source/include/mem_cache_directory.h
r495 r814 1 1 #ifndef SOCLIB_CABA_MEM_CACHE_DIRECTORY_H 2 #define SOCLIB_CABA_MEM_CACHE_DIRECTORY_H 2 #define SOCLIB_CABA_MEM_CACHE_DIRECTORY_H 3 3 4 4 #include <inttypes.h> … … 14 14 15 15 //////////////////////////////////////////////////////////////////////// 16 // A LRU entry 16 // A LRU entry 17 17 //////////////////////////////////////////////////////////////////////// 18 18 class LruEntry { … … 20 20 public: 21 21 22 bool recent; 22 bool recent; 23 23 24 24 void init() … … 33 33 //////////////////////////////////////////////////////////////////////// 34 34 class Owner{ 35 35 36 36 public: 37 37 // Fields … … 66 66 67 67 //////////////////////////////////////////////////////////////////////// 68 // A directory entry 68 // A directory entry 69 69 //////////////////////////////////////////////////////////////////////// 70 70 class DirectoryEntry { … … 81 81 tag_t tag; // tag of the entry 82 82 size_t count; // number of copies 83 Owner owner; // an owner of the line 83 Owner owner; // an owner of the line 84 84 size_t ptr; // pointer to the next owner 85 85 … … 109 109 owner = source.owner; 110 110 ptr = source.ptr; 111 } 112 113 ///////////////////////////////////////////////////////////////////// 114 // The init() function initializes the entry 111 } 112 113 ///////////////////////////////////////////////////////////////////// 114 // The init() function initializes the entry 115 115 ///////////////////////////////////////////////////////////////////// 116 116 void init() … … 125 125 126 126 ///////////////////////////////////////////////////////////////////// 127 // The copy() function copies an existing source entry to a target 127 // The copy() function copies an existing source entry to a target 128 128 ///////////////////////////////////////////////////////////////////// 129 129 void copy(const DirectoryEntry &source) 130 130 { 131 valid 131 valid = source.valid; 132 132 cache_coherent = source.cache_coherent; 133 133 is_cnt = source.is_cnt; 134 dirty 135 lock 136 tag 134 dirty = source.dirty; 135 lock = source.lock; 136 tag = source.tag; 137 137 count = source.count; 138 138 owner = source.owner; … … 141 141 142 142 //////////////////////////////////////////////////////////////////// 143 // The print() function prints the entry 143 // The print() function prints the entry 144 144 //////////////////////////////////////////////////////////////////// 145 145 void print() 146 146 { 147 std::cout << "Valid = " << valid 147 std::cout << "Valid = " << valid 148 148 << " ; COHERENCE = " << cache_coherent 149 << " ; IS COUNT = " << is_cnt 150 << " ; Dirty = " << dirty 151 << " ; Lock = " << lock 152 << " ; Tag = " << std::hex << tag << std::dec 153 << " ; Count = " << count 154 << " ; Owner = " << owner.srcid 155 << " " << owner.inst 149 << " ; IS COUNT = " << is_cnt 150 << " ; Dirty = " << dirty 151 << " ; Lock = " << lock 152 << " ; Tag = " << std::hex << tag << std::dec 153 << " ; Count = " << count 154 << " ; Owner = " << owner.srcid 155 << " " << owner.inst 156 156 << " ; Pointer = " << ptr << std::endl; 157 157 } … … 160 160 161 161 //////////////////////////////////////////////////////////////////////// 162 // The directory 162 // The directory 163 163 //////////////////////////////////////////////////////////////////////// 164 164 class CacheDirectory { … … 171 171 172 172 // Directory constants 173 size_t 174 size_t 175 size_t 176 size_t 177 uint32_t 173 size_t m_ways; 174 size_t m_sets; 175 size_t m_words; 176 size_t m_width; 177 uint32_t lfsr; 178 178 179 179 // the directory & lru tables 180 DirectoryEntry 181 LruEntry 180 DirectoryEntry **m_dir_tab; 181 LruEntry **m_lru_tab; 182 182 183 183 public: … … 186 186 // Constructor 187 187 //////////////////////// 188 CacheDirectory( size_t ways, size_t sets, size_t words, size_t address_width) 189 { 190 m_ways = ways; 188 CacheDirectory( size_t ways, size_t sets, size_t words, size_t address_width) 189 { 190 m_ways = ways; 191 191 m_sets = sets; 192 192 m_words = words; … … 223 223 // LRU is updated. 224 224 // Arguments : 225 // - address : the address of the entry 225 // - address : the address of the entry 226 226 // - way : (return argument) the way of the entry in case of hit 227 // The function returns a copy of a (valid or invalid) entry 227 // The function returns a copy of a (valid or invalid) entry 228 228 ///////////////////////////////////////////////////////////////////// 229 229 DirectoryEntry read(const addr_t &address, size_t &way) … … 240 240 bool valid = m_dir_tab[set][i].valid; 241 241 hit = equal && valid; 242 if ( hit ) { 242 if ( hit ) { 243 243 way = i; 244 244 break; 245 } 245 } 246 246 } 247 247 if ( hit ) { … … 255 255 ///////////////////////////////////////////////////////////////////// 256 256 // The inval function invalidate an entry defined by the set and 257 // way arguments. 257 // way arguments. 258 258 ///////////////////////////////////////////////////////////////////// 259 259 void inval( const size_t &way, const size_t &set ) … … 266 266 // changing the LRU 267 267 // Arguments : 268 // - address : the address of the entry 269 // The function returns a copy of a (valid or invalid) entry 270 ///////////////////////////////////////////////////////////////////// 271 DirectoryEntry read_neutral( const addr_t &address, 268 // - address : the address of the entry 269 // The function returns a copy of a (valid or invalid) entry 270 ///////////////////////////////////////////////////////////////////// 271 DirectoryEntry read_neutral( const addr_t &address, 272 272 size_t* ret_way, 273 273 size_t* ret_set ) … … 279 279 #undef L2 280 280 281 for ( size_t way = 0 ; way < m_ways ; way++ ) 281 for ( size_t way = 0 ; way < m_ways ; way++ ) 282 282 { 283 283 bool equal = ( m_dir_tab[set][way].tag == tag ); … … 286 286 { 287 287 *ret_set = set; 288 *ret_way = way; 288 *ret_way = way; 289 289 return DirectoryEntry(m_dir_tab[set][way]); 290 290 } 291 } 291 } 292 292 return DirectoryEntry(); 293 293 } // end read_neutral() 294 294 295 295 ///////////////////////////////////////////////////////////////////// 296 // The write function writes a new entry, 296 // The write function writes a new entry, 297 297 // and updates the LRU bits if necessary. 298 298 // Arguments : … … 301 301 // - entry : the entry value 302 302 ///////////////////////////////////////////////////////////////////// 303 void write( const size_t &set, 304 const size_t &way, 303 void write( const size_t &set, 304 const size_t &way, 305 305 const DirectoryEntry &entry) 306 306 { 307 assert( (set<m_sets) 307 assert( (set<m_sets) 308 308 && "Cache Directory write : The set index is invalid"); 309 assert( (way<m_ways) 309 assert( (way<m_ways) 310 310 && "Cache Directory write : The way index is invalid"); 311 311 … … 315 315 // update LRU bits 316 316 bool all_recent = true; 317 for ( size_t i=0 ; i<m_ways ; i++ ) 317 for ( size_t i=0 ; i<m_ways ; i++ ) 318 318 { 319 319 if ( i != way ) all_recent = m_lru_tab[set][i].recent && all_recent; 320 320 } 321 if ( all_recent ) 321 if ( all_recent ) 322 322 { 323 323 for( size_t i=0 ; i<m_ways ; i++ ) m_lru_tab[set][i].recent = false; 324 } 325 else 324 } 325 else 326 326 { 327 327 m_lru_tab[set][way].recent = true; … … 349 349 DirectoryEntry select(const size_t &set, size_t &way) 350 350 { 351 assert( (set < m_sets) 351 assert( (set < m_sets) 352 352 && "Cache Directory : (select) The set index is invalid"); 353 353 … … 404 404 405 405 ///////////////////////////////////////////////////////////////////// 406 // 406 // Global initialisation function 407 407 ///////////////////////////////////////////////////////////////////// 408 408 void init() 409 409 { 410 for ( size_t set=0 ; set<m_sets ; set++ ) 411 { 412 for ( size_t way=0 ; way<m_ways ; way++ ) 410 for ( size_t set=0 ; set<m_sets ; set++ ) 411 { 412 for ( size_t way=0 ; way<m_ways ; way++ ) 413 413 { 414 414 m_dir_tab[set][way].init(); … … 446 446 owner.inst = entry.owner.inst; 447 447 owner.srcid = entry.owner.srcid; 448 next 448 next = entry.next; 449 449 } // end constructor 450 450 451 451 ///////////////////////////////////////////////////////////////////// 452 // The copy() function copies an existing source entry to a target 452 // The copy() function copies an existing source entry to a target 453 453 ///////////////////////////////////////////////////////////////////// 454 454 void copy(const HeapEntry &entry) 455 455 { 456 owner.inst 457 owner.srcid 458 next 456 owner.inst = entry.owner.inst; 457 owner.srcid = entry.owner.srcid; 458 next = entry.next; 459 459 } // end copy() 460 460 461 461 //////////////////////////////////////////////////////////////////// 462 // The print() function prints the entry 462 // The print() function prints the entry 463 463 //////////////////////////////////////////////////////////////////// 464 464 void print(){ 465 std::cout 465 std::cout 466 466 << " -- owner.inst : " << std::dec << owner.inst << std::endl 467 467 << " -- owner.srcid : " << std::dec << owner.srcid << std::endl … … 473 473 474 474 //////////////////////////////////////////////////////////////////////// 475 // The Heap 475 // The Heap 476 476 //////////////////////////////////////////////////////////////////////// 477 477 class HeapDirectory{ 478 478 479 479 private: 480 480 // Registers and the heap … … 506 506 507 507 ///////////////////////////////////////////////////////////////////// 508 // 508 // Global initialisation function 509 509 ///////////////////////////////////////////////////////////////////// 510 510 void init(){ … … 541 541 if(ptr_temp == m_heap_tab[ptr_temp].next) end = true; 542 542 ptr_temp = m_heap_tab[ptr_temp].next; 543 } 543 } 544 544 } // end print_list() 545 545 … … 552 552 553 553 ///////////////////////////////////////////////////////////////////// 554 // The next_free_ptr() function returns the pointer 554 // The next_free_ptr() function returns the pointer 555 555 // to the next free entry. 556 556 ///////////////////////////////////////////////////////////////////// … … 560 560 561 561 ///////////////////////////////////////////////////////////////////// 562 // The next_free_entry() function returns 562 // The next_free_entry() function returns 563 563 // a copy of the next free entry. 564 564 ///////////////////////////////////////////////////////////////////// … … 566 566 return HeapEntry(m_heap_tab[ptr_free]); 567 567 } // end next_free_entry() 568 568 569 569 ///////////////////////////////////////////////////////////////////// 570 570 // The write_free_entry() function modify the next free entry. … … 624 624 625 625 //////////////////////////////////////////////////////////////////////// 626 // Cache Data 627 //////////////////////////////////////////////////////////////////////// 628 class CacheData 626 // Cache Data 627 //////////////////////////////////////////////////////////////////////// 628 class CacheData 629 629 { 630 630 private: … … 639 639 /////////////////////////////////////////////////////// 640 640 CacheData(uint32_t ways, uint32_t sets, uint32_t words) 641 : m_sets(sets), m_ways(ways), m_words(words) 641 : m_sets(sets), m_ways(ways), m_words(words) 642 642 { 643 643 m_cache_data = new uint32_t ** [ways]; 644 for ( size_t i=0 ; i < ways ; i++ ) 644 for ( size_t i=0 ; i < ways ; i++ ) 645 645 { 646 646 m_cache_data[i] = new uint32_t * [sets]; 647 647 } 648 for ( size_t i=0; i<ways; i++ ) 648 for ( size_t i=0; i<ways; i++ ) 649 649 { 650 for ( size_t j=0; j<sets; j++ ) 650 for ( size_t j=0; j<sets; j++ ) 651 651 { 652 652 m_cache_data[i][j] = new uint32_t [words]; … … 655 655 } 656 656 //////////// 657 ~CacheData() 657 ~CacheData() 658 658 { 659 659 for(size_t i=0; i<m_ways ; i++) … … 673 673 uint32_t read ( const uint32_t &way, 674 674 const uint32_t &set, 675 const uint32_t &word) const 675 const uint32_t &word) const 676 676 { 677 677 assert((set < m_sets ) && "Cache data error: Trying to read a wrong set" ); … … 697 697 const uint32_t &word, 698 698 const uint32_t &data, 699 const uint32_t &be = 0xF) 699 const uint32_t &be = 0xF) 700 700 { 701 701 … … 707 707 if (be == 0x0) return; 708 708 709 if (be == 0xF) 709 if (be == 0xF) 710 710 { 711 m_cache_data[way][set][word] = data; 711 m_cache_data[way][set][word] = data; 712 712 return; 713 713 } … … 719 719 if (be & 0x8) mask = mask | 0xFF000000; 720 720 721 m_cache_data[way][set][word] = 721 m_cache_data[way][set][word] = 722 722 (data & mask) | (m_cache_data[way][set][word] & ~mask); 723 723 }
Note: See TracChangeset
for help on using the changeset viewer.