diff options
author | Rusty Russell <rusty@rustcorp.com.au> | 2012-01-12 00:14:43 -0500 |
---|---|---|
committer | Rusty Russell <rusty@rustcorp.com.au> | 2012-01-12 00:14:43 -0500 |
commit | 41f0377f73039ca6fe97a469d1941a89cd9757f1 (patch) | |
tree | 380814eb3ad8092069c784539b5b88f8a9506240 /drivers/virtio | |
parent | f96fde41f7f9af6cf20f6a1919f5d9670f84d574 (diff) |
virtio: support unlocked queue kick
Based on patch by Christoph for virtio_blk speedup:
Split virtqueue_kick to be able to do the actual notification
outside the lock protecting the virtqueue. This patch was
originally done by Stefan Hajnoczi, but I can't find the
original one anymore and had to recreated it from memory.
Pointers to the original or corrections for the commit message
are welcome.
Stefan's patch was here:
https://github.com/stefanha/linux/commit/a6d06644e3a58e57a774e77d7dc34c4a5a2e7496
http://www.spinics.net/lists/linux-virtualization/msg14616.html
Third time's the charm!
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Diffstat (limited to 'drivers/virtio')
-rw-r--r-- | drivers/virtio/virtio_ring.c | 60 |
1 files changed, 48 insertions, 12 deletions
diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c index 6ea92a6d1134..c56bbe799241 100644 --- a/drivers/virtio/virtio_ring.c +++ b/drivers/virtio/virtio_ring.c | |||
@@ -262,19 +262,22 @@ add_head: | |||
262 | EXPORT_SYMBOL_GPL(virtqueue_add_buf); | 262 | EXPORT_SYMBOL_GPL(virtqueue_add_buf); |
263 | 263 | ||
264 | /** | 264 | /** |
265 | * virtqueue_kick - update after add_buf | 265 | * virtqueue_kick_prepare - first half of split virtqueue_kick call. |
266 | * @vq: the struct virtqueue | 266 | * @vq: the struct virtqueue |
267 | * | 267 | * |
268 | * After one or more virtqueue_add_buf calls, invoke this to kick | 268 | * Instead of virtqueue_kick(), you can do: |
269 | * the other side. | 269 | * if (virtqueue_kick_prepare(vq)) |
270 | * virtqueue_notify(vq); | ||
270 | * | 271 | * |
271 | * Caller must ensure we don't call this with other virtqueue | 272 | * This is sometimes useful because the virtqueue_kick_prepare() needs |
272 | * operations at the same time (except where noted). | 273 | * to be serialized, but the actual virtqueue_notify() call does not. |
273 | */ | 274 | */ |
274 | void virtqueue_kick(struct virtqueue *_vq) | 275 | bool virtqueue_kick_prepare(struct virtqueue *_vq) |
275 | { | 276 | { |
276 | struct vring_virtqueue *vq = to_vvq(_vq); | 277 | struct vring_virtqueue *vq = to_vvq(_vq); |
277 | u16 new, old; | 278 | u16 new, old; |
279 | bool needs_kick; | ||
280 | |||
278 | START_USE(vq); | 281 | START_USE(vq); |
279 | /* Descriptors and available array need to be set before we expose the | 282 | /* Descriptors and available array need to be set before we expose the |
280 | * new available array entries. */ | 283 | * new available array entries. */ |
@@ -287,13 +290,46 @@ void virtqueue_kick(struct virtqueue *_vq) | |||
287 | /* Need to update avail index before checking if we should notify */ | 290 | /* Need to update avail index before checking if we should notify */ |
288 | virtio_mb(vq); | 291 | virtio_mb(vq); |
289 | 292 | ||
290 | if (vq->event ? | 293 | if (vq->event) { |
291 | vring_need_event(vring_avail_event(&vq->vring), new, old) : | 294 | needs_kick = vring_need_event(vring_avail_event(&vq->vring), |
292 | !(vq->vring.used->flags & VRING_USED_F_NO_NOTIFY)) | 295 | new, old); |
293 | /* Prod other side to tell it about changes. */ | 296 | } else { |
294 | vq->notify(&vq->vq); | 297 | needs_kick = !(vq->vring.used->flags & VRING_USED_F_NO_NOTIFY); |
295 | 298 | } | |
296 | END_USE(vq); | 299 | END_USE(vq); |
300 | return needs_kick; | ||
301 | } | ||
302 | EXPORT_SYMBOL_GPL(virtqueue_kick_prepare); | ||
303 | |||
304 | /** | ||
305 | * virtqueue_notify - second half of split virtqueue_kick call. | ||
306 | * @vq: the struct virtqueue | ||
307 | * | ||
308 | * This does not need to be serialized. | ||
309 | */ | ||
310 | void virtqueue_notify(struct virtqueue *_vq) | ||
311 | { | ||
312 | struct vring_virtqueue *vq = to_vvq(_vq); | ||
313 | |||
314 | /* Prod other side to tell it about changes. */ | ||
315 | vq->notify(_vq); | ||
316 | } | ||
317 | EXPORT_SYMBOL_GPL(virtqueue_notify); | ||
318 | |||
319 | /** | ||
320 | * virtqueue_kick - update after add_buf | ||
321 | * @vq: the struct virtqueue | ||
322 | * | ||
323 | * After one or more virtqueue_add_buf calls, invoke this to kick | ||
324 | * the other side. | ||
325 | * | ||
326 | * Caller must ensure we don't call this with other virtqueue | ||
327 | * operations at the same time (except where noted). | ||
328 | */ | ||
329 | void virtqueue_kick(struct virtqueue *vq) | ||
330 | { | ||
331 | if (virtqueue_kick_prepare(vq)) | ||
332 | virtqueue_notify(vq); | ||
297 | } | 333 | } |
298 | EXPORT_SYMBOL_GPL(virtqueue_kick); | 334 | EXPORT_SYMBOL_GPL(virtqueue_kick); |
299 | 335 | ||