src/memory/memory.c
static void mem_process_mlc_reqs() {
  Mem_Req* req = NULL;
  int      ii;
  int      reqbuf_id;
  int      mlc_queue_removal_count       = 0;
  int      l1_queue_insertion_count      = 0;
  int      mlc_queue_reserve_entry_count = 0;

  /* Go thru the mlc_queue and try to access MLC for each request */

  for(ii = 0; ii < mem->mlc_queue.entry_count; ii++) {
    reqbuf_id = mem->mlc_queue.base[ii].reqbuf;
    req       = &(mem->req_buffer[reqbuf_id]);

    // this is just a print
    if(req->state == MRS_INV) {
      print_mem_queue(QUEUE_L1 | QUEUE_BUS_OUT | QUEUE_L1FILL | QUEUE_MLC |
                      QUEUE_MLC_FILL);
    }

    ASSERTM(req->proc_id, req->state != MRS_INV,
            "id:%d state:%s type:%s rc:%d mlc:%d l1:%d mf:%d\n", req->id,
            mem_req_state_names[req->state], Mem_Req_Type_str(req->type),
            mem->req_count, mem->mlc_queue.entry_count,
            mem->l1_queue.entry_count, mem->mlc_fill_queue.entry_count);

    /* if the request is not yet ready, then try the next one */
    if(cycle_count < req->rdy_cycle)
      continue;

    /* Request is ready: see what state it is in */

    /* If this is a new request, reserve MLC port and transition to wait state
     */
    if(req->state == MRS_MLC_NEW) {
      mem_start_mlc_access(req);
      STAT_EVENT(req->proc_id, MLC_ACCESS);
      if(req->type == MRT_DPRF || req->type == MRT_IPRF)
        STAT_EVENT(req->proc_id, MLC_PREF_ACCESS);
      else
        STAT_EVENT(req->proc_id, MLC_DEMAND_ACCESS);
    } else {
      ASSERTM(req->proc_id, req->state == MRS_MLC_WAIT,
              "id:%d state:%s type:%s rc:%d mlc:%d l1:%d mf:%d\n", req->id,
              mem_req_state_names[req->state], Mem_Req_Type_str(req->type),
              mem->req_count, mem->mlc_queue.entry_count,
              mem->l1_queue.entry_count, mem->mlc_fill_queue.entry_count);
      if(mem_complete_mlc_access(req, &(mem->mlc_queue.base[ii]),
                                 &l1_queue_insertion_count,
                                 &mlc_queue_reserve_entry_count))
        mlc_queue_removal_count++;
    }
  }

  ASSERT(req->proc_id, l1_queue_insertion_count <= mlc_queue_removal_count);
  ASSERT(req->proc_id,
         mlc_queue_reserve_entry_count <= l1_queue_insertion_count);

  /* Remove requests from mlc access queue */
  if((mlc_queue_removal_count > 0)) {
    /* After this sort requests that should be removed will be at the tail of
     * the mlc_queue */
    DEBUG(0, "mlc_queue removal\n");
    qsort(mem->mlc_queue.base, mem->mlc_queue.entry_count,
          sizeof(Mem_Queue_Entry), mem_compare_priority);
    mem->mlc_queue.entry_count -= mlc_queue_removal_count;
    ASSERT(req->proc_id, mem->mlc_queue.entry_count >= 0);
    /* if HIER_MSHR_ON, requests stay in the queues until filled (by reserving
     * entries) */
    if(HIER_MSHR_ON) {
      mem->mlc_queue.reserved_entry_count += mlc_queue_reserve_entry_count;
    }
  }

  /* Sort the l1 queue if requests were inserted */
  if(!ALL_FIFO_QUEUES && (l1_queue_insertion_count > 0)) {
    qsort(mem->l1_queue.base, mem->l1_queue.entry_count,
          sizeof(Mem_Queue_Entry), mem_compare_priority);
  }
}
/**************************************************************************************/
/* mem_process_mlc_reqs: */
/* Access MLC if port is ready - If MLC miss, then put the request into miss
 * queue */
