diff mbox

ODP Buffer Management support for Scatter-gather list

Message ID 1403309770199.7872@caviumnetworks.com
State New
Headers show

Commit Message

Rosenboim, Leonid June 21, 2014, 12:16 a.m. UTC
Here are my 2 cents:


Regarding buffer split/merge APIs, I can think of situations where an implementation might need to allocate an additional buffer if there is no sufficient space for e.g. storing the S/G array, so I suggest to add a odp_pool_t argument to both split and merge functions.

An application that has no specific preference, may just pass the value of the first buffer's pool identifier in that argument, and I think that should fit most application needs.


Regarding the request to be able to create buffers from application-specified memory regions, I strongly recommend to assign this functionality to odp_buffer_pool.h module, instead of odp_buffer.h,

and to create an API for creating a pool using user-supplied memory range.

An application then can create a buffer pool using that special memory (e.g. shmem), and subsequently use the pool id to allocate and release (bot explicitly and implicitly) buffers from that pool as required.


- Leo
diff mbox

Patch

diff --git a/include/odp_buffer.h b/include/odp_buffer.h
index d79e76d..c313168 100644
--- a/include/odp_buffer.h
+++ b/include/odp_buffer.h
@@ -92,6 +92,79 @@  int odp_buffer_is_valid(odp_buffer_t buf);
  */
 void odp_buffer_print(odp_buffer_t buf);

+/**
+*Number of segments in this scatter-gather List
+*
+*@param buf    Buffer Handle
+*
+*@return       Total number of segments in this scatter-gather List.
+*
+**/
+int odp_buffer_segment_count(odp_buffer_t buf)
+
+/**
+*Address of the segment in the buffer list.
+*
+*@param buf    Buffer Handle
+*@param n      Index number for the segment in the SG list
+*@param size   Returns the size of the current addressable segment
+
+*@return       Segment start address
+**/
+
+void* odp_buffer_segment_addr(odp_buffer_t buf, int n, size_t* size);
+
+/*
+*Creates ODP Buffer from a memory region
+*
+*@param addr   Address of the memory region
+*@param size    Size of the memory region
+*
+*@return       Buffer Handle to the newly create odp buffer
+*/
+odp_buffer_t     odp_buffer_from_memory_region(void* addr, int size );

We should keep consistent with buffer sizes, odp_buffer_size for instance returns a size_t. Also, does this assume that the data will be copied, so that the user can safely free the memory area pointed to by addr?

+
+/**
+* Merge Buffer list into a singe buffer
+*@param buf    Array of ODP Buffer Handles
+*@param num    Number of Buffers in the buf Array
+
+*@return       Buffer Handle to the newly created odp buffer
+**/
+odp_buffer_t    odp_buffer_merge(odp_buffer_t[] buf, int num);
+

Which pool should the resulting buffer be allocated from? Will there be an SG list in the resulting buffer or just one big chunk?

+/**
+* Split a single Buffer into a list of odp buffers
+*
+*@param buf    Buffer Handle
+*
+*@param        size    Maximum size of the individual buffers
+*
+*@return       Array of newly created Buffer Handle
+**/
+odp_buffer_t[] odp_buffer_split(odp_buffer_t buf, int size);

This doesn't seem entirely related to SG support. Is there zero-copy here?
+
+/**
+* Append a buffer at the end of a scatter-gather list of buffer
+*
+*@param buf    Buffer Handle to the scatter-gather list of buffer
+*
+*@param tail   Buffer Handle to the buffer which is appended
+*
+*@return       1 if success 0 otherwise
+**/
+int odp_buffer_append(odp_buffer_t buf, odp_buffer_t tail );
+
+/**
+* Add a buffer at the head of a existing Scatter-gather Buffer
+*
+*@param buf    Buffer Handle to the scatter-gather list of buffer
+*