Skip to contentSkip to conversation

Add GEM to i915 DRM driver

resubmit In review Eric Anholt 3 participants 9 messages Aug 26, 2008 – Sep 23, 2008

Subsystems (8)
lore
Share & tools
lore
#2 lore raw

PATCH 1/1 Export kmap_atomic_pfn for DRM-GEM.

In reply to Eric Anholt

The driver would like to map IO space directly for copying data in when appropriate, to avoid CPU cache flushing for streaming writes. kmap_atomic_pfn lets us avoid IPIs associated with ioremap for this process.

---
 arch/x86/mm/highmem_32.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
arch/x86/mm/highmem_32.c +1 -0
index 165c871..d52e91d 100644
@@ -137,6 +137,7 @@ void *kmap_atomic_pfn(unsigned long pfn, enum km_type type)
 
 	return (void*) vaddr;
 }
+EXPORT_SYMBOL(kmap_atomic_pfn);
 
 struct page *kmap_atomic_to_page(void *ptr)
 {
Signature · 1 line
1.5.6.3
#1 lore raw

PATCH 1/1 Export shmem_file_setup for DRM-GEM

In reply to Eric Anholt

From: Keith Packard <[email protected]>

GEM needs to create shmem files to back buffer objects. Though currently creation of files for objects could have been driven from userland, the modesetting work will require allocation of buffer objects before userland is running, for boot-time message display.

---
 mm/shmem.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
mm/shmem.c +1 -0
index 04fb4f1..515909d 100644
@@ -2582,6 +2582,7 @@ put_memory:
 	shmem_unacct_size(flags, size);
 	return ERR_PTR(error);
 }
