[PATCH] Basic support for a cpu cycle eater job
[fio.git] / ioengines.c
index 7b1c1bd3a3360e9feadd4def4eb8c90bd83111aa..01492bcf5645434bac6dee82f3c89a1dcf6d9b06 100644 (file)
 #include <errno.h>
 #include <assert.h>
 #include <time.h>
+#include <string.h>
 #include <sys/mman.h>
 #include <sys/poll.h>
 #include "fio.h"
 #include "os.h"
 
-#ifdef FIO_HAVE_LIBAIO
-
-#define ev_to_iou(ev)  (struct io_u *) ((unsigned long) (ev)->obj)
-
-static int fio_io_sync(struct thread_data *td)
-{
-       return fsync(td->fd);
-}
-
 static int fill_timespec(struct timespec *ts)
 {
 #ifdef _POSIX_TIMERS
@@ -60,6 +52,15 @@ static unsigned long long ts_utime_since_now(struct timespec *t)
        return sec + nsec;
 }
 
+static int fio_io_sync(struct thread_data *td)
+{
+       return fsync(td->fd);
+}
+
+#ifdef FIO_HAVE_LIBAIO
+
+#define ev_to_iou(ev)  (struct io_u *) ((unsigned long) (ev)->obj)
+
 struct libaio_data {
        io_context_t aio_ctx;
        struct io_event *aio_events;
@@ -86,7 +87,7 @@ static int fio_libaio_getevents(struct thread_data *td, int min, int max,
                                struct timespec *t)
 {
        struct libaio_data *ld = td->io_data;
-       int r;
+       long r;
 
        do {
                r = io_getevents(ld->aio_ctx, min, max, ld->aio_events, t);
@@ -99,14 +100,14 @@ static int fio_libaio_getevents(struct thread_data *td, int min, int max,
                        break;
        } while (1);
 
-       return r;
+       return (int) r;
 }
 
 static int fio_libaio_queue(struct thread_data *td, struct io_u *io_u)
 {
        struct libaio_data *ld = td->io_data;
        struct iocb *iocb = &io_u->iocb;
-       int ret;
+       long ret;
 
        do {
                ret = io_submit(ld->aio_ctx, 1, &iocb);
@@ -120,7 +121,7 @@ static int fio_libaio_queue(struct thread_data *td, struct io_u *io_u)
                        break;
        } while (1);
 
-       return ret;
+       return (int) ret;
 
 }
 
@@ -374,7 +375,7 @@ static int fio_syncio_queue(struct thread_data *td, struct io_u *io_u)
        if ((unsigned int) ret != io_u->buflen) {
                if (ret > 0) {
                        io_u->resid = io_u->buflen - ret;
-                       io_u->error = ENODATA;
+                       io_u->error = EIO;
                } else
                        io_u->error = errno;
        }
@@ -609,7 +610,7 @@ static int fio_sgio_prep(struct thread_data *td, struct io_u *io_u)
        int nr_blocks, lba;
 
        if (io_u->buflen & (sd->bs - 1)) {
-               fprintf(stderr, "read/write not sector aligned\n");
+               log_err("read/write not sector aligned\n");
                return EINVAL;
        }
 
@@ -717,7 +718,7 @@ int fio_sgio_init(struct thread_data *td)
                if (ret)
                        return ret;
        } else {
-               fprintf(stderr, "ioengine sgio only works on block devices\n");
+               log_err("ioengine sgio only works on block devices\n");
                return 1;
        }
 
@@ -917,3 +918,17 @@ int fio_spliceio_init(struct thread_data *td)
 }
 
 #endif /* FIO_HAVE_SPLICE */
+
+int fio_cpuio_init(struct thread_data *td)
+{
+       if (!td->cpuload) {
+               td_vmsg(td, EINVAL, "cpu thread needs rate");
+               return 1;
+       } else if (td->cpuload > 100)
+               td->cpuload = 100;
+
+       td->read_iolog = td->write_iolog = 0;
+       td->fd = -1;
+
+       return 0;
+}