src/memory/memory.c
Flag new_mem_dc_wb_req(Mem_Req_Type type, uns8 proc_id, Addr addr, uns size,
                       uns delay, Op* op, Flag done_func(Mem_Req*),
                       Counter unique_num, Flag used_onpath) {
  Mem_Req*         new_req              = NULL;
  Mem_Req*         matching_req         = NULL;
  Mem_Queue_Entry* queue_entry          = NULL;
  Flag             demand_hit_prefetch  = FALSE;
  Flag             demand_hit_writeback = FALSE;
  Flag             kicked_out =
    FALSE; /* did this request kick out another one in the queue */
  Flag    ramulator_match = FALSE;
  Counter priority_offset = freq_cycle_count(FREQ_DOMAIN_L1);
  Counter new_priority;

  ASSERT(proc_id, (type == MRT_WB) || (type == MRT_WB_NODIRTY));
  ASSERTM(proc_id, proc_id == get_proc_id_from_cmp_addr(addr),
          "Proc ID (%d) does not match proc ID in address (%d)!\n", proc_id,
          get_proc_id_from_cmp_addr(addr));

  new_priority = Mem_Req_Priority_Offset[type] + priority_offset;

  /* Step 1: Figure out if this access is already in the request buffer */

  matching_req = mem_search_reqbuf(
    proc_id, addr, type, size, &demand_hit_prefetch, &demand_hit_writeback,
    QUEUE_L1 | QUEUE_BUS_OUT | /*QUEUE_MEM |*/ QUEUE_L1FILL, &queue_entry,
    &ramulator_match);  // CMP: QUEUE_L1FILL: this is a bug? Seems like no.
                        // Doublecheck!!

  /* Step 2: Found matching request. Adjust it based on the current request */

  if(matching_req) {
    ASSERT(matching_req->proc_id, queue_entry);
    DEBUG(matching_req->proc_id,
          "Hit in mem buffer  index:%d  type:%s  addr:0x%s  size:%d  op_num:%d "
          " off_path:%d\n",
          matching_req->id, Mem_Req_Type_str(matching_req->type),
          hexstr64s(matching_req->addr), matching_req->size,
          op ? (int)op->op_num : -1, op ? op->off_path : FALSE);
    return (mem_adjust_matching_request(
      matching_req, type, addr, size, DEST_MLC, delay, op, done_func,
      unique_num, demand_hit_prefetch, demand_hit_writeback, &queue_entry,
      new_priority, ramulator_match));
  }

  /* Step 2.5: Check if there is space in the appropriate queue */
  if(MLC_PRESENT) {
    if(queue_full(&mem->mlc_queue)) {
      STAT_EVENT(proc_id, REJECTED_QUEUE_MLC);
      return FALSE;
    }
  } else {
    if(queue_full(&mem->l1_queue)) {
      STAT_EVENT(proc_id, REJECTED_QUEUE_L1);
      return FALSE;
    }
  }

  /* Step 3: Not already in request buffer. Figure out if a free request buffer
   * exists */
  new_req = mem_allocate_req_buffer(proc_id, type, FALSE);

  /* Step 4: No free request buffer - If demand, try to kick
     something out from the l1 access queue (not bus_out and
     definitely not bus_in, because we may not be able to take stuff
     out of there) */
  if(new_req == NULL) { /* Step 2.1.1: Cannot kick out anything - just return */
    DEBUG(proc_id,
          "Request denied in mem buffer  addr:%s rc:%d mlc:%d l1:%d bo:%d "
          "lf:%d mf:%d rf:%d\n",
          hexstr64s(addr), mem->req_count, mem->mlc_queue.entry_count,
          mem->l1_queue.entry_count, mem->bus_out_queue.entry_count,
          mem->l1fill_queue.entry_count, mem->mlc_fill_queue.entry_count,
          mem->req_buffer_free_list.count);
    STAT_EVENT(proc_id, MEM_REQ_BUFFER_FULL);
    if((type == MRT_IFETCH) || (type == MRT_DFETCH) || (type == MRT_DSTORE))
      STAT_EVENT(proc_id, MEM_REQ_BUFFER_FULL_DENIED_DEMAND);
    STAT_EVENT(proc_id, MEM_REQ_BUFFER_FULL_DENIED_IFETCH + type);
    return FALSE;
  }

  /* Step 5: Allocate a new request buffer -- new_req */
  mem_init_new_req(new_req, type, MLC_PRESENT ? QUEUE_MLC : QUEUE_L1, proc_id,
                   addr, size, delay, op, done_func, unique_num, kicked_out,
                   new_priority);
  new_req->wb_used_onpath = used_onpath;  // DC WB requests carry this flag

  /* Step 6: Insert the request into the l1 queue if it is not already there */
  if(MLC_PRESENT)
    insert_new_req_into_mlc_queue(proc_id, new_req);
  else
    insert_new_req_into_l1_queue(proc_id, new_req);

  return TRUE;
}
/**************************************************************************************/
/* new_mem_dc_wb_req: */
/* Returns TRUE if the request is successfully entered into the memory system */
Returns TRUE if the request is successfully entered into the memory system
Returns TRUE if the request is successfully entered into the memory system
Flag new_mem_dc_wb_req(Mem_Req_Type type, uns8 proc_id, Addr addr, uns size,
                       uns delay, Op* op, Flag done_func(Mem_Req*),
                       Counter unique_num, Flag used_onpath) {
  Mem_Req*         new_req              = NULL;
  Mem_Req*         matching_req         = NULL;
  Mem_Queue_Entry* queue_entry          = NULL;
  Flag             demand_hit_prefetch  = FALSE;
  Flag             demand_hit_writeback = FALSE;
  Flag             kicked_out =
    FALSE; 
  Flag    ramulator_match = FALSE;
  Counter priority_offset = freq_cycle_count(FREQ_DOMAIN_L1);
  Counter new_priority;
  ASSERT(proc_id, (type == MRT_WB) || (type == MRT_WB_NODIRTY));
  ASSERTM(proc_id, proc_id == get_proc_id_from_cmp_addr(addr),
          "Proc ID (%d) does not match proc ID in address (%d)!\n", proc_id,
          get_proc_id_from_cmp_addr(addr));
  new_priority = Mem_Req_Priority_Offset[type] + priority_offset;
  matching_req = mem_search_reqbuf(
    proc_id, addr, type, size, &demand_hit_prefetch, &demand_hit_writeback,
    QUEUE_L1 | QUEUE_BUS_OUT |  QUEUE_L1FILL, &queue_entry,
    &ramulator_match);  
  if(matching_req) {
    ASSERT(matching_req->proc_id, queue_entry);
    DEBUG(matching_req->proc_id,
          "Hit in mem buffer  index:%d  type:%s  addr:0x%s  size:%d  op_num:%d "
          " off_path:%d\n",
          matching_req->id, Mem_Req_Type_str(matching_req->type),
          hexstr64s(matching_req->addr), matching_req->size,
          op ? (int)op->op_num : -1, op ? op->off_path : FALSE);
    return (mem_adjust_matching_request(
      matching_req, type, addr, size, DEST_MLC, delay, op, done_func,
      unique_num, demand_hit_prefetch, demand_hit_writeback, &queue_entry,
      new_priority, ramulator_match));
  }
  if(MLC_PRESENT) {
    if(queue_full(&mem->mlc_queue)) {
      STAT_EVENT(proc_id, REJECTED_QUEUE_MLC);
      return FALSE;
    }
  } else {
    if(queue_full(&mem->l1_queue)) {
      STAT_EVENT(proc_id, REJECTED_QUEUE_L1);
      return FALSE;
    }
  }
  new_req = mem_allocate_req_buffer(proc_id, type, FALSE);
  if(new_req == NULL) { 
    DEBUG(proc_id,
          "Request denied in mem buffer  addr:%s rc:%d mlc:%d l1:%d bo:%d "
          "lf:%d mf:%d rf:%d\n",
          hexstr64s(addr), mem->req_count, mem->mlc_queue.entry_count,
          mem->l1_queue.entry_count, mem->bus_out_queue.entry_count,
          mem->l1fill_queue.entry_count, mem->mlc_fill_queue.entry_count,
          mem->req_buffer_free_list.count);
    STAT_EVENT(proc_id, MEM_REQ_BUFFER_FULL);
    if((type == MRT_IFETCH) || (type == MRT_DFETCH) || (type == MRT_DSTORE))
      STAT_EVENT(proc_id, MEM_REQ_BUFFER_FULL_DENIED_DEMAND);
    STAT_EVENT(proc_id, MEM_REQ_BUFFER_FULL_DENIED_IFETCH + type);
    return FALSE;
  }
  mem_init_new_req(new_req, type, MLC_PRESENT ? QUEUE_MLC : QUEUE_L1, proc_id,
                   addr, size, delay, op, done_func, unique_num, kicked_out,
                   new_priority);
  new_req->wb_used_onpath = used_onpath;  
  if(MLC_PRESENT)
    insert_new_req_into_mlc_queue(proc_id, new_req);
  else
    insert_new_req_into_l1_queue(proc_id, new_req);
  return TRUE;
}
Flag new_mem_dc_wb_req ( Mem_Req_Type type , uns8 proc_id , Addr addr , uns size , uns delay , Op * op , Flag done_func ( Mem_Req * ) , Counter unique_num , Flag used_onpath ) { Mem_Req * new_req = NULL ; Mem_Req * matching_req = NULL ; Mem_Queue_Entry * queue_entry = NULL ; Flag demand_hit_prefetch = FALSE ; Flag demand_hit_writeback = FALSE ; Flag kicked_out = FALSE ; Flag ramulator_match = FALSE ; Counter priority_offset = freq_cycle_count ( FREQ_DOMAIN_L1 ) ; Counter new_priority ; ASSERT ( proc_id , ( type == MRT_WB ) || ( type == MRT_WB_NODIRTY ) ) ; ASSERTM ( proc_id , proc_id == get_proc_id_from_cmp_addr ( addr ) , " \n " , proc_id , get_proc_id_from_cmp_addr ( addr ) ) ; new_priority = Mem_Req_Priority_Offset [ type ] + priority_offset ; matching_req = mem_search_reqbuf ( proc_id , addr , type , size , & demand_hit_prefetch , & demand_hit_writeback , QUEUE_L1 | QUEUE_BUS_OUT | QUEUE_L1FILL , & queue_entry , & ramulator_match ) ; if ( matching_req ) { ASSERT ( matching_req -> proc_id , queue_entry ) ; DEBUG ( matching_req -> proc_id , " " " \n " , matching_req -> id , Mem_Req_Type_str ( matching_req -> type ) , hexstr64s ( matching_req -> addr ) , matching_req -> size , op ? ( int ) op -> op_num : -1 , op ? op -> off_path : FALSE ) ; return ( mem_adjust_matching_request ( matching_req , type , addr , size , DEST_MLC , delay , op , done_func , unique_num , demand_hit_prefetch , demand_hit_writeback , & queue_entry , new_priority , ramulator_match ) ) ; } if ( MLC_PRESENT ) { if ( queue_full ( & mem -> mlc_queue ) ) { STAT_EVENT ( proc_id , REJECTED_QUEUE_MLC ) ; return FALSE ; } } else { if ( queue_full ( & mem -> l1_queue ) ) { STAT_EVENT ( proc_id , REJECTED_QUEUE_L1 ) ; return FALSE ; } } new_req = mem_allocate_req_buffer ( proc_id , type , FALSE ) ; if ( new_req == NULL ) { DEBUG ( proc_id , " " " \n " , hexstr64s ( addr ) , mem -> req_count , mem -> mlc_queue . entry_count , mem -> l1_queue . entry_count , mem -> bus_out_queue . entry_count , mem -> l1fill_queue . entry_count , mem -> mlc_fill_queue . entry_count , mem -> req_buffer_free_list . count ) ; STAT_EVENT ( proc_id , MEM_REQ_BUFFER_FULL ) ; if ( ( type == MRT_IFETCH ) || ( type == MRT_DFETCH ) || ( type == MRT_DSTORE ) ) STAT_EVENT ( proc_id , MEM_REQ_BUFFER_FULL_DENIED_DEMAND ) ; STAT_EVENT ( proc_id , MEM_REQ_BUFFER_FULL_DENIED_IFETCH + type ) ; return FALSE ; } mem_init_new_req ( new_req , type , MLC_PRESENT ? QUEUE_MLC : QUEUE_L1 , proc_id , addr , size , delay , op , done_func , unique_num , kicked_out , new_priority ) ; new_req -> wb_used_onpath = used_onpath ; if ( MLC_PRESENT ) insert_new_req_into_mlc_queue ( proc_id , new_req ) ; else insert_new_req_into_l1_queue ( proc_id , new_req ) ; return TRUE ; }
new_mem_dc_wb_req:
Returns TRUE if the request is successfully entered into the memory system
new_mem_dc_wb_req : Returns TRUE if the request is successfully entered into the memory system
/* did this request kick out another one in the queue */ /* Step 1: Figure out if this access is already in the request buffer */ /*QUEUE_MEM |*/ // CMP: QUEUE_L1FILL: this is a bug? Seems like no. // Doublecheck!! /* Step 2: Found matching request. Adjust it based on the current request */ /* Step 2.5: Check if there is space in the appropriate queue */ /* Step 3: Not already in request buffer. Figure out if a free request buffer
   * exists */ /* Step 4: No free request buffer - If demand, try to kick
     something out from the l1 access queue (not bus_out and
     definitely not bus_in, because we may not be able to take stuff
     out of there) */ /* Step 2.1.1: Cannot kick out anything - just return */ /* Step 5: Allocate a new request buffer -- new_req */ // DC WB requests carry this flag /* Step 6: Insert the request into the l1 queue if it is not already there */