diff mbox

[API-NEXT,v3,1/3] api: pool: add packet user area initializer for pool creation parameters

Message ID 1439486903-14811-1-git-send-email-zoltan.kiss@linaro.org
State Superseded
Headers show

Commit Message

Zoltan Kiss Aug. 13, 2015, 5:28 p.m. UTC
Applications can preset certain parts of the packet user area, so when that
memory will be allocated it starts from a known state. If the platform
allocates the memory during pool creation, it's enough to run the
constructor after that. If it's allocating memory on demand, it should
call the constructor each time.
Porting applications to ODP can benefit from this. If the application can't
afford to change its whole packet handling to ODP, it's likely it needs to
maintain its own metadata in the user area. And probably it needs to set
constant fields in that metadata e.g. to mark that this is an ODP packet,
and/or store the handle of the packet itself.

Signed-off-by: Zoltan Kiss <zoltan.kiss@linaro.org>
---
v2:
- restrict this feature to packet user area
- expand comments

v3:
- include packet.h in pool.h

 include/odp/api/packet.h |  3 +++
 include/odp/api/pool.h   | 26 ++++++++++++++++++++++++++
 2 files changed, 29 insertions(+)

Comments

Bill Fischofer Aug. 13, 2015, 8:42 p.m. UTC | #1
Some grammatical nits:

On Thu, Aug 13, 2015 at 12:28 PM, Zoltan Kiss <zoltan.kiss@linaro.org>
wrote:

