void sim_PIPELINE_MT4 (int argc, char **argv, Processor *P, Thread *T0, unsigned CycleCount) { Thread * T1= Thread_dup (T0, "T1"); Thread * T2= Thread_dup (T0, "T2"); Thread * T3= Thread_dup (T0, "T3"); PIPE *PP0 = PIPE_init (T0); PIPE *PP1 = PIPE_init (T1); PIPE *PP2 = PIPE_init (T2); PIPE *PP3 = PIPE_init (T3); PIPE *PP; unsigned CYCLE = 0; int NO_ISSUE=0, turn=0; // thread 0 starts with priority int PC, classID, PIPE_avail; int seed = 0; if (argc>1) { P->PIPE_width = atoll(argv[1]); } if (argc>2) { seed = atoll(argv[2]); } srand(seed); for (; CYCLE < CycleCount; CYCLE++) { printf("%3d ", CYCLE); Processor_reset( P ); PIPE_avail= P->PIPE_width; // round-robin priority: do nothing // random priority at the beginning, then round-robin turn = rand()%4; switch (turn) { case 0: PP=PP0; break; case 1: PP=PP1; break; case 2: PP=PP2; break; case 3: PP=PP3; break; } NO_ISSUE = 0; // init exit condition while (PIPE_avail && NO_ISSUE < 4) { PC = Thread_getPC (PP->T); classID = Thread_getClassID ( PP->T, PC ); if ( Processor_checkResource ( P, classID ) && PIPE_check (PP, PC, CYCLE)) { PIPE_setFinished (PP, PC, CYCLE + Processor_getLatency ( P, Thread_getOpID( PP->T, PC ) )); Processor_consumeResource ( P, classID ); output_thread ( P, PP->T, PC ); Thread_next (PP->T); PIPE_avail--; NO_ISSUE = 0; // init exit condition } else NO_ISSUE++; // avoid deadilock situation // Round-Robin policy for next turns turn++; if (turn>3) turn=0; switch (turn) { case 0: PP=PP0; break; case 1: PP=PP1; break; case 2: PP=PP2; break; case 3: PP=PP3; break; } } while (PIPE_avail) { output_thread (0, 0, 0); PIPE_avail--; } printf("\n"); } printf ("\n\nProcessor: In-Order PIPELINE(%d) x 4 H/W Threads (random policy each cycle, then round-robin)\n", P->PIPE_width); printf ("CPI: %f IPC: %f T0: %d T1: %d T2: %d T3: %d\n\n", ((float) CycleCount) / (T0->ICount+T1->ICount+T2->ICount+T3->ICount), ((float) T0->ICount+T1->ICount+T2->ICount+T3->ICount) / CycleCount, T0->ICount, T1->ICount, T2->ICount, T3->ICount); }
DLL_EXPORT int device_output_thread(atransport * t, struct dll_io_bridge * io_bridge) { D("SPAWNED device_output_thread\n"); output_thread((void *)t, io_bridge); return 0; }
void sim_PIPELINE_MT2 (int argc, char **argv, Processor *P, Thread *T0, unsigned CycleCount) { unsigned CYCLE = 0; int NO_ISSUE=0, PC, classID, policy=0, PIPE_avail; Thread * T1= Thread_dup (T0, "T1"); PIPE *PP0 = PIPE_init (T0); PIPE *PP1 = PIPE_init (T1); PIPE *PP, *PPmain; if (argc>1) { P->PIPE_width = atoll(argv[1]); } if (argc>2) { policy = atoll(argv[2]); } PP = PPmain = PP0; // Thread 0 starts with priority for (; CYCLE < CycleCount; CYCLE++) { printf("%3d ", CYCLE); Processor_reset( P ); PIPE_avail= P->PIPE_width; if (policy==1) // Last thread executing gains priority PP = PP; // do not change priority else if (policy==2) // Each cycle priority swaps { if (PPmain==PP0) PPmain=PP1; // switch threads else PPmain=PP0; PP = PPmain; } else // Thread 0 always has priority PP = PP0; // thread 0 has priority NO_ISSUE = 0; // init exit condition while (PIPE_avail && NO_ISSUE < 2) { PC = Thread_getPC (PP->T); classID = Thread_getClassID ( PP->T, PC ); if ( Processor_checkResource ( P, classID ) && PIPE_check (PP, PC, CYCLE)) { PIPE_setFinished (PP, PC, CYCLE + Processor_getLatency ( P, Thread_getOpID( PP->T, PC ) )); Processor_consumeResource ( P, classID ); output_thread ( P, PP->T, PC ); Thread_next (PP->T); PIPE_avail--; NO_ISSUE = 0; // init exit condition } else NO_ISSUE++; // avoid deadlock situation if (PP==PP0) PP=PP1; // switch threads else PP=PP0; } while (PIPE_avail) { output_thread (0, 0, 0); PIPE_avail--; } printf("\n"); } printf ("\n\nProcessor: In-Order PIPELINE(%d) x 2 H/W Threads (", P->PIPE_width); switch (policy) { case 0: printf("Thread 0 always first - then round-robin"); break; case 1: printf("Last thread executing always first - then round-robin"); break; case 2: printf("Swap first thread - then round-robin"); break; } printf (")\n"); printf ("CPI: %f IPC: %f T0-ICount: %d T1-ICount: %d\n\n", ((float) CycleCount) / (T0->ICount+T1->ICount), ((float) T0->ICount + T1->ICount) / CycleCount, T0->ICount, T1->ICount); }
int main(int argc, char **argv) { int dirn; struct stat stat_buf; char *spool; char *file; int i; int found = 1; dirn = parse_args(argc, argv); if (signal(SIGHUP, closedown) == SIG_ERR) { perror("Signal"); exit(1); } if (signal(SIGINT, closedown) == SIG_ERR) { perror("Signal"); exit(1); } if (input_conf) { inhibit_thread_flattening = 1; } /* Initialize key/data structures. */ init(); time(&start_time); if (do_output_thread) { // First output_thread(stdout, find_node("*****@*****.**"), 0); // Second //output_thread(stdout, find_node("*****@*****.**"), 0); //output_threads("gmane.discuss"); exit(0); } if (lock_user != NULL) lock_and_uid(lock_user); if (input_spool) { spool = cmalloc(strlen(news_spool) + 1); memcpy(spool, news_spool, strlen(news_spool)); inhibit_thread_flattening = 1; inhibit_file_writes = 0; *(spool+strlen(news_spool)-1) = 0; //input_directory("/mirror/var/spool/news/articles/gmane/comp/lib/glibc/bugs"); //input_directory("/mirror/var/spool/news/articles/gmane/comp/gnu/stow/bugs"); //input_directory("/mirror/var/spool/news/articles/gmane/linux"); //input_directory("/mirror/var/spool/news/articles/gmane/discuss"); //input_directory("/mirror/var/spool/news/articles/gmane/test"); //input_directory("/mirror/var/spool/news/articles/gmane/comp/graphics/ipe/general"); //input_directory(spool); input_directory("/mirror/var/spool/news/articles/gmane/comp/hardware", 1); flush(); clean_up(); clean_up_hash(); printf("Total files: %d, total nodes: %d\n", commands, current_node); exit(0); } if (input_conf) { if (skip_until_group != NULL) found = 0; inhibit_thread_flattening = 1; inhibit_file_writes = 0; for (i = 1; i < num_groups; i++) { if (found == 0 && !strcmp(get_string(groups[i].group_name), skip_until_group)) found = 1; if (found == 1) input_group(get_string(groups[i].group_name)); } flush(); clean_up(); clean_up_hash(); printf("Total files: %d, total nodes: %d\n", commands, current_node); exit(0); } if (dirn == 1) file = "/mirror/var/spool/news/articles/gmane/discuss/4001"; else file = argv[dirn]; if (stat(file, &stat_buf) == -1) { perror("interactive"); exit(0); } if (S_ISREG(stat_buf.st_mode)) thread_file(file); flush(); clean_up(); clean_up_hash(); exit(0); }