int main(int argc, char **argv) { int n = 20, pid, i, j, h; int time[3]; // time[0] priority1, time[1] priority 2... time[0] = time [1] = time[2] = 0; int retime, rutime, stime; enum priority prio; if(argc > 1) n = atoi(argv[1]); for(i = 0; i < 3*n; ++i){ pid = fork(); if(pid == 0) { // Child set_prio((getpid() % 3)+1); for(j = 0; j < 100; ++j) for(h = 0; h < 1000000; ++h){} exit(); } } while( (pid = wait2(&retime, &rutime, &stime)) > 0 ) { prio = pid % 3; // To know which priority the child has printf(1, "process id: %d, priority: %s \n", pid, get_prio_name(prio)); printf(1, "Time it took to complete: %d \n", rutime + retime + stime); time[prio] += rutime + retime + stime ; } turnaroundtime(PRIO_1, n, time[PRIO_1]); turnaroundtime(PRIO_2, n, time[PRIO_2]); turnaroundtime(PRIO_3, n, time[PRIO_3]); exit(); }
template<> OS_PROCESS void TDebugProc::exec() { const timeout_t sleep_time = 200; const uint8_t report_period = 1000 / sleep_time; const uint32_t baud = 115200UL; const uint32_t divider = (F_CPU + 8 * baud) / (16 * baud) - 1; UCSR0B = 0; UCSR0A = 0; UCSR0C = (1 << UCSZ01) | (1 << UCSZ00); UBRR0H = divider >> 8; UBRR0L = divider; UCSR0B = (1 << RXEN0) | (1 << TXEN0); FILE uart_file; fdev_setup_stream( &uart_file, uart_putc, NULL, _FDEV_SETUP_WRITE); stdout = &uart_file; // Reset VT100 properties, clear screen and go home, print sample header printf_P(PSTR("\x1B" "c" "\x1B[2J" "\tscmRTOS: 4-Debug sample\n" "Prio ")); for(uint8_t i = 0; i < OS::PROCESS_COUNT; i++) { printf_P(PSTR("%7s"), get_prio_name(i)); } for (;;) { uint8_t report_div = report_period; do { sleep(sleep_time); } while(--report_div); profiler.process_data(); // Go to 3'd line, clear to end of screen and print statistics printf_P(PSTR("\x1B[3;1H" "\x1B[J" "Stack")); for(uint8_t i = 0; i < OS::PROCESS_COUNT; i++) { unsigned stack = OS::get_proc(i)->stack_slack() * sizeof(stack_item_t); printf_P(PSTR("%7u"), stack); } printf_P(PSTR("\nCPU %%")); for(uint8_t i = 0; i < OS::PROCESS_COUNT; i++) { unsigned cpu = profiler.get_result(i); printf_P(PSTR("%4u.%02u"), cpu/100, cpu%100); } } } // TProc4::exec()
void statistics(enum priority prio, int n, int time, const char * test_group){ printf(1, "Average %s for %s is %d \n", test_group, get_prio_name(prio), time/n); }