Changeset 289
- Timestamp:
- Jan 20, 2013, 7:09:37 PM (12 years ago)
- Location:
- trunk/modules/vci_mem_cache_v4/caba/source
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/modules/vci_mem_cache_v4/caba/source/include/mem_cache_directory_v4.h
r284 r289 620 620 }; // end class HeapDirectory 621 621 622 //////////////////////////////////////////////////////////////////////// 623 // Cache Data 624 //////////////////////////////////////////////////////////////////////// 625 class CacheData { 626 private: 627 const uint32_t m_sets; 628 const uint32_t m_ways; 629 const uint32_t m_words; 630 631 uint32_t *** m_cache_data; 632 633 public: 634 635 CacheData(uint32_t ways, uint32_t sets, uint32_t words) 636 : m_sets(sets), m_ways(ways), m_words(words) { 637 638 m_cache_data = new uint32_t ** [ways]; 639 for ( size_t i=0 ; i < ways ; i++ ) { 640 m_cache_data[i] = new uint32_t * [sets]; 641 } 642 for ( size_t i=0; i<ways; i++ ) { 643 for ( size_t j=0; j<sets; j++ ) { 644 m_cache_data[i][j] = new uint32_t [words]; 645 } 646 } 647 } 648 649 ~CacheData() { 650 for(size_t i=0; i<m_ways ; i++){ 651 for(size_t j=0; j<m_sets ; j++){ 652 delete [] m_cache_data[i][j]; 653 } 654 } 655 for(size_t i=0; i<m_ways ; i++){ 656 delete [] m_cache_data[i]; 657 } 658 delete [] m_cache_data; 659 } 660 661 uint32_t read ( 662 const uint32_t &way, 663 const uint32_t &set, 664 const uint32_t &word) const { 665 666 assert((set < m_sets ) && "Cache data error: Trying to read a wrong set" ); 667 assert((way < m_ways ) && "Cache data error: Trying to read a wrong way" ); 668 assert((word < m_words) && "Cache data error: Trying to read a wrong word"); 669 670 return m_cache_data[way][set][word]; 671 } 672 673 void read_line( 674 const uint32_t &way, 675 const uint32_t &set, 676 sc_core::sc_signal<uint32_t> * cache_line) 677 { 678 assert((set < m_sets ) && "Cache data error: Trying to read a wrong set" ); 679 assert((way < m_ways ) && "Cache data error: Trying to read a wrong way" ); 680 681 for (uint32_t word=0; word<m_words; word++) 682 cache_line[word].write(m_cache_data[way][set][word]); 683 } 684 685 void write ( 686 const uint32_t &way, 687 const uint32_t &set, 688 const uint32_t &word, 689 const uint32_t &data, 690 const uint32_t &be = 0xF) { 691 692 assert((set < m_sets ) && "Cache data error: Trying to write a wrong set" ); 693 assert((way < m_ways ) && "Cache data error: Trying to write a wrong way" ); 694 assert((word < m_words) && "Cache data error: Trying to write a wrong word"); 695 assert((be <= 0xF ) && "Cache data error: Trying to write a wrong word cell"); 696 697 if (be == 0x0) return; 698 699 if (be == 0xF) { 700 m_cache_data[way][set][word] = data; 701 return; 702 } 703 704 uint32_t mask = 0; 705 if (be & 0x1) mask = mask | 0x000000FF; 706 if (be & 0x2) mask = mask | 0x0000FF00; 707 if (be & 0x4) mask = mask | 0x00FF0000; 708 if (be & 0x8) mask = mask | 0xFF000000; 709 710 m_cache_data[way][set][word] = 711 (data & mask) | (m_cache_data[way][set][word] & ~mask); 712 } 713 }; // end class CacheData 622 714 623 715 }} // end namespaces -
trunk/modules/vci_mem_cache_v4/caba/source/include/vci_mem_cache_v4.h
r284 r289 420 420 UpdateTab m_update_tab; // pending update & invalidate 421 421 CacheDirectory m_cache_directory; // data cache directory 422 CacheData m_cache_data; // data array[set][way][word] 422 423 HeapDirectory m_heap; // heap for copies 423 424 data_t *** m_cache_data; // data array[set][way][word]425 424 426 425 // adress masks -
trunk/modules/vci_mem_cache_v4/caba/source/src/vci_mem_cache_v4.cpp
r284 r289 276 276 p_vci_ixr("vci_ixr"), 277 277 278 m_seglist(mtp.getSegmentList(vci_tgt_index)), 279 m_cseglist(mtc.getSegmentList(vci_tgt_index_cleanup)), 280 278 281 m_initiators( 1 << vci_param::S ), 279 282 m_heap_size( heap_size ), … … 283 286 m_srcid_ixr( mtx.indexForId(vci_ixr_index) ), 284 287 m_srcid_ini( mtc.indexForId(vci_ini_index) ), 285 m_seglist(mtp.getSegmentList(vci_tgt_index)),286 m_cseglist(mtc.getSegmentList(vci_tgt_index_cleanup)),287 288 m_transaction_tab_lines(transaction_tab_lines), 288 289 m_transaction_tab( transaction_tab_lines, nwords ), … … 290 291 m_update_tab( update_tab_lines ), 291 292 m_cache_directory( nways, nsets, nwords, vci_param::N ), 293 m_cache_data( nways, nsets, nwords ), 292 294 m_heap( m_heap_size ), 293 295 … … 409 411 m_cseg[i] = &(*seg); 410 412 i++; 411 }412 413 // Memory cache allocation & initialisation414 m_cache_data = new data_t**[nways];415 for ( size_t i=0 ; i<nways ; ++i ) {416 m_cache_data[i] = new data_t*[nsets];417 }418 for ( size_t i=0; i<nways; ++i ) {419 for ( size_t j=0; j<nsets; ++j ) {420 m_cache_data[i][j] = new data_t[nwords];421 for ( size_t k=0; k<nwords; k++){422 m_cache_data[i][j][k]=0;423 }424 }425 413 } 426 414 … … 558 546 ///////////////////////////////// 559 547 { 560 for(size_t i=0; i<m_ways ; i++){561 for(size_t j=0; j<m_sets ; j++){562 delete [] m_cache_data[i][j];563 }564 }565 for(size_t i=0; i<m_ways ; i++){566 delete [] m_cache_data[i];567 }568 delete [] m_cache_data;569 570 548 delete [] r_ixr_rsp_to_xram_rsp_rok; 571 549 … … 1318 1296 size_t set = m_y[(vci_addr_t)(m_cmd_read_addr_fifo.read())]; 1319 1297 size_t way = r_read_way.read(); 1320 for ( size_t i=0 ; i<m_words ; i++ ) r_read_data[i] = m_cache_data[way][set][i]; 1298 1299 m_cache_data.read_line(way, set, r_read_data); 1321 1300 1322 1301 // update the cache directory … … 1412 1391 size_t set = m_y[(vci_addr_t)(m_cmd_read_addr_fifo.read())]; 1413 1392 size_t way = r_read_way.read(); 1414 for ( size_t i=0 ; i<m_words ; i++ ) r_read_data[i] = m_cache_data[way][set][i]; 1393 1394 m_cache_data.read_line(way, set, r_read_data); 1415 1395 1416 1396 // update the cache directory … … 1789 1769 1790 1770 // initialize the be field for all words 1791 for ( size_t i=0 ; i<m_words ; i++ ) 1792 { 1793 if ( i == index ) r_write_be[i] = m_cmd_write_be_fifo.read(); 1794 else r_write_be[i] = 0x0; 1795 } 1796 1797 if( !((m_cmd_write_be_fifo.read() == 0x0)||(m_cmd_write_be_fifo.read() == 0xF)) ) 1798 r_write_byte = true; 1799 else 1800 r_write_byte = false; 1771 for ( size_t word=0 ; word<m_words ; word++ ) 1772 { 1773 if ( word == index ) r_write_be[word] = m_cmd_write_be_fifo.read(); 1774 else r_write_be[word] = 0x0; 1775 } 1801 1776 1802 1777 if( m_cmd_write_eop_fifo.read() ) … … 1854 1829 r_write_data[index] = m_cmd_write_data_fifo.read(); 1855 1830 r_write_word_count = r_write_word_count.read() + 1; 1856 1857 if( !((m_cmd_write_be_fifo.read() == 0x0)||(m_cmd_write_be_fifo.read() == 0xF)) )1858 r_write_byte = true;1859 1831 1860 1832 if ( m_cmd_write_eop_fifo.read() ) … … 1917 1889 else 1918 1890 { 1919 if (r_write_byte.read()) 1920 { 1921 r_write_fsm = WRITE_DIR_READ; 1922 } 1923 else 1924 { 1925 r_write_fsm = WRITE_DIR_HIT; 1926 } 1891 r_write_fsm = WRITE_DIR_HIT; 1927 1892 } 1928 1893 } … … 1961 1926 size_t set = m_y[(vci_addr_t)(r_write_address.read())]; 1962 1927 size_t way = r_write_way.read(); 1963 for(size_t i=0 ; i<m_words ; i++)1928 for(size_t word=0 ; word<m_words ; word++) 1964 1929 { 1965 1930 data_t mask = 0; 1966 if (r_write_be[ i].read() & 0x1) mask = mask | 0x000000FF;1967 if (r_write_be[ i].read() & 0x2) mask = mask | 0x0000FF00;1968 if (r_write_be[ i].read() & 0x4) mask = mask | 0x00FF0000;1969 if (r_write_be[ i].read() & 0x8) mask = mask | 0xFF000000;1931 if (r_write_be[word].read() & 0x1) mask = mask | 0x000000FF; 1932 if (r_write_be[word].read() & 0x2) mask = mask | 0x0000FF00; 1933 if (r_write_be[word].read() & 0x4) mask = mask | 0x00FF0000; 1934 if (r_write_be[word].read() & 0x8) mask = mask | 0xFF000000; 1970 1935 1971 1936 // complete only if mask is not null (for energy consumption) 1972 if ( r_write_be[i].read() || r_write_is_cnt.read() ) 1973 { 1974 r_write_data[i] = (r_write_data[i].read() & mask) | 1975 (m_cache_data[way][set][i] & ~mask); 1976 } 1937 r_write_data[word] = (r_write_data[word].read() & mask) | 1938 (m_cache_data.read(way, set, word) & ~mask); 1939 1977 1940 } // end for 1978 1941 1979 1942 // test if a coherence broadcast is required 1980 if( r_write_is_cnt.read() && r_write_count.read() ) 1981 { 1982 r_write_fsm = WRITE_BC_TRT_LOCK; 1983 } 1984 else 1985 { 1986 r_write_fsm = WRITE_DIR_HIT; 1987 } 1943 r_write_fsm = WRITE_BC_TRT_LOCK; 1988 1944 1989 1945 #if DEBUG_MEMC_WRITE … … 2034 1990 if( no_update ) 2035 1991 { 2036 for(size_t i=0 ; i<m_words ; i++) 2037 { 2038 if ( r_write_be[i].read() ) 1992 for(size_t word=0 ; word<m_words ; word++) 1993 { 1994 m_cache_data.write(way, set, word, r_write_data[word].read(), r_write_be[word].read()); 1995 1996 if ( m_monitor_ok ) 2039 1997 { 2040 m_cache_data[way][set][i] = r_write_data[i].read(); 2041 2042 if ( m_monitor_ok ) 2043 { 2044 vci_addr_t address = (r_write_address.read() & ~(vci_addr_t)0x3F) | i<<2; 2045 char buf[80]; 2046 snprintf(buf, 80, "WRITE_DIR_HIT srcid %d", r_write_srcid.read()); 2047 check_monitor( buf, address, r_write_data[i].read() ); 2048 } 1998 vci_addr_t address = (r_write_address.read() & ~(vci_addr_t)0x3F) | word<<2; 1999 char buf[80]; 2000 snprintf(buf, 80, "WRITE_DIR_HIT srcid %d", r_write_srcid.read()); 2001 check_monitor( buf, address, r_write_data[word].read() ); 2049 2002 } 2050 2003 } … … 2122 2075 if ( wok ) // write data in cache 2123 2076 { 2124 for(size_t i=0 ; i<m_words ; i++)2077 for(size_t word=0 ; word<m_words ; word++) 2125 2078 { 2126 if ( r_write_be[i].read() ) 2127 { 2128 m_cache_data[way][set][i] = r_write_data[i].read(); 2129 2130 if ( m_monitor_ok ) 2131 { 2132 vci_addr_t address = (r_write_address.read() & ~(vci_addr_t)0x3F) | i<<2; 2133 char buf[80]; 2134 snprintf(buf, 80, "WRITE_UPT_LOCK srcid %d", srcid); 2135 check_monitor(buf, address, r_write_data[i].read() ); 2136 } 2079 m_cache_data.write(way, set, word, r_write_data[word].read(), r_write_be[word].read()); 2080 2081 if ( m_monitor_ok ) 2082 { 2083 vci_addr_t address = (r_write_address.read() & ~(vci_addr_t)0x3F) | word<<2; 2084 char buf[80]; 2085 snprintf(buf, 80, "WRITE_UPT_LOCK srcid %d", srcid); 2086 check_monitor(buf, address, r_write_data[word].read() ); 2137 2087 } 2138 2088 } … … 2373 2323 2374 2324 // initialize the be field for all words 2375 for ( size_t i=0 ; i<m_words ; i++ )2325 for ( size_t word=0 ; word<m_words ; word++ ) 2376 2326 { 2377 if ( i == index ) r_write_be[i] = m_cmd_write_be_fifo.read();2378 else r_write_be[i] = 0x0;2327 if ( word == index ) r_write_be[word] = m_cmd_write_be_fifo.read(); 2328 else r_write_be[word] = 0x0; 2379 2329 } 2380 2381 if( !((m_cmd_write_be_fifo.read() == 0x0)||(m_cmd_write_be_fifo.read() == 0xF)) )2382 r_write_byte = true;2383 else2384 r_write_byte = false;2385 2330 2386 2331 if( m_cmd_write_eop_fifo.read() ) … … 2428 2373 } 2429 2374 #endif 2430 size_t 2431 size_t 2432 vci_addr_t addr 2375 size_t hit_index = 0; 2376 size_t wok_index = 0; 2377 vci_addr_t addr = (vci_addr_t)r_write_address.read(); 2433 2378 bool hit_read = m_transaction_tab.hit_read(m_nline[addr], hit_index); 2434 2379 bool hit_write = m_transaction_tab.hit_write(m_nline[addr]); … … 3112 3057 3113 3058 // copy the victim line in a local buffer 3114 for (size_t i=0 ; i<m_words ; i++) 3115 r_xram_rsp_victim_data[i] = m_cache_data[way][set][i]; 3059 m_cache_data.read_line(way, set, r_xram_rsp_victim_data); 3116 3060 3117 3061 r_xram_rsp_victim_copy = victim.owner.srcid; … … 3228 3172 size_t set = r_xram_rsp_victim_set.read(); 3229 3173 size_t way = r_xram_rsp_victim_way.read(); 3230 for(size_t i=0; i<m_words ; i++)3231 { 3232 m_cache_data [way][set][i] = r_xram_rsp_trt_buf.wdata[i];3174 for(size_t word=0; word<m_words ; word++) 3175 { 3176 m_cache_data.write(way, set, word, r_xram_rsp_trt_buf.wdata[word]); 3233 3177 3234 3178 if ( m_monitor_ok ) 3235 3179 { 3236 vci_addr_t address = r_xram_rsp_trt_buf.nline<<6 | i<<2;3237 check_monitor("XRAM_RSP_DIR_UPDT", address, r_xram_rsp_trt_buf.wdata[ i]);3180 vci_addr_t address = r_xram_rsp_trt_buf.nline<<6 | word<<2; 3181 check_monitor("XRAM_RSP_DIR_UPDT", address, r_xram_rsp_trt_buf.wdata[word]); 3238 3182 } 3239 3183 } … … 4413 4357 4414 4358 // read data in cache & check data change 4415 bool ok = ( r_cas_rdata[0].read() == m_cache_data [way][set][word]);4359 bool ok = ( r_cas_rdata[0].read() == m_cache_data.read(way, set, word) ); 4416 4360 if ( r_cas_cpt.read()==4 ) // 64 bits CAS 4417 ok &= ( r_cas_rdata[1] == m_cache_data [way][set][word+1]);4361 ok &= ( r_cas_rdata[1] == m_cache_data.read(way, set, word+1)); 4418 4362 4419 4363 // to avoid livelock, force the atomic access to fail pseudo-randomly … … 4435 4379 std::cout << " <MEMC " << name() << ".CAS_DIR_HIT_READ> Test if CAS success:" 4436 4380 << " / expected value = " << r_cas_rdata[0].read() 4437 << " / actual value = " << m_cache_data [way][set][word]4381 << " / actual value = " << m_cache_data.read(way, set, word) 4438 4382 << " / forced_fail = " << forced_fail << std::endl; 4439 4383 } … … 4469 4413 4470 4414 // cache update 4471 m_cache_data [way][set][word] = r_cas_wdata.read();4415 m_cache_data.write(way, set, word, r_cas_wdata.read()); 4472 4416 if(r_cas_cpt.read()==4) 4473 m_cache_data [way][set][word+1] = m_cmd_cas_wdata_fifo.read();4417 m_cache_data.write(way, set, word+1, m_cmd_cas_wdata_fifo.read()); 4474 4418 4475 4419 // monitor … … 4530 4474 size_t word = m_x[(vci_addr_t)(m_cmd_cas_addr_fifo.read())]; 4531 4475 4532 m_cache_data [way][set][word] = r_cas_wdata.read();4476 m_cache_data.write(way, set, word, r_cas_wdata.read()); 4533 4477 if(r_cas_cpt.read()==4) 4534 m_cache_data [way][set][word+1] = m_cmd_cas_wdata_fifo.read();4478 m_cache_data.write(way, set, word+1, m_cmd_cas_wdata_fifo.read()); 4535 4479 4536 4480 // monitor … … 4714 4658 else 4715 4659 { 4716 r_cas_to_ixr_cmd_data[i] = m_cache_data [way][set][i];4660 r_cas_to_ixr_cmd_data[i] = m_cache_data.read(way, set, i); 4717 4661 } 4718 4662 } … … 4768 4712 size_t word = m_x[(vci_addr_t)(m_cmd_cas_addr_fifo.read())]; 4769 4713 4770 m_cache_data [way][set][word] = r_cas_wdata.read();4714 m_cache_data.write(way, set, word, r_cas_wdata.read()); 4771 4715 if(r_cas_cpt.read()==4) 4772 m_cache_data [way][set][word+1] = m_cmd_cas_wdata_fifo.read();4716 m_cache_data.write(way, set, word+1, m_cmd_cas_wdata_fifo.read()); 4773 4717 4774 4718 // monitor
Note: See TracChangeset
for help on using the changeset viewer.