Mercurial > cgi-bin > hgwebdir.cgi > PR > Applications > Vthread > Vthread__Best_Effort_Msg__Bench
comparison main.c @ 21:08b37152b48d
cleanup
| author | Merten Sach <msach@mailbox.tu-berlin.de> |
|---|---|
| date | Tue, 13 Mar 2012 19:09:11 +0100 |
| parents | 29b273cf3b1f |
| children |
comparison
equal
deleted
inserted
replaced
| 4:c24d544a2a0a | 5:f4432a43330f |
|---|---|
| 217 return; | 217 return; |
| 218 } | 218 } |
| 219 if(msg == (BROADCAST_ACK) && threadData->broadcasterStatus == RECEIVING_ACK) | 219 if(msg == (BROADCAST_ACK) && threadData->broadcasterStatus == RECEIVING_ACK) |
| 220 { | 220 { |
| 221 threadData->receivedACKs++; | 221 threadData->receivedACKs++; |
| 222 if(threadData->receivedACKs == NUM_CORES/2)//chose next broadcaster | 222 if(threadData->receivedACKs == NUM_CORES-2)//chose next broadcaster |
| 223 { | 223 { |
| 224 do{ | 224 do{ |
| 225 receiverID = randomNumber(&seed1, &seed2) % NUM_CORES; | 225 receiverID = randomNumber(&seed1, &seed2) % NUM_CORES; |
| 226 }while(receiverID == comEndpoint->endpointID); | 226 }while(receiverID == comEndpoint->endpointID); |
| 227 | 227 |
| 235 { | 235 { |
| 236 printf("endpoint %d received termination request\n", comEndpoint->endpointID); | 236 printf("endpoint %d received termination request\n", comEndpoint->endpointID); |
| 237 threadData->terminate = TRUE; | 237 threadData->terminate = TRUE; |
| 238 return; | 238 return; |
| 239 } | 239 } |
| 240 // | 240 //I'm the next broadcaster! |
| 241 threadData->broadcasterStatus = BROADCASTING; | 241 threadData->broadcasterStatus = BROADCASTING; |
| 242 } | 242 } |
| 243 | 243 |
| 244 unsigned int global_broadcast_counter; | 244 unsigned int global_broadcast_counter; |
| 245 | 245 |
| 246 double | 246 double |
| 247 worker_TLF(void* _params, VirtProcr* animatingPr) | 247 worker_TLF(void* _params, VirtProcr* animatingPr) |
| 248 { | 248 { |
| 249 unsigned int msgCounter; | 249 unsigned int msgCounter; |
| 250 unsigned int broadcaster; | |
| 251 uint32_t wait_iterations; | |
| 252 WorkerParams* params = (WorkerParams*)_params; | 250 WorkerParams* params = (WorkerParams*)_params; |
| 253 unsigned int totalWorkCycles = 0, totalBadCycles = 0; | 251 unsigned int totalWorkCycles = 0, totalBadCycles = 0; |
| 254 unsigned int totalSyncCycles = 0, totalBadSyncCycles = 0; | 252 unsigned int totalSyncCycles = 0, totalBadSyncCycles = 0; |
| 255 unsigned int workspace1=0, numGoodSyncs = 0, numGoodTasks = 0; | 253 unsigned int workspace1=0, numGoodSyncs = 0, numGoodTasks = 0; |
| 256 double workspace2=0.0; | 254 double workspace2=0.0; |
| 277 params->centralMsgExchange, | 275 params->centralMsgExchange, |
| 278 params->coreID, | 276 params->coreID, |
| 279 msgHandler, | 277 msgHandler, |
| 280 params); | 278 params); |
| 281 | 279 |
| 282 lossyCom__endpointID_t receiverID; | |
| 283 msgCounter = 0; | 280 msgCounter = 0; |
| 284 while(msgCounter <= num_msg_to_send) | 281 while(msgCounter <= num_msg_to_send) |
| 285 { | 282 { |
| 286 int i; | |
| 287 | |
| 288 if(params->broadcasterStatus == BROADCASTING) | 283 if(params->broadcasterStatus == BROADCASTING) |
| 289 { | 284 { |
| 290 if(msgCounter == num_msg_to_send)//send termination msg | 285 if(msgCounter == num_msg_to_send)//send termination msg |
| 291 { | 286 { |
| 292 lossyCom__sendMsg(&comEndpoint,BROADCAST_ID, TERMINATE); | 287 lossyCom__broadcastMsg(&comEndpoint, TERMINATE); |
| 293 break; | 288 break; |
| 294 }else{ //generate and send random message | 289 }else{ //generate and send random message |
| 295 params->receivedACKs = 0; | 290 params->receivedACKs = 0; |
| 296 lossyCom__sendMsg(&comEndpoint, BROADCAST_ID, BROADCAST); | 291 lossyCom__broadcastMsg(&comEndpoint, BROADCAST); |
| 297 global_broadcast_counter++; | 292 global_broadcast_counter++; |
| 298 if(global_broadcast_counter % 1000 == 0){ | 293 if(global_broadcast_counter % 1000 == 0){ |
| 299 printf("broadcast count: %d\n", global_broadcast_counter); | 294 printf("broadcast count: %d\n", global_broadcast_counter); |
| 300 } | 295 } |
| 301 params->broadcasterStatus = RECEIVING_ACK; //mark msg as send | 296 params->broadcasterStatus = RECEIVING_ACK; //mark msg as send |
| 318 //sanity check (400K is about 20K iters) | 313 //sanity check (400K is about 20K iters) |
| 319 if( numCycles < 400000 ) {totalWorkCycles += numCycles; numGoodTasks++;} | 314 if( numCycles < 400000 ) {totalWorkCycles += numCycles; numGoodTasks++;} |
| 320 else {totalBadCycles += numCycles; } | 315 else {totalBadCycles += numCycles; } |
| 321 #endif | 316 #endif |
| 322 | 317 |
| 318 //wait for all threads to finish | |
| 323 barrier_wait(params->barrier, animatingPr); | 319 barrier_wait(params->barrier, animatingPr); |
| 324 | 320 |
| 325 params->totalWorkCycles = totalWorkCycles; | 321 params->totalWorkCycles = totalWorkCycles; |
| 326 params->totalBadCycles = totalBadCycles; | 322 params->totalBadCycles = totalBadCycles; |
| 327 params->numGoodTasks = numGoodTasks; | 323 params->numGoodTasks = numGoodTasks; |
| 342 | 338 |
| 343 | 339 |
| 344 /* this is run after the VMS is set up*/ | 340 /* this is run after the VMS is set up*/ |
| 345 void benchmark(void *_params, VirtProcr *animatingPr) | 341 void benchmark(void *_params, VirtProcr *animatingPr) |
| 346 { | 342 { |
| 347 int i, cpuID, idx; | 343 int i; |
| 348 struct barrier_t barr; | 344 struct barrier_t barr; |
| 349 BenchParams *params; | 345 BenchParams *params; |
| 350 | 346 |
| 351 params = (BenchParams *)_params; | 347 params = (BenchParams *)_params; |
| 352 | 348 |
| 366 global_broadcast_counter = 0; | 362 global_broadcast_counter = 0; |
| 367 | 363 |
| 368 // init random number generator for wait and msg content | 364 // init random number generator for wait and msg content |
| 369 seed1 = rand()%1000; | 365 seed1 = rand()%1000; |
| 370 seed2 = rand()%1000; | 366 seed2 = rand()%1000; |
| 371 | 367 |
| 368 #ifdef MEASURE_PERF | |
| 372 //save cycles before execution of threads, to get total exe cycles | 369 //save cycles before execution of threads, to get total exe cycles |
| 373 measurement_t *startExeCycles, *endExeCycles; | 370 measurement_t *startExeCycles, *endExeCycles; |
| 374 startExeCycles = params->startExeCycles; | 371 startExeCycles = params->startExeCycles; |
| 375 | 372 |
| 376 #ifdef MEASURE_PERF | 373 |
| 377 int nread = read(cycles_counter_main_fd, &(startExeCycles->cycles), | 374 int nread = read(cycles_counter_main_fd, &(startExeCycles->cycles), |
| 378 sizeof(startExeCycles->cycles)); | 375 sizeof(startExeCycles->cycles)); |
| 379 if(nread<0) perror("Error reading cycles counter"); | 376 if(nread<0) perror("Error reading cycles counter"); |
| 380 #endif | 377 #endif |
| 381 | 378 |
