Exemple #1
0
void startTest(){
  int rc;
  int rankMessage = 0;
  pthread_t thread;

  rc = sem_init(&semWaitEnoughMembers, 0, 0);
  if (rc)
    ERROR_AT_LINE(rc, errno, __FILE__, __LINE__, "sem_init()");

  // We initialize the trains protocol
  if (gettimeofday(&timeTrInitBegin, NULL ) < 0)
    ERROR_AT_LINE(EXIT_FAILURE, errno, __FILE__, __LINE__, "gettimeofday");
  rc = trInit(trainsNumber, alternateMaxWagonLen, 0, 0, callbackCircuitChange, callbackODeliver, reqOrder);
  if (rc < 0) {
    trError_at_line(rc, trErrno, __FILE__, __LINE__, "tr_init()");
    exit(EXIT_FAILURE);
  }
  if (gettimeofday(&timeTrInitEnd, NULL ) < 0)
    ERROR_AT_LINE(EXIT_FAILURE, errno, __FILE__, __LINE__, "gettimeofday");

  // We wait until there are enough members
  do {
    rc = sem_wait(&semWaitEnoughMembers);
  } while ((rc < 0) && (errno == EINTR));
  if (rc)
    ERROR_AT_LINE(EXIT_FAILURE, errno, __FILE__, __LINE__, "sem_wait()");

  // We start the warm-up phase
  rc = pthread_create(&thread, NULL, timeKeeper, NULL );
  if (rc < 0)
    ERROR_AT_LINE(EXIT_FAILURE, rc, __FILE__, __LINE__, "pthread_create");
  rc = pthread_detach(thread);
  if (rc < 0)
    ERROR_AT_LINE(EXIT_FAILURE, rc, __FILE__, __LINE__, "pthread_detach");

  // We check if process should be a broadcasting process
  if (rank < broadcasters) {
    // It is the case
    do {
      message *mp = newmsg(size);
      if (mp == NULL ) {
        trError_at_line(rc, trErrno, __FILE__, __LINE__, "newmsg()");
        exit(EXIT_FAILURE);
      }
      rankMessage++;
      *((int*) (mp->payload)) = rankMessage;
      if (oBroadcast(TEST_MESSAGE, mp) < 0) {
        trError_at_line(rc, trErrno, __FILE__, __LINE__, "oBroadcast()");
        exit(EXIT_FAILURE);
      }
    } while (1);
  } else {
    // Sleep enough time to be sure that this thread does not exist
    // before all other jobs are done
    sleep(warmup + measurement + cooldown + 1);
  }
}
Exemple #2
0
int main(int argc, char *argv[]){

  int i, j;
  int rc;
  int msgCounter;
  int wagonSizes[] = { 1024, 2048, 4096, 8192, 16384, 32768, 65536 };
  int payloadSizes[] = { 10, 100, 200, 500, 1000, 2000, 5000, 10000, 15000,
      20000 };
  struct timeval debut, fin, duree;
  struct rusage debutCPU, finCPU, dureeCPU;
  long elapsedTime, cpuTime;

  MUTEX_LOCK(stateMachineMutex);
  automatonState = SEVERAL;
  MUTEX_UNLOCK(stateMachineMutex);

  printf("Début de l'experience\n");

  for (i = 0; i < 7; i++) {
    for (j = 0; j < 10; j++) {
      // initialisation du wagon
      wagonMaxLen = wagonSizes[i];
      wagonToSend = newWiw();
      msgCounter = 0;

// start timers
      printf("Début du remplissage...\n");
      getrusage(RUSAGE_SELF, &debutCPU);
      gettimeofday(&debut, NULL );

// remplissage du wagon

      while (wagonToSend->p_wagon->header.len + payloadSizes[j]
          + sizeof(messageHeader) < wagonMaxLen) {
        message *mp = newmsg(payloadSizes[j]);
        if (mp == NULL ) {
          trError_at_line(rc, trErrno, __FILE__, __LINE__, "newmsg()");
          exit(EXIT_FAILURE);
        }
        if (utoBroadcast(mp) < 0) {
          trError_at_line(rc, trErrno, __FILE__, __LINE__, "utoBroadcast()");
          exit(EXIT_FAILURE);
        }
        msgCounter++;
      }

// stop timers
      gettimeofday(&fin, NULL );
      getrusage(RUSAGE_SELF, &finCPU);
      printf("Remplissage terminé\n");

// calculs
      timersub(&(finCPU.ru_utime), &(debutCPU.ru_utime), &(dureeCPU.ru_utime));
      timersub(&(finCPU.ru_stime), &(debutCPU.ru_stime), &(dureeCPU.ru_stime));
      timersub(&fin, &debut, &duree);

      elapsedTime = (1000000 * duree.tv_sec + duree.tv_usec);
      cpuTime = ((1000000
          * (dureeCPU.ru_utime.tv_sec + dureeCPU.ru_stime.tv_sec))
          + dureeCPU.ru_utime.tv_usec + dureeCPU.ru_stime.tv_usec);

      printf("********************************\n"
          "*********************************\n"
          "Messages de %d octets dans un wagon de %d octets\n", payloadSizes[j],
          wagonSizes[i]);
      printf("%d messages écrits\n", msgCounter);
      if (msgCounter > 0) {
        printf(
            "Temps absolu écoulé :          %9ld usec par message (%9ld au total)\n",
            elapsedTime / msgCounter, elapsedTime);
        printf(
            "Temps CPU (user+sys) écoulé :  %9ld usec par message (%9ld au total)\n",
            cpuTime / msgCounter, cpuTime);
      }
      printf("**************************\n");

      // free ressources
      freeWiw(wagonToSend);

    }
  }

  return EXIT_SUCCESS;
}
Exemple #3
0
/* Thread taking care of respecting the times of the experiment. */
void *timeKeeper(void *null){
  int rc;
  t_counters countersBegin, countersEnd;
  struct rusage rusageBegin, rusageEnd;
  struct timeval timeBegin, timeEnd;
  struct timeval startSomme, stopSomme, diffCPU, diffTimeval;

  // Warm-up phase
  usleep(warmup * 1000000);

  // Measurement phase
  if (gettimeofday(&timeBegin, NULL ) < 0)
    ERROR_AT_LINE(EXIT_FAILURE, errno, __FILE__, __LINE__, "gettimeofday");
  if (getrusage(RUSAGE_SELF, &rusageBegin) < 0)
    ERROR_AT_LINE(EXIT_FAILURE, errno, __FILE__, __LINE__, "getrusage");
  countersBegin = counters;

  usleep(measurement * 1000000);

  if (gettimeofday(&timeEnd, NULL ) < 0)
    ERROR_AT_LINE(EXIT_FAILURE, errno, __FILE__, __LINE__, "gettimeofday");
  if (getrusage(RUSAGE_SELF, &rusageEnd) < 0)
    ERROR_AT_LINE(EXIT_FAILURE, errno, __FILE__, __LINE__, "getrusage");
  countersEnd = counters;

  measurementDone = true;

  // Cool-down phase
  usleep(cooldown * 1000000);

  // We display the results
  printf(
      "%s --broadcasters %d --cooldown %d --wagonMaxLen %d --measurement %d --number %d --size %d --trainsNumber %d  --warmup %d\n",
      programName, broadcasters, cooldown, alternateMaxWagonLen, measurement, number, size,
      trainsNumber, warmup);

  printDiffTimeval("time for tr_init (in sec)", timeTrInitEnd, timeTrInitBegin);

  printDiffTimeval("elapsed time (in sec)", timeEnd, timeBegin);

  printDiffTimeval("ru_utime (in sec)", rusageEnd.ru_utime,
      rusageBegin.ru_utime);
  printDiffTimeval("ru_stime (in sec)", rusageEnd.ru_stime,
      rusageBegin.ru_stime);

  timeradd(&rusageBegin.ru_utime, &rusageBegin.ru_stime, &startSomme);
  timeradd(&rusageEnd.ru_utime, &rusageEnd.ru_stime, &stopSomme);
  printDiffTimeval("ru_utime+ru_stime (in sec)", stopSomme, startSomme);

  printf("number of messages delivered to the application ; %llu\n",
      countersEnd.messages_delivered - countersBegin.messages_delivered);
  printf("number of bytes delivered to the application ; %llu\n",
      countersEnd.messages_bytes_delivered
          - countersBegin.messages_bytes_delivered);
  printf("number of bytes of trains received from the network ; %llu\n",
      countersEnd.trains_bytes_received - countersBegin.trains_bytes_received);
  printf("number of trains received from the network ; %llu\n",
      countersEnd.trains_received - countersBegin.trains_received);
  printf("number of bytes of recent trains received from the network ; %llu\n",
      countersEnd.recent_trains_bytes_received
          - countersBegin.recent_trains_bytes_received);
  printf("number of recent trains received from the network ; %llu\n",
      countersEnd.recent_trains_received
          - countersBegin.recent_trains_received);
  printf("number of wagons delivered to the application ; %llu\n",
      countersEnd.wagons_delivered - countersBegin.wagons_delivered);
  printf("number of times automaton has been in state WAIT ; %llu\n",
      countersEnd.wait_states - countersBegin.wait_states);
  printf("number of calls to commRead() ; %llu\n",
      countersEnd.comm_read - countersBegin.comm_read);
  printf("number of bytes read by commRead() calls ; %llu\n",
      countersEnd.comm_read_bytes - countersBegin.comm_read_bytes);
  printf("number of calls to commReadFully() ; %llu\n",
      countersEnd.comm_readFully - countersBegin.comm_readFully);
  printf("number of bytes read by commReadFully() calls ; %llu\n",
      countersEnd.comm_readFully_bytes - countersBegin.comm_readFully_bytes);
  printf("number of calls to commWrite() ; %llu\n",
      countersEnd.comm_write - countersBegin.comm_write);
  printf("number of bytes written by commWrite() calls ; %llu\n",
      countersEnd.comm_write_bytes - countersBegin.comm_write_bytes);
  printf("number of calls to commWritev() ; %llu\n",
      countersEnd.comm_writev - countersBegin.comm_writev);
  printf("number of bytes written by commWritev() calls ; %llu\n",
      countersEnd.comm_writev_bytes - countersBegin.comm_writev_bytes);
  printf("number of calls to newmsg() ; %llu\n",
      countersEnd.newmsg - countersBegin.newmsg);
  printf(
      "number of times there was flow control when calling newmsg() ; %llu\n",
      countersEnd.flowControl - countersBegin.flowControl);

  timersub(&stopSomme, &startSomme, &diffCPU);
  timersub(&timeEnd, &timeBegin, &diffTimeval);
  printf(
      "Broadcasters / number / size / ntr / Average number of delivered wagons per recent train received / Average number of msg per wagon / Throughput of o-broadcasts in Mbps / %%CPU ; %d ; %d ; %d ; %d ; %g ; %g ; %g ; %g\n",
      broadcasters, number, size, ntr,
      ((double) (countersEnd.wagons_delivered - countersBegin.wagons_delivered))
          / ((double) (countersEnd.recent_trains_received
              - countersBegin.recent_trains_received)),
      ((double) (countersEnd.messages_delivered
          - countersBegin.messages_delivered))
          / ((double) (countersEnd.wagons_delivered
              - countersBegin.wagons_delivered)),
      ((double) (countersEnd.messages_bytes_delivered
          - countersBegin.messages_bytes_delivered) * 8)
          / ((double) (diffTimeval.tv_sec * 1000000 + diffTimeval.tv_usec)),
      ((double) (diffCPU.tv_sec * 1000000 + diffCPU.tv_usec)
          / (double) (diffTimeval.tv_sec * 1000000 + diffTimeval.tv_usec)));

  // Termination phase
  rc = trTerminate();
  if (rc < 0) {
    trError_at_line(rc, trErrno, __FILE__, __LINE__, "tr_init()");
    exit(EXIT_FAILURE);
  }
  exit(EXIT_SUCCESS);

  return NULL ;
}
Exemple #4
0
int main(int argc, char *argv[]){

#ifdef INSERTION_TEST

  int rc;
  int rankMessage = 0;
  pthread_t timeKeeperThread;

  if (argc != 7) {
    printf("%s wagonMaxLen size interval participantNumber trainsNumber position\n", argv[0]);
    printf("\t- wagonMaxLen is the maximum size of wagons\n");
    printf("\t- size is the size of messages (should be more than %lu)\n", sizeof(int));
    printf("\t- interval is the time (in seconds) between each event during the experience\n");
    printf("\t- participantNumber is the number of participant during the experience\n");
    printf("\t- trainsNumber is the number of trains during the experience\n");
    printf("\t- position is the position of the participant during the experience (first one has position number 1, NOT 0)\n");
    return EXIT_FAILURE;
  }

  // We initialize the different variables which will be used
  wagonMaxLen = atoi(argv[1]);
  size = atoi(argv[2]);
  if (size < sizeof(int)){
    printf("size should be more than sizeof(int) = %zu\n", sizeof(int));
  }
  interval = atoi(argv[3]);
  participantNumber = atoi(argv[4]);
  trainsNumber = atoi(argv[5]);
  position = atoi(argv[6]);

  /* We wait a number of sec between insertion */
  int delay = (position - 1) * interval;
  if (delay > 0) {
    printf("%d sec before insertion\n", delay);
    usleep(delay * 1000000);
  }

  // We create the timeKeeper thread
  rc = pthread_create(&timeKeeperThread, NULL, timeKeeper, NULL );
  if (rc < 0)
    ERROR_AT_LINE(EXIT_FAILURE, rc, __FILE__, __LINE__, "pthread_create");
  rc = pthread_detach(timeKeeperThread);
  if (rc < 0)
    ERROR_AT_LINE(EXIT_FAILURE, rc, __FILE__, __LINE__, "pthread_detach");

  // We initialize the trains protocol
  rc = trInit(trainsNumber, wagonMaxLen, 0, 0, callbackCircuitChange, callbackODeliver, UNIFORM_TOTAL_ORDER);
  if (rc < 0) {
    trError_at_line(rc, trErrno, __FILE__, __LINE__, "trInit()");
    return EXIT_FAILURE;
  }

  // Process sends messages
  while (!terminate) {
    message *mp = newmsg(size);
    if (mp == NULL ) {
      trError_at_line(rc, trErrno, __FILE__, __LINE__, "newmsg()");
      return EXIT_FAILURE;
    }
    rankMessage++;
    *((int*) (mp->payload)) = rankMessage;
    if (oBroadcast(TEST_MESSAGE, mp) < 0) {
      trError_at_line(rc, trErrno, __FILE__, __LINE__, "oBroadcast()");
      return EXIT_FAILURE;
    }
  }

  rc = trTerminate();
  if (rc < 0) {
    trError_at_line(rc, trErrno, __FILE__, __LINE__, "trInit()");
    return EXIT_FAILURE;
  }

#else /* INSERTION_TEST */

  printf("To run insertion duration tests, you have to compile with the tests target\n");

#endif /* INSERTION_TEST */

  return EXIT_SUCCESS;
}