Access MLC if port is ready - If MLC miss, then put the request into miss
queue
Access MLC if port is ready - If MLC miss then put the request into miss queue
static void mem_process_mlc_reqs() {
  Mem_Req* req = NULL;
  int      ii;
  int      reqbuf_id;
  int      mlc_queue_removal_count       = 0;
  int      l1_queue_insertion_count      = 0;
  int      mlc_queue_reserve_entry_count = 0;
  for(ii = 0; ii < mem->mlc_queue.entry_count; ii++) {
    reqbuf_id = mem->mlc_queue.base[ii].reqbuf;
    req       = &(mem->req_buffer[reqbuf_id]);
    if(req->state == MRS_INV) {
      print_mem_queue(QUEUE_L1 | QUEUE_BUS_OUT | QUEUE_L1FILL | QUEUE_MLC |
                      QUEUE_MLC_FILL);
    }
    ASSERTM(req->proc_id, req->state != MRS_INV,
            "id:%d state:%s type:%s rc:%d mlc:%d l1:%d mf:%d\n", req->id,
            mem_req_state_names[req->state], Mem_Req_Type_str(req->type),
            mem->req_count, mem->mlc_queue.entry_count,
            mem->l1_queue.entry_count, mem->mlc_fill_queue.entry_count);
    if(cycle_count < req->rdy_cycle)
      continue;
    if(req->state == MRS_MLC_NEW) {
      mem_start_mlc_access(req);
      STAT_EVENT(req->proc_id, MLC_ACCESS);
      if(req->type == MRT_DPRF || req->type == MRT_IPRF)
        STAT_EVENT(req->proc_id, MLC_PREF_ACCESS);
      else
        STAT_EVENT(req->proc_id, MLC_DEMAND_ACCESS);
    } else {
      ASSERTM(req->proc_id, req->state == MRS_MLC_WAIT,
              "id:%d state:%s type:%s rc:%d mlc:%d l1:%d mf:%d\n", req->id,
              mem_req_state_names[req->state], Mem_Req_Type_str(req->type),
              mem->req_count, mem->mlc_queue.entry_count,
              mem->l1_queue.entry_count, mem->mlc_fill_queue.entry_count);
      if(mem_complete_mlc_access(req, &(mem->mlc_queue.base[ii]),
                                 &l1_queue_insertion_count,
                                 &mlc_queue_reserve_entry_count))
        mlc_queue_removal_count++;
    }
  }
  ASSERT(req->proc_id, l1_queue_insertion_count <= mlc_queue_removal_count);
  ASSERT(req->proc_id,
         mlc_queue_reserve_entry_count <= l1_queue_insertion_count);
  if((mlc_queue_removal_count > 0)) {
    DEBUG(0, "mlc_queue removal\n");
    qsort(mem->mlc_queue.base, mem->mlc_queue.entry_count,
          sizeof(Mem_Queue_Entry), mem_compare_priority);
    mem->mlc_queue.entry_count -= mlc_queue_removal_count;
    ASSERT(req->proc_id, mem->mlc_queue.entry_count >= 0);
    if(HIER_MSHR_ON) {
      mem->mlc_queue.reserved_entry_count += mlc_queue_reserve_entry_count;
    }
  }
  if(!ALL_FIFO_QUEUES && (l1_queue_insertion_count > 0)) {
    qsort(mem->l1_queue.base, mem->l1_queue.entry_count,
          sizeof(Mem_Queue_Entry), mem_compare_priority);
  }
}
static void mem_process_mlc_reqs ( ) { Mem_Req * req = NULL ; int ii ; int reqbuf_id ; int mlc_queue_removal_count = 0 ; int l1_queue_insertion_count = 0 ; int mlc_queue_reserve_entry_count = 0 ; for ( ii = 0 ; ii < mem -> mlc_queue . entry_count ; ii ++ ) { reqbuf_id = mem -> mlc_queue . base [ ii ] . reqbuf ; req = & ( mem -> req_buffer [ reqbuf_id ] ) ; if ( req -> state == MRS_INV ) { print_mem_queue ( QUEUE_L1 | QUEUE_BUS_OUT | QUEUE_L1FILL | QUEUE_MLC | QUEUE_MLC_FILL ) ; } ASSERTM ( req -> proc_id , req -> state != MRS_INV , " \n " , req -> id , mem_req_state_names [ req -> state ] , Mem_Req_Type_str ( req -> type ) , mem -> req_count , mem -> mlc_queue . entry_count , mem -> l1_queue . entry_count , mem -> mlc_fill_queue . entry_count ) ; if ( cycle_count < req -> rdy_cycle ) continue ; if ( req -> state == MRS_MLC_NEW ) { mem_start_mlc_access ( req ) ; STAT_EVENT ( req -> proc_id , MLC_ACCESS ) ; if ( req -> type == MRT_DPRF || req -> type == MRT_IPRF ) STAT_EVENT ( req -> proc_id , MLC_PREF_ACCESS ) ; else STAT_EVENT ( req -> proc_id , MLC_DEMAND_ACCESS ) ; } else { ASSERTM ( req -> proc_id , req -> state == MRS_MLC_WAIT , " \n " , req -> id , mem_req_state_names [ req -> state ] , Mem_Req_Type_str ( req -> type ) , mem -> req_count , mem -> mlc_queue . entry_count , mem -> l1_queue . entry_count , mem -> mlc_fill_queue . entry_count ) ; if ( mem_complete_mlc_access ( req , & ( mem -> mlc_queue . base [ ii ] ) , & l1_queue_insertion_count , & mlc_queue_reserve_entry_count ) ) mlc_queue_removal_count ++ ; } } ASSERT ( req -> proc_id , l1_queue_insertion_count <= mlc_queue_removal_count ) ; ASSERT ( req -> proc_id , mlc_queue_reserve_entry_count <= l1_queue_insertion_count ) ; if ( ( mlc_queue_removal_count > 0 ) ) { DEBUG ( 0 , " \n " ) ; qsort ( mem -> mlc_queue . base , mem -> mlc_queue . entry_count , sizeof ( Mem_Queue_Entry ) , mem_compare_priority ) ; mem -> mlc_queue . entry_count -= mlc_queue_removal_count ; ASSERT ( req -> proc_id , mem -> mlc_queue . entry_count >= 0 ) ; if ( HIER_MSHR_ON ) { mem -> mlc_queue . reserved_entry_count += mlc_queue_reserve_entry_count ; } } if ( ! ALL_FIFO_QUEUES && ( l1_queue_insertion_count > 0 ) ) { qsort ( mem -> l1_queue . base , mem -> l1_queue . entry_count , sizeof ( Mem_Queue_Entry ) , mem_compare_priority ) ; } }
mem_process_mlc_reqs:
Access MLC if port is ready - If MLC miss, then put the request into miss
 queue
mem_process_mlc_reqs : Access MLC if port is ready - If MLC miss then put the request into miss queue
/* Go thru the mlc_queue and try to access MLC for each request */ // this is just a print /* if the request is not yet ready, then try the next one */ /* Request is ready: see what state it is in */ /* If this is a new request, reserve MLC port and transition to wait state
     */ /* Remove requests from mlc access queue */ /* After this sort requests that should be removed will be at the tail of
     * the mlc_queue */ /* if HIER_MSHR_ON, requests stay in the queues until filled (by reserving
     * entries) */ /* Sort the l1 queue if requests were inserted */