X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;f=bertos%2Fbenchmark%2Fcontext_switch.c;h=12298892a9c9bfebd15724ded8674b52d65e149f;hb=362204d3e1aabcfde4877219d5ea3406e2d6f9ef;hp=92d9d9dcd8e58894a906448554251959bd9b1006;hpb=8e9b1ada815064b18774695225d12986bc36bb10;p=bertos.git diff --git a/bertos/benchmark/context_switch.c b/bertos/benchmark/context_switch.c index 92d9d9dc..12298892 100644 --- a/bertos/benchmark/context_switch.c +++ b/bertos/benchmark/context_switch.c @@ -47,57 +47,50 @@ #include #include +#if CONFIG_USE_HP_TIMER #include +static Serial out; +#endif #include -#define PROC_STACK_SIZE 1024 +#define PROC_STACK_SIZE KERN_MINSTACKSIZE static PROC_DEFINE_STACK(hp_stack, PROC_STACK_SIZE); static PROC_DEFINE_STACK(lp_stack, PROC_STACK_SIZE); static Process *hp_proc, *lp_proc, *main_proc; -Serial out; - #if CONFIG_USE_HP_TIMER - static hptime_t start, end; - #endif static void NORETURN hp_process(void) { - proc_setPri(hp_proc, 2); - while (1) { sig_wait(SIG_USER0); - #if CONFIG_USE_HP_TIMER - end = timer_clock_hp(); - #endif #if CONFIG_USE_LED LED_ON(); #endif - timer_delay(100); - sig_send(main_proc, SIG_USER1); + #if CONFIG_USE_HP_TIMER + end = timer_hw_hpread(); + #endif + sig_send(main_proc, SIG_USER0); } } static void NORETURN lp_process(void) { - proc_setPri(lp_proc, 1); - while (1) { - sig_wait(SIG_USER1); - #if CONFIG_USE_HP_TIMER - start = timer_clock_hp(); - #endif + sig_wait(SIG_USER0); #if CONFIG_USE_LED LED_ON(); LED_OFF(); #endif - + #if CONFIG_USE_HP_TIMER + start = timer_hw_hpread(); + #endif sig_send(hp_proc, SIG_USER0); } } @@ -109,27 +102,35 @@ void NORETURN context_switch(void) timer_init(); proc_init(); - ser_init(&out, CONFIG_CTX_DEBUG_PORT); - ser_setbaudrate(&out, CONFIG_CTX_DEBUG_BAUDRATE); + #if CONFIG_USE_HP_TIMER + ser_init(&out, CONFIG_CTX_DEBUG_PORT); + ser_setbaudrate(&out, CONFIG_CTX_DEBUG_BAUDRATE); + #endif #if CONFIG_USE_LED LED_INIT(); #endif + proc_forbid(); hp_proc = proc_new(hp_process, NULL, PROC_STACK_SIZE, hp_stack); lp_proc = proc_new(lp_process, NULL, PROC_STACK_SIZE, lp_stack); main_proc = proc_current(); + proc_setPri(hp_proc, 2); + proc_setPri(lp_proc, 1); + proc_permit(); while (1) { + timer_delay(100); + + sig_send(lp_proc, SIG_USER0); + sig_wait(SIG_USER0); + #if CONFIG_USE_HP_TIMER - kfile_printf(&out.fd, "Switch: %lu.%lu usec\n", - hptime_to_us((end - start)), - hptime_to_us((end - start) * 1000) % 1000); + kfile_printf(&out.fd, + "Switch: %lu.%lu usec\n\r", + hptime_to_us((end - start)), + hptime_to_us((end - start) * 1000) % 1000); #endif - - sig_send(lp_proc, SIG_USER1); - sig_wait(SIG_USER1); } - }