> Applications can preset certain parts of the packet user area, so when that
> memory will be allocated it starts from a known state. If the platform
> allocates the memory during pool creation, it's enough to run the
> constructor after that. If it's allocating memory on demand, it should
> call the constructor each time.
> Porting applications to ODP can benefit from this. If the application can't
> afford to change its whole packet handling to ODP, it's likely it needs to
> maintain its own metadata in the user area. And probably it needs to set
> constant fields in that metadata e.g. to mark that this is an ODP packet,
> and/or store the handle of the packet itself.
>
> Signed-off-by: Zoltan Kiss <zoltan.kiss@linaro.org>
> ---
> v2:
> - restrict this feature to packet user area
> - expand comments
>
> v3:
> - include packet.h in pool.h
>
>  include/odp/api/packet.h |  3 +++
>  include/odp/api/pool.h   | 26 ++++++++++++++++++++++++++
>  2 files changed, 29 insertions(+)
>
> diff --git a/include/odp/api/packet.h b/include/odp/api/packet.h
> index 3a454b5..f5d2142 100644
> --- a/include/odp/api/packet.h
> +++ b/include/odp/api/packet.h
> @@ -73,6 +73,9 @@ extern "C" {
>   * @note The default headroom and tailroom used for packets is specified
> by
>   * the ODP_CONFIG_PACKET_HEADROOM and ODP_CONFIG_PACKET_TAILROOM defines
> in
>   * odp_config.h.
> + * @note Data changed in user area might be preserved by the platform from
> + * previous usage of the buffer, so values preset in uarea_init() are not
> + * guaranteed.
>   */
>  odp_packet_t odp_packet_alloc(odp_pool_t pool, uint32_t len);
>
> diff --git a/include/odp/api/pool.h b/include/odp/api/pool.h
> index 2e79a55..4268770 100644
> --- a/include/odp/api/pool.h
> +++ b/include/odp/api/pool.h
> @@ -21,6 +21,7 @@ extern "C" {
>
>
>  #include <odp/std_types.h>
> +#include <odp/packet.h>
>
>  /** @defgroup odp_pool ODP POOL
>   *  Operations on a pool.
> @@ -41,6 +42,23 @@ extern "C" {
>  #define ODP_POOL_NAME_LEN  32
>
>  /**
> + * Packet user area initializer callback function for pools.
> + *
> + * @param pkt                   Handle of the packet
> + * @param uarea_init_arg        Opaque pointer defined in odp_pool_param_t
> + *
> + * @note If the application specifies this pointer, it expects that every
> buffer
> + * is initialized exactly once with it when the underlying memory is
> allocated.
> + * It is not called from odp_packet_alloc(), unless the platform choose to
>

+ * It is not called from odp_packet_alloc(), unless the platform *chooses*
to



> + * allocate the memory at that point. Applications can only assume that
> this
> + * callback were called once before the packet were first used. Any
> subsequent
>

+ * callback *is* called once before the packet *is* first used. Any
subsequent


> + * change to the user area might be preserved after odp_packet_free()
> called, so
>

+ * change to the user area might be preserved after odp_packet_free() *is*
called, so


> + * applications should take care of (re)initialization if they change data
> + * preset by this function.
> + */
> +typedef void (odp_packet_uarea_init_t)(odp_packet_t pkt, void
> *uarea_init_arg);
> +
> +/**
>   * Pool parameters
>   * Used to communicate pool creation options.
>   */
> @@ -82,6 +100,14 @@ typedef struct odp_pool_param_t {
>                         /** User area size in bytes. Specify as 0 if no
> user
>                             area is needed. */
>                         uint32_t uarea_size;
> +
> +                       /** Initialize every packet's user area at
> allocation
> +                           time. Use NULL if no initialization needed. */
> +                       odp_packet_uarea_init_t *uarea_init;
> +
> +                       /** Opaque pointer passed to packet user area
> +                           constructor. */
> +                       void *uarea_init_arg;
>                 } pkt;
>                 struct {
>                         /** Number of timeouts in the pool */
> --
> 1.9.1
>
> _______________________________________________
> lng-odp mailing list
> lng-odp@lists.linaro.org
> https://lists.linaro.org/mailman/listinfo/lng-odp
>
diff mbox

Patch

diff --git a/include/odp/api/packet.h b/include/odp/api/packet.h
index 3a454b5..f5d2142 100644
--- a/include/odp/api/packet.h
+++ b/include/odp/api/packet.h
@@ -73,6 +73,9 @@  extern "C" {
  * @note The default headroom and tailroom used for packets is specified by
  * the ODP_CONFIG_PACKET_HEADROOM and ODP_CONFIG_PACKET_TAILROOM defines in
  * odp_config.h.
+ * @note Data changed in user area might be preserved by the platform from
+ * previous usage of the buffer, so values preset in uarea_init() are not
+ * guaranteed.
  */
 odp_packet_t odp_packet_alloc(odp_pool_t pool, uint32_t len);
 
diff --git a/include/odp/api/pool.h b/include/odp/api/pool.h
index 2e79a55..4268770 100644
--- a/include/odp/api/pool.h
+++ b/include/odp/api/pool.h
@@ -21,6 +21,7 @@  extern "C" {
 
 
 #include <odp/std_types.h>
+#include <odp/packet.h>
 
 /** @defgroup odp_pool ODP POOL
  *  Operations on a pool.
@@ -41,6 +42,23 @@  extern "C" {
 #define ODP_POOL_NAME_LEN  32
 
 /**
+ * Packet user area initializer callback function for pools.
+ *
+ * @param pkt                   Handle of the packet
+ * @param uarea_init_arg        Opaque pointer defined in odp_pool_param_t
+ *
+ * @note If the application specifies this pointer, it expects that every buffer
+ * is initialized exactly once with it when the underlying memory is allocated.
+ * It is not called from odp_packet_alloc(), unless the platform choose to
+ * allocate the memory at that point. Applications can only assume that this
+ * callback were called once before the packet were first used. Any subsequent
+ * change to the user area might be preserved after odp_packet_free() called, so
+ * applications should take care of (re)initialization if they change data
+ * preset by this function.
+ */
+typedef void (odp_packet_uarea_init_t)(odp_packet_t pkt, void *uarea_init_arg);
+
+/**
  * Pool parameters
  * Used to communicate pool creation options.
  */
@@ -82,6 +100,14 @@  typedef struct odp_pool_param_t {
 			/** User area size in bytes. Specify as 0 if no user
 			    area is needed. */
 			uint32_t uarea_size;
+
+			/** Initialize every packet's user area at allocation
+			    time. Use NULL if no initialization needed. */
+			odp_packet_uarea_init_t *uarea_init;
+
+			/** Opaque pointer passed to packet user area
+			    constructor. */
+			void *uarea_init_arg;
 		} pkt;
 		struct {
 			/** Number of timeouts in the pool */