#include #include #include "callout.h" int iters = 1000; /* how many times to run */ void info(int type, callout_id_t h, char *name) { int n; if (!callout_getstats(h, &n)) n = -1; printf("%s TYPE: %d HANDLE: %d COUNT: %d\n", name, type, (int)h, n); } void clock_func(int type, callout_id_t h, callout_event_closure_t cl) { info(type, h, (char*)cl); } void network_func(int type, callout_id_t h, callout_event_closure_t cl) { info(type, h, (char*)cl); } void disk_func(int type, callout_id_t h, callout_event_closure_t cl) { info(type, h, (char*)cl); } void pagefault_func(int type, callout_id_t h, callout_event_closure_t cl) { info(type, h, (char*)cl); } void tty_func(int type, callout_id_t h, callout_event_closure_t cl) { info(type, h, (char*)cl); } genevent() { iters--; if (iters <= 0) { callout_shutdown(); } return iters % CALLOUT_EVENT_LAST; } void usage(char *p) { fprintf(stderr,"Usage: %s [-i cnt]\n", p); exit(-1); } main(int argc, char **argv) { callout_id_t r; if (argc > 1) { if (strcmp(argv[1], "-i") == 0) { if (argc > 2) { iters = atoi(argv[2]); } else usage(argv[0]); } } r = callout_register(CALLOUT_EVENT_CLOCK, clock_func, strdup("CLOCK")); r = callout_register(CALLOUT_EVENT_NETWORK, network_func, strdup("NETWORK")); r = callout_register(CALLOUT_EVENT_DISK, disk_func, strdup("DISK")); r = callout_register(CALLOUT_EVENT_PAGEFAULT, pagefault_func, strdup("PAGEFAULT")); r = callout_register(CALLOUT_EVENT_TTY, tty_func, strdup("TTY")); /* TIMERS WOULD START HERE */ callout_boot(genevent); /* TIMERS WOULD END HERE */ }