예제 #1
0
DInst *QEMUReader::executeHead(FlowID fid)
/* speculative advance of execution {{{1 */
{
  if (!ruffer[fid].empty()) {
    DInst *dinst = ruffer[fid].getHead();
    ruffer[fid].popHead();
    I(dinst); // We just added, there should be one or more
    return dinst;
  }


  int conta = 0;
  while(!tsfifo[fid].full()) {
    
    pthread_mutex_lock(&mutex_ctrl); // BEGIN

    if (tsfifo_snd_mutex_blocked[fid]) {
      tsfifo_snd_mutex_blocked[fid] = 0;
      pthread_mutex_unlock(&tsfifo_snd_mutex[fid]);
      //MSG("2.alarmt snd%d",fid);
    }
#if 0
    if (tsfifo_rcv_mutex_blocked == 0) {
      tsfifo_rcv_mutex_blocked = 1;
      pthread_mutex_unlock(&mutex_ctrl); // END

      //MSG("1.sleep  rcv%d",fid);
      pthread_mutex_lock(&tsfifo_rcv_mutex);
      //MSG("1.wakeup rcv%d",fid);
    }else{
      pthread_mutex_unlock(&mutex_ctrl); // END
    }
#else
    pthread_mutex_unlock(&mutex_ctrl); // END
#endif

    if (qsamplerlist[fid]->isActive(fid) == false) {
      MSG("DOWN");
      return 0;
    }

    if (!live_qemu_active) {
      pthread_mutex_lock(&mutex_live);
      pthread_cond_wait(&cond_live, &mutex_live);
      pthread_mutex_unlock(&mutex_live);
    }

    if (conta++>100) {
      //printf("+%d",fid);
      return 0;
    }
  }

  for(int i=32;i<tsfifo[fid].size();i++) {
    RAWDInst  *rinst = tsfifo[fid].getHeadRef();
    DInst **dinsth = ruffer[fid].getInsertPointRef();

    *dinsth = DInst::create(rinst->getInst(), rinst->getPC(), rinst->getAddr(), fid, rinst->getStatsFlag());

    ruffer[fid].add();
    tsfifo[fid].pop();
  }

  if (tsfifo_snd_mutex_blocked[fid]) {
    tsfifo_snd_mutex_blocked[fid] = 0;
    pthread_mutex_unlock(&tsfifo_snd_mutex[fid]);
  }

  if (ruffer[fid].empty())
    return 0;

  DInst *dinst = ruffer[fid].getHead();
  ruffer[fid].popHead();
  I(dinst); // We just added, there should be one or more
  return dinst;
}