From b8de77cd2a205cb64bfb835f2789bee06af43db6 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Thu, 12 Jan 2012 15:44:43 +1030 Subject: [PATCH] --- yaml --- r: 284239 b: refs/heads/master c: 41f0377f73039ca6fe97a469d1941a89cd9757f1 h: refs/heads/master i: 284237: 3169824d2355c97a98236b445aeb90c10568818d 284235: 4582e9ecb0f22412a87c419af5d7ed136110d4a6 284231: 26dbddca5c3232cab7a1c4bb48cd32297f90df03 284223: 6a08649ccedcfcb6bbd2c2958d76e1ebdf7eef04 v: v3 --- [refs] | 2 +- trunk/drivers/virtio/virtio_ring.c | 60 ++++++++++++++++++++++++------ trunk/include/linux/virtio.h | 4 ++ 3 files changed, 53 insertions(+), 13 deletions(-) diff --git a/[refs] b/[refs] index cdc0743473f3..0df3b3b0bb91 100644 --- a/[refs] +++ b/[refs] @@ -1,2 +1,2 @@ --- -refs/heads/master: f96fde41f7f9af6cf20f6a1919f5d9670f84d574 +refs/heads/master: 41f0377f73039ca6fe97a469d1941a89cd9757f1 diff --git a/trunk/drivers/virtio/virtio_ring.c b/trunk/drivers/virtio/virtio_ring.c index 6ea92a6d1134..c56bbe799241 100644 --- a/trunk/drivers/virtio/virtio_ring.c +++ b/trunk/drivers/virtio/virtio_ring.c @@ -262,19 +262,22 @@ int virtqueue_add_buf(struct virtqueue *_vq, EXPORT_SYMBOL_GPL(virtqueue_add_buf); /** - * virtqueue_kick - update after add_buf + * virtqueue_kick_prepare - first half of split virtqueue_kick call. * @vq: the struct virtqueue * - * After one or more virtqueue_add_buf calls, invoke this to kick - * the other side. + * Instead of virtqueue_kick(), you can do: + * if (virtqueue_kick_prepare(vq)) + * virtqueue_notify(vq); * - * Caller must ensure we don't call this with other virtqueue - * operations at the same time (except where noted). + * This is sometimes useful because the virtqueue_kick_prepare() needs + * to be serialized, but the actual virtqueue_notify() call does not. */ -void virtqueue_kick(struct virtqueue *_vq) +bool virtqueue_kick_prepare(struct virtqueue *_vq) { struct vring_virtqueue *vq = to_vvq(_vq); u16 new, old; + bool needs_kick; + START_USE(vq); /* Descriptors and available array need to be set before we expose the * new available array entries. */ @@ -287,13 +290,46 @@ void virtqueue_kick(struct virtqueue *_vq) /* Need to update avail index before checking if we should notify */ virtio_mb(vq); - if (vq->event ? - vring_need_event(vring_avail_event(&vq->vring), new, old) : - !(vq->vring.used->flags & VRING_USED_F_NO_NOTIFY)) - /* Prod other side to tell it about changes. */ - vq->notify(&vq->vq); - + if (vq->event) { + needs_kick = vring_need_event(vring_avail_event(&vq->vring), + new, old); + } else { + needs_kick = !(vq->vring.used->flags & VRING_USED_F_NO_NOTIFY); + } END_USE(vq); + return needs_kick; +} +EXPORT_SYMBOL_GPL(virtqueue_kick_prepare); + +/** + * virtqueue_notify - second half of split virtqueue_kick call. + * @vq: the struct virtqueue + * + * This does not need to be serialized. + */ +void virtqueue_notify(struct virtqueue *_vq) +{ + struct vring_virtqueue *vq = to_vvq(_vq); + + /* Prod other side to tell it about changes. */ + vq->notify(_vq); +} +EXPORT_SYMBOL_GPL(virtqueue_notify); + +/** + * virtqueue_kick - update after add_buf + * @vq: the struct virtqueue + * + * After one or more virtqueue_add_buf calls, invoke this to kick + * the other side. + * + * Caller must ensure we don't call this with other virtqueue + * operations at the same time (except where noted). + */ +void virtqueue_kick(struct virtqueue *vq) +{ + if (virtqueue_kick_prepare(vq)) + virtqueue_notify(vq); } EXPORT_SYMBOL_GPL(virtqueue_kick); diff --git a/trunk/include/linux/virtio.h b/trunk/include/linux/virtio.h index ec1706e7df50..31fe3a62874b 100644 --- a/trunk/include/linux/virtio.h +++ b/trunk/include/linux/virtio.h @@ -34,6 +34,10 @@ int virtqueue_add_buf(struct virtqueue *vq, void virtqueue_kick(struct virtqueue *vq); +bool virtqueue_kick_prepare(struct virtqueue *vq); + +void virtqueue_notify(struct virtqueue *vq); + void *virtqueue_get_buf(struct virtqueue *vq, unsigned int *len); void virtqueue_disable_cb(struct virtqueue *vq);