/* A work in progress, hope to have a smoothly rotating curser and count as first test of vsync */ /* Done. works pretty good now, and simplified a few things as well */ /* curser rotates 60 times a second along with vsync */ #include /* where does O_RDWR come from? */ #include /* where does stderr come from? */ #include /* where does stderr come from? */ #include /* where SIGINT lives */ #include /* where close lives */ #include /* where errno lives */ #include /* where _IOWR lives */ #include /* where rdtscll lives */ #define __user #include "/usr/src/linux/drivers/char/drm/drm.h" /* all the drm ioctls and structures */ #include "vsync.h" /* where vsync stuff lives */ int dri_fd = -1; #ifdef RUNVSYNC int main() { unsigned long long int lasttick, thistick, ticks, maxval = 0, minval = ~0, total = 0, meanval; int count = 1; if (dri_init() == -1) { printf("can't open dri device\n"); exit(1); } signal(SIGINT, (__sighandler_t) dri_close); dri_vblank(); rdtscll(lasttick); for (;;) { /* note: need to use fprintf, as printf will cache and only really print every once in a while */ dri_vblank(); rdtscll(thistick); ticks = thistick - lasttick; lasttick = thistick; maxval = (maxval > ticks) ? maxval : ticks; minval = (minval < ticks) ? minval : ticks; total += ticks; meanval = total / count; fprintf(stderr, "\\:%i\t:%llu\t:%llu\t:%llu\t:%llu \r", count++, ticks, maxval, minval, meanval); dri_vblank(); rdtscll(thistick); ticks = thistick - lasttick; lasttick = thistick; maxval = (maxval > ticks) ? maxval : ticks; minval = (minval < ticks) ? minval : ticks; total += ticks; meanval = total / count; fprintf(stderr, "|:%i\t:%llu\t:%llu\t:%llu\t:%llu \r", count++, ticks, maxval, minval, meanval); dri_vblank(); rdtscll(thistick); ticks = thistick - lasttick; lasttick = thistick; maxval = (maxval > ticks) ? maxval : ticks; minval = (minval < ticks) ? minval : ticks; total += ticks; meanval = total / count; fprintf(stderr, "/:%i\t:%llu\t:%llu\t:%llu\t:%llu \r", count++, ticks, maxval, minval, meanval); dri_vblank(); rdtscll(thistick); ticks = thistick - lasttick; lasttick = thistick; maxval = (maxval > ticks) ? maxval : ticks; minval = (minval < ticks) ? minval : ticks; total += ticks; meanval = total / count; fprintf(stderr, "-:%i\t:%llu\t:%llu\t:%llu\t:%llu \r", count++, ticks, maxval, minval, meanval); } } #endif /* RUNVSYNC */ int dri_init(void) { dri_fd = open ("/dev/dri/card0", O_RDWR); return (dri_fd); } void dri_close(void) { fprintf(stderr, "\nShutting down!\n"); if (dri_fd != -1) close(dri_fd); exit(0); } void dri_vblank(void) { int ret; drm_wait_vblank_t vbl; vbl.request.type = _DRM_VBLANK_RELATIVE; vbl.request.sequence = 1; do { ret = ioctl( dri_fd, DRM_IOCTL_WAIT_VBLANK, &vbl ); /* vbl.request.type &= ~_DRM_VBLANK_RELATIVE; */ vbl.request.type = (drm_vblank_seq_type_t) (vbl.request.type & ~_DRM_VBLANK_RELATIVE); } while (ret && errno == EINTR); return; }