static void event(void *cookie) { int err; err = rt_task_set_periodic(NULL, TM_NOW, rt_timer_ns2ticks(sampling_period)); if (err) { warning("failed to enter periodic timing (%s)\n", symerror(err)); return; } for (;;) { err = rt_task_wait_period(NULL); if (err) { if (err != -ETIMEDOUT) exit(EXIT_FAILURE); late++; } switch_count++; err = rt_sem_broadcast(&switch_sem); switch_tsc = rt_timer_tsc(); if (err) { if (err != -EIDRM && err != -EINVAL) warning("failed to broadcast semaphore (%s)\n", symerror(err)); break; } } }
void __traceobj_check_warn(struct traceobj *trobj, const char *file, int line, int received, int expected) { dump_marks_on_error(trobj); warning("wrong return status:\n %s:%d => %s (want %s)", file, line, symerror(received > 0 ? -received : received), symerror(expected > 0 ? -expected : expected)); }
void backtrace_dump(struct backtrace_data *btd) { struct error_frame *ef; FILE *tracefp = stderr; int n = 0; if (btd == NULL) btd = &main_btd; SIGSAFE_LOCK_ENTRY(&__printlock); if (btd->inner == NULL) goto no_error; fprintf(tracefp, "%s\n[ ERROR BACKTRACE: thread %s ]\n\n", dashes, btd->name); for (ef = btd->inner; ef; ef = ef->next, n++) fprintf(tracefp, "%s #%-2d %s in %s(), %s:%d\n", ef->next ? " " : "=>", n, symerror(ef->retval), ef->fn, ef->file, ef->lineno); fputs(dashes, tracefp); fputc('\n', tracefp); fflush(tracefp); flush_backtrace(btd); no_error: SIGSAFE_LOCK_EXIT(&__printlock); }
int main(int argc, char *const *argv) { int err, c; copperplate_init(&argc, &argv); while ((c = getopt(argc, argv, "hp:n:i:")) != EOF) switch (c) { case 'h': /* ./switch --h[istogram] */ do_histogram = 1; break; case 'p': sampling_period = atoi(optarg) * 1000; break; case 'n': nsamples = atoi(optarg); break; case 'i': warmup = atoi(optarg); break; default: fprintf(stderr, "usage: switch [options]\n" "\t-h - enable histogram\n" "\t-p <period_us> - timer period\n" "\t-n <samples> - number of samples to collect\n" "\t-i <samples> - number of _first_ samples to ignore\n"); exit(2); } if (sampling_period == 0) sampling_period = 100000; /* ns */ if (nsamples <= 0) { warning("disregarding -n <%lld>, using -n <100000> " "samples\n", nsamples); nsamples = 100000; } signal(SIGINT, SIG_IGN); signal(SIGTERM, SIG_IGN); setlinebuf(stdout); mlockall(MCL_CURRENT|MCL_FUTURE); printf("== Sampling period: %llu us\n", sampling_period / 1000); printf("== Do not interrupt this program\n"); err = rt_task_create(&worker_task, "worker", 0, 98, 0); if (err) { warning("failed to create WORKER task (%s)\n", symerror(err)); return 1; } err = rt_task_start(&worker_task, &worker, NULL); if (err) { warning("failed to start WORKER task (%s)\n", symerror(err)); return 1; } err = rt_task_create(&event_task, "event", 0, 99, 0); if (err) { warning("failed to create EVENT task (%s)\n", symerror(err)); return 1; } err = rt_task_start(&event_task, &event, NULL); if (err) { warning("failed to start EVENT task (%s)\n", symerror(err)); return 1; } for (;;) pause(); return 0; }
static void worker(void *cookie) { long long minj = 10000000, maxj = -10000000, dt, sumj = 0; unsigned long long count = 0; int err, n; err = rt_sem_create(&switch_sem, "dispsem", 0, S_FIFO); if (err) { warning("failed to create semaphore (%s)\n", symerror(err)); return; } for (n = 0; n < nsamples; n++) { err = rt_sem_p(&switch_sem, TM_INFINITE); if (err) { if (err != -EIDRM && err != -EINVAL) warning("failed to pend on semaphore (%s)\n", symerror(err)); exit(EXIT_FAILURE); } dt = (long) (rt_timer_tsc() - switch_tsc); if (switch_count - count > 1) { lost += switch_count - count; count = switch_count; continue; } if (++count < warmup) continue; if (dt > maxj) maxj = dt; if (dt < minj) minj = dt; sumj += dt; if (do_histogram) add_histogram(dt); } rt_sem_delete(&switch_sem); minjitter = minj; maxjitter = maxj; avgjitter = sumj / n; printf("RTH|%12s|%12s|%12s|%12s\n", "lat min", "lat avg", "lat max", "lost"); printf("RTD|%12.3f|%12.3f|%12.3f|%12lld\n", rt_timer_tsc2ns(minjitter) / 1000.0, rt_timer_tsc2ns(avgjitter) / 1000.0, rt_timer_tsc2ns(maxjitter) / 1000.0, lost); if (late) printf("LATE: %d\n", late); if (do_histogram) dump_histogram(); exit(0); }