diff mbox series

[4/4] drm/virtio: Use IDAs more efficiently

Message ID 20180926160031.15721-5-willy@infradead.org (mailing list archive)
State New, archived
Headers show
Series Improve virtio ID allocation | expand

Commit Message

Matthew Wilcox (Oracle) Sept. 26, 2018, 4 p.m. UTC
0-based IDAs are more efficient than any other base.  Convert the
1-based IDAs to be 0-based.

Signed-off-by: Matthew Wilcox <willy@infradead.org>
---
 drivers/gpu/drm/virtio/virtgpu_kms.c | 3 ++-
 drivers/gpu/drm/virtio/virtgpu_vq.c  | 7 +++++--
 2 files changed, 7 insertions(+), 3 deletions(-)

Comments

Matthew Wilcox (Oracle) Sept. 26, 2018, 4:04 p.m. UTC | #1
On Wed, Sep 26, 2018 at 09:00:31AM -0700, Matthew Wilcox wrote:
> @@ -59,6 +59,7 @@ static int virtio_gpu_context_create(struct virtio_gpu_device *vgdev,
>  
>  	if (handle < 0)
>  		return handle;
> +	handle++;
>  	virtio_gpu_cmd_context_create(vgdev, handle, nlen, name);
>  	return handle;
>  }

Uh.  This line is missing.

-       int handle = ida_alloc_min(&vgdev->ctx_id_ida, 1, GFP_KERNEL);
+       int handle = ida_alloc(&vgdev->ctx_id_ida, GFP_KERNEL);

It'll be there in v2 ;-)
Gerd Hoffmann Oct. 2, 2018, 11:43 a.m. UTC | #2
On Wed, Sep 26, 2018 at 09:04:55AM -0700, Matthew Wilcox wrote:
> On Wed, Sep 26, 2018 at 09:00:31AM -0700, Matthew Wilcox wrote:
> > @@ -59,6 +59,7 @@ static int virtio_gpu_context_create(struct virtio_gpu_device *vgdev,
> >  
> >  	if (handle < 0)
> >  		return handle;
> > +	handle++;
> >  	virtio_gpu_cmd_context_create(vgdev, handle, nlen, name);
> >  	return handle;
> >  }
> 
> Uh.  This line is missing.
> 
> -       int handle = ida_alloc_min(&vgdev->ctx_id_ida, 1, GFP_KERNEL);
> +       int handle = ida_alloc(&vgdev->ctx_id_ida, GFP_KERNEL);
> 
> It'll be there in v2 ;-)

I've touched the resource/object id handling too, see my "drm/virtio:
rework ttm resource handling" patch series
(https://patchwork.freedesktop.org/series/50382/).  Which still needs a
review btw.

I think that series obsoletes patch 3/4 (object id fixes) of your
series.  The other patches should rebase without too much trouble, you
could do that as well when preparing v2 ...

cheers,
  Gerd
Matthew Wilcox (Oracle) Oct. 2, 2018, 12:55 p.m. UTC | #3
On Tue, Oct 02, 2018 at 01:43:28PM +0200, Gerd Hoffmann wrote:
> On Wed, Sep 26, 2018 at 09:04:55AM -0700, Matthew Wilcox wrote:
> > On Wed, Sep 26, 2018 at 09:00:31AM -0700, Matthew Wilcox wrote:
> > > @@ -59,6 +59,7 @@ static int virtio_gpu_context_create(struct virtio_gpu_device *vgdev,
> > >  
> > >  	if (handle < 0)
> > >  		return handle;
> > > +	handle++;
> > >  	virtio_gpu_cmd_context_create(vgdev, handle, nlen, name);
> > >  	return handle;
> > >  }
> > 
> > Uh.  This line is missing.
> > 
> > -       int handle = ida_alloc_min(&vgdev->ctx_id_ida, 1, GFP_KERNEL);
> > +       int handle = ida_alloc(&vgdev->ctx_id_ida, GFP_KERNEL);
> > 
> > It'll be there in v2 ;-)
> 
> I've touched the resource/object id handling too, see my "drm/virtio:
> rework ttm resource handling" patch series
> (https://patchwork.freedesktop.org/series/50382/).  Which still needs a
> review btw.

Um, according to patchwork, you only posted it yesterday.  Does DRM
normally expect a review within 24 hours?

> I think that series obsoletes patch 3/4 (object id fixes) of your
> series.  The other patches should rebase without too much trouble, you
> could do that as well when preparing v2 ...

It seems a little odd to me to expect a drive-by contributor (ie me) to
rebase their patches on top of a patch series which wasn't even posted
at the time they contributed their original patch.  If it was already
in -next, that'd be a reasonable request.
diff mbox series

Patch

diff --git a/drivers/gpu/drm/virtio/virtgpu_kms.c b/drivers/gpu/drm/virtio/virtgpu_kms.c
index bf609dcae224..b576c9ef6323 100644
--- a/drivers/gpu/drm/virtio/virtgpu_kms.c
+++ b/drivers/gpu/drm/virtio/virtgpu_kms.c
@@ -59,6 +59,7 @@  static int virtio_gpu_context_create(struct virtio_gpu_device *vgdev,
 
 	if (handle < 0)
 		return handle;
+	handle++;
 	virtio_gpu_cmd_context_create(vgdev, handle, nlen, name);
 	return handle;
 }
@@ -67,7 +68,7 @@  static void virtio_gpu_context_destroy(struct virtio_gpu_device *vgdev,
 				      uint32_t ctx_id)
 {
 	virtio_gpu_cmd_context_destroy(vgdev, ctx_id);
-	ida_free(&vgdev->ctx_id_ida, ctx_id);
+	ida_free(&vgdev->ctx_id_ida, ctx_id - 1);
 }
 
 static void virtio_gpu_init_vq(struct virtio_gpu_queue *vgvq,
diff --git a/drivers/gpu/drm/virtio/virtgpu_vq.c b/drivers/gpu/drm/virtio/virtgpu_vq.c
index 387951c971d4..81297fe0147d 100644
--- a/drivers/gpu/drm/virtio/virtgpu_vq.c
+++ b/drivers/gpu/drm/virtio/virtgpu_vq.c
@@ -40,12 +40,15 @@ 
 
 int virtio_gpu_resource_id_get(struct virtio_gpu_device *vgdev)
 {
-	return ida_alloc_min(&vgdev->resource_ida, 1, GFP_KERNEL);
+	int handle = ida_alloc(&vgdev->resource_ida, GFP_KERNEL);
+	if (handle < 0)
+		return handle;
+	return handle + 1;
 }
 
 void virtio_gpu_resource_id_put(struct virtio_gpu_device *vgdev, uint32_t id)
 {
-	ida_free(&vgdev->resource_ida, id);
+	ida_free(&vgdev->resource_ida, id - 1);
 }
 
 void virtio_gpu_ctrl_ack(struct virtqueue *vq)