+EXPORT_SYMBOL(shmem_file_setup);
 
 /**
  * shmem_zero_setup - setup a shared anonymous mapping
Signature · 1 line
1.5.6.3
#0 lore raw

This patch series brings a long-awaited kernel memory manager to the i915 driver. This will allow us to do correct composited OpenGL, speed up OpenGL-based compositing, and enable framebuffer objects and other "new" OpenGL extensions. This patchset is also being built to enable kernel modesetting for a non-root, flicker-free X Server.

This is a re-submit of the changes for DRM-GEM. It relies on patches submitted by airlied which are currently queued in linux-next. The tree still has all the changes required, based off of 2.6.27-rc4.

git://people.freedesktop.org/~anholt/linux-2.6 on the drm-gem-merge branch
http://cgit.freedesktop.org/~anholt/linux-2.6/log/?h=drm-gem-merge

New in this edition since the original submission:

- Exporting kmap_atomic_pfn.
(The previous submission was slow because it was checking for the drm_compat.c version of this function from the external tree)
- shmem_getpage usage replaced with read_mapping_page.
- fixes for software fallbacks on tiled buffers.
- speedups for software fallbacks.
- replaced pci_read_base usage with using the MCHBAR mirror aperture
- fixed some issues on X server exit

What's not new in this edition:

Still using shmem_file_setup. We need to be able to allocate objects from the kernel, and didn't get any clear agreement that doing a VFS dance would be preferable to letting us behave like other kernel subsystems and use the function.

Still using small integers to identify our objects rather than fds. We need more than just basic syscalls on the objects -- the alternate mmap issue is more serious than before, for X pixmap usage. There are also the ioctls for cache management for software fallbacks. And the issue of getting high fds and large numbers of them still remained.

Still have an issue with PAT on x86_64 -- initialization fails because ioremap() apparently has different semantics there than on x86 or non-PAT x86_64 (if somebody has mapped the space and there's a WC MTRR, the ioremap that defaults to UC- ends up conflicting on it and failing even though it seems like it's not supposed to).

#3 lore raw

PATCH 1/1 drm: Add GEM ("graphics execution manager") to i915 driver.

In reply to Eric Anholt

GEM allows the creation of persistent buffer objects accessible by the graphics device through new ioctls for managing execution of commands on the device. The userland API is almost entirely driver-specific to ensure that any driver building on this model can easily map the interface to individual driver requirements.

GEM is used by the 2d driver for managing its internal state allocations and will be used for pixmap storage to reduce memory consumption and enable zero-copy GLX_EXT_texture_from_pixmap, and in the 3d driver is used to enable GL_EXT_framebuffer_object and GL_ARB_pixel_buffer_object.

---
 drivers/gpu/drm/Makefile               |    5 +-
 drivers/gpu/drm/drm_agpsupport.c       |   51 +-
 drivers/gpu/drm/drm_cache.c            |   76 +
 drivers/gpu/drm/drm_drv.c              |    4 +
 drivers/gpu/drm/drm_fops.c             |    6 +
 drivers/gpu/drm/drm_gem.c              |  420 ++++++
 drivers/gpu/drm/drm_memory.c           |    2 +
 drivers/gpu/drm/drm_mm.c               |    5 +-
 drivers/gpu/drm/drm_proc.c             |  135 ++-
 drivers/gpu/drm/drm_stub.c             |   10 +
 drivers/gpu/drm/i915/Makefile          |    6 +-
 drivers/gpu/drm/i915/i915_dma.c        |   94 +-
 drivers/gpu/drm/i915/i915_drv.c        |    8 +-
 drivers/gpu/drm/i915/i915_drv.h        |  253 ++++-
 drivers/gpu/drm/i915/i915_gem.c        | 2509 ++++++++++++++++++++++++++++++++
 drivers/gpu/drm/i915/i915_gem_debug.c  |  201 +++
 drivers/gpu/drm/i915/i915_gem_proc.c   |  292 ++++
 drivers/gpu/drm/i915/i915_gem_tiling.c |  256 ++++
 drivers/gpu/drm/i915/i915_irq.c        |    8 +-
 drivers/gpu/drm/i915/i915_reg.h        |   37 +-
 include/drm/drm.h                      |   31 +
 include/drm/drmP.h                     |  151 ++
 include/drm/i915_drm.h                 |  332 +++++
 23 files changed, 4835 insertions(+), 57 deletions(-)
 create mode 100644 drivers/gpu/drm/drm_cache.c
 create mode 100644 drivers/gpu/drm/drm_gem.c
 create mode 100644 drivers/gpu/drm/i915/i915_gem.c
 create mode 100644 drivers/gpu/drm/i915/i915_gem_debug.c
 create mode 100644 drivers/gpu/drm/i915/i915_gem_proc.c
 create mode 100644 drivers/gpu/drm/i915/i915_gem_tiling.c
drivers/gpu/drm/Makefile +3 -2
index e9f9a97..74da994 100644
@@ -4,8 +4,9 @@
 
 ccflags-y := -Iinclude/drm
 
-drm-y       :=	drm_auth.o drm_bufs.o drm_context.o drm_dma.o drm_drawable.o \
-		drm_drv.o drm_fops.o drm_ioctl.o drm_irq.o \
+drm-y       :=	drm_auth.o drm_bufs.o drm_cache.o \
+		drm_context.o drm_dma.o drm_drawable.o \
+		drm_drv.o drm_fops.o drm_gem.o drm_ioctl.o drm_irq.o \
 		drm_lock.o drm_memory.o drm_proc.o drm_stub.o drm_vm.o \
 		drm_agpsupport.o drm_scatter.o ati_pcigart.o drm_pci.o \
 		drm_sysfs.o drm_hashtab.o drm_sman.o drm_mm.o
drivers/gpu/drm/drm_agpsupport.c +50 -1

60 lines not on this page · raw message

drivers/gpu/drm/drm_cache.c new file +76 -0

76 lines not on this page · raw message

drivers/gpu/drm/drm_drv.c +4 -0
index 452c2d8..f934414 100644
@@ -117,6 +117,10 @@ static struct drm_ioctl_desc drm_ioctls[] = {
 	DRM_IOCTL_DEF(DRM_IOCTL_WAIT_VBLANK, drm_wait_vblank, 0),
 
 	DRM_IOCTL_DEF(DRM_IOCTL_UPDATE_DRAW, drm_update_drawable_info, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
+
+	DRM_IOCTL_DEF(DRM_IOCTL_GEM_CLOSE, drm_gem_close_ioctl, 0),
+	DRM_IOCTL_DEF(DRM_IOCTL_GEM_FLINK, drm_gem_flink_ioctl, DRM_AUTH),
+	DRM_IOCTL_DEF(DRM_IOCTL_GEM_OPEN, drm_gem_open_ioctl, DRM_AUTH),
 };
 
 #define DRM_CORE_IOCTL_COUNT	ARRAY_SIZE( drm_ioctls )
drivers/gpu/drm/drm_fops.c +6 -0
index 851a53f..c0a309a 100644
@@ -256,6 +256,9 @@ static int drm_open_helper(struct inode *inode, struct file *filp,
 
 	INIT_LIST_HEAD(&priv->lhead);
 
+	if (dev->driver->driver_features & DRIVER_GEM)
+		drm_gem_open(dev, priv);
+
 	if (dev->driver->open) {
 		ret = dev->driver->open(dev, priv);
 		if (ret < 0)
@@ -400,6 +403,9 @@ int drm_release(struct inode *inode, struct file *filp)
 		dev->driver->reclaim_buffers(dev, file_priv);
 	}
 
+	if (dev->driver->driver_features & DRIVER_GEM)
+		drm_gem_release(dev, file_priv);
+
 	drm_fasync(-1, filp, 0);
 
 	mutex_lock(&dev->ctxlist_mutex);
drivers/gpu/drm/drm_gem.c new file +420 -0

420 lines not on this page · raw message

drivers/gpu/drm/drm_memory.c +2 -0
index 0177012..803bc9e 100644
@@ -133,6 +133,7 @@ int drm_free_agp(DRM_AGP_MEM * handle, int pages)
 {
 	return drm_agp_free_memory(handle) ? 0 : -EINVAL;
 }
+EXPORT_SYMBOL(drm_free_agp);
 
 /** Wrapper around agp_bind_memory() */
 int drm_bind_agp(DRM_AGP_MEM * handle, unsigned int start)
