summaryrefslogtreecommitdiff
path: root/io_u_queue.c
diff options
context:
space:
mode:
authorJens Axboe <axboe@kernel.dk>2013-05-28 14:16:55 +0200
committerJens Axboe <axboe@kernel.dk>2013-05-28 14:16:55 +0200
commit2ae0b204743d6b4048c6fffd46c6280a70f2ecd1 (patch)
tree87e09c9731a50eec331d52824de73b69283f4936 /io_u_queue.c
parent6e5c4b8e46c95ca75e30e1110a0d24b2df9c47e9 (diff)
Replace list based free/busy/requeue list with FIFO + ring
Cache friendliness of the list is pretty low. This has provably lower overhead. Signed-off-by: Jens Axboe <axboe@kernel.dk>
Diffstat (limited to 'io_u_queue.c')
-rw-r--r--io_u_queue.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/io_u_queue.c b/io_u_queue.c
new file mode 100644
index 0000000..5734e9c
--- /dev/null
+++ b/io_u_queue.c
@@ -0,0 +1,43 @@
+#include <stdlib.h>
+#include "io_u_queue.h"
+
+int io_u_qinit(struct io_u_queue *q, unsigned int nr)
+{
+ q->io_us = calloc(sizeof(struct io_u *), nr);
+ if (!q->io_us)
+ return 1;
+
+ q->nr = 0;
+ return 0;
+}
+
+void io_u_qexit(struct io_u_queue *q)
+{
+ free(q->io_us);
+}
+
+int io_u_rinit(struct io_u_ring *ring, unsigned int nr)
+{
+ ring->max = nr + 1;
+ if (ring->max & (ring->max - 1)) {
+ ring->max--;
+ ring->max |= ring->max >> 1;
+ ring->max |= ring->max >> 2;
+ ring->max |= ring->max >> 4;
+ ring->max |= ring->max >> 8;
+ ring->max |= ring->max >> 16;
+ ring->max++;
+ }
+
+ ring->ring = calloc(sizeof(struct io_u *), ring->max);
+ if (!ring->ring)
+ return 1;
+
+ ring->head = ring->tail = 0;
+ return 0;
+}
+
+void io_u_rexit(struct io_u_ring *ring)
+{
+ free(ring->ring);
+}