src/memory/memory.c
static void mem_process_l1_reqs() {
  Mem_Req* req = NULL;
  int      ii;
  int      reqbuf_id;
  int      l1_queue_removal_count       = 0;
  int      out_queue_insertion_count    = 0;
  int      l1_queue_reserve_entry_count = 0;

  /* Go thru the l1_queue and try to access L1 for each request */

  for(ii = 0; ii < mem->l1_queue.entry_count; ii++) {
    reqbuf_id = mem->l1_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 l1:%d bi:%d lf:%d\n", req->id,
            mem_req_state_names[req->state], Mem_Req_Type_str(req->type),
            mem->req_count, mem->l1_queue.entry_count,
            mem->bus_out_queue.entry_count, mem->l1fill_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 L1 port and transition to wait state */
    if(req->state == MRS_L1_NEW) {
      mem_start_l1_access(req);
      STAT_EVENT(req->proc_id, L1_ACCESS);
      if(req->type == MRT_DPRF || req->type == MRT_IPRF)
        STAT_EVENT(req->proc_id, L1_PREF_ACCESS);
      else
        STAT_EVENT(req->proc_id, L1_DEMAND_ACCESS);
    } else {
      ASSERTM(req->proc_id, req->state == MRS_L1_WAIT,
              "id:%d state:%s type:%s rc:%d l1:%d bi:%d lf:%d\n", req->id,
              mem_req_state_names[req->state], Mem_Req_Type_str(req->type),
              mem->req_count, mem->l1_queue.entry_count,
              mem->bus_out_queue.entry_count, mem->l1fill_queue.entry_count);

      if(mem_complete_l1_access(req, &(mem->l1_queue.base[ii]),
                                &out_queue_insertion_count,
                                &l1_queue_reserve_entry_count))
        l1_queue_removal_count++;
    }
  }

  ASSERT(req->proc_id, out_queue_insertion_count <= l1_queue_removal_count);
  ASSERT(req->proc_id,
         l1_queue_reserve_entry_count <= out_queue_insertion_count);

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

  /* Sort the out queue if requests were inserted */
  if(!ALL_FIFO_QUEUES && (out_queue_insertion_count > 0)) {
    if(CONSTANT_MEMORY_LATENCY) {  // request went straight to L1 fill queue
      qsort(mem->l1fill_queue.base, mem->l1fill_queue.entry_count,
            sizeof(Mem_Queue_Entry), mem_compare_priority);
    } else {
      qsort(mem->bus_out_queue.base, mem->bus_out_queue.entry_count,
            sizeof(Mem_Queue_Entry), mem_compare_priority);
    }
  }
}
/**************************************************************************************/
/* mem_process_new_reqs: */
/* Access L1 if port is ready - If L1 miss, then put the request into miss queue
 */
