src/mem/ruby/structures/CacheMemory.cc
//added by hongyu: when an eviction happens, it is checked that whether a trigger happens.
added by hongyu: when an eviction happens, it is checked that whether a trigger happens.
added by hongyu : when an eviction happens it is checked that whether a trigger happens .
void 
CacheMemory::newEvict(int evicting_core_id, int evicted_core_id, Addr addr){
  DPRINTF(WayEvictMICRO17, "prefetch controller observed: %d, %d, %#x\n", evicting_core_id, evicted_core_id, addr);
  int temp_table[4][4] = {{-1, 0, 1, 2}, {0, -1, 3, 4}, {1, 3, -1, 5}, {2, 4, 5, -1}};
  if (!evict_record_built){
    for (int i=0; i<6; i++){
      switch_count.push_back(0);
      evict_direction.push_back(false);
      address_record.push_back(std::vector<Addr>());
    }
    evict_record_built=true;
  }
  bool same_direction=true;
  int table_index=temp_table[evicting_core_id][evicted_core_id];
  if (evict_direction[table_index] && evicting_core_id<evicted_core_id){
    same_direction=false;
  }
  if (!evict_direction[table_index] && evicting_core_id>evicted_core_id){
    same_direction=false;
  }
  if (same_direction){
    address_record[table_index].push_back(addr);
  }else{
    switch_count[table_index]+=1;
    if (switch_count[table_index]>50){
       DPRINTF(WayEvictMICRO17, "frequent switch detected: %#x\n", addr);
       triggered_core_id.push_back(evicted_core_id);
    }    
    evict_direction[table_index]=!evict_direction[table_index];
    address_record[table_index].clear();
  }
}
void CacheMemory :: newEvict ( int evicting_core_id , int evicted_core_id , Addr addr ) { DPRINTF ( WayEvictMICRO17 , " \n " , evicting_core_id , evicted_core_id , addr ) ; int temp_table [ 4 ] [ 4 ] = { { -1 , 0 , 1 , 2 } , { 0 , -1 , 3 , 4 } , { 1 , 3 , -1 , 5 } , { 2 , 4 , 5 , -1 } } ; if ( ! evict_record_built ) { for ( int i = 0 ; i < 6 ; i ++ ) { switch_count . push_back ( 0 ) ; evict_direction . push_back ( false ) ; address_record . push_back ( std :: vector < Addr > ( ) ) ; } evict_record_built = true ; } bool same_direction = true ; int table_index = temp_table [ evicting_core_id ] [ evicted_core_id ] ; if ( evict_direction [ table_index ] && evicting_core_id < evicted_core_id ) { same_direction = false ; } if ( ! evict_direction [ table_index ] && evicting_core_id > evicted_core_id ) { same_direction = false ; } if ( same_direction ) { address_record [ table_index ] . push_back ( addr ) ; } else { switch_count [ table_index ] += 1 ; if ( switch_count [ table_index ] > 50 ) { DPRINTF ( WayEvictMICRO17 , " \n " , addr ) ; triggered_core_id . push_back ( evicted_core_id ) ; } evict_direction [ table_index ] = ! evict_direction [ table_index ] ; address_record [ table_index ] . clear ( ) ; } }
added by hongyu: when an eviction happens, it is checked that whether a trigger happens.
added by hongyu : when an eviction happens it is checked that whether a trigger happens .
// the eviction information between cores with id x and y are stored in the temp_table[x][y]th element in the vector. // if the eviction record is not built, initialize it. //check whether the eviction series switch from A evicts B to B evicts A. the number of switch/time is an essential factor to identify the attack //if the eviction continues in the same direction, record it // if the direction changes, check whether the number of eviction go beyond the threshold. current threshold is 50. // if triggers, push the id of triggered core.