summaryrefslogtreecommitdiff
path: root/fifo.h
diff options
context:
space:
mode:
authorJens Axboe <jens.axboe@oracle.com>2007-05-16 09:25:09 +0200
committerJens Axboe <jens.axboe@oracle.com>2007-05-16 09:25:09 +0200
commite28875637094451a3c5ec4071f964c1a02dd8f5b (patch)
tree77487b30c2cddb4b11ee63519e98d240d49ee7e2 /fifo.h
parentd84f8d4931be0c7519bd9f97f9914b07578a9854 (diff)
downloadfio-e28875637094451a3c5ec4071f964c1a02dd8f5b.tar.gz
fio-e28875637094451a3c5ec4071f964c1a02dd8f5b.tar.bz2
blktrace support: speedup reading of data
We used to read in data in really small chunks (48 bytes at the time, the size of the trace). This is really slow for large traces, so add a fifo frontend to refill the cache in much larger sizes. Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
Diffstat (limited to 'fifo.h')
-rw-r--r--fifo.h48
1 files changed, 48 insertions, 0 deletions
diff --git a/fifo.h b/fifo.h
new file mode 100644
index 00000000..6a9115d4
--- /dev/null
+++ b/fifo.h
@@ -0,0 +1,48 @@
+/*
+ * A simple FIFO implementation.
+ *
+ * Copyright (C) 2004 Stelian Pop <stelian@popies.net>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
+struct fifo {
+ unsigned char *buffer; /* the buffer holding the data */
+ unsigned int size; /* the size of the allocated buffer */
+ unsigned int in; /* data is added at offset (in % size) */
+ unsigned int out; /* data is extracted from off. (out % size) */
+};
+
+struct fifo *fifo_alloc(unsigned int);
+unsigned int fifo_put(struct fifo *, void *, unsigned int);
+unsigned int fifo_get(struct fifo *, void *, unsigned int);
+
+static inline unsigned int fifo_len(struct fifo *fifo)
+{
+ return fifo->in - fifo->out;
+}
+
+#define min(x,y) ({ \
+ typeof(x) _x = (x); \
+ typeof(y) _y = (y); \
+ (void) (&_x == &_y); \
+ _x < _y ? _x : _y; })
+
+#define max(x,y) ({ \
+ typeof(x) _x = (x); \
+ typeof(y) _y = (y); \
+ (void) (&_x == &_y); \
+ _x > _y ? _x : _y; })
+