Back to index

libdrm  2.4.37
Classes | Defines | Functions | Variables
vbltest.c File Reference
#include "config.h"
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <sys/poll.h>
#include <sys/time.h>
#include "xf86drm.h"
#include "xf86drmMode.h"

Go to the source code of this file.

Classes

struct  vbl_info

Defines

#define ARRAY_SIZE(arr)   (sizeof(arr) / sizeof((arr)[0]))

Functions

static void vblank_handler (int fd, unsigned int frame, unsigned int sec, unsigned int usec, void *data)
static void usage (char *name)
int main (int argc, char **argv)

Variables

char * optarg
int optind
int opterr
int optopt
static char optstr [] = "s"
int secondary = 0

Class Documentation

struct vbl_info

Definition at line 63 of file vbltest.c.

Class Members
unsigned int vbl_count

Define Documentation

#define ARRAY_SIZE (   arr)    (sizeof(arr) / sizeof((arr)[0]))

Definition at line 55 of file vbltest.c.


Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 103 of file vbltest.c.

{
       int i, c, fd, ret;
       char *modules[] = { "i915", "radeon", "nouveau", "vmwgfx", "exynos" };
       drmVBlank vbl;
       drmEventContext evctx;
       struct vbl_info handler_info;

       opterr = 0;
       while ((c = getopt(argc, argv, optstr)) != -1) {
              switch (c) {
              case 's':
                     secondary = 1;
                     break;
              default:
                     usage(argv[0]);
                     break;
              }
       }

       for (i = 0; i < ARRAY_SIZE(modules); i++) {
              printf("trying to load module %s...", modules[i]);
              fd = drmOpen(modules[i], NULL);
              if (fd < 0) {
                     printf("failed.\n");
              } else {
                     printf("success.\n");
                     break;
              }
       }

       if (i == ARRAY_SIZE(modules)) {
              fprintf(stderr, "failed to load any modules, aborting.\n");
              return -1;
       }

       /* Get current count first */
       vbl.request.type = DRM_VBLANK_RELATIVE;
       if (secondary)
              vbl.request.type |= DRM_VBLANK_SECONDARY;
       vbl.request.sequence = 0;
       ret = drmWaitVBlank(fd, &vbl);
       if (ret != 0) {
              printf("drmWaitVBlank (relative) failed ret: %i\n", ret);
              return -1;
       }

       printf("starting count: %d\n", vbl.request.sequence);

       handler_info.vbl_count = 0;
       gettimeofday(&handler_info.start, NULL);

       /* Queue an event for frame + 1 */
       vbl.request.type = DRM_VBLANK_RELATIVE | DRM_VBLANK_EVENT;
       if (secondary)
              vbl.request.type |= DRM_VBLANK_SECONDARY;
       vbl.request.sequence = 1;
       vbl.request.signal = (unsigned long)&handler_info;
       ret = drmWaitVBlank(fd, &vbl);
       if (ret != 0) {
              printf("drmWaitVBlank (relative, event) failed ret: %i\n", ret);
              return -1;
       }

       /* Set up our event handler */
       memset(&evctx, 0, sizeof evctx);
       evctx.version = DRM_EVENT_CONTEXT_VERSION;
       evctx.vblank_handler = vblank_handler;
       evctx.page_flip_handler = NULL;

       /* Poll for events */
       while (1) {
              struct timeval timeout = { .tv_sec = 3, .tv_usec = 0 };
              fd_set fds;
              int ret;

              FD_ZERO(&fds);
              FD_SET(0, &fds);
              FD_SET(fd, &fds);
              ret = select(fd + 1, &fds, NULL, NULL, &timeout);

              if (ret <= 0) {
                     fprintf(stderr, "select timed out or error (ret %d)\n",
                            ret);
                     continue;
              } else if (FD_ISSET(0, &fds)) {
                     break;
              }

              ret = drmHandleEvent(fd, &evctx);
              if (ret != 0) {
                     printf("drmHandleEvent failed: %i\n", ret);
                     return -1;
              }
       }

       return 0;
}

Here is the call graph for this function:

static void usage ( char *  name) [static]

Definition at line 96 of file vbltest.c.

{
       fprintf(stderr, "usage: %s [-s]\n", name);
       fprintf(stderr, "\t-s\tuse secondary pipe\n");
       exit(0);
}
static void vblank_handler ( int  fd,
unsigned int  frame,
unsigned int  sec,
unsigned int  usec,
void *  data 
) [static]

Definition at line 68 of file vbltest.c.

{
       drmVBlank vbl;
       struct timeval end;
       struct vbl_info *info = data;
       double t;

       vbl.request.type = DRM_VBLANK_RELATIVE | DRM_VBLANK_EVENT;
       if (secondary)
              vbl.request.type |= DRM_VBLANK_SECONDARY;
       vbl.request.sequence = 1;
       vbl.request.signal = (unsigned long)data;

       drmWaitVBlank(fd, &vbl);

       info->vbl_count++;

       if (info->vbl_count == 60) {
              gettimeofday(&end, NULL);
              t = end.tv_sec + end.tv_usec * 1e-6 -
                     (info->start.tv_sec + info->start.tv_usec * 1e-6);
              fprintf(stderr, "freq: %.02fHz\n", info->vbl_count / t);
              info->vbl_count = 0;
              info->start = end;
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

char* optarg
int opterr
int optind
int optopt
char optstr[] = "s" [static]

Definition at line 59 of file vbltest.c.

int secondary = 0

Definition at line 61 of file vbltest.c.