// Trigger All Bricks void block_exec(t_block *block) { t_link *link; t_brick *brick; // Reset State block_reset(block); // Trigger for(link=block->bricks->first;link;link=link->next) { brick = link->data; if( !brick->brick_state.hold) { brick->exe( brick); if( brick->brick_state.singular && brick->brick_state.use_hold) { brick->brick_state.hold = 1; } } } }
cache_block * hknuca_replacement(cache_bank *bank,int address,int tag,int data,int p){ int i,l = 0,c,setnum,count = 0; cache_block *localblock = NULL,*centralblock = NULL; set *homecacheset = NULL,*replcacheset = NULL,*rereplcacheset = NULL; int localclustnum,centralclustnum,rerepl = 0; int row1,row2,col1,col2; int banknum = bank->banknum; if(p < cores / 2){ row1 = 0; col1 = p; } else{ row1 = 3; col1 = p - (cores / 2); } row2 = banknum / 4; col2 = banknum % 4; setnum = address % nsets; homecacheset = home_cacheset(address); localclustnum = bank->clustnum; l = lrublock(cgrid1.grid[row1][col1]->cachebank[row2][col2]->sets[setnum]); while(l == -1) l = lrublock(cgrid1.grid[row1][col1]->cachebank[row2][col2]->sets[setnum]); localblock = cgrid1.grid[row1][col1]->cachebank[row2][col2]->sets[setnum]->ways[l]; replcacheset = home_cacheset(localblock->address); if(row1 == 0) { centralclustnum = cgrid1.grid[row1+1][col1]->cachebank[row2][col2]->clustnum; for(i = 0;i < bassoc;i++) { centralblock = cgrid1.grid[row1+1][col1]->cachebank[row2][col2]->sets[setnum]->ways[i]; if(centralblock->data == 0){ c = i; break; } else count++; } if(count == bassoc){ c = lrublock(cgrid1.grid[row1+1][col1]->cachebank[row2][col2]->sets[setnum]); rerepl = 1; (coreprop1[p].nrepl)++;; // write back the existing central block } centralblock = cgrid1.grid[row1+1][col1]->cachebank[row2][col2]->sets[setnum]->ways[c]; if(rerepl){ rereplcacheset = home_cacheset(centralblock->address); (rereplcacheset->hk_nuka[centralclustnum])--; } (replcacheset->hk_nuka[localclustnum])--; (replcacheset->hk_nuka[centralclustnum])++; block_par_assign(centralblock,localblock->data,localblock->address,localblock->tag,localblock->last_accessed,localblock->naccesses); (coreprop1[p].nrepl)++; (homecacheset->hk_nuka[localclustnum])++; block_par_assign(localblock,data,address,tag,time(NULL),1); } else if(row1 == 3) { centralclustnum = cgrid1.grid[row1-1][col1]->cachebank[row2][col2]->clustnum; for(i = 0;i < bassoc;i++) { centralblock = cgrid1.grid[row1-1][col1]->cachebank[row2][col2]->sets[setnum]->ways[i]; if(centralblock->data == 0){ c = i; break; } else count++; } if(count == bassoc){ c = lrublock(cgrid1.grid[row1-1][col1]->cachebank[row2][col2]->sets[setnum]); rerepl = 1; (coreprop1[p].nrepl)++; // write back the existing central block } centralblock = cgrid1.grid[row1-1][col1]->cachebank[row2][col2]->sets[setnum]->ways[c]; if(rerepl){ rereplcacheset = home_cacheset(centralblock->address); (rereplcacheset->hk_nuka[centralclustnum])--; } (replcacheset->hk_nuka[localclustnum])--; (replcacheset->hk_nuka[centralclustnum])++; block_par_assign(centralblock,localblock->data,localblock->address,localblock->tag,localblock->last_accessed,localblock->naccesses); (coreprop1[p].nrepl)++; (homecacheset->hk_nuka[localclustnum])++; block_par_assign(localblock,data,address,tag,time(NULL),1); } else { // write back to main memory (replcacheset->hk_nuka[localclustnum])--; block_reset(localblock); (coreprop1[p].nrepl)++; (homecacheset->hk_nuka[localclustnum])++; block_par_assign(localblock,data,address,tag,time(NULL),1); } return localblock; }
cache_block * cacheblock_replacement(cache_bank *bank,int address,int tag,int data,int p){ int i,l = 0,c,setnum,count = 0; cache_block *localblock = NULL,*centralblock = NULL; int row1,row2,col1,col2; int banknum = (address / nsets) % nbankscluster; if(p < cores / 2){ row1 = 0; col1 = p; } else{ row1 = 3; col1 = p - (cores / 2); } row2 = banknum / 4; col2 = banknum % 4; setnum = address % nsets; l = lrublock(cgrid.grid[row1][col1]->cachebank[row2][col2]->sets[setnum]); while(l == -1) l = lrublock(cgrid.grid[row1][col1]->cachebank[row2][col2]->sets[setnum]); localblock = cgrid.grid[row1][col1]->cachebank[row2][col2]->sets[setnum]->ways[l]; if(row1 == 0) { for(i = 0;i < bassoc;i++) { centralblock = cgrid.grid[row1+1][col1]->cachebank[row2][col2]->sets[setnum]->ways[i]; if(centralblock->data == 0){ c = i; break; } else count++; } if(count == bassoc){ c = lrublock(cgrid.grid[row1+1][col1]->cachebank[row2][col2]->sets[setnum]); (coreprop0[p].nrepl)++;; // write back the existing central block } centralblock = cgrid.grid[row1+1][col1]->cachebank[row2][col2]->sets[setnum]->ways[c]; block_par_assign(centralblock,localblock->data,localblock->address,localblock->tag,localblock->last_accessed,localblock->naccesses); (coreprop0[p].nrepl)++; block_par_assign(localblock,data,address,tag,time(NULL),1); } else if(row1 == 3) { for(i = 0;i < bassoc;i++) { centralblock = cgrid.grid[row1-1][col1]->cachebank[row2][col2]->sets[setnum]->ways[i]; if(centralblock->data == 0){ c = i; break; } else count++; } if(count == bassoc){ c = lrublock(cgrid.grid[row1-1][col1]->cachebank[row2][col2]->sets[setnum]); (coreprop0[p].nrepl)++; // write back the existing central block } centralblock = cgrid.grid[row1-1][col1]->cachebank[row2][col2]->sets[setnum]->ways[c]; block_par_assign(centralblock,localblock->data,localblock->address,localblock->tag,localblock->last_accessed,localblock->naccesses); (coreprop0[p].nrepl)++; block_par_assign(localblock,data,address,tag,time(NULL),1); } else { // write back to main memory block_reset(localblock); (coreprop0[p].nrepl)++; block_par_assign(localblock,data,address,tag,time(NULL),1); } return localblock; }