Access L1 if port is ready - If L1 miss, then put the request into miss queue
Access L1 if port is ready - If L1 miss then put the request into miss queue
static void mem_process_l1_reqs() {
  Mem_Req* req = NULL;
  int      ii;
  int      reqbuf_id;
  int      l1_queue_removal_count       = 0;
  int      out_queue_insertion_count    = 0;
  int      l1_queue_reserve_entry_count = 0;
  for(ii = 0; ii < mem->l1_queue.entry_count; ii++) {
    reqbuf_id = mem->l1_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 l1:%d bi:%d lf:%d\n", req->id,
            mem_req_state_names[req->state], Mem_Req_Type_str(req->type),
            mem->req_count, mem->l1_queue.entry_count,
            mem->bus_out_queue.entry_count, mem->l1fill_queue.entry_count);
    if(cycle_count < req->rdy_cycle)
      continue;
    if(req->state == MRS_L1_NEW) {
      mem_start_l1_access(req);
      STAT_EVENT(req->proc_id, L1_ACCESS);
      if(req->type == MRT_DPRF || req->type == MRT_IPRF)
        STAT_EVENT(req->proc_id, L1_PREF_ACCESS);
      else
        STAT_EVENT(req->proc_id, L1_DEMAND_ACCESS);
    } else {
      ASSERTM(req->proc_id, req->state == MRS_L1_WAIT,
              "id:%d state:%s type:%s rc:%d l1:%d bi:%d lf:%d\n", req->id,
              mem_req_state_names[req->state], Mem_Req_Type_str(req->type),
              mem->req_count, mem->l1_queue.entry_count,
              mem->bus_out_queue.entry_count, mem->l1fill_queue.entry_count);
      if(mem_complete_l1_access(req, &(mem->l1_queue.base[ii]),
                                &out_queue_insertion_count,
                                &l1_queue_reserve_entry_count))
        l1_queue_removal_count++;
    }
  }
  ASSERT(req->proc_id, out_queue_insertion_count <= l1_queue_removal_count);
  ASSERT(req->proc_id,
         l1_queue_reserve_entry_count <= out_queue_insertion_count);
  if(l1_queue_removal_count > 0) {
    DEBUG(0, "l1_queue removal\n");
    qsort(mem->l1_queue.base, mem->l1_queue.entry_count,
          sizeof(Mem_Queue_Entry), mem_compare_priority);
    mem->l1_queue.entry_count -= l1_queue_removal_count;
    ASSERT(req->proc_id, mem->l1_queue.entry_count >= 0);
    if(HIER_MSHR_ON) {
      mem->l1_queue.reserved_entry_count += l1_queue_reserve_entry_count;
    }
  }
  if(!ALL_FIFO_QUEUES && (out_queue_insertion_count > 0)) {
    if(CONSTANT_MEMORY_LATENCY) {  
      qsort(mem->l1fill_queue.base, mem->l1fill_queue.entry_count,
            sizeof(Mem_Queue_Entry), mem_compare_priority);
    } else {
      qsort(mem->bus_out_queue.base, mem->bus_out_queue.entry_count,
            sizeof(Mem_Queue_Entry), mem_compare_priority);
    }
  }
}
static void mem_process_l1_reqs ( ) { Mem_Req * req = NULL ; int ii ; int reqbuf_id ; int l1_queue_removal_count = 0 ; int out_queue_insertion_count = 0 ; int l1_queue_reserve_entry_count = 0 ; for ( ii = 0 ; ii < mem -> l1_queue . entry_count ; ii ++ ) { reqbuf_id = mem -> l1_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 -> l1_queue . entry_count , mem -> bus_out_queue . entry_count , mem -> l1fill_queue . entry_count ) ; if ( cycle_count < req -> rdy_cycle ) continue ; if ( req -> state == MRS_L1_NEW ) { mem_start_l1_access ( req ) ; STAT_EVENT ( req -> proc_id , L1_ACCESS ) ; if ( req -> type == MRT_DPRF || req -> type == MRT_IPRF ) STAT_EVENT ( req -> proc_id , L1_PREF_ACCESS ) ; else STAT_EVENT ( req -> proc_id , L1_DEMAND_ACCESS ) ; } else { ASSERTM ( req -> proc_id , req -> state == MRS_L1_WAIT , " \n " , req -> id , mem_req_state_names [ req -> state ] , Mem_Req_Type_str ( req -> type ) , mem -> req_count , mem -> l1_queue . entry_count , mem -> bus_out_queue . entry_count , mem -> l1fill_queue . entry_count ) ; if ( mem_complete_l1_access ( req , & ( mem -> l1_queue . base [ ii ] ) , & out_queue_insertion_count , & l1_queue_reserve_entry_count ) ) l1_queue_removal_count ++ ; } } ASSERT ( req -> proc_id , out_queue_insertion_count <= l1_queue_removal_count ) ; ASSERT ( req -> proc_id , l1_queue_reserve_entry_count <= out_queue_insertion_count ) ; if ( l1_queue_removal_count > 0 ) { DEBUG ( 0 , " \n " ) ; qsort ( mem -> l1_queue . base , mem -> l1_queue . entry_count , sizeof ( Mem_Queue_Entry ) , mem_compare_priority ) ; mem -> l1_queue . entry_count -= l1_queue_removal_count ; ASSERT ( req -> proc_id , mem -> l1_queue . entry_count >= 0 ) ; if ( HIER_MSHR_ON ) { mem -> l1_queue . reserved_entry_count += l1_queue_reserve_entry_count ; } } if ( ! ALL_FIFO_QUEUES && ( out_queue_insertion_count > 0 ) ) { if ( CONSTANT_MEMORY_LATENCY ) { qsort ( mem -> l1fill_queue . base , mem -> l1fill_queue . entry_count , sizeof ( Mem_Queue_Entry ) , mem_compare_priority ) ; } else { qsort ( mem -> bus_out_queue . base , mem -> bus_out_queue . entry_count , sizeof ( Mem_Queue_Entry ) , mem_compare_priority ) ; } } }
mem_process_new_reqs:
Access L1 if port is ready - If L1 miss, then put the request into miss queue
mem_process_new_reqs : Access L1 if port is ready - If L1 miss then put the request into miss queue
/* Go thru the l1_queue and try to access L1 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 L1 port and transition to wait state */ /* Remove requests from l1 access queue */ /* After this sort requests that should be removed will be at the tail of
     * the l1_queue */ /* if HIER_MSHR_ON, requests stay in the queues until filled (by reserving
     * entries) */ /* Sort the out queue if requests were inserted */ // request went straight to L1 fill queue