From: Chia-I Wu <olvaffe@gmail.com>
To: dri-devel@lists.freedesktop.org
Cc: kraxel@redhat.com, gurchetansingh@chromium.org
Subject: [PATCH 06/11] drm/virtio: set up virtqueue sgs before locking
Date: Wed, 5 Feb 2020 10:19:50 -0800 [thread overview]
Message-ID: <20200205181955.202485-7-olvaffe@gmail.com> (raw)
In-Reply-To: <20200205181955.202485-1-olvaffe@gmail.com>
sgs setup does not need to be in the critical section.
Signed-off-by: Chia-I Wu <olvaffe@gmail.com>
---
drivers/gpu/drm/virtio/virtgpu_vq.c | 66 +++++++++++++++--------------
1 file changed, 35 insertions(+), 31 deletions(-)
diff --git a/drivers/gpu/drm/virtio/virtgpu_vq.c b/drivers/gpu/drm/virtio/virtgpu_vq.c
index 1e27f4c09341e..6ccb2a54dfb3c 100644
--- a/drivers/gpu/drm/virtio/virtgpu_vq.c
+++ b/drivers/gpu/drm/virtio/virtgpu_vq.c
@@ -318,34 +318,19 @@ static struct sg_table *vmalloc_to_sgt(char *data, uint32_t size, int *sg_ents)
return sgt;
}
-static bool virtio_gpu_queue_ctrl_buffer_locked(struct virtio_gpu_device *vgdev,
- struct virtio_gpu_vbuffer *vbuf,
- struct scatterlist *vout)
+static bool virtio_gpu_queue_ctrl_sgs_locked(struct virtio_gpu_device *vgdev,
+ struct virtio_gpu_vbuffer *vbuf,
+ struct scatterlist **sgs,
+ int outcnt,
+ int incnt)
{
struct virtqueue *vq = vgdev->ctrlq.vq;
- struct scatterlist *sgs[3], vcmd, vresp;
- int outcnt = 0, incnt = 0;
bool notify = false;
int ret;
if (!vgdev->vqs_ready)
return notify;
- sg_init_one(&vcmd, vbuf->buf, vbuf->size);
- sgs[outcnt + incnt] = &vcmd;
- outcnt++;
-
- if (vout) {
- sgs[outcnt + incnt] = vout;
- outcnt++;
- }
-
- if (vbuf->resp_size) {
- sg_init_one(&vresp, vbuf->resp_buf, vbuf->resp_size);
- sgs[outcnt + incnt] = &vresp;
- incnt++;
- }
-
ret = virtqueue_add_sgs(vq, sgs, outcnt, incnt, vbuf, GFP_ATOMIC);
WARN_ON(ret);
@@ -361,26 +346,45 @@ static void virtio_gpu_queue_fenced_ctrl_buffer(struct virtio_gpu_device *vgdev,
struct virtio_gpu_fence *fence)
{
struct virtqueue *vq = vgdev->ctrlq.vq;
- struct scatterlist *vout = NULL, sg;
+ struct scatterlist *sgs[3], vcmd, vout, vresp;
struct sg_table *sgt = NULL;
+ int elemcnt = 0, outcnt = 0, incnt = 0;
bool notify;
- int outcnt = 0;
+ /* set up vcmd */
+ sg_init_one(&vcmd, vbuf->buf, vbuf->size);
+ elemcnt++;
+ sgs[outcnt] = &vcmd;
+ outcnt++;
+
+ /* set up vout */
if (vbuf->data_size) {
if (is_vmalloc_addr(vbuf->data_buf)) {
+ int sg_ents;
sgt = vmalloc_to_sgt(vbuf->data_buf, vbuf->data_size,
- &outcnt);
+ &sg_ents);
if (!sgt) {
if (fence && vbuf->objs)
virtio_gpu_array_unlock_resv(vbuf->objs);
return;
}
- vout = sgt->sgl;
+
+ elemcnt += sg_ents;
+ sgs[outcnt] = sgt->sgl;
} else {
- sg_init_one(&sg, vbuf->data_buf, vbuf->data_size);
- vout = &sg;
- outcnt = 1;
+ sg_init_one(&vout, vbuf->data_buf, vbuf->data_size);
+ elemcnt++;
+ sgs[outcnt] = &vout;
}
+ outcnt++;
+ }
+
+ /* set up vresp */
+ if (vbuf->resp_size) {
+ sg_init_one(&vresp, vbuf->resp_buf, vbuf->resp_size);
+ elemcnt++;
+ sgs[outcnt + incnt] = &vresp;
+ incnt++;
}
again:
@@ -394,10 +398,9 @@ static void virtio_gpu_queue_fenced_ctrl_buffer(struct virtio_gpu_device *vgdev,
* to wait for free space, which can result in fence ids being
* submitted out-of-order.
*/
- if (vq->num_free < 2 + outcnt) {
+ if (vq->num_free < elemcnt) {
spin_unlock(&vgdev->ctrlq.qlock);
- wait_event(vgdev->ctrlq.ack_queue,
- vq->num_free >= 2 + outcnt);
+ wait_event(vgdev->ctrlq.ack_queue, vq->num_free >= elemcnt);
goto again;
}
@@ -409,7 +412,8 @@ static void virtio_gpu_queue_fenced_ctrl_buffer(struct virtio_gpu_device *vgdev,
virtio_gpu_array_unlock_resv(vbuf->objs);
}
}
- notify = virtio_gpu_queue_ctrl_buffer_locked(vgdev, vbuf, vout);
+ notify = virtio_gpu_queue_ctrl_sgs_locked(vgdev, vbuf, sgs, outcnt,
+ incnt);
spin_unlock(&vgdev->ctrlq.qlock);
if (notify) {
if (vgdev->disable_notify)
--
2.25.0.341.g760bfbb309-goog
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel
next prev parent reply other threads:[~2020-02-05 18:20 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-02-05 18:19 [PATCH 00/11] drm/virtio: fixes and cleanups for vbuf queuing Chia-I Wu
2020-02-05 18:19 ` [PATCH 01/11] drm/virtio: fix a wait_event condition Chia-I Wu
2020-02-05 18:19 ` [PATCH 02/11] drm/virtio: remove incorrect ENOSPC check Chia-I Wu
2020-02-05 18:19 ` [PATCH 03/11] drm/virtio: add virtio_gpu_vbuf_ctrl_hdr Chia-I Wu
2020-02-05 18:19 ` [PATCH 04/11] drm/virtio: no need to pass virtio_gpu_ctrl_hdr Chia-I Wu
2020-02-05 18:19 ` [PATCH 05/11] drm/virtio: unlock object array on errors Chia-I Wu
2020-02-05 18:19 ` Chia-I Wu [this message]
2020-02-05 18:19 ` [PATCH 07/11] drm/virtio: move locking into virtio_gpu_queue_ctrl_sgs Chia-I Wu
2020-02-05 18:19 ` [PATCH 08/11] drm/virtio: move the check for vqs_ready earlier Chia-I Wu
2020-02-05 18:19 ` [PATCH 09/11] drm/virtio: avoid an infinite loop Chia-I Wu
2020-02-06 9:49 ` Gerd Hoffmann
2020-02-06 18:15 ` Chia-I Wu
2020-02-05 18:19 ` [PATCH 10/11] drm/virtio: move virtqueue_notify into virtio_gpu_queue_ctrl_sgs Chia-I Wu
2020-02-05 18:19 ` [PATCH 11/11] drm/virtio: rework virtio_gpu_enable_notify Chia-I Wu
2020-02-06 11:17 ` [PATCH 00/11] drm/virtio: fixes and cleanups for vbuf queuing Gerd Hoffmann
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200205181955.202485-7-olvaffe@gmail.com \
--to=olvaffe@gmail.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=gurchetansingh@chromium.org \
--cc=kraxel@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.