@@ -145,6 +146,7 @@ int drm_unbind_agp(DRM_AGP_MEM * handle)
 {
 	return drm_agp_unbind_memory(handle);
 }
+EXPORT_SYMBOL(drm_unbind_agp);
 
 #else  /*  __OS_HAS_AGP  */
 static inline void *agp_remap(unsigned long offset, unsigned long size,
drivers/gpu/drm/drm_mm.c +4 -1
index dcff9e9..217ad7d 100644
@@ -169,6 +169,7 @@ struct drm_mm_node *drm_mm_get_block(struct drm_mm_node * parent,
 
 	return child;
 }
+EXPORT_SYMBOL(drm_mm_get_block);
 
 /*
  * Put a block. Merge with the previous and / or next block if they are free.
@@ -217,6 +218,7 @@ void drm_mm_put_block(struct drm_mm_node * cur)
 		drm_free(cur, sizeof(*cur), DRM_MEM_MM);
 	}
 }
+EXPORT_SYMBOL(drm_mm_put_block);
 
 struct drm_mm_node *drm_mm_search_free(const struct drm_mm * mm,
 				  unsigned long size,
@@ -265,6 +267,7 @@ int drm_mm_clean(struct drm_mm * mm)
 
 	return (head->next->next == head);
 }
+EXPORT_SYMBOL(drm_mm_search_free);
 
 int drm_mm_init(struct drm_mm * mm, unsigned long start, unsigned long size)
 {
@@ -273,7 +276,7 @@ int drm_mm_init(struct drm_mm * mm, unsigned long start, unsigned long size)
 
 	return drm_mm_create_tail_node(mm, start, size);
 }
-
+EXPORT_SYMBOL(drm_mm_init);
 
 void drm_mm_takedown(struct drm_mm * mm)
 {
drivers/gpu/drm/drm_proc.c +122 -13

190 lines not on this page · raw message

drivers/gpu/drm/drm_stub.c +10 -0
index c2f584f..82f4657 100644
@@ -152,6 +152,15 @@ static int drm_fill_in_dev(struct drm_device * dev, struct pci_dev *pdev,
 		goto error_out_unreg;
 	}
 
+	if (driver->driver_features & DRIVER_GEM) {
+		retcode = drm_gem_init(dev);
+		if (retcode) {
+			DRM_ERROR("Cannot initialize graphics execution "
+				  "manager (GEM)\n");
+			goto error_out_unreg;
+		}
+	}
+
 	return 0;
 
       error_out_unreg:
@@ -317,6 +326,7 @@ int drm_put_dev(struct drm_device * dev)
 int drm_put_minor(struct drm_minor **minor_p)
 {
 	struct drm_minor *minor = *minor_p;
+
 	DRM_DEBUG("release secondary minor %d\n", minor->index);
 
 	if (minor->type == DRM_MINOR_LEGACY)
drivers/gpu/drm/i915/Makefile +5 -1
index b032808..0399ca8 100644
@@ -3,7 +3,11 @@
 # Direct Rendering Infrastructure (DRI) in XFree86 4.1.0 and higher.
 
 ccflags-y := -Iinclude/drm
-i915-y := i915_drv.o i915_dma.o i915_irq.o i915_mem.o i915_opregion.o
+i915-y := i915_drv.o i915_dma.o i915_irq.o i915_mem.o i915_opregion.o \
+	i915_gem.o \
+	i915_gem_debug.o \
+	i915_gem_proc.o \
+	i915_gem_tiling.o
 
 i915-$(CONFIG_COMPAT)   += i915_ioc32.o
 
drivers/gpu/drm/i915/i915_dma.c +76 -18

151 lines not on this page · raw message

drivers/gpu/drm/i915/i915_drv.c +7 -1
index d95eca2..e7c05d8 100644
@@ -546,11 +546,13 @@ static struct drm_driver driver = {
 	.driver_features =
 	    DRIVER_USE_AGP | DRIVER_REQUIRE_AGP | /* DRIVER_USE_MTRR |*/
 	    DRIVER_HAVE_IRQ | DRIVER_IRQ_SHARED | DRIVER_IRQ_VBL |
-	    DRIVER_IRQ_VBL2,
+	    DRIVER_IRQ_VBL2 | DRIVER_GEM,
 	.load = i915_driver_load,
 	.unload = i915_driver_unload,
+	.open = i915_driver_open,
 	.lastclose = i915_driver_lastclose,
 	.preclose = i915_driver_preclose,
+	.postclose = i915_driver_postclose,
 	.suspend = i915_suspend,
 	.resume = i915_resume,
 	.device_is_agp = i915_driver_device_is_agp,
@@ -563,6 +565,10 @@ static struct drm_driver driver = {
 	.reclaim_buffers = drm_core_reclaim_buffers,
 	.get_map_ofs = drm_core_get_map_ofs,
 	.get_reg_ofs = drm_core_get_reg_ofs,
+	.proc_init = i915_gem_proc_init,
+	.proc_cleanup = i915_gem_proc_cleanup,
+	.gem_init_object = i915_gem_init_object,
+	.gem_free_object = i915_gem_free_object,
 	.ioctls = i915_ioctls,
 	.fops = {
 		 .owner = THIS_MODULE,
drivers/gpu/drm/i915/i915_drv.h +249 -4

329 lines not on this page · raw message

drivers/gpu/drm/i915/i915_gem.c new file +2509 -0

1,634 lines not on this page · raw message

drivers/gpu/drm/i915/i915_gem_debug.c new file +201 -0

201 lines not on this page · raw message

drivers/gpu/drm/i915/i915_gem_proc.c new file +292 -0

292 lines not on this page · raw message

drivers/gpu/drm/i915/i915_gem_tiling.c new file +256 -0

256 lines not on this page · raw message

drivers/gpu/drm/i915/i915_irq.c +5 -3
index ae7d3a8..615d2b4 100644

Lines of this file are not shown. View the raw message.

drivers/gpu/drm/i915/i915_reg.h +24 -13
index 43ad2cb..5c2d9f2 100644

Lines of this file are not shown. View the raw message.

include/drm/drm.h +31 -0
index 38d3c6b..dc347ef 100644

Lines of this file are not shown. View the raw message.

include/drm/drmP.h +151 -0

151 lines not on this page · raw message

include/drm/i915_drm.h +332 -0

332 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

Signature · 1 line
1.5.6.3

Part of the diff is not shown here. View the raw message.

#4 lore raw

Re: [PATCH] Export kmap_atomic_pfn for DRM-GEM.

In reply to Eric Anholt
Quoted 22 lines · Eric Anholt

The driver would like to map IO space directly for copying data in when appropriate, to avoid CPU cache flushing for streaming writes. kmap_atomic_pfn lets us avoid IPIs associated with ioremap for this process.

---
 arch/x86/mm/highmem_32.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
arch/x86/mm/highmem_32.c +1 -0
index 165c871..d52e91d 100644
@@ -137,6 +137,7 @@ void *kmap_atomic_pfn(unsigned long pfn, enum km_type
 type)
 
 	return (void*) vaddr;
 }
+EXPORT_SYMBOL(kmap_atomic_pfn);
 
 struct page *kmap_atomic_to_page(void *ptr)
Quoted 1 line

{

I wonder if you ever tested my vmap rework patches with this issue? It seems somewhat x86 specific and also not conceptually so clean to use kmap_atomic_pfn for this. vmap may not be used by all architectures but I think it might be able to cover some of them.

As I said, there are some other possible improvements that can be made to my vmap rewrite if performance isn't good enough, but I simply have not seen numbers...

Thanks,
Nick

#5 lore raw

Re: [PATCH] Export kmap_atomic_pfn for DRM-GEM.

Quoted 31 lines · Nick Piggin
Quoted 22 lines · Eric Anholt

The driver would like to map IO space directly for copying data in when appropriate, to avoid CPU cache flushing for streaming writes. kmap_atomic_pfn lets us avoid IPIs associated with ioremap for this process.

---
 arch/x86/mm/highmem_32.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
arch/x86/mm/highmem_32.c +1 -0
index 165c871..d52e91d 100644
@@ -137,6 +137,7 @@ void *kmap_atomic_pfn(unsigned long pfn, enum km_type
 type)
 
 	return (void*) vaddr;
 }
+EXPORT_SYMBOL(kmap_atomic_pfn);
 
 struct page *kmap_atomic_to_page(void *ptr)
Quoted 1 line

{

I wonder if you ever tested my vmap rework patches with this issue? It seems somewhat x86 specific and also not conceptually so clean to use kmap_atomic_pfn for this. vmap may not be used by all architectures but I think it might be able to cover some of them.

Quoted 3 lines

As I said, there are some other possible improvements that can be made to my vmap rewrite if performance isn't good enough, but I simply have not seen numbers...

The consumer of this is a driver for Intel platforms, so being x86-specific is not a worry this patch series.

However, when other DRM drivers get around to doing memory management, I'm sure they'll also be interested in an ioremap_wc that doesn't eat ipi costs. For us, the ipis for flushing were eating over 10% of CPU time. If your patch series cuts that cost, we could drop this piece at that point.

Signature · 2 lines
Eric Anholt
[email protected]                         [email protected]
#6 lore raw

Re: [PATCH] Export kmap_atomic_pfn for DRM-GEM.

Quoted 31 lines · Eric Anholt
Quoted 30 lines · Nick Piggin
Quoted 22 lines · Eric Anholt

The driver would like to map IO space directly for copying data in when appropriate, to avoid CPU cache flushing for streaming writes. kmap_atomic_pfn lets us avoid IPIs associated with ioremap for this process.

---
 arch/x86/mm/highmem_32.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
arch/x86/mm/highmem_32.c +1 -0
index 165c871..d52e91d 100644
@@ -137,6 +137,7 @@ void *kmap_atomic_pfn(unsigned long pfn, enum
 km_type type)
 
 	return (void*) vaddr;
 }
+EXPORT_SYMBOL(kmap_atomic_pfn);
 
 struct page *kmap_atomic_to_page(void *ptr)
Quoted 1 line

{

I wonder if you ever tested my vmap rework patches with this issue? It seems somewhat x86 specific and also not conceptually so clean to use kmap_atomic_pfn for this. vmap may not be used by all architectures but I think it might be able to cover some of them.

Quoted 6 lines
Quoted 3 lines

As I said, there are some other possible improvements that can be made to my vmap rewrite if performance isn't good enough, but I simply have not seen numbers...

The consumer of this is a driver for Intel platforms, so being x86-specific is not a worry this patch series.

It would help verify and improve the new vmap code, and it would be "doing the right thing" to begin with. It would avoid some nasty ifdefery in your driver too. And what about 64 bit x86 that doesn't have kmap_atomic_pfn? Or x86 builds without highmem?

Quoted 5 lines

However, when other DRM drivers get around to doing memory management, I'm sure they'll also be interested in an ioremap_wc that doesn't eat ipi costs. For us, the ipis for flushing were eating over 10% of CPU time. If your patch series cuts that cost, we could drop this piece at that point.

It can cut the cost quite significantly on normal vmap/vunmap loads I tested. Whether it will work as well on your workload, I don't know but I would have liked to find out. I raised this issue quite a while back, so I'm disappointed it had not been tried...

#7 lore raw

Re: [PATCH] Export kmap_atomic_pfn for DRM-GEM.

Quoted 10 lines · Nick Piggin
Quoted 5 lines

However, when other DRM drivers get around to doing memory management, I'm sure they'll also be interested in an ioremap_wc that doesn't eat ipi costs. For us, the ipis for flushing were eating over 10% of CPU time. If your patch series cuts that cost, we could drop this piece at that point.

It can cut the cost quite significantly on normal vmap/vunmap loads I tested. Whether it will work as well on your workload, I don't know but I would have liked to find out. I raised this issue quite a while back, so I'm disappointed it had not been tried...

I think Eric has code with the vmap changes now?

Given our discussions at KS/Plumbers would you be ok with acking these patches? Or do you want a repost so you can check out the vmap stuff?

After talking a bit more about it, I think we agreed that the ioctl interface is actually a better approach then trying to shoehorn this stuff into system calls, so aside from the vmap code (which could be done in 2.6.29 or whenever the vmap stuff lands) I think this patchset is pretty close to what we want in drm-next now...

Thanks,
Jesse

#8 lore raw

Re: [PATCH] Export kmap_atomic_pfn for DRM-GEM.

Quoted 14 lines · Jesse Barnes
Quoted 10 lines · Nick Piggin
Quoted 5 lines

However, when other DRM drivers get around to doing memory management, I'm sure they'll also be interested in an ioremap_wc that doesn't eat ipi costs. For us, the ipis for flushing were eating over 10% of CPU time. If your patch series cuts that cost, we could drop this piece at that point.

It can cut the cost quite significantly on normal vmap/vunmap loads I tested. Whether it will work as well on your workload, I don't know but I would have liked to find out. I raised this issue quite a while back, so I'm disappointed it had not been tried...

I think Eric has code with the vmap changes now?

Quoted 8 lines

Given our discussions at KS/Plumbers would you be ok with acking these patches? Or do you want a repost so you can check out the vmap stuff?

After talking a bit more about it, I think we agreed that the ioctl interface is actually a better approach then trying to shoehorn this stuff into system calls, so aside from the vmap code (which could be done in 2.6.29 or whenever the vmap stuff lands) I think this patchset is pretty close to what we want in drm-next now...

I've been trying to get a good test of the vmap changes. Unfortunately, it looks like things have changed in ioremap in the intervening time between when I last tested and now. I was taking 2.6.27-rc5-mm1 (since that was the only git tree I found with Nick's changes in it, unfortunately) and merging our stuff into there then reverting the kmap_atomic_prot_pfn bit.

However, we've moved from 10% cost in unmapping due to IPIing to a >30% cost in mapping due to change_page_attr. This is regardless of whether I do ioremap or ioremap_wc. The physical range is covered by a WC MTRR, and the X Server's mapping the memory using the _wc resource. In the DRM, I just tried moving every ioremap to _wc, and it's the same. The call chain looks like

i915_gem_pwrite_ioctl (60%)
ioremap_wc (39%)
ioremap_nocache (39%)
ioremap_caller (39%)
ioremap_change_attr (36%)
_set_memory_uc (36%)
change_page_attr_set_clr (36%)
vm_unmap_aliases (31%)

Maybe if I go back and generate a tree of just Nick's changes and try to merge them forward I can get a good test. However, it looks to me like we've got some serious brokenness in ioremap and attribute handling coming up.

Signature · 2 lines
Eric Anholt
[email protected]                         [email protected]