DeviceQueue: removed code for fixed size memory allocation
authorRoni Häcki <roni.haecki@inf.ethz.ch>
Thu, 11 Aug 2016 13:50:44 +0000 (15:50 +0200)
committerRoni Häcki <roni.haecki@inf.ethz.ch>
Thu, 11 Aug 2016 13:50:44 +0000 (15:50 +0200)
Signed-off-by: Roni Häcki <roni.haecki@inf.ethz.ch>

lib/devif/region.c
lib/devif/region.h
lib/devif/region_pool.c
lib/devif/region_pool.h

index 20311d2..6f24e9d 100644 (file)
@@ -8,42 +8,23 @@
  */
 
 #include <barrelfish/barrelfish.h>
+#include <devif/queue_interface.h>
 #include "region.h"
 #include "dqi_debug.h"
 
 /**
- * @brief initialized a region
- *
- * @param region                Return pointer to the region
- * @param region_id             The ID of the region,
- * @param cap                   Capability of the memory region
- *
- * @returns error on failure or SYS_ERR_OK on success
- */
-/*
-errval_t region_init_variable_sized(struct region** region,
-                     uint32_t region_id,
-                     struct capref* cap)
-{
-    USER_PANIC("NIY for variable sized buffers\n");
-    return SYS_ERR_OK;
-}
-*/
-/**
  * @brief initialized a region from which only fixed size buffers are used
  *
  * @param region                Return pointer to the region
  * @param region_id             The ID of the region,
  * @param cap                   Capability of the memory region
- * @param len                   Length of the fixed sized buffers
  *
  * @returns error on failure or SYS_ERR_OK on success
  */
 
 errval_t region_init(struct region** region,
-                     uint32_t region_id,
-                     struct capref* cap,
-                     size_t len)
+                     regionid_t region_id,
+                     struct capref* cap)
 {
     errval_t err;
     struct frame_identity id;
@@ -64,16 +45,6 @@ errval_t region_init(struct region** region,
     tmp->base_addr = id.base;
     tmp->len = id.bytes;
 
-    // Init state for fixed buffer region
-    tmp->fixed_size = true;
-    tmp->next_buf = 0;  
-    tmp->num_buf = id.bytes/len;
-    tmp->in_use = calloc(sizeof(bool)*tmp->num_buf, 1);
-    if (region == NULL) {
-        free(tmp);
-        return LIB_ERR_MALLOC_FAIL;
-    }
-
     *region = tmp;   
     
     DQI_DEBUG("Initialize Region size=%ld addr=%16lx num_bufs=%ld \n",
@@ -92,15 +63,6 @@ errval_t region_init(struct region** region,
  */
 errval_t region_destroy(struct region* region)
 {
-    for (int i = 0; i < region->num_buf; i++) {
-        if (region->in_use[i]) {
-            DQI_DEBUG("Could not destroy region, some buffers stil in use \n");
-            // TODO reasonable error;
-            return -1;      
-        }
-    }
-
-    free(region->in_use);
     free(region);
     return SYS_ERR_OK;
 }
@@ -108,43 +70,18 @@ errval_t region_destroy(struct region* region)
  * @brief Get a buffer from a region
  *
  * @param region                The region to get the buffer from
+ * @param addr                  The physical address of the buffer
  * @param len                   lenght of the buffer
- * @param base_addr             Return pointer to the physical address 
- *                              of the buffer
  *
  * @returns error on failure or SYS_ERR_OK on success
  */
-errval_t region_get_buffer(struct region* region,
-                           uint32_t* buffer_id,
-                           lpaddr_t* addr)
+errval_t region_get_buffer_id(struct region* region,
+                              lpaddr_t addr,
+                              bufferid_t* buffer_id)
 {
-    if (region->fixed_size) {
-        uint32_t count = 0;
-        // Try to find empty slot, If we did not find 
-        // a slot after making a whole round, return error
-        while (count < region->num_buf+1) {
-            if (!region->in_use[region->next_buf]) {
-                *buffer_id = region->next_buf;
-                *addr = (region->base_addr + (region->next_buf* 
-                         region->buf_len));
-                region->in_use[region->next_buf] = true;
-                region->next_buf = (region->next_buf + 1) % region->num_buf;
-
-                DQI_DEBUG("Got buffer id=%d addr=%16lx \n", *buffer_id, *addr);
-                return SYS_ERR_OK;
-            } else {
-                region->next_buf = (region->next_buf + 1) % region->num_buf;
-                count++;
-            }
-        }   
-
-    } else {
-        USER_PANIC("NIY for variable sized buffers\n");
-    }
-
-    DQI_DEBUG("Failed to get buffer \n");
-    // TODO reasonable error
-    return -1;
+    *buffer_id = 0;
+    DQI_DEBUG("Got buffer id=%d addr=%16lx \n", *buffer_id, *addr);
+    return SYS_ERR_OK;
 }
 
 
@@ -152,27 +89,30 @@ errval_t region_get_buffer(struct region* region,
  * @brief Return a buffer to the region
  *
  * @param region                The region to return the buffer to
- * @param len                   Lenght of the buffer returned 
  * @param buffer_id             The id of the buffer to return to the region
- * @param addr                  The physical address of the freed buffer
  *
  * @returns error on failure or SYS_ERR_OK on success
  */
-errval_t region_free_buffer(struct region* region,
-                            uint32_t buffer_id)
+errval_t region_free_buffer_id(struct region* region,
+                               bufferid_t buffer_id)
 {
-    if (region->fixed_size) {
-        // Can not free buffer that is not used
-        if (region->in_use[buffer_id] != true) {
-            // TODO reasonable error
-            return -1;
-        }
-        region->in_use[buffer_id] = false;
-    } else {
-        USER_PANIC("NIY for variable sized buffers\n");
-    }
-
     DQI_DEBUG("Returned buffer id=%d \n", buffer_id);
     return SYS_ERR_OK;
 }
 
+
+/**
+ * @brief Return a if a buffer to the region is in use
+ *
+ * @param region                The region to return the buffer to
+ * @param buffer_id             The id of the buffer
+ *
+ * @returns true if the buffer is in use otherwise false
+ */
+bool region_buffer_id_in_use(struct region* region,
+                             bufferid_t buffer_id)
+{
+    DQI_DEBUG("Returned buffer id=%d \n", buffer_id);
+    return true;
+}
+
index 10f425d..12c8a35 100644 (file)
 
 
 #include <barrelfish/barrelfish.h>
+#include <devif/queue_interface.h>
 
 struct region {
     // ID of the region
-    uint32_t region_id;
+    regionid_t region_id;
     // Base address of the region
     lpaddr_t base_addr;
     // Capability of the region
     struct capref* cap;
     // Lenght of the memory region
     size_t len;
-
-    // Are the buffers fixed size?
-    bool fixed_size;
-    // State for fixed sized buffers
-    size_t num_buf;
-    size_t buf_len;
-    size_t next_buf;  
-    bool* in_use;
+    // 
 };
 
 /**
@@ -41,9 +35,8 @@ struct region {
  * @returns error on failure or SYS_ERR_OK on success
  */
 errval_t region_init(struct region** region,
-                     uint32_t region_id,
-                     struct capref* cap,
-                     size_t len);
+                     regionid_t region_id,
+                     struct capref* cap);
 /**
  * @brief free up a region
  *
@@ -54,46 +47,28 @@ errval_t region_init(struct region** region,
 errval_t region_destroy(struct region* region);
 
 /**
- * @brief initialized a region from which only fixed size buffers are used
- *
- * @param region                Return pointer to the region
- * @param region_id             The ID of the region,
- * @param cap                   Capability of the memory region
- * @param len                   Length of the fixed sized buffers
- *
- * @returns error on failure or SYS_ERR_OK on success
- */
-/*
-errval_t region_init_variable_size(struct region** region,
-                                   uint32_t region_id,
-                                   struct capref* cap,
-                                   size_t len);
-*/
-/**
- * @brief Get a buffer from a region
+ * @brief Get a buffer id from a region
  *
  * @param region                The region to get the buffer from
+ * @param addr                  The physical address of the buffer
  * @param buffer_id             Return pointer to the buffer id of the buffer
- * @param addr                  Return pointer to the physical address 
- *                              of the buffer
  *
  * @returns error on failure or SYS_ERR_OK on success
  */
-errval_t region_get_buffer(struct region* region,
-                           uint32_t* buffer_id,
-                           lpaddr_t* addr);
+errval_t region_get_buffer_id(struct region* region,
+                              lpaddr_t addr,
+                              bufferid_t* buffer_id);
 
 /**
- * @brief Return a buffer to the region
+ * @brief Return a buffer id to the region
  *
  * @param region                The region to return the buffer to
  * @param buffer_id             The id of the buffer to return to the region
- * @param addr                  The physical address of the freed buffer
  *
  * @returns error on failure or SYS_ERR_OK on success
  */
-errval_t region_free_buffer(struct region* region,
-                            uint32_t buffer_id);
+errval_t region_free_buffer_id(struct region* region,
+                               bufferid_t buffer_id);
 
 
 /**
@@ -104,10 +79,6 @@ errval_t region_free_buffer(struct region* region,
  *
  * @returns true if the buffer is in use otherwise false
  */
-inline bool region_buffer_in_use(struct region* region,
-                                 uint32_t buffer_id)
-{
-    return region->in_use[buffer_id];
-}
-
+bool region_buffer_id_in_use(struct region* region,
+                             bufferid_t buffer_id);
 #endif /* REGION_H_ */
index d38e966..954dea7 100644 (file)
@@ -157,7 +157,7 @@ static errval_t region_pool_grow(struct region_pool* pool)
  */
 errval_t region_pool_add_region(struct region_pool* pool, 
                                 struct capref cap,
-                                uint32_t* region_id)
+                                regionid_t* region_id)
 {
     errval_t err;
     struct region* region;
@@ -190,7 +190,7 @@ errval_t region_pool_add_region(struct region_pool* pool,
     // TODO size 
     err = region_init(&region,
                       pool->region_offset + pool->num_regions + offset,
-                      &cap, 4096);
+                      &cap);
 
     // insert into pool
     pool->pool[region->region_id % pool->size] = region;
@@ -209,7 +209,7 @@ errval_t region_pool_add_region(struct region_pool* pool,
  * @returns error on failure or SYS_ERR_OK on success
  */
 errval_t region_pool_remove_region(struct region_pool* pool, 
-                                   uint32_t region_id,
+                                   regionid_t region_id,
                                    struct capref* cap)
 {
     struct region* region;
@@ -240,8 +240,8 @@ errval_t region_pool_remove_region(struct region_pool* pool,
  * @returns error on failure or SYS_ERR_OK on success
  */
 static errval_t region_pool_get_region(struct region_pool* pool,
-                                uint32_t region_id,
-                                struct region** region)
+                                       regionid_t region_id,
+                                       struct region** region)
 {
     *region = pool->pool[region_id % pool->size];
     if (region == NULL) {
@@ -254,20 +254,20 @@ static errval_t region_pool_get_region(struct region_pool* pool,
 
 
 /**
- * @brief get a page sized buffer from a region of the pool
+ * @brief get a buffer id from a region
  *
  * @param pool          The pool to get the region from
  * @param region_id     The id of the region to get the buffer from
+ * @param addr          The physical address of the buffer
  * @param buffer_id     Return pointer to the buffer id
- * @param addr          Return pointer to the physical address of the buffer
  *
  * @returns error on failure or SYS_ERR_OK on success
  */
 
-errval_t region_pool_get_buffer_from_region(struct region_pool* pool,
-                                            uint32_t region_id,
-                                            uint32_t* buffer_id,
-                                            lpaddr_t* addr)
+errval_t region_pool_get_buffer_id_from_region(struct region_pool* pool,
+                                               regionid_t region_id,
+                                               lpaddr_t addr,
+                                               bufferid_t* buffer_id)
 {
     errval_t err;
     struct region* region;
@@ -276,8 +276,7 @@ errval_t region_pool_get_buffer_from_region(struct region_pool* pool,
         return err;
     }
     
-    // TODO size
-    err = region_get_buffer(region, buffer_id, addr);
+    err = region_get_buffer_id(region, addr, buffer_id);
     if (err_is_fail(err)) {
         return err;
     }
@@ -286,7 +285,7 @@ errval_t region_pool_get_buffer_from_region(struct region_pool* pool,
 }
 
 /**
- * @brief return a page sized buffer to a region of the pool
+ * @brief returns the buffer id to the pool of free ids
  *
  * @param pool          The pool to get the region from
  * @param region_id     The id of the region to get the buffer from
@@ -296,9 +295,9 @@ errval_t region_pool_get_buffer_from_region(struct region_pool* pool,
  * @returns error on failure or SYS_ERR_OK on success
  */
 
-errval_t region_pool_return_buffer_to_region(struct region_pool* pool,
-                                             uint32_t region_id,
-                                             uint32_t buffer_id)
+errval_t region_pool_return_buffer_id_to_region(struct region_pool* pool,
+                                                regionid_t region_id,
+                                                bufferid_t buffer_id)
 {
     errval_t err;
     struct region* region;
@@ -308,7 +307,7 @@ errval_t region_pool_return_buffer_to_region(struct region_pool* pool,
     }
     
     // TODO size
-    err = region_free_buffer(region, buffer_id);
+    err = region_free_buffer_id(region, buffer_id);
     if (err_is_fail(err)) {
         return err;
     }
@@ -325,9 +324,9 @@ errval_t region_pool_return_buffer_to_region(struct region_pool* pool,
  *
  * @returns true if the buffer is in use otherwise false
  */
-bool region_pool_buffer_of_region_in_use(struct region_pool* pool,
-                                         uint32_t region_id,
-                                         uint32_t buffer_id)
+bool region_pool_buffer_id_of_region_in_use(struct region_pool* pool,
+                                            regionid_t region_id,
+                                            bufferid_t buffer_id)
 {
     errval_t err;
     struct region* region;
@@ -336,5 +335,5 @@ bool region_pool_buffer_of_region_in_use(struct region_pool* pool,
         return false;
     }
     
-    return region_buffer_in_use(region, buffer_id);
+    return region_buffer_id_in_use(region, buffer_id);
 }
index 6dd01b8..352ffc7 100644 (file)
@@ -11,6 +11,7 @@
 
 
 #include <barrelfish/barrelfish.h>
+#include <devif/queue_interface.h>
 
 struct region_pool;
 struct region;
@@ -45,7 +46,7 @@ errval_t region_pool_destroy(struct region_pool* pool);
  */
 errval_t region_pool_add_region(struct region_pool* pool, 
                                 struct capref cap,
-                                uint32_t* region_id);
+                                regionid_t* region_id);
 
 /**
  * @brief remove a memory region from the region pool
@@ -57,7 +58,7 @@ errval_t region_pool_add_region(struct region_pool* pool,
  * @returns error on failure or SYS_ERR_OK on success
  */
 errval_t region_pool_remove_region(struct region_pool* pool, 
-                                   uint32_t region_id,
+                                   regionid_t region_id,
                                    struct capref* cap);
 
 /**
@@ -65,16 +66,16 @@ errval_t region_pool_remove_region(struct region_pool* pool,
  *
  * @param pool          The pool to get the region from
  * @param region_id     The id of the region to get the buffer from
+ * @param addr          The physical address of the buffer
  * @param buffer_id     Return pointer to the buffer id
- * @param addr          Return pointer to the physical address of the buffer
  *
  * @returns error on failure or SYS_ERR_OK on success
  */
 
-errval_t region_pool_get_buffer_from_region(struct region_pool* pool,
-                                            uint32_t region_id,
-                                            uint32_t* buffer_id,
-                                            lpaddr_t* addr);
+errval_t region_pool_get_buffer_id_from_region(struct region_pool* pool,
+                                               bufferid_t region_id,
+                                               lpaddr_t addr,
+                                               bufferid_t* buffer_id);
 
 /**
  * @brief return a page sized buffer to a region of the pool
@@ -86,9 +87,9 @@ errval_t region_pool_get_buffer_from_region(struct region_pool* pool,
  * @returns error on failure or SYS_ERR_OK on success
  */
 
-errval_t region_pool_return_buffer_to_region(struct region_pool* pool,
-                                             uint32_t region_id,
-                                             uint32_t buffer_id);
+errval_t region_pool_return_buffer_id_to_region(struct region_pool* pool,
+                                                regionid_t region_id,
+                                                bufferid_t buffer_id);
 
 /**
  * @brief return if a buffer of a region is in use
@@ -99,7 +100,7 @@ errval_t region_pool_return_buffer_to_region(struct region_pool* pool,
  *
  * @returns error on failure or SYS_ERR_OK on success
  */
-bool region_pool_buffer_of_region_in_use(struct region_pool* pool,
-                                         uint32_t region_id,
-                                         uint32_t buffer_id);
+bool region_pool_buffer_id_of_region_in_use(struct region_pool* pool,
+                                            regionid_t region_id,
+                                            bufferid_t buffer_id);
 #endif /* REGION_POOL_H_ */