Skip to contentSkip to conversation

intel: Add support for overriding the PCI ID via an environment variable

PATCH In review Kenneth Graunke 6 participants 10 messages Feb 21, 2012 – Mar 5, 2012

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 intel: Add support for overriding the PCI ID via an environment variable

For example:

    export INTEL_DEVID_OVERRIDE=0x162

If this variable is set, don't actually submit the batchbuffer to the GPU, it probably contains commands for the wrong generation of hardware.

---
 intel/intel_bufmgr_gem.c |   43 ++++++++++++++++++++++++++++++++++---------
 1 files changed, 34 insertions(+), 9 deletions(-)
intel/intel_bufmgr_gem.c +34 -9
index 0f33b71..fcb4764 100644
@@ -1788,7 +1788,8 @@ drm_intel_gem_bo_mrb_exec2(drm_intel_bo *bo, int used,
 {
 	drm_intel_bufmgr_gem *bufmgr_gem = (drm_intel_bufmgr_gem *)bo->bufmgr;
 	struct drm_i915_gem_execbuffer2 execbuf;
-	int ret, i;
+	int ret = 0;
+	int i;
 
 	switch (flags & 0x7) {
 	default:
@@ -1828,6 +1829,9 @@ drm_intel_gem_bo_mrb_exec2(drm_intel_bo *bo, int used,
 	execbuf.rsvd1 = 0;
 	execbuf.rsvd2 = 0;
 
+	if (getenv("INTEL_DEVID_OVERRIDE"))
+		goto skip_execution;
+
 	ret = drmIoctl(bufmgr_gem->fd,
 		       DRM_IOCTL_I915_GEM_EXECBUFFER2,
 		       &execbuf);
@@ -1845,6 +1849,7 @@ drm_intel_gem_bo_mrb_exec2(drm_intel_bo *bo, int used,
 	}
 	drm_intel_update_buffer_offsets2(bufmgr_gem);
 
+skip_execution:
 	if (bufmgr_gem->bufmgr.debug)
 		drm_intel_gem_dump_validation_list(bufmgr_gem);
 
@@ -2315,6 +2320,33 @@ drm_intel_bufmgr_gem_set_vma_cache_size(drm_intel_bufmgr *bufmgr, int limit)
 }
 
 /**
+ * Get the PCI ID for the device.  This can be overridden by setting the
+ * INTEL_DEVID_OVERRIDE environment variable to the desired ID.
+ */
+static int
+get_pci_device_id(drm_intel_bufmgr_gem *bufmgr_gem)
+{
+	char *devid_override;
+	int devid;
+	int ret;
+	drm_i915_getparam_t gp;
+
+	devid_override = getenv("INTEL_DEVID_OVERRIDE");
+	if (devid_override)
+		return strtod(devid_override, NULL);
+
+	VG_CLEAR(gp);
+	gp.param = I915_PARAM_CHIPSET_ID;
+	gp.value = &devid;
+	ret = drmIoctl(bufmgr_gem->fd, DRM_IOCTL_I915_GETPARAM, &gp);
+	if (ret) {
+		fprintf(stderr, "get chip id failed: %d [%d]\n", ret, errno);
+		fprintf(stderr, "param: %d, val: %d\n", gp.param, *gp.value);
+	}
+	return devid;
+}
+
+/**
  * Initializes the GEM buffer manager, which uses the kernel to allocate, map,
  * and manage map buffer objections.
  *
@@ -2356,14 +2388,7 @@ drm_intel_bufmgr_gem_init(int fd, int batch_size)
 			(int)bufmgr_gem->gtt_size / 1024);
 	}
 
-	VG_CLEAR(gp);
-	gp.param = I915_PARAM_CHIPSET_ID;
-	gp.value = &bufmgr_gem->pci_device;
-	ret = drmIoctl(bufmgr_gem->fd, DRM_IOCTL_I915_GETPARAM, &gp);
-	if (ret) {
-		fprintf(stderr, "get chip id failed: %d [%d]\n", ret, errno);
-		fprintf(stderr, "param: %d, val: %d\n", gp.param, *gp.value);
-	}
+	bufmgr_gem->pci_device = get_pci_device_id(bufmgr_gem);
 
 	if (IS_GEN2(bufmgr_gem->pci_device))
 		bufmgr_gem->gen = 2;
Signature · 1 line
1.7.7.6
#1 lore raw

PATCH 2/2 intel: Remove Ironlake from IS_GEN4 macro.

---
 intel/intel_chipset.h |    2 --
 1 files changed, 0 insertions(+), 2 deletions(-)
intel/intel_chipset.h +0 -2
index e3a30fc..1b6e357 100644
@@ -96,8 +96,6 @@
 		      dev == 0x2E22 ||	\
 		      dev == 0x2E32 ||	\
 		      dev == 0x2E42 ||	\
-		      dev == 0x0042 ||	\
-		      dev == 0x0046 ||	\
 		      IS_I965GM(dev) || \
 		      IS_G4X(dev))
 
Signature · 1 line
1.7.7.6
Reviewed-by on v1 2/2
#2 lore raw

Re: [PATCH 2/2] intel: Remove Ironlake from IS_GEN4 macro.

Quoted 1 line · Kenneth Graunke

A task for a rainy afternoon would be to rigorously use the verbose PCI_ID_* names rather than the raw values.

intel/intel_chipset.h line 98

Quoted 12 lines
---
 intel/intel_chipset.h |    2 --
 1 files changed, 0 insertions(+), 2 deletions(-)
intel/intel_chipset.h +0 -0
index e3a30fc..1b6e357 100644
@@ -96,8 +96,6 @@
 		      dev == 0x2E22 ||	\
 		      dev == 0x2E32 ||	\
 		      dev == 0x2E42 ||	\

Note that these 5 IDs are part of IS_G4X, can you kill them as well (in another patch).
-Chris

Signature · 1 line
Chris Wilson, Intel Open Source Technology Centre
#3 lore raw

Re: [PATCH 2/2] intel: Remove Ironlake from IS_GEN4 macro.

Quoted 12 lines · Chris Wilson
Quoted 1 line · Kenneth Graunke

A task for a rainy afternoon would be to rigorously use the verbose PCI_ID_* names rather than the raw values.

Quoted 4 lines
---
  intel/intel_chipset.h |    2 --
  1 files changed, 0 insertions(+), 2 deletions(-)
Quoted 11 lines

intel/intel_chipset.h line 98

Quoted 8 lines
intel/intel_chipset.h +0 -0
index e3a30fc..1b6e357 100644
@@ -96,8 +96,6 @@
  		      dev == 0x2E22 ||	\
  		      dev == 0x2E32 ||	\
  		      dev == 0x2E42 ||	\

Note that these 5 IDs are part of IS_G4X, can you kill them as well (in another patch).
-Chris

Hm. I guess I consider G4X to be part of GEN4. At least in Mesa, G4X is explicitly included:

#define IS_GEN4(devid) (devid == ... || ... || IS_G4X(devid))

Using that instead of hardcoding the IDs would be cleaner, though.

#4 lore raw
In reply to Kenneth Graunke

intel/intel_bufmgr_gem.c drm_intel_gem_bo_mrb_exec2(drm_intel_bo *bo, int used, · line 1833

Quoted 6 lines · Kenneth Graunke
intel/intel_bufmgr_gem.c +2 -0
@@ -1828,6 +1829,9 @@ drm_intel_gem_bo_mrb_exec2(drm_intel_bo *bo, int used,
 	execbuf.rsvd1 = 0;
 	execbuf.rsvd2 = 0;
 
+	if (getenv("INTEL_DEVID_OVERRIDE"))
+		goto skip_execution;

I'm not thrilled about calling getenv() for every execbuffer. And what about the original execbuffer path?
-Chris

Signature · 1 line
Chris Wilson, Intel Open Source Technology Centre
#5 lore raw
Quoted 9 lines · Chris Wilson

intel/intel_bufmgr_gem.c drm_intel_gem_bo_mrb_exec2(drm_intel_bo *bo, int used, · line 1833

Quoted 6 lines · Kenneth Graunke
intel/intel_bufmgr_gem.c +2 -0
@@ -1828,6 +1829,9 @@ drm_intel_gem_bo_mrb_exec2(drm_intel_bo *bo, int used,
  	execbuf.rsvd1 = 0;
  	execbuf.rsvd2 = 0;
 
+	if (getenv("INTEL_DEVID_OVERRIDE"))
+		goto skip_execution;

I'm not thrilled about calling getenv() for every execbuffer.

Good point. I'll have to fix that.

Quoted 2 lines

And what about the original execbuffer path?
-Chris

Does anybody care? I'm not even sure how I'd test it.

A little bit of background: this is a stepping stone on the way to simulator support.

When INTEL_DEVID_OVERRIDE is set, Mesa will generate code/batches for that system, rather than the current machine. It also implicitly sets INTEL_NO_HW=1, which makes it avoid calling execbuf2. This at least allows INTEL_DEBUG=vs,wm,bat style dumps, which is handy.

However, our .aub trace file support is in libdrm, so I need Mesa to execbuf, or I don't get aub file dumps. But I don't want libdrm to -actually- exec it.

#6 lore raw
Quoted 27 lines · Kenneth Graunke
Quoted 9 lines · Chris Wilson

intel/intel_bufmgr_gem.c drm_intel_gem_bo_mrb_exec2(drm_intel_bo *bo, int used, · line 1833

Quoted 6 lines · Kenneth Graunke
intel/intel_bufmgr_gem.c +2 -0
@@ -1828,6 +1829,9 @@ drm_intel_gem_bo_mrb_exec2(drm_intel_bo *bo, int used,
 	execbuf.rsvd1 = 0;
 	execbuf.rsvd2 = 0;
 
+	if (getenv("INTEL_DEVID_OVERRIDE"))
+		goto skip_execution;

I'm not thrilled about calling getenv() for every execbuffer.

Good point. I'll have to fix that.

Quoted 2 lines

And what about the original execbuffer path?
-Chris

Does anybody care? I'm not even sure how I'd test it.

A little bit of background: this is a stepping stone on the way to simulator support.

When INTEL_DEVID_OVERRIDE is set, Mesa will generate code/batches for that system, rather than the current machine. It also implicitly sets INTEL_NO_HW=1, which makes it avoid calling execbuf2. This at least allows INTEL_DEBUG=vs,wm,bat style dumps, which is handy.

Quoted 3 lines

However, our .aub trace file support is in libdrm, so I need Mesa to execbuf, or I don't get aub file dumps. But I don't want libdrm to -actually- exec it.

What about adding a function to libdrm to stop all execbuf calls from actually calling the kernel ioctl? Something like drm_intel_gem_bufmgr_enable_no_hw() ... Maybe combine it right away with the aub-trace grabbing code.
-Daniel

Signature · 3 lines
Daniel Vetter
Mail: [email protected]
Mobile: +41 (0)79 365 57 48
#7 lore raw
In reply to Chris Wilson
Quoted 5 lines · On Tue, 21 Feb 2012 21:11:07 +0000 Chris Wilson <[email protected]>…
Quoted 4 lines · Kenneth Graunke
intel/intel_bufmgr_gem.c +0 -0
@@ -1828,6 +1829,9 @@ drm_intel_gem_bo_mrb_exec2(drm_intel_bo *bo, int used,
 	execbuf.rsvd1 = 0;
 	execbuf.rsvd2 = 0;
 
Quoted 7 lines

intel/intel_bufmgr_gem.c drm_intel_gem_bo_mrb_exec2(drm_intel_bo *bo, int used, · line 1833

Quoted 2 lines
intel/intel_bufmgr_gem.c +2 -0
+	if (getenv("INTEL_DEVID_OVERRIDE"))
+		goto skip_execution;

I'm not thrilled about calling getenv() for every execbuffer. And what about the original execbuffer path?
-Chris

I agree. I think the right way to do this is if the environment variable is set, you can override the function pointer in drm_intel_bufmgr_gem_init or something like that.

Also, I think it's a bit misleading that the effect of overriding the devid is to not emit batches. If nothing else because we may actually want to override the devid and have it do something in the future, and expecting the override to not emit could be bad.

#8 lore raw
In reply to Chris Wilson
Quoted 10 lines · Chris Wilson

intel/intel_bufmgr_gem.c drm_intel_gem_bo_mrb_exec2(drm_intel_bo *bo, int used, · line 1833

Quoted 6 lines · Kenneth Graunke
intel/intel_bufmgr_gem.c +2 -0
@@ -1828,6 +1829,9 @@ drm_intel_gem_bo_mrb_exec2(drm_intel_bo *bo, int used,
 	execbuf.rsvd1 = 0;
 	execbuf.rsvd2 = 0;
 
+	if (getenv("INTEL_DEVID_OVERRIDE"))
+		goto skip_execution;

I'm not thrilled about calling getenv() for every execbuffer. And what about the original execbuffer path?

I'm not thrilled about allowing the user to modify X server behaviour with an env variable. This is setuid root after all. I guess this also applies to the existing calls to getenv in the dri driver.

Cheers,
Julien

#9 lore raw
Quoted 13 lines · Julien Cristau
Quoted 10 lines · Chris Wilson

intel/intel_bufmgr_gem.c drm_intel_gem_bo_mrb_exec2(drm_intel_bo *bo, int used, · line 1833

Quoted 6 lines · Kenneth Graunke
intel/intel_bufmgr_gem.c +2 -0
@@ -1828,6 +1829,9 @@ drm_intel_gem_bo_mrb_exec2(drm_intel_bo *bo, int used,
 	execbuf.rsvd1 = 0;
 	execbuf.rsvd2 = 0;
 
+	if (getenv("INTEL_DEVID_OVERRIDE"))
+		goto skip_execution;

I'm not thrilled about calling getenv() for every execbuffer. And what about the original execbuffer path?

Quoted 3 lines

I'm not thrilled about allowing the user to modify X server behaviour with an env variable. This is setuid root after all. I guess this also applies to the existing calls to getenv in the dri driver.

Yeah, this seems roughly of the same class as the many environment variables we've always had. I'm going to take a shot at disabling a bunch under setuid, though.

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx