diff mbox

[API-NEXT,2/5] drv: adding odpdrv_shm_sreserve and odpdrv_shm_sfree()

Message ID 1482319702-5766-3-git-send-email-christophe.milard@linaro.org
State New
Headers show

Commit Message

Christophe Milard Dec. 21, 2016, 11:28 a.m. UTC
The two functions are meant to be used fo small amount of memory
allocation.
They are quicker, lighter and have a smaller granularity than the
odpdrv_shm_reserve() / odpdrv_shm_free_*() sets of function, but also
lacks some of their functionality (lookup, export, flags).

Signed-off-by: Christophe Milard <christophe.milard@linaro.org>

---
 include/odp/drv/spec/shm.h | 41 ++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 40 insertions(+), 1 deletion(-)

-- 
2.7.4
diff mbox

Patch

diff --git a/include/odp/drv/spec/shm.h b/include/odp/drv/spec/shm.h
index ef64f5d..d2ccfe2 100644
--- a/include/odp/drv/spec/shm.h
+++ b/include/odp/drv/spec/shm.h
@@ -200,9 +200,11 @@  int odpdrv_shm_info(odpdrv_shm_t shm, odpdrv_shm_info_t *info);
 
 /**
  * Print all shared memory blocks and returns the number of allocated blocks.
+ * Also gives the status of the odpdrv_shm_sreserve() pool allocator.
  * This function is meant for debug.
  * @param title  A string to be printed before the shared memory status
- * @return       The total number of allocated blocks
+ * @return       The total number of allocated blocks (allocated with
+ *		 odpdrv_shm_reserve()).
  */
 int odpdrv_shm_print_all(const char *title);
 
@@ -220,6 +222,43 @@  int odpdrv_shm_print_all(const char *title);
 uint64_t odpdrv_shm_to_u64(odpdrv_shm_t hdl);
 
 /**
+ * Reserve a small contiguous block of shared memory
+ * odpdrv_shm_sreserve() is meant to reserve small amount of memory from
+ * a preallocated pool. The size of this pool is limited, so
+ * odpdrv_shm_sreserve() should be used for small allocations (e.g. less than
+ * a 1/2 page size).
+ * While odpdrv_shm_reserve() granularity is large (likely the page size),
+ * odpdrv_shm_sreserve() has a much smaller granularity, making it ideal for
+ * small allocations such as those done to populate a linked list.
+ * Addresses returned by odpdrv_shm_sreserve() are sharable between all ODP
+ * threads. Buffer allocated through odpdrv_shm_sreserve() are enonymous and
+ * can therefore not by looked up by name. Neither can they be exported
+ * to other ODP instances.
+ * Buffers allocated with this function should be release with
+ * odpdrv_shm_sfree().
+ *
+ * @param[in] size   Block size in bytes
+ *
+ * @return The address of the reserved block.
+ * @retval NULL on failure
+ */
+void *odpdrv_shm_sreserve(uint64_t size);
+
+/**
+ * Free a contiguous block of shared memory previously allocated with
+ * odpdrv_shm_reserve()
+ *
+ * Frees a previously reserved block of shared memory.
+ * @note Freeing memory that is in use will result in UNDEFINED behavior
+ *
+ * @param[in] addr address (as returned by odpdrv_shm_sreserve()).
+ *
+ * @retval 0 on success
+ * @retval <0 on failure
+ */
+int odpdrv_shm_sfree(void *addr);
+
+/**
  * @}
  */