Intel produces fairly beefy Xeon servers on which it would be nice to be
able to run shader-db to get some results pretty fast. Unfortunately those
don't ship with any intel graphics IP (only ancient Matrox cards).
This new script stubs a bunch of ioctls so that we can run shader-db on
hardware that doesn't have a /dev/dri/renderD128.
Example :
./intel_run -j70 -pskl -oi965 shaders
Signed-off-by: Lionel Landwerlin
---
Makefile | 10 ++-
intel_run| 5 ++
intel_stub.c | 237 +++
3 files changed, 251 insertions(+), 1 deletion(-)
create mode 100755 intel_run
create mode 100644 intel_stub.c
diff --git a/Makefile b/Makefile
index 9422b32..52a764f 100644
--- a/Makefile
+++ b/Makefile
@@ -23,7 +23,15 @@ CFLAGS ?= -g -O2 -march=native -pipe
CFLAGS += -std=gnu99 -fopenmp
LDLIBS = -lepoxy -lgbm
+INTEL_STUB_CFLAGS = -g -fPIC -shared -Wall `pkg-config libdrm_intel --cflags`
+INTEL_STUB_LIBS = -ldl
+
+all: intel_stub.so run
+
+intel_stub.so: intel_stub.c
+ gcc $(INTEL_STUB_CFLAGS) $< -o $@ $(INTEL_STUB_LIBS)
+
run:
clean:
- rm -f run
+ rm -f intel_stub.so run
diff --git a/intel_run b/intel_run
new file mode 100755
index 000..10114ff
--- /dev/null
+++ b/intel_run
@@ -0,0 +1,5 @@
+#!/bin/bash
+# -*- mode: sh -*-
+
+LD_PRELOAD=${PWD}/intel_stub.so${LD_PPRELOAD:+:${LD_PRELOAD}} \
+ exec ./run $@
diff --git a/intel_stub.c b/intel_stub.c
new file mode 100644
index 000..4917656
--- /dev/null
+++ b/intel_stub.c
@@ -0,0 +1,237 @@
+/*
+ * Copyright © 2015-2017 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+#define _GNU_SOURCE /* for RTLD_NEXT */
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+static void *(*libc_mmap)(void *addr, size_t len, int prot, int flags,
+ int fildes, off_t off);
+static int (*libc_open)(const char *pathname, int flags, mode_t mode);
+static int (*libc_close)(int fd);
+static int (*libc_ioctl)(int fd, unsigned long request, void *argp);
+static int (*libc_fstat)(int fd, struct stat *buf);
+static int (*libc__fxstat)(int ver, int fd, struct stat *buf);
+static int (*libc_fcntl)(int fd, int cmd, int param);
+static ssize_t (*libc_readlink)(const char *pathname, char *buf, size_t
bufsiz);
+
+static int drm_fd = 0xBEEF;
+
+#define DRM_MAJOR 226
+
+#define SYSFS_PATH "/sys/dev/char/226:0/device/subsystem"
+
+static int
+dispatch_version(int fd, unsigned long request,
+ struct drm_version *version)
+{
+ static const char name[] = "i915";
+ static const char date[] = "20160919";
+ static const char desc[] = "Intel Graphics";
+
+ version->version_major = 1;
+ version->version_minor = 6;
+ version->version_patchlevel = 0;
+
+ if (version->name)
+ strncpy(version->name, name, version->name_len);
+ version->name_len = strlen(name);
+ if (version->date)
+ strncpy(version->date, date, version->date_len);
+ version->date_len = strlen(date);
+ if (version->desc)
+ strncpy(version->desc, desc, version->desc_len);
+ version->desc_len = strlen(desc);
+
+ return 0;
+}
+
+__attribute__ ((visibility ("default"))) int
+open(const char *path, int flags, ...)
+{
+ va_list args;
+ mode_t mode;
+
+ if (strcmp(path, "/dev/dri/renderD128") == 0)
+ return drm_fd;
+
+ va_start(args, flags);
+ mode = va_arg(args, int);
+ va_end(args);
+
+ return libc_open(path, flags, mode);
+}
+
+__attribute__ ((visibility ("default"))) int
+close(int fd)
+{
+ if (fd == drm_fd)
+ return 0;
+
+ return libc_close(fd);
+}
+
+__attribute__ ((visibility ("default"))) int
+fstat(int fd, struct stat