From 68913715a2982572e88f943fd4fbe1b07e2fc720 Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Wed, 16 Mar 2016 13:51:15 +0000 Subject: [PATCH] test: Look at Present scaling with number of cpus Signed-off-by: Chris Wilson --- test/present-speed.c | 54 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/test/present-speed.c b/test/present-speed.c index 4d339041..1e6e48be 100644 --- a/test/present-speed.c +++ b/test/present-speed.c @@ -52,6 +52,7 @@ #include #include #include +#include #include "dri3.h" @@ -119,6 +120,9 @@ static int _check_error_handler(Display *display, XErrorEvent *event) { + if (_x_error_occurred < 0) + return True; + printf("X11 error from display %s, serial=%ld, error=%d, req=%d.%d\n", DisplayString(display), event->serial, @@ -312,6 +316,7 @@ static void run(Display *dpy, Window win, const char *name, unsigned options) if (_x_error_occurred) abort(); + _x_error_occurred = -1; xcb_present_select_input(c, eid, win, 0); XSync(dpy, True); xcb_unregister_for_special_event(c, Q); @@ -329,6 +334,51 @@ static void run(Display *dpy, Window win, const char *name, unsigned options) completed / (elapsed(&start, &end) / 1000000)); } +static int isqrt(int x) +{ + int i; + + for (i = 2; i*i < x; i++) + ; + return i; +} + +static void siblings(int max_width, int max_height, int ncpus, unsigned options) +{ + int sq_ncpus = isqrt(ncpus); + int width = max_width / sq_ncpus; + int height = max_height/ sq_ncpus; + int child; + + if (ncpus <= 1) + return; + + for (child = 0; child < ncpus; child++) { + for (; fork() == 0; exit(0)) { + int x = (child % sq_ncpus) * width; + int y = (child / sq_ncpus) * height; + XSetWindowAttributes attr = { .override_redirect = 1 }; + Display *dpy = XOpenDisplay(NULL); + Window win = XCreateWindow(dpy, DefaultRootWindow(dpy), + x, y, width, height, 0, + DefaultDepth(dpy, DefaultScreen(dpy)), + InputOutput, + DefaultVisual(dpy, DefaultScreen(dpy)), + CWOverrideRedirect, &attr); + XMapWindow(dpy, win); + run(dpy, win, "sibling", options); + } + } + + while (child) { + int status = -1; + pid_t pid = wait(&status); + if (pid == -1) + continue; + child--; + } +} + static int has_present(Display *dpy) { xcb_connection_t *c = XGetXCBConnection(dpy); @@ -551,6 +601,10 @@ static void loop(Display *dpy, XRRScreenResources *res, unsigned options) XDestroyWindow(dpy, win); XSync(dpy, True); + siblings(mode->width, mode->height, + sysconf(_SC_NPROCESSORS_ONLN), + options); + XRRSetCrtcConfig(dpy, res, output->crtcs[c], CurrentTime, 0, 0, None, RR_Rotate_0, NULL, 0); }