intel/dev: add a small non installable tool to print device info
Mostly for debug purposes.
$ ./build/src/intel/dev/intel_device_info
/dev/dri/renderD128:
name: Intel(R) UHD Graphics 620 (WHL GT2)
gen: 9
PCI id: 0x3ea0
revision: 2
slice0.subslice0: 11111111
slice0.subslice1: 11111111
slice0.subslice2: 11111111
slices: 1
subslices: 3
EUs: 24
EU threads: 168
LLC: 1
threads per EU: 7
L3 banks: 4
max VS threads: 336
max TCS threads: 336
max TES threads: 336
max GS threads: 336
max WM threads: 256
max CS threads: 56
timestamp frequency: 12000000
v2: Missing license (Marcin)
Fix stderr usage (Marcin)
v3: Reformat topology printing (Marcin)
Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Reviewed-by: Marcin Ĺšlusarz <marcin.slusarz@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6957>
diff --git a/src/intel/dev/gen_device_info.h b/src/intel/dev/gen_device_info.h
index d3514a1..9ebc008 100644
--- a/src/intel/dev/gen_device_info.h
+++ b/src/intel/dev/gen_device_info.h
@@ -284,6 +284,16 @@
subslice / 8] & (1U << (subslice % 8))) != 0;
}
+static inline bool
+gen_device_info_eu_available(const struct gen_device_info *devinfo,
+ int slice, int subslice, int eu)
+{
+ unsigned subslice_offset = slice * devinfo->eu_slice_stride +
+ subslice * devinfo->eu_subslice_stride;
+
+ return (devinfo->eu_masks[subslice_offset + eu / 8] & (1U << eu % 8)) != 0;
+}
+
int gen_device_name_to_pci_device_id(const char *name);
const char *gen_get_device_name(int devid);
diff --git a/src/intel/dev/intel_device_info.c b/src/intel/dev/intel_device_info.c
new file mode 100644
index 0000000..5114da7
--- /dev/null
+++ b/src/intel/dev/intel_device_info.c
@@ -0,0 +1,114 @@
+/*
+ * Copyright © 2020 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.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdarg.h>
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+
+#include <xf86drm.h>
+
+#include "gen_device_info.h"
+
+static int
+error(char *fmt, ...)
+{
+ va_list ap;
+ va_start(ap, fmt);
+ vfprintf(stderr, fmt, ap);
+ va_end(ap);
+
+ return EXIT_FAILURE;
+}
+
+int
+main(int argc, char *argv[])
+{
+ drmDevicePtr devices[8];
+ int max_devices;
+
+ max_devices = drmGetDevices2(0, devices, ARRAY_SIZE(devices));
+ if (max_devices < 1)
+ return error("Not device found");
+
+ for (int i = 0; i < max_devices; i++) {
+ struct gen_device_info devinfo;
+ const char *path = devices[i]->nodes[DRM_NODE_RENDER];
+ int fd = open(path, O_RDWR | O_CLOEXEC);
+
+ if (fd < 0)
+ continue;
+
+ bool success = gen_get_device_info_from_fd(fd, &devinfo);
+ close(fd);
+
+ if (!success)
+ continue;
+
+ fprintf(stdout, "%s:\n", path);
+
+ fprintf(stdout, " name: %s\n", gen_get_device_name(devinfo.chipset_id));
+ fprintf(stdout, " gen: %u\n", devinfo.gen);
+ fprintf(stdout, " PCI id: 0x%x\n", devinfo.chipset_id);
+ fprintf(stdout, " revision: %u\n", devinfo.revision);
+
+ uint32_t n_s = 0, n_ss = 0, n_eus = 0;
+ for (unsigned s = 0; s < devinfo.num_slices; s++) {
+ n_s += (devinfo.slice_masks & (1u << s)) ? 1 : 0;
+ for (unsigned ss = 0; ss < devinfo.num_subslices[s]; ss++) {
+ fprintf(stdout, " slice%u.subslice%u: ", s, ss);
+ if (gen_device_info_subslice_available(&devinfo, s, ss)) {
+ n_ss++;
+ for (unsigned eu = 0; eu < devinfo.num_eu_per_subslice; eu++) {
+ n_eus += gen_device_info_eu_available(&devinfo, s, ss, eu) ? 1 : 0;
+ fprintf(stdout, "%s", gen_device_info_eu_available(&devinfo, s, ss, eu) ? "1" : "0");
+ }
+ } else {
+ fprintf(stderr, "fused");
+ }
+ fprintf(stdout, "\n");
+ }
+ }
+ fprintf(stdout, " slices: %u\n", n_s);
+ fprintf(stdout, " subslices: %u\n", n_ss);
+ fprintf(stdout, " EUs: %u\n", n_eus);
+ fprintf(stdout, " EU threads: %u\n", n_eus * devinfo.num_thread_per_eu);
+
+ fprintf(stdout, " LLC: %u\n", devinfo.has_llc);
+ fprintf(stdout, " threads per EU: %u\n", devinfo.num_thread_per_eu);
+ fprintf(stdout, " L3 banks: %u\n", devinfo.l3_banks);
+ fprintf(stdout, " max VS threads: %u\n", devinfo.max_vs_threads);
+ fprintf(stdout, " max TCS threads: %u\n", devinfo.max_tcs_threads);
+ fprintf(stdout, " max TES threads: %u\n", devinfo.max_tes_threads);
+ fprintf(stdout, " max GS threads: %u\n", devinfo.max_gs_threads);
+ fprintf(stdout, " max WM threads: %u\n", devinfo.max_wm_threads);
+ fprintf(stdout, " max CS threads: %u\n", devinfo.max_cs_threads);
+ fprintf(stdout, " timestamp frequency: %lu\n", devinfo.timestamp_frequency);
+ }
+
+ return EXIT_SUCCESS;
+}
diff --git a/src/intel/dev/meson.build b/src/intel/dev/meson.build
index 5e58258..fa18e1a 100644
--- a/src/intel/dev/meson.build
+++ b/src/intel/dev/meson.build
@@ -46,3 +46,16 @@
suite : ['intel'],
)
endif
+
+if with_intel_tools
+ intel_device_info = executable(
+ 'intel_device_info',
+ files('intel_device_info.c'),
+ dependencies : [dep_libdrm, dep_dl, dep_thread, dep_m],
+ include_directories : [inc_include, inc_src, inc_intel],
+ link_with : libintel_dev,
+ c_args : [no_override_init_args],
+ gnu_symbol_visibility : 'hidden',
+ install : false
+ )
+endif