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; }
void trainHandling(womim *p_womim) { int id = p_womim->msg.body.train.stamp.id; int round = p_womim->msg.body.train.stamp.round; wagon *p_wag; counters.recent_trains_received++; counters.recent_trains_bytes_received += p_womim->msg.len; //printf("TRAIN id=%d\n", id); if (round == lts[id].stamp.round) { round = (round + 1) % nbRounds; } if (requiredOrder != CAUSAL_ORDER) { // Thus (requiredOrder == TOTAL_ORDER) || (requiredOrder == UNIFORM_TOTAL_ORDER)) bqueueExtend(wagonsToDeliver, unstableWagons[id][(round + 1) % nbRounds]); cleanList(unstableWagons[id][(round + 1) % nbRounds]); } if (id == 0) { lts[0].circuit = addrUpdateCircuit(p_womim->msg.body.train.circuit, myAddress, cameProc, goneProc); cameProc = 0; signalDepartures(goneProc, lts[0].circuit, false); goneProc = 0; } else { lts[id].circuit = lts[0].circuit; } releaseWiw(&(lts[id].w.w_w)); lts[id].w.len = 0; freeWiw(lts[id].p_wtosend); lts[id].p_wtosend = NULL; for (p_wag = firstWagon(&(p_womim->msg)); p_wag != NULL ; p_wag = nextWagon(p_womim, p_wag)) { if (addrIsMember(p_wag->header.sender, lts[id].circuit) && !(addrIsMember(p_wag->header.sender, goneProc)) && !(addrIsMine(p_wag->header.sender))) { // We add a wiw (corresponding to this p_wag) to unstableWagons[id][round] // (in case of TOTAL_ORDER or UNIFORM_TOTAL_ORDER) or directly to // wagonsToDeliver (in case of CAUSAL_ORDER) wiw *wi = malloc(sizeof(wiw)); assert(wi != NULL); wi->p_wagon = p_wag; wi->p_womim = p_womim; MUTEX_LOCK(p_womim->pfx.mutex); p_womim->pfx.counter++; MUTEX_UNLOCK(p_womim->pfx.mutex); if (requiredOrder != CAUSAL_ORDER) { // Thus (requiredOrder == TOTAL_ORDER) || (requiredOrder == UNIFORM_TOTAL_ORDER)) listAppend(unstableWagons[id][round], wi); } else { bqueueEnqueue(wagonsToDeliver, wi); } // Shall this wagon be sent to our successor if (!addrIsEqual(succ,p_wag->header.sender)) { // Yes, it must sent if (lts[id].w.w_w.p_wagon == NULL ) { // lts must be updated to point on the first wagon to be sent lts[id].w.w_w.p_wagon = p_wag; lts[id].w.w_w.p_womim = p_womim; MUTEX_LOCK(lts[id].w.w_w.p_womim->pfx.mutex); lts[id].w.w_w.p_womim->pfx.counter++; MUTEX_UNLOCK(lts[id].w.w_w.p_womim->pfx.mutex); } // We adapt len lts[id].w.len += p_wag->header.len; } } } lts[id].stamp.round = (char) round; MUTEX_LOCK(mutexWagonToSend); if (firstMsg(wagonToSend->p_wagon) != NULL ) { wagonToSend->p_wagon->header.round = round; // We add a wiw (corresponding to this p_wag) to wagonToSend wiw *wi = malloc(sizeof(wiw)); assert(wi != NULL); *wi = *wagonToSend; // We do not need to lock wagonToSend->p_wagon->pfx.mutex // as we are for the moment alone to access to // wagonToSend->p_wagon->pfx.counter wagonToSend->p_womim->pfx.counter++; if (requiredOrder != CAUSAL_ORDER) { // Thus (requiredOrder == TOTAL_ORDER) || (requiredOrder == UNIFORM_TOTAL_ORDER)) listAppend(unstableWagons[id][round], wi); } else { bqueueEnqueue(wagonsToDeliver, wi); } lts[id].p_wtosend = wagonToSend; wagonToSend = newWiw(); } MUTEX_UNLOCK(mutexWagonToSend); pthread_cond_signal(&condWagonToSend); lts[id].stamp.lc = p_womim->msg.body.train.stamp.lc + 1; }