void start(void) { volatile int checker = 0; /* This variable checks that you correctly gave the child process a new stack. */ pid_t p; int status; app_printf("About to start a new process...\n"); p = sys_fork(); if (p == 0) run_child(); else if (p > 0) { app_printf("Main process %d!\n", sys_getpid()); do { status = sys_wait(p); //app_printf("W"); } while (status == WAIT_TRYAGAIN); app_printf("Child %d exited with status %d!\n", p, status); // Check whether the child process corrupted our stack. // (This check doesn't find all errors, but it helps.) if (checker != 0) { app_printf("Error: stack collision!\n"); sys_exit(1); } else sys_exit(0); } else { app_printf("Error!\n"); sys_exit(1); } }
char* initialize ( char* cmdline ) { // Get comnmand line std::string str = cmdline; std::vector<std::string> args; while ( str.length() > 0) { args.push_back ( strSplit ( str, " " ) ); } fileName = ""; for (int n=0; n < args.size(); n++ ) { if ( args[n].compare ( "-f" ) == 0 ) { startFrame = strToI ( args[n+1] ); } if ( args[n].compare ( "-d" ) == 0 ) { // max_draw maxDraw = strToI ( args[n+1] ); } if ( args[n].find_first_of ( "." ) != std::string::npos ) { fileName = args[n]; } } if ( fileName.length()== 0 || args.size()==0 ) { app_printf ( "USAGE: state_view [-f #] [-d #] filename.raw\n\n" ); app_printf ( " -f # Start at frame \n" ); app_printf ( " -d # Maximum number of draw calls to read \n" ); _getch(); exit(-1); } for (int n=0; n < 10; n++ ) bShow[n] = true; // Initialize camera cam.setPos ( 0, 0, 1 ); cam.setToPos ( -window_width*3/8, -window_height*3/8, 1 ); cam.updateMatricies (); // Initialize bin and call names setup_bins (); // Load trace file char fname[256]; strcpy ( fname, fileName.c_str() ); load_trace_raw ( fname ); // required init functions init2D ( "arial_12" ); // specify font file (.bin/tga) setText ( 1.0, -0.5 ); // scale by 0.5, kerning adjust -0.5 pixels setview2D ( window_width, window_height ); // draw visualization layer drawMatrix (); PERF_INIT ( false ); // Enable CPU perf (do not require nv-perfmarker DLL) PERF_SET ( false, 2, false, "" ); // Perf CPU?, CPU level, NV Perfmarkers, Log filename return "NVIDIA State Viewer, by Rama Hoetzlein"; // Return Window title }
int check_dependency (command_t cmd, outfile_t head) { if (cmd == NULL || head == NULL) { app_printf("do something"); return -1; } int dependency=0; //dependency_text[i] should be a char* while (cmd -> depend_file->filename != NULL) { outfile_t depend = head; while (depend != outfile_tail) { if cmd -> depend_file->filename == depend->text) { add_to_waitlist(depend->cmd, depend_file->cmd) //(waited command, waiting command) cmd->dependency ++; //has dependency, count+1 break; //跳出子循环; } depend = depend ->next; } } return cmd->dependency; }
void pmain(void) { volatile int checker = 30; /* This variable checks for some common stack errors. */ pid_t p; int i, status; app_printf("About to start a new process...\n"); p = sys_fork(); if (p == 0) { // Check that the kernel correctly copied the parent's stack. check(checker, 30, "new child"); checker = 30 + sys_getpid(); // Yield several times to help test Exercise 3 app_printf("Child process %d!\n", sys_getpid()); for (i = 0; i < 20; i++) sys_yield(); // Check that no one else corrupted our stack. check(checker, 30 + sys_getpid(), "end child"); sys_exit(1000); } else if (p > 0) { // Check that the child didn't corrupt our stack. check(checker, 30, "main parent"); app_printf("Main process %d!\n", sys_getpid()); do { status = sys_wait(p); } while (status == WAIT_TRYAGAIN); app_printf("Child %d exited with status %d!\n", p, status); check(status, 1000, "sys_wait for child"); // Check again that the child didn't corrupt our stack. check(checker, 30, "end parent"); sys_exit(0); } else { app_printf("Error!\n"); sys_exit(1); } }
static void check(int actual_value, int expected_value, const char *type) { if (actual_value != expected_value) { app_printf("Problem at %s (got %d, expected %d)!\n", type, actual_value, expected_value); sys_exit(1); } }
void run_child(void) { int input_counter = counter; counter++; /* Note that all "processes" share an address space, so this change to 'counter' will be visible to all processes. */ app_printf("Process %d lives, counter %d!\n", sys_getpid(), input_counter); sys_exit(input_counter); }
void start(void) { int x = 0; pid_t p = sys_fork(); if (p == 0) x++; else if (p > 0) sys_wait(p); app_printf("%d",x); sys_exit(0); }
void run_child(void) { int i; volatile int checker = 1; /* This variable checks that you correctly gave this process a new stack. If the parent's 'checker' changed value after the child ran, there's a problem! */ app_printf("Child process %d!\n", sys_getpid()); // Yield a couple times to help people test Exercise 3 for (i = 0; i < 20; i++) sys_yield(); sys_exit(1000); }
void run_child(void) { int input_counter = counter; counter++; /* Note that all "processes" share an address space, so this change to 'counter' will be visible to all processes. */ pid_t curpid = sys_getpid(); if(curpid % 2==0) { int i=3; for(;i<NPROCS; i += 2) sys_kill(i); } app_printf("Process %d lives, counter %d!\n", sys_getpid(), input_counter); sys_exit(input_counter); }
void run_child(void) { int input_counter = counter; counter++; /* Note that all "processes" share an address space, so this change to 'counter' will be visible to all processes. */ // int pid = sys_getpid(); // if(pid % 2 == 0) // { //even number // int i; // for( i = 3; i< NPROCS; i += 2) // sys_kill(i); // } app_printf("Process %d lives, counter %d!\n", sys_getpid(), input_counter); sys_exit(input_counter); }
void run_child(void) { int input_counter = counter; counter++; /* Note that all "processes" share an address space, so this change to 'counter' will be visible to all processes. */ if (NPROCS != 1 && ((sys_getpid() % 2) == 0)) { int i = 3; while (i < NPROCS) { int killed_pid = sys_kill(i); i = i + 2; } } app_printf("Process %d lives, counter %d!\n", sys_getpid(), input_counter); sys_exit(input_counter); }
void run_child(void) { int input_counter = counter; counter++; /* Note that all "processes" share an address space, so this change to 'counter' will be visible to all processes. */ // if even# process, kill off odd# processes (except for thread 1) if ((sys_getpid() % 2) == 0 && NPROCS > 2) { int pid; for (pid = 3; pid < NPROCS; pid += 2) { int result = sys_kill(pid); } } app_printf("Process %d lives, counter %d!\n", sys_getpid(), input_counter); sys_exit(input_counter); }
void load_trace_raw ( char* fname ) { unsigned long totalBytes = getFileSize ( fname ); unsigned long currBytes = 0; FILE* fp = fopen ( fname, "rb" ); char header[2048]; char buf[2048]; Call cl; Event e; char typ, nameID; unsigned long long tstart, tstop; int fnum, size = 0; int cstart = 0, cnum = 0; mMaxSize = 1; int num_frame = 0; int num_draw = 0; Frame f; f.clear (); frame = 0; while ( !feof(fp) && (num_draw < maxDraw || maxDraw==0)) { readbytes ( header, 18, 1, fp ); // 18 byte header parseHeader ( header, typ, nameID, tstart, tstop ); switch ( typ ) { case 'C': { readbytes ( buf, 20, 1, fp ); if ( num_frame >= startFrame ) { parseTrace ( buf, nameID, cl ); mCalls.push_back ( cl ); cnum++; } } break; case 'D': { currBytes = getFilePos ( fp ); if ( f.totalDraw % 100 == 0 ) { if ( maxDraw == 0 ) { app_printf ( "%dk read, %.2f%% of file, %.2f%% done\n", currBytes/1024, currBytes*100.0f/totalBytes, currBytes*100.0f/totalBytes ); } else { app_printf ( "%dk read, %.2f%% of file, %.2f%% done\n", currBytes/1024, currBytes*100.0f/totalBytes, num_draw*100.0f/maxDraw ); } } readbytes ( buf, NUM_BIN*9 + 9, 1, fp ); if ( num_frame >= startFrame ) { parseTrace ( buf, nameID, e ); e.frame = frame; e.call_num = cnum; e.call_start = cstart; mEvents.push_back ( e ); cstart += cnum; cnum = 0; if ( e.bin_size[BIN_DRAW] > mMaxSize ) mMaxSize = e.bin_size[BIN_DRAW]; if ( e.bin_id[BIN_DRAW] > mMaxPrim ) mMaxPrim = e.bin_id[BIN_DRAW]; num_draw++; for (int n=0; n < NUM_BIN; n++) { f.binChange[n] += (e.bin_change[n]==BIN_CREATE || e.bin_change[n]==BIN_CHANGE) ? 1 : 0; f.binSwitch[n] += (e.bin_change[n]==BIN_SWITCH ) ? 1 : 0; f.binReuse[n] += (e.bin_change[n]==BIN_REUSE ) ? 1 : 0; f.binUnique[n] = (e.bin_id[n] > f.binUnique[n] ) ? e.bin_id[n] : f.binUnique[n]; } f.totalDraw++; f.totalTransfer += e.bin_size[BIN_DRAW]; f.totalPrim += e.bin_id[BIN_DRAW]; } } break; case 'F': { readbytes ( buf, 8, 1, fp ); if ( num_frame >= startFrame ) { mFrames.push_back ( f ); // record frame data f.clear (); frame++; parseTrace ( buf, fnum, size ); e.name_id = nameID; e.name = "Present"; e.call_num = cnum; e.call_start = cstart; e.count = 1; for (int n=0; n < NUM_BIN; n++ ) { e.bin_id[n] = -1; e.bin_change[n] = -1; } mEvents.push_back ( e ); cstart += cnum; cnum = 0; } num_frame++; } break; }; } // read may not have gotten to end of frame mFrames.push_back ( f ); if ( mFrames.size() == 0 || mEvents.size() == 0 ) { app_printf ( "Error: No frames or events detected.\n" ); app_printf ( "Try running trace again. \n" ); _getch(); exit(-1); } fclose ( fp ); }