2004-10-26 16:26:09

by John Gilbert

[permalink] [raw]
Subject: svgalib_helper from svgalib-1.9.19 and RTL 2.6.9-mm1-V0.2 lockup

/* 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 <fcntl.h> /* where does O_RDWR come from? */
#include <stdio.h> /* where does stderr come from? */
#include <stdlib.h> /* where does stderr come from? */
#include <signal.h> /* where SIGINT lives */
#include <unistd.h> /* where close lives */
#include <errno.h> /* where errno lives */
#include <sys/ioctl.h> /* where _IOWR lives */
#include <asm-i386/msr.h> /* where rdtscll lives */
#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;
} while (ret && errno == EINTR);
return;
}



Attachments:
vsync.c (2.95 kB)