devif: "null" backend which simply forwards everything
authorRoni Häcki <roni.haecki@inf.ethz.ch>
Thu, 24 Aug 2017 10:38:36 +0000 (12:38 +0200)
committerRoni Häcki <roni.haecki@inf.ethz.ch>
Thu, 24 Aug 2017 10:38:36 +0000 (12:38 +0200)
Using this for measuring the overhead of the stacking itself

Signed-off-by: Roni Häcki <roni.haecki@inf.ethz.ch>

include/devif/backends/null.h [new file with mode: 0644]
lib/devif/backends/null/Hakefile [new file with mode: 0644]
lib/devif/backends/null/devif_backend_null.c [new file with mode: 0644]

diff --git a/include/devif/backends/null.h b/include/devif/backends/null.h
new file mode 100644 (file)
index 0000000..75d1f45
--- /dev/null
@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 2016 ETH Zurich.
+ * All rights reserved.
+ *
+ * This file is distributed under the terms in the attached LICENSE file.
+ * If you do not find this file, copies can be found by writing to:
+ * ETH Zurich D-INFK, Universitaetstr. 6, CH-8092 Zurich. Attn: Systems Group.
+ */
+#ifndef NULL_H_
+#define NULL_H_ 1
+
+
+#include <barrelfish/barrelfish.h>
+
+/*
+ * Simple queue that does nothing but forward to another queue
+ */
+
+struct null_q;
+
+/**
+ */
+errval_t null_create(struct null_q** q,
+                     struct devq* other_q);
+
+/**
+ */
+errval_t null_destroy(struct null_q* q, struct devq* other_q);
+
+
+#endif /* NULL_H_ */
diff --git a/lib/devif/backends/null/Hakefile b/lib/devif/backends/null/Hakefile
new file mode 100644 (file)
index 0000000..a7ca8ff
--- /dev/null
@@ -0,0 +1,22 @@
+--------------------------------------------------------------------------
+-- Copyright (c) 2016, ETH Zurich.
+-- All rights reserved.
+--
+-- This file is distributed under the terms in the attached LICENSE file.
+-- If you do not find this file, copies can be found by writing to:
+-- ETH Zurich D-INFK, Universitaetstr. 6, CH-8092 Zurich. Attn: Systems Group.
+--
+-- Hakefile for lib/devif/backend/null
+-- 
+-- Null layer for device interface.
+--
+--------------------------------------------------------------------------
+
+[
+    build library { 
+        target = "devif_backend_null",
+        cFiles = ["devif_backend_null.c"],
+        addCFlags = [ "-DLIBRARY" ],
+        addLibraries = libDeps ["devif_internal"]
+    }
+]
diff --git a/lib/devif/backends/null/devif_backend_null.c b/lib/devif/backends/null/devif_backend_null.c
new file mode 100644 (file)
index 0000000..39262cb
--- /dev/null
@@ -0,0 +1,100 @@
+/*
+ * Copyright (c) 2007, 2008, 2009, 2010, 2011, 2012, ETH Zurich.
+ * All rights reserved.
+ *
+ * This file is distributed under the terms in the attached LICENSE file.
+ * If you do not find this file, copies can be found by writing to:
+ * ETH Zurich D-INFK, Haldeneggsteig 4, CH-8092 Zurich. Attn: Systems Group.
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <barrelfish/barrelfish.h>
+#include <barrelfish/waitset.h>
+#include <devif/queue_interface.h>
+#include "../../queue_interface_internal.h"
+#include <devif/backends/null.h>
+
+struct null_q {
+    struct devq my_q;
+    struct devq* q;
+};
+
+static errval_t null_register(struct devq* q, struct capref cap,
+                              regionid_t rid) 
+{
+    struct null_q* que = (struct null_q*) q;
+    return que->q->f.reg(que->q, cap, rid);
+}
+
+static errval_t null_deregister(struct devq* q, regionid_t rid) 
+{
+    struct null_q* que = (struct null_q*) q;
+    return que->q->f.dereg(que->q, rid);
+}
+
+
+static errval_t null_control(struct devq* q, uint64_t cmd, uint64_t value,
+                             uint64_t* ret)
+{
+    struct null_q* que = (struct null_q*) q;
+    return que->q->f.ctrl(que->q, cmd, value, ret);
+}
+
+
+static errval_t null_notify(struct devq* q)
+{
+    struct null_q* que = (struct null_q*) q;
+    return que->q->f.notify(que->q);
+}
+
+static errval_t null_enqueue(struct devq* q, regionid_t rid, genoffset_t offset,
+                             genoffset_t len, genoffset_t valid_data,
+                             genoffset_t valid_length, uint64_t flags)
+{
+    struct null_q* que = (struct null_q*) q;
+    return que->q->f.enq(que->q, rid, offset, len, valid_data, valid_length, flags);
+}
+
+static errval_t null_dequeue(struct devq* q, regionid_t* rid, genoffset_t* offset,
+                             genoffset_t* len, genoffset_t* valid_data,
+                             genoffset_t* valid_length, uint64_t* flags)
+{
+    struct null_q* que = (struct null_q*) q;
+    return que->q->f.deq(que->q, rid, offset, len, valid_data, valid_length, flags);
+}
+
+/**
+ * Public functions
+ *
+ */
+
+errval_t null_create(struct null_q** q, struct devq* other_q)
+{
+    errval_t err;
+    *q = malloc(sizeof(struct null_q));
+    assert(*q);
+
+    (*q)->q = other_q;
+    err = devq_init(&(*q)->my_q, false);
+    if (err_is_fail(err)) {
+        return err;
+    }   
+
+    (*q)->my_q.f.reg = null_register;
+    (*q)->my_q.f.dereg = null_deregister;
+    (*q)->my_q.f.ctrl = null_control;
+    (*q)->my_q.f.notify = null_notify;
+    (*q)->my_q.f.enq = null_enqueue;
+    (*q)->my_q.f.deq = null_dequeue;
+    return SYS_ERR_OK;
+}
+
+errval_t null_destroy(struct null_q* q, struct devq* devq)
+{
+    devq = q->q;
+    free(q);    
+
+    return SYS_ERR_OK;
+}
+