[Intel-gfx] [PATCH igt] tools: Stop opening the driver just to find the debugfs
Chris Wilson
chris at chris-wilson.co.uk
Mon Nov 20 16:01:24 UTC 2017
Since the tools want to work without the module loaded, remove the
assumption that we want to load the driver to find debugfs.
Signed-off-by: Chris Wilson <chris at chris-wilson.co.uk>
---
lib/igt_debugfs.c | 15 ++++++---------
tools/intel_display_poller.c | 8 +-------
tools/intel_forcewaked.c | 9 ++-------
tools/intel_gpu_top.c | 7 +------
tools/intel_guc_logger.c | 10 +++-------
tools/intel_infoframes.c | 7 +------
tools/intel_panel_fitter.c | 8 ++------
tools/intel_reg.c | 10 +++-------
tools/intel_watermark.c | 20 +++++++-------------
9 files changed, 26 insertions(+), 68 deletions(-)
diff --git a/lib/igt_debugfs.c b/lib/igt_debugfs.c
index 40cfd87a..658126e3 100644
--- a/lib/igt_debugfs.c
+++ b/lib/igt_debugfs.c
@@ -150,18 +150,15 @@ char *igt_debugfs_path(int device, char *path, int pathlen)
const char *debugfs_root;
int idx;
- if (fstat(device, &st)) {
- igt_debug("Couldn't stat FD for DRM device: %s\n", strerror(errno));
- return NULL;
- }
+ debugfs_root = igt_debugfs_mount();
+ igt_assert(debugfs_root);
- if (!S_ISCHR(st.st_mode)) {
+ memset(&st, 0, sizeof(st));
+ if (fstat(device, &st))
+ igt_debug("Couldn't stat FD for DRM device: %s\n", strerror(errno));
+ else if (!S_ISCHR(st.st_mode))
igt_debug("FD for DRM device not a char device!\n");
- return NULL;
- }
- debugfs_root = igt_debugfs_mount();
- igt_assert(debugfs_root);
idx = minor(st.st_rdev);
snprintf(path, pathlen, "%s/dri/%d/name", debugfs_root, idx);
diff --git a/tools/intel_display_poller.c b/tools/intel_display_poller.c
index 828ca52b..a26e2ecf 100644
--- a/tools/intel_display_poller.c
+++ b/tools/intel_display_poller.c
@@ -965,7 +965,6 @@ int main(int argc, char *argv[])
int pipe = 0, bit = 0, target_scanline = 0, target_fuzz = 1;
bool test_pixelcount = false;
uint32_t devid;
- int drm_fd;
uint32_t min[2*128] = {};
uint32_t max[2*128] = {};
uint32_t a, b;
@@ -1187,10 +1186,7 @@ int main(int argc, char *argv[])
break;
}
- /* Just to make sure we open the right debugfs files */
- drm_fd = drm_open_driver_master(DRIVER_INTEL);
-
- intel_register_access_init(intel_get_pci_device(), 0, drm_fd);
+ intel_register_access_init(intel_get_pci_device(), 0, -1);
printf("%s?\n", test_name(test, pipe, bit, test_pixelcount));
@@ -1267,8 +1263,6 @@ int main(int argc, char *argv[])
intel_register_access_fini();
- close(drm_fd);
-
if (quit)
return 0;
diff --git a/tools/intel_forcewaked.c b/tools/intel_forcewaked.c
index aa8e3f8b..02fbf888 100644
--- a/tools/intel_forcewaked.c
+++ b/tools/intel_forcewaked.c
@@ -64,7 +64,6 @@ is_alive(void) {
int main(int argc, char *argv[])
{
- int drm_fd;
int ret;
if (argc > 2 || (argc == 2 && !strncmp(argv[1], "-h", 2))) {
@@ -81,10 +80,7 @@ int main(int argc, char *argv[])
INFO_PRINT("started daemon");
}
- /* Just to make sure we open the right debugfs files */
- drm_fd = drm_open_driver_master(DRIVER_INTEL);
-
- ret = intel_register_access_init(intel_get_pci_device(), 1, drm_fd);
+ ret = intel_register_access_init(intel_get_pci_device(), 1, -1);
if (ret) {
INFO_PRINT("Couldn't init register access\n");
exit(1);
@@ -95,14 +91,13 @@ int main(int argc, char *argv[])
if (!is_alive()) {
INFO_PRINT("gpu reset? restarting daemon\n");
intel_register_access_fini();
- ret = intel_register_access_init(intel_get_pci_device(), 1, drm_fd);
+ ret = intel_register_access_init(intel_get_pci_device(), 1, -1);
if (ret)
INFO_PRINT("Reg access init fail\n");
}
sleep(1);
}
intel_register_access_fini();
- close(drm_fd);
INFO_PRINT("Forcewake unlock\n");
if (daemonized) {
diff --git a/tools/intel_gpu_top.c b/tools/intel_gpu_top.c
index 7454de87..83cf53ea 100644
--- a/tools/intel_gpu_top.c
+++ b/tools/intel_gpu_top.c
@@ -409,7 +409,6 @@ usage(const char *appname)
int main(int argc, char **argv)
{
uint32_t devid;
- int drm_fd;
struct pci_device *pci_dev;
struct ring render_ring = {
.name = "render",
@@ -510,11 +509,8 @@ int main(int argc, char **argv)
top_bits_sorted[i] = &top_bits[i];
}
- /* Just to make sure we open the right debugfs files */
- drm_fd = drm_open_driver(DRIVER_INTEL);
-
/* Grab access to the registers */
- intel_register_access_init(pci_dev, 0, drm_fd);
+ intel_register_access_init(pci_dev, 0, -1);
ring_init(&render_ring);
if (IS_GEN4(devid) || IS_GEN5(devid))
@@ -717,6 +713,5 @@ int main(int argc, char **argv)
fclose(output);
intel_register_access_fini();
- close(drm_fd);
return 0;
}
diff --git a/tools/intel_guc_logger.c b/tools/intel_guc_logger.c
index 7c6115a6..031fd84d 100644
--- a/tools/intel_guc_logger.c
+++ b/tools/intel_guc_logger.c
@@ -46,7 +46,7 @@ int verbosity_level = 3; /* by default capture logs at max verbosity */
uint32_t produced, consumed;
uint64_t total_bytes_written;
int num_buffers = NUM_SUBBUFS;
-int relay_fd, drm_fd, outfile_fd = -1;
+int relay_fd, outfile_fd = -1;
uint32_t test_duration, max_filesize;
pthread_cond_t underflow_cond, overflow_cond;
bool stop_logging, discard_oldlogs, capturing_stopped;
@@ -58,7 +58,7 @@ static void guc_log_control(bool enable_logging)
uint64_t val;
int ret;
- control_fd = igt_debugfs_open(drm_fd, CONTROL_FILE_NAME, O_WRONLY);
+ control_fd = igt_debugfs_open(-1, CONTROL_FILE_NAME, O_WRONLY);
igt_assert_f(control_fd >= 0, "couldn't open the guc log control file\n");
val = enable_logging ? ((verbosity_level << 4) | 0x1) : 0;
@@ -227,7 +227,7 @@ static void init_flusher_thread(void)
static void open_relay_file(void)
{
- relay_fd = igt_debugfs_open(drm_fd, RELAY_FILE_NAME, O_RDONLY);
+ relay_fd = igt_debugfs_open(-1, RELAY_FILE_NAME, O_RDONLY);
igt_assert_f(relay_fd >= 0, "couldn't open the guc log file\n");
/* Purge the old/boot-time logs from the relay buffer.
@@ -373,9 +373,6 @@ int main(int argc, char **argv)
process_command_line(argc, argv);
- /* Just to make sure we open the right debugfs files */
- drm_fd = drm_open_driver_master(DRIVER_INTEL);
-
init_main_thread();
/* Use a separate thread for flushing the logs to a file on disk.
@@ -436,6 +433,5 @@ int main(int argc, char **argv)
free(read_buffer);
close(relay_fd);
close(outfile_fd);
- close(drm_fd);
igt_exit();
}
diff --git a/tools/intel_infoframes.c b/tools/intel_infoframes.c
index 813430c9..2ef5d4fd 100644
--- a/tools/intel_infoframes.c
+++ b/tools/intel_infoframes.c
@@ -1081,7 +1081,6 @@ printf("Options:\n"
int main(int argc, char *argv[])
{
int opt;
- int drm_fd;
int ret = 0;
Transcoder transcoder = TRANSC_INVALID;
DipType dip = DIP_INVALID;
@@ -1108,11 +1107,8 @@ int main(int argc, char *argv[])
printf("WARNING: This is just a debugging tool! Don't expect it to work"
" perfectly: the Kernel might undo our changes.\n");
- /* Just to make sure we open the right debugfs files */
- drm_fd = drm_open_driver_master(DRIVER_INTEL);
-
pci_dev = intel_get_pci_device();
- intel_register_access_init(pci_dev, 0, drm_fd);
+ intel_register_access_init(pci_dev, 0, -1);
intel_check_pch();
if (IS_GEN4(pci_dev->device_id))
@@ -1261,6 +1257,5 @@ int main(int argc, char *argv[])
out:
intel_register_access_fini();
- close(drm_fd);
return ret;
}
diff --git a/tools/intel_panel_fitter.c b/tools/intel_panel_fitter.c
index 48b2fd89..137ef61a 100644
--- a/tools/intel_panel_fitter.c
+++ b/tools/intel_panel_fitter.c
@@ -266,7 +266,7 @@ static void print_usage(void)
int main (int argc, char *argv[])
{
- int opt, drm_fd;
+ int opt;
int ret = 0;
char intel_pipe = '\0';
int x = 0, y = 0;
@@ -279,11 +279,8 @@ int main (int argc, char *argv[])
"with overscan compensation properties: it is just a temporary "
"solution that may or may not work. Use it at your own risk.\n");
- /* Just to make sure we open the right debugfs files */
- drm_fd = drm_open_driver_master(DRIVER_INTEL);
-
pci_dev = intel_get_pci_device();
- intel_register_access_init(pci_dev, 0, drm_fd);
+ intel_register_access_init(pci_dev, 0, -1);
devid = pci_dev->device_id;
if (!HAS_PCH_SPLIT(devid)) {
@@ -346,6 +343,5 @@ int main (int argc, char *argv[])
out:
intel_register_access_fini();
- close(drm_fd);
return ret;
}
diff --git a/tools/intel_reg.c b/tools/intel_reg.c
index d6f81840..00d2a4a1 100644
--- a/tools/intel_reg.c
+++ b/tools/intel_reg.c
@@ -58,7 +58,6 @@ struct config {
struct pci_device *pci_dev;
char *mmiofile;
uint32_t devid;
- int drm_fd;
/* read: number of registers to read */
uint32_t count;
@@ -411,7 +410,7 @@ static int intel_reg_read(struct config *config, int argc, char *argv[])
if (config->mmiofile)
intel_mmio_use_dump_file(config->mmiofile);
else
- intel_register_access_init(config->pci_dev, 0, config->drm_fd);
+ intel_register_access_init(config->pci_dev, 0, -1);
for (i = 1; i < argc; i++) {
struct reg reg;
@@ -441,7 +440,7 @@ static int intel_reg_write(struct config *config, int argc, char *argv[])
return EXIT_FAILURE;
}
- intel_register_access_init(config->pci_dev, 0, config->drm_fd);
+ intel_register_access_init(config->pci_dev, 0, -1);
for (i = 1; i < argc; i += 2) {
struct reg reg;
@@ -479,7 +478,7 @@ static int intel_reg_dump(struct config *config, int argc, char *argv[])
if (config->mmiofile)
intel_mmio_use_dump_file(config->mmiofile);
else
- intel_register_access_init(config->pci_dev, 0, config->drm_fd);
+ intel_register_access_init(config->pci_dev, 0, -1);
for (i = 0; i < config->regcount; i++) {
reg = &config->regs[i];
@@ -879,9 +878,6 @@ int main(int argc, char *argv[])
config.devid = config.pci_dev->device_id;
}
- /* Just to make sure we open the right debugfs files */
- config.drm_fd = __drm_open_driver(DRIVER_INTEL);
-
if (read_reg_spec(&config) < 0) {
return EXIT_FAILURE;
}
diff --git a/tools/intel_watermark.c b/tools/intel_watermark.c
index d8c78480..de0b0831 100644
--- a/tools/intel_watermark.c
+++ b/tools/intel_watermark.c
@@ -34,7 +34,6 @@
static uint32_t display_base;
static uint32_t devid;
-static int drm_fd;
static uint32_t read_reg(uint32_t addr)
{
@@ -143,7 +142,7 @@ static void ilk_wm_dump(void)
int num_pipes = is_gen7_plus(devid) ? 3 : 2;
struct ilk_wm wm = {};
- intel_register_access_init(intel_get_pci_device(), 0, drm_fd);
+ intel_register_access_init(intel_get_pci_device(), 0, -1);
for (i = 0; i < num_pipes; i++) {
dspcntr[i] = read_reg(0x70180 + i * 0x1000);
@@ -291,7 +290,7 @@ static void vlv_wm_dump(void)
uint32_t dsp_ss_pm, ddr_setup2;
struct gmch_wm wms[MAX_PLANE] = {};
- intel_register_access_init(intel_get_pci_device(), 0, drm_fd);
+ intel_register_access_init(intel_get_pci_device(), 0, -1);
dsparb = read_reg(0x70030);
dsparb2 = read_reg(0x70060);
@@ -507,7 +506,7 @@ static void g4x_wm_dump(void)
uint32_t mi_arb_state;
struct gmch_wm wms[MAX_PLANE] = {};
- intel_register_access_init(intel_get_pci_device(), 0, drm_fd);
+ intel_register_access_init(intel_get_pci_device(), 0, -1);
dspacntr = read_reg(0x70180);
dspbcntr = read_reg(0x71180);
@@ -593,7 +592,7 @@ static void gen4_wm_dump(void)
uint32_t mi_arb_state;
struct gmch_wm wms[MAX_PLANE] = {};
- intel_register_access_init(intel_get_pci_device(), 0, drm_fd);
+ intel_register_access_init(intel_get_pci_device(), 0, -1);
dsparb = read_reg(0x70030);
fw1 = read_reg(0x70034);
@@ -664,7 +663,7 @@ static void pnv_wm_dump(void)
uint32_t cbr;
struct gmch_wm wms[MAX_PLANE] = {};
- intel_register_access_init(intel_get_pci_device(), 0, drm_fd);
+ intel_register_access_init(intel_get_pci_device(), 0, -1);
dsparb = read_reg(0x70030);
fw1 = read_reg(0x70034);
@@ -754,7 +753,7 @@ static void gen3_wm_dump(void)
uint32_t mi_arb_state;
struct gmch_wm wms[MAX_PLANE] = {};
- intel_register_access_init(intel_get_pci_device(), 0, drm_fd);
+ intel_register_access_init(intel_get_pci_device(), 0, -1);
dsparb = read_reg(0x70030);
instpm = read_reg(0x20c0);
@@ -823,7 +822,7 @@ static void gen2_wm_dump(void)
uint32_t mi_state;
struct gmch_wm wms[MAX_PLANE] = {};
- intel_register_access_init(intel_get_pci_device(), 0, drm_fd);
+ intel_register_access_init(intel_get_pci_device(), 0, -1);
dsparb = read_reg(0x70030);
mem_mode = read_reg(0x20cc);
@@ -900,9 +899,6 @@ int main(int argc, char *argv[])
{
devid = intel_get_pci_device()->device_id;
- /* Just to make sure we open the right debugfs files */
- drm_fd = drm_open_driver_master(DRIVER_INTEL);
-
if (IS_VALLEYVIEW(devid) || IS_CHERRYVIEW(devid)) {
display_base = 0x180000;
vlv_wm_dump();
@@ -923,7 +919,5 @@ int main(int argc, char *argv[])
return 1;
}
- close(drm_fd);
-
return 0;
}
--
2.15.0
More information about the Intel-gfx
mailing list