static int cmd_cksum_bench(int argc, const cmd_args *argv) { #define BUFSIZE 0x1000 #define ITER 16384 void *buf = malloc(BUFSIZE); if (!buf) return -1; bigtime_t t; uint32_t crc; t = current_time_hires(); crc = 0; for (int i = 0; i < ITER; i++) { crc = crc32(crc, buf, BUFSIZE); } t = current_time_hires() - t; printf("took %llu usecs to crc32 %d bytes (%lld bytes/sec)\n", t, BUFSIZE * ITER, (BUFSIZE * ITER) * 1000000ULL / t); thread_sleep(500); t = current_time_hires(); crc = 0; for (int i = 0; i < ITER; i++) { crc = adler32(crc, buf, BUFSIZE); } t = current_time_hires() - t; printf("took %llu usecs to adler32 %d bytes (%lld bytes/sec)\n", t, BUFSIZE * ITER, (BUFSIZE * ITER) * 1000000ULL / t); free(buf); return 0; }
void spin(uint32_t usecs) { bigtime_t start = current_time_hires(); while ((current_time_hires() - start) < usecs) ; }
static enum handler_return threadload(struct timer *t, lk_time_t now, void *arg) { static struct thread_stats old_stats; static lk_bigtime_t last_idle_time; lk_bigtime_t idle_time = thread_stats.idle_time; if (get_current_thread()->priority == IDLE_PRIORITY) { idle_time += current_time_hires() - thread_stats.last_idle_timestamp; } lk_bigtime_t delta_time = idle_time - last_idle_time; lk_bigtime_t busy_time = 1000000ULL - (delta_time > 1000000ULL ? 1000000ULL : delta_time); uint busypercent = (busy_time * 10000) / (1000000); // printf("idle_time %lld, busytime %lld\n", idle_time - last_idle_time, busy_time); printf("LOAD: %d.%02d%%, cs %d, ints %d, timer ints %d, timers %d\n", busypercent / 100, busypercent % 100, thread_stats.context_switches - old_stats.context_switches, thread_stats.interrupts - old_stats.interrupts, thread_stats.timer_ints - old_stats.timer_ints, thread_stats.timers - old_stats.timers); old_stats = thread_stats; last_idle_time = idle_time; return INT_NO_RESCHEDULE; }
static enum handler_return threadload(struct timer *t, time_t now, void *arg) { static struct thread_stats old_stats; static bigtime_t last_idle_time; timer_set_oneshot(t, 1000, &threadload, NULL); bigtime_t idle_time = thread_stats.idle_time; if (current_thread == idle_thread) { idle_time += current_time_hires() - thread_stats.last_idle_timestamp; } bigtime_t busy_time = 1000000ULL - (idle_time - last_idle_time); uint busypercent = (busy_time * 10000) / (1000000); // printf("idle_time %lld, busytime %lld\n", idle_time - last_idle_time, busy_time); printf("LOAD: %d.%02d%%, cs %d, ints %d, timer ints %d, timers %d\n", busypercent / 100, busypercent % 100, thread_stats.context_switches - old_stats.context_switches, thread_stats.interrupts - old_stats.interrupts, thread_stats.timer_ints - old_stats.timer_ints, thread_stats.timers - old_stats.timers); old_stats = thread_stats; last_idle_time = idle_time; return INT_NO_RESCHEDULE; }
static int cmd_cksum_bench(int argc, const cmd_args *argv) { #define BUFSIZE 0x1000 #define ITER 16384 void *buf; bool freebuf; if (argc > 1) { buf = argv[1].p; freebuf = false; } else { buf = malloc(BUFSIZE); freebuf = true; } if (!buf) return -1; lk_bigtime_t t; uint32_t crc; printf("buffer at %p, size %u\n", buf, BUFSIZE); t = current_time_hires(); crc = 0; for (int i = 0; i < ITER; i++) { crc = crc32(crc, buf, BUFSIZE); } t = current_time_hires() - t; printf("took %llu usecs to crc32 %d bytes (%lld bytes/sec)\n", t, BUFSIZE * ITER, (BUFSIZE * ITER) * 1000000ULL / t); thread_sleep(500); t = current_time_hires(); crc = 0; for (int i = 0; i < ITER; i++) { crc = adler32(crc, buf, BUFSIZE); } t = current_time_hires() - t; printf("took %llu usecs to adler32 %d bytes (%lld bytes/sec)\n", t, BUFSIZE * ITER, (BUFSIZE * ITER) * 1000000ULL / t); if (freebuf) free(buf); return 0; }
void kernel_evlog_add(uintptr_t id, uintptr_t arg0, uintptr_t arg1) { if (kernel_evlog_enable) { uint index = evlog_bump_head(&kernel_evlog); kernel_evlog.items[index] = (uintptr_t)current_time_hires(); kernel_evlog.items[index+1] = (arch_curr_cpu_num() << 16) | id; kernel_evlog.items[index+2] = arg0; kernel_evlog.items[index+3] = arg1; } }
static int preempt_tester(void *arg) { spin(1000000); printf("exiting ts %lld\n", current_time_hires()); atomic_add(&preempt_count, -1); #undef COUNT return 0; }
static int preempt_tester(void *arg) { #define COUNT (8*1024*1024) int i; for (i = 0; i < COUNT; i++) __asm__ volatile("nop"); printf("exiting ts %lld\n", current_time_hires()); atomic_add(&preempt_count, -1); return 0; }
static enum handler_return threadload(struct timer *t, lk_time_t now, void *arg) { static struct thread_stats old_stats[SMP_MAX_CPUS]; static lk_bigtime_t last_idle_time[SMP_MAX_CPUS]; for (uint i = 0; i < SMP_MAX_CPUS; i++) { /* dont display time for inactiv cpus */ if (!mp_is_cpu_active(i)) continue; lk_bigtime_t idle_time = thread_stats[i].idle_time; /* if the cpu is currently idle, add the time since it went idle up until now to the idle counter */ bool is_idle = !!mp_is_cpu_idle(i); if (is_idle) { idle_time += current_time_hires() - thread_stats[i].last_idle_timestamp; } lk_bigtime_t delta_time = idle_time - last_idle_time[i]; lk_bigtime_t busy_time = 1000000ULL - (delta_time > 1000000ULL ? 1000000ULL : delta_time); uint busypercent = (busy_time * 10000) / (1000000); printf("cpu %u LOAD: " "%u.%02u%%, " "cs %lu, " "pmpts %lu, " #if WITH_SMP "rs_ipis %lu, " #endif "ints %lu, " "tmr ints %lu, " "tmrs %lu\n", i, busypercent / 100, busypercent % 100, thread_stats[i].context_switches - old_stats[i].context_switches, thread_stats[i].preempts - old_stats[i].preempts, #if WITH_SMP thread_stats[i].reschedule_ipis - old_stats[i].reschedule_ipis, #endif thread_stats[i].interrupts - old_stats[i].interrupts, thread_stats[i].timer_ints - old_stats[i].timer_ints, thread_stats[i].timers - old_stats[i].timers); old_stats[i] = thread_stats[i]; last_idle_time[i] = idle_time; } return INT_NO_RESCHEDULE; }
static int cmd_threadstats(int argc, const cmd_args *argv) { printf("thread stats:\n"); printf("\ttotal idle time: %lld\n", thread_stats.idle_time); printf("\ttotal busy time: %lld\n", current_time_hires() - thread_stats.idle_time); printf("\treschedules: %d\n", thread_stats.reschedules); printf("\tcontext_switches: %d\n", thread_stats.context_switches); printf("\tpreempts: %d\n", thread_stats.preempts); printf("\tyields: %d\n", thread_stats.yields); printf("\tinterrupts: %d\n", thread_stats.interrupts); printf("\ttimer interrupts: %d\n", thread_stats.timer_ints); printf("\ttimers: %d\n", thread_stats.timers); return 0; }
static int cmd_threadstats(int argc, const cmd_args *argv) { for (uint i = 0; i < SMP_MAX_CPUS; i++) { if (!mp_is_cpu_active(i)) continue; printf("thread stats (cpu %d):\n", i); printf("\ttotal idle time: %lld\n", thread_stats[i].idle_time); printf("\ttotal busy time: %lld\n", current_time_hires() - thread_stats[i].idle_time); printf("\treschedules: %lu\n", thread_stats[i].reschedules); #if WITH_SMP printf("\treschedule_ipis: %lu\n", thread_stats[i].reschedule_ipis); #endif printf("\tcontext_switches: %lu\n", thread_stats[i].context_switches); printf("\tpreempts: %lu\n", thread_stats[i].preempts); printf("\tyields: %lu\n", thread_stats[i].yields); printf("\tinterrupts: %lu\n", thread_stats[i].interrupts); printf("\ttimer interrupts: %lu\n", thread_stats[i].timer_ints); printf("\ttimers: %lu\n", thread_stats[i].timers); } return 0; }
void clock_tests(void) { uint32_t c; lk_time_t t; lk_bigtime_t t2; thread_sleep(100); c = arch_cycle_count(); t = current_time(); c = arch_cycle_count() - c; printf("%u cycles per current_time()\n", c); thread_sleep(100); c = arch_cycle_count(); t2 = current_time_hires(); c = arch_cycle_count() - c; printf("%u cycles per current_time_hires()\n", c); printf("making sure time never goes backwards\n"); { printf("testing current_time()\n"); lk_time_t start = current_time(); lk_time_t last = start; for (;;) { t = current_time(); //printf("%lu %lu\n", last, t); if (TIME_LT(t, last)) { printf("WARNING: time ran backwards: %lu < %lu\n", last, t); } last = t; if (last - start > 5000) break; } } { printf("testing current_time_hires()\n"); lk_bigtime_t start = current_time_hires(); lk_bigtime_t last = start; for (;;) { t2 = current_time_hires(); //printf("%llu %llu\n", last, t2); if (t2 < last) { printf("WARNING: time ran backwards: %llu < %llu\n", last, t2); } last = t2; if (last - start > 5000000) break; } } printf("making sure current_time() and current_time_hires() are always the same base\n"); { lk_time_t start = current_time(); for (;;) { t = current_time(); t2 = current_time_hires(); if (t > (t2 / 1000)) { printf("WARNING: current_time() ahead of current_time_hires() %lu %llu\n", t, t2); } if (t - start > 5000) break; } } printf("counting to 5, in one second intervals\n"); for (int i = 0; i < 5; i++) { thread_sleep(1000); printf("%d\n", i + 1); } printf("measuring cpu clock against current_time_hires()\n"); for (int i = 0; i < 5; i++) { uint cycles = arch_cycle_count(); lk_bigtime_t start = current_time_hires(); while ((current_time_hires() - start) < 1000000) ; cycles = arch_cycle_count() - cycles; printf("%u cycles per second\n", cycles); } }