diff mbox

[1/2] Added timeout buffer type

Message ID 1403618747-28212-1-git-send-email-petri.savolainen@linaro.org
State Accepted
Commit 9b8a4bbc3b230857a0d782fa25acf74f6b4e967d
Headers show

Commit Message

Petri Savolainen June 24, 2014, 2:05 p.m. UTC
Added 'timeout' and 'any' buffer types. Timer and buffer pool
modifications to use those.

Signed-off-by: Petri Savolainen <petri.savolainen@linaro.org>
---
 include/odp_buffer.h                               |  8 ++-
 include/odp_packet.h                               |  2 +-
 include/odp_timer.h                                | 31 +++++++--
 .../linux-generic/include/odp_timer_internal.h     | 78 ++++++++++++++++++++++
 platform/linux-generic/source/odp_buffer_pool.c    | 19 ++++++
 platform/linux-generic/source/odp_timer.c          | 29 ++++----
 6 files changed, 147 insertions(+), 20 deletions(-)
 create mode 100644 platform/linux-generic/include/odp_timer_internal.h

Comments

Maxim Uvarov June 26, 2014, 5:42 p.m. UTC | #1
Applied, thanks!

Maxim.

On 06/24/2014 06:05 PM, Petri Savolainen wrote:
> Added 'timeout' and 'any' buffer types. Timer and buffer pool
> modifications to use those.
>
> Signed-off-by: Petri Savolainen <petri.savolainen@linaro.org>
> ---
>   include/odp_buffer.h                               |  8 ++-
>   include/odp_packet.h                               |  2 +-
>   include/odp_timer.h                                | 31 +++++++--
>   .../linux-generic/include/odp_timer_internal.h     | 78 ++++++++++++++++++++++
>   platform/linux-generic/source/odp_buffer_pool.c    | 19 ++++++
>   platform/linux-generic/source/odp_timer.c          | 29 ++++----
>   6 files changed, 147 insertions(+), 20 deletions(-)
>   create mode 100644 platform/linux-generic/include/odp_timer_internal.h
>
> diff --git a/include/odp_buffer.h b/include/odp_buffer.h
> index d79e76d..b3d6f4a 100644
> --- a/include/odp_buffer.h
> +++ b/include/odp_buffer.h
> @@ -62,9 +62,11 @@ size_t odp_buffer_size(odp_buffer_t buf);
>   int odp_buffer_type(odp_buffer_t buf);
>   
>   #define ODP_BUFFER_TYPE_INVALID (-1) /**< Buffer type invalid */
> -#define ODP_BUFFER_TYPE_RAW       0  /**< Raw buffer */
> -#define ODP_BUFFER_TYPE_PACKET    1  /**< Packet buffer */
> -#define ODP_BUFFER_TYPE_TIMER     2  /**< Timer buffer */
> +#define ODP_BUFFER_TYPE_ANY       0  /**< Buffer that can hold any other
> +					  buffer type */
> +#define ODP_BUFFER_TYPE_RAW       1  /**< Raw buffer, no additional metadata */
> +#define ODP_BUFFER_TYPE_PACKET    2  /**< Packet buffer */
> +#define ODP_BUFFER_TYPE_TIMEOUT   3  /**< Timeout buffer */
>   
>   /**
>    * Tests if buffer is part of a scatter/gather list
> diff --git a/include/odp_packet.h b/include/odp_packet.h
> index 932b009..59759bb 100644
> --- a/include/odp_packet.h
> +++ b/include/odp_packet.h
> @@ -24,7 +24,7 @@ extern "C" {
>   /**
>    * ODP packet descriptor
>    */
> -typedef uint32_t odp_packet_t;
> +typedef odp_buffer_t odp_packet_t;
>   
>   /** Invalid packet */
>   #define ODP_PACKET_INVALID ODP_BUFFER_INVALID
> diff --git a/include/odp_timer.h b/include/odp_timer.h
> index 80babd1..01db839 100644
> --- a/include/odp_timer.h
> +++ b/include/odp_timer.h
> @@ -25,8 +25,8 @@ extern "C" {
>   
>   
>   /**
> -* ODP timer handle
> -*/
> + * ODP timer handle
> + */
>   typedef uint32_t odp_timer_t;
>   
>   /** Invalid timer */
> @@ -34,8 +34,8 @@ typedef uint32_t odp_timer_t;
>   
>   
>   /**
> -* ODP timeout handle
> -*/
> + * ODP timeout handle
> + */
>   typedef odp_buffer_t odp_timer_tmo_t;
>   
>   /** Invalid timeout */
> @@ -43,6 +43,12 @@ typedef odp_buffer_t odp_timer_tmo_t;
>   
>   
>   /**
> + * Timeout notification
> + */
> +typedef odp_buffer_t odp_timeout_t;
> +
> +
> +/**
>    * Create a timer
>    *
>    * Creates a new timer with requested properties.
> @@ -133,6 +139,23 @@ odp_timer_tmo_t odp_timer_absolute_tmo(odp_timer_t timer, uint64_t tmo_tick,
>    */
>   int odp_timer_cancel_tmo(odp_timer_t timer, odp_timer_tmo_t tmo);
>   
> +/**
> + * Convert buffer handle to timeout handle
> + *
> + * @param buf  Buffer handle
> + *
> + * @return Timeout buffer handle
> + */
> +odp_timeout_t odp_timeout_from_buffer(odp_buffer_t buf);
> +
> +/**
> + * Return absolute timeout tick
> + *
> + * @param tmo Timeout buffer handle
> + *
> + * @return Absolute timeout tick
> + */
> +uint64_t odp_timeout_tick(odp_timeout_t tmo);
>   
>   #ifdef __cplusplus
>   }
> diff --git a/platform/linux-generic/include/odp_timer_internal.h b/platform/linux-generic/include/odp_timer_internal.h
> new file mode 100644
> index 0000000..f99a10e
> --- /dev/null
> +++ b/platform/linux-generic/include/odp_timer_internal.h
> @@ -0,0 +1,78 @@
> +/* Copyright (c) 2013, Linaro Limited
> + * All rights reserved.
> + *
> + * SPDX-License-Identifier:     BSD-3-Clause
> + */
> +
> +
> +/**
> + * @file
> + *
> + * ODP timer timeout descriptor - implementation internal
> + */
> +
> +#ifndef ODP_TIMER_INTERNAL_H_
> +#define ODP_TIMER_INTERNAL_H_
> +
> +#ifdef __cplusplus
> +extern "C" {
> +#endif
> +
> +#include <odp_std_types.h>
> +#include <odp_queue.h>
> +#include <odp_buffer.h>
> +#include <odp_buffer_internal.h>
> +#include <odp_buffer_pool_internal.h>
> +#include <odp_timer.h>
> +
> +struct timeout_t;
> +
> +typedef struct timeout_t {
> +	struct timeout_t *next;
> +	int               timer_id;
> +	int               tick;
> +	uint64_t          tmo_tick;
> +	odp_queue_t       queue;
> +	odp_buffer_t      buf;
> +	odp_buffer_t      tmo_buf;
> +} timeout_t;
> +
> +
> +struct odp_timeout_hdr_t;
> +
> +/**
> + * Timeout notification header
> + */
> +typedef struct odp_timeout_hdr_t {
> +	odp_buffer_hdr_t buf_hdr;
> +
> +	timeout_t meta;
> +
> +	uint8_t payload[];
> +} odp_timeout_hdr_t;
> +
> +
> +
> +ODP_ASSERT(sizeof(odp_timeout_hdr_t) ==
> +	   ODP_OFFSETOF(odp_timeout_hdr_t, payload),
> +	   ODP_TIMEOUT_HDR_T__SIZE_ERR);
> +
> +ODP_ASSERT(sizeof(odp_timeout_hdr_t) % sizeof(uint64_t) == 0,
> +	   ODP_TIMEOUT_HDR_T__SIZE_ERR2);
> +
> +
> +/**
> + * Return timeout header
> + */
> +static inline odp_timeout_hdr_t *odp_timeout_hdr(odp_timeout_t tmo)
> +{
> +	return (odp_timeout_hdr_t *)odp_buf_to_hdr((odp_buffer_t)tmo);
> +}
> +
> +
> +
> +#ifdef __cplusplus
> +}
> +#endif
> +
> +#endif
> diff --git a/platform/linux-generic/source/odp_buffer_pool.c b/platform/linux-generic/source/odp_buffer_pool.c
> index 90214ba..f4aedff 100644
> --- a/platform/linux-generic/source/odp_buffer_pool.c
> +++ b/platform/linux-generic/source/odp_buffer_pool.c
> @@ -9,6 +9,7 @@
>   #include <odp_buffer_pool_internal.h>
>   #include <odp_buffer_internal.h>
>   #include <odp_packet_internal.h>
> +#include <odp_timer_internal.h>
>   #include <odp_shared_memory.h>
>   #include <odp_align.h>
>   #include <odp_internal.h>
> @@ -39,6 +40,15 @@
>   
>   #define NULL_INDEX ((uint32_t)-1)
>   
> +union buffer_type_any_u {
> +	odp_buffer_hdr_t  buf;
> +	odp_packet_hdr_t  pkt;
> +	odp_timeout_hdr_t tmo;
> +};
> +
> +ODP_ASSERT(sizeof(union buffer_type_any_u) % sizeof(uint64_t) == 0,
> +	   BUFFER_TYPE_ANY_U__SIZE_ERR);
> +
>   
>   typedef union pool_entry_u {
>   	struct pool_entry_s s;
> @@ -214,6 +224,11 @@ static void fill_hdr(void *ptr, pool_entry_t *pool, uint32_t index,
>   	if (pool->s.buf_type == ODP_BUFFER_TYPE_PACKET) {
>   		odp_packet_hdr_t *packet_hdr = ptr;
>   		payload = packet_hdr->payload;
> +	} else if (pool->s.buf_type == ODP_BUFFER_TYPE_TIMEOUT) {
> +		odp_timeout_hdr_t *tmo_hdr = ptr;
> +		payload = tmo_hdr->payload;
> +	} else if (pool->s.buf_type == ODP_BUFFER_TYPE_ANY) {
> +		payload = ((uint8_t *)ptr) + sizeof(union buffer_type_any_u);
>   	}
>   
>   	memset(hdr, 0, size);
> @@ -255,6 +270,10 @@ static void link_bufs(pool_entry_t *pool)
>   		hdr_size = sizeof(odp_buffer_hdr_t);
>   	else if (buf_type == ODP_BUFFER_TYPE_PACKET)
>   		hdr_size = sizeof(odp_packet_hdr_t);
> +	else if (buf_type == ODP_BUFFER_TYPE_TIMEOUT)
> +		hdr_size = sizeof(odp_timeout_hdr_t);
> +	else if (buf_type == ODP_BUFFER_TYPE_ANY)
> +		hdr_size = sizeof(union buffer_type_any_u);
>   	else {
>   		ODP_ERR("odp_buffer_pool_create: Bad type %i\n",
>   			buf_type);
> diff --git a/platform/linux-generic/source/odp_timer.c b/platform/linux-generic/source/odp_timer.c
> index 85369d3..509a890 100644
> --- a/platform/linux-generic/source/odp_timer.c
> +++ b/platform/linux-generic/source/odp_timer.c
> @@ -5,6 +5,8 @@
>    */
>   
>   #include <odp_timer.h>
> +#include <odp_timer_internal.h>
> +#include <odp_buffer_pool_internal.h>
>   #include <odp_internal.h>
>   #include <odp_atomic.h>
>   #include <odp_spinlock.h>
> @@ -20,17 +22,6 @@
>   #define MAX_TICKS     1024
>   #define RESOLUTION_NS 1000000
>   
> -struct timeout_t;
> -
> -typedef struct timeout_t {
> -	struct timeout_t *next;
> -	int               timer_id;
> -	int               tick;
> -	uint64_t          tmo_tick;
> -	odp_queue_t       queue;
> -	odp_buffer_t      buf;
> -	odp_buffer_t      tmo_buf;
> -} timeout_t;
>   
>   typedef struct {
>   	odp_spinlock_t lock;
> @@ -250,6 +241,7 @@ odp_timer_tmo_t odp_timer_absolute_tmo(odp_timer_t timer, uint64_t tmo_tick,
>   	uint64_t cur_tick;
>   	timeout_t *new_tmo;
>   	odp_buffer_t tmo_buf;
> +	odp_timeout_hdr_t *tmo_hdr;
>   
>   	id = timer - 1;
>   
> @@ -273,7 +265,8 @@ odp_timer_tmo_t odp_timer_absolute_tmo(odp_timer_t timer, uint64_t tmo_tick,
>   		return ODP_TIMER_TMO_INVALID;
>   	}
>   
> -	new_tmo = (timeout_t *)odp_buffer_addr(tmo_buf);
> +	tmo_hdr = odp_timeout_hdr((odp_timeout_t) tmo_buf);
> +	new_tmo = &tmo_hdr->meta;
>   
>   	new_tmo->timer_id = id;
>   	new_tmo->tick     = (int)tick;
> @@ -330,3 +323,15 @@ uint64_t odp_timer_current_tick(odp_timer_t timer)
>   	id = timer - 1;
>   	return odp_timer.timer[id].cur_tick;
>   }
> +
> +odp_timeout_t odp_timeout_from_buffer(odp_buffer_t buf)
> +{
> +	return (odp_timeout_t) buf;
> +}
> +
> +uint64_t odp_timeout_tick(odp_timeout_t tmo)
> +{
> +	odp_timeout_hdr_t *tmo_hdr;
> +	tmo_hdr = (odp_timeout_hdr_t *)odp_buf_to_hdr((odp_buffer_t)tmo);
> +	return tmo_hdr->meta.tick;
> +}
diff mbox

Patch

diff --git a/include/odp_buffer.h b/include/odp_buffer.h
index d79e76d..b3d6f4a 100644
--- a/include/odp_buffer.h
+++ b/include/odp_buffer.h
@@ -62,9 +62,11 @@  size_t odp_buffer_size(odp_buffer_t buf);
 int odp_buffer_type(odp_buffer_t buf);
 
 #define ODP_BUFFER_TYPE_INVALID (-1) /**< Buffer type invalid */
-#define ODP_BUFFER_TYPE_RAW       0  /**< Raw buffer */
-#define ODP_BUFFER_TYPE_PACKET    1  /**< Packet buffer */
-#define ODP_BUFFER_TYPE_TIMER     2  /**< Timer buffer */
+#define ODP_BUFFER_TYPE_ANY       0  /**< Buffer that can hold any other
+					  buffer type */
+#define ODP_BUFFER_TYPE_RAW       1  /**< Raw buffer, no additional metadata */
+#define ODP_BUFFER_TYPE_PACKET    2  /**< Packet buffer */
+#define ODP_BUFFER_TYPE_TIMEOUT   3  /**< Timeout buffer */
 
 /**
  * Tests if buffer is part of a scatter/gather list
diff --git a/include/odp_packet.h b/include/odp_packet.h
index 932b009..59759bb 100644
--- a/include/odp_packet.h
+++ b/include/odp_packet.h
@@ -24,7 +24,7 @@  extern "C" {
 /**
  * ODP packet descriptor
  */
-typedef uint32_t odp_packet_t;
+typedef odp_buffer_t odp_packet_t;
 
 /** Invalid packet */
 #define ODP_PACKET_INVALID ODP_BUFFER_INVALID
diff --git a/include/odp_timer.h b/include/odp_timer.h
index 80babd1..01db839 100644
--- a/include/odp_timer.h
+++ b/include/odp_timer.h
@@ -25,8 +25,8 @@  extern "C" {
 
 
 /**
-* ODP timer handle
-*/
+ * ODP timer handle
+ */
 typedef uint32_t odp_timer_t;
 
 /** Invalid timer */
@@ -34,8 +34,8 @@  typedef uint32_t odp_timer_t;
 
 
 /**
-* ODP timeout handle
-*/
+ * ODP timeout handle
+ */
 typedef odp_buffer_t odp_timer_tmo_t;
 
 /** Invalid timeout */
@@ -43,6 +43,12 @@  typedef odp_buffer_t odp_timer_tmo_t;
 
 
 /**
+ * Timeout notification
+ */
+typedef odp_buffer_t odp_timeout_t;
+
+
+/**
  * Create a timer
  *
  * Creates a new timer with requested properties.
@@ -133,6 +139,23 @@  odp_timer_tmo_t odp_timer_absolute_tmo(odp_timer_t timer, uint64_t tmo_tick,
  */
 int odp_timer_cancel_tmo(odp_timer_t timer, odp_timer_tmo_t tmo);
 
+/**
+ * Convert buffer handle to timeout handle
+ *
+ * @param buf  Buffer handle
+ *
+ * @return Timeout buffer handle
+ */
+odp_timeout_t odp_timeout_from_buffer(odp_buffer_t buf);
+
+/**
+ * Return absolute timeout tick
+ *
+ * @param tmo Timeout buffer handle
+ *
+ * @return Absolute timeout tick
+ */
+uint64_t odp_timeout_tick(odp_timeout_t tmo);
 
 #ifdef __cplusplus
 }
diff --git a/platform/linux-generic/include/odp_timer_internal.h b/platform/linux-generic/include/odp_timer_internal.h
new file mode 100644
index 0000000..f99a10e
--- /dev/null
+++ b/platform/linux-generic/include/odp_timer_internal.h
@@ -0,0 +1,78 @@ 
+/* Copyright (c) 2013, Linaro Limited
+ * All rights reserved.
+ *
+ * SPDX-License-Identifier:     BSD-3-Clause
+ */
+
+
+/**
+ * @file
+ *
+ * ODP timer timeout descriptor - implementation internal
+ */
+
+#ifndef ODP_TIMER_INTERNAL_H_
+#define ODP_TIMER_INTERNAL_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <odp_std_types.h>
+#include <odp_queue.h>
+#include <odp_buffer.h>
+#include <odp_buffer_internal.h>
+#include <odp_buffer_pool_internal.h>
+#include <odp_timer.h>
+
+struct timeout_t;
+
+typedef struct timeout_t {
+	struct timeout_t *next;
+	int               timer_id;
+	int               tick;
+	uint64_t          tmo_tick;
+	odp_queue_t       queue;
+	odp_buffer_t      buf;
+	odp_buffer_t      tmo_buf;
+} timeout_t;
+
+
+struct odp_timeout_hdr_t;
+
+/**
+ * Timeout notification header
+ */
+typedef struct odp_timeout_hdr_t {
+	odp_buffer_hdr_t buf_hdr;
+
+	timeout_t meta;
+
+	uint8_t payload[];
+} odp_timeout_hdr_t;
+
+
+
+ODP_ASSERT(sizeof(odp_timeout_hdr_t) ==
+	   ODP_OFFSETOF(odp_timeout_hdr_t, payload),
+	   ODP_TIMEOUT_HDR_T__SIZE_ERR);
+
+ODP_ASSERT(sizeof(odp_timeout_hdr_t) % sizeof(uint64_t) == 0,
+	   ODP_TIMEOUT_HDR_T__SIZE_ERR2);
+
+
+/**
+ * Return timeout header
+ */
+static inline odp_timeout_hdr_t *odp_timeout_hdr(odp_timeout_t tmo)
+{
+	return (odp_timeout_hdr_t *)odp_buf_to_hdr((odp_buffer_t)tmo);
+}
+
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/platform/linux-generic/source/odp_buffer_pool.c b/platform/linux-generic/source/odp_buffer_pool.c
index 90214ba..f4aedff 100644
--- a/platform/linux-generic/source/odp_buffer_pool.c
+++ b/platform/linux-generic/source/odp_buffer_pool.c
@@ -9,6 +9,7 @@ 
 #include <odp_buffer_pool_internal.h>
 #include <odp_buffer_internal.h>
 #include <odp_packet_internal.h>
+#include <odp_timer_internal.h>
 #include <odp_shared_memory.h>
 #include <odp_align.h>
 #include <odp_internal.h>
@@ -39,6 +40,15 @@ 
 
 #define NULL_INDEX ((uint32_t)-1)
 
+union buffer_type_any_u {
+	odp_buffer_hdr_t  buf;
+	odp_packet_hdr_t  pkt;
+	odp_timeout_hdr_t tmo;
+};
+
+ODP_ASSERT(sizeof(union buffer_type_any_u) % sizeof(uint64_t) == 0,
+	   BUFFER_TYPE_ANY_U__SIZE_ERR);
+
 
 typedef union pool_entry_u {
 	struct pool_entry_s s;
@@ -214,6 +224,11 @@  static void fill_hdr(void *ptr, pool_entry_t *pool, uint32_t index,
 	if (pool->s.buf_type == ODP_BUFFER_TYPE_PACKET) {
 		odp_packet_hdr_t *packet_hdr = ptr;
 		payload = packet_hdr->payload;
+	} else if (pool->s.buf_type == ODP_BUFFER_TYPE_TIMEOUT) {
+		odp_timeout_hdr_t *tmo_hdr = ptr;
+		payload = tmo_hdr->payload;
+	} else if (pool->s.buf_type == ODP_BUFFER_TYPE_ANY) {
+		payload = ((uint8_t *)ptr) + sizeof(union buffer_type_any_u);
 	}
 
 	memset(hdr, 0, size);
@@ -255,6 +270,10 @@  static void link_bufs(pool_entry_t *pool)
 		hdr_size = sizeof(odp_buffer_hdr_t);
 	else if (buf_type == ODP_BUFFER_TYPE_PACKET)
 		hdr_size = sizeof(odp_packet_hdr_t);
+	else if (buf_type == ODP_BUFFER_TYPE_TIMEOUT)
+		hdr_size = sizeof(odp_timeout_hdr_t);
+	else if (buf_type == ODP_BUFFER_TYPE_ANY)
+		hdr_size = sizeof(union buffer_type_any_u);
 	else {
 		ODP_ERR("odp_buffer_pool_create: Bad type %i\n",
 			buf_type);
diff --git a/platform/linux-generic/source/odp_timer.c b/platform/linux-generic/source/odp_timer.c
index 85369d3..509a890 100644
--- a/platform/linux-generic/source/odp_timer.c
+++ b/platform/linux-generic/source/odp_timer.c
@@ -5,6 +5,8 @@ 
  */
 
 #include <odp_timer.h>
+#include <odp_timer_internal.h>
+#include <odp_buffer_pool_internal.h>
 #include <odp_internal.h>
 #include <odp_atomic.h>
 #include <odp_spinlock.h>
@@ -20,17 +22,6 @@ 
 #define MAX_TICKS     1024
 #define RESOLUTION_NS 1000000
 
-struct timeout_t;
-
-typedef struct timeout_t {
-	struct timeout_t *next;
-	int               timer_id;
-	int               tick;
-	uint64_t          tmo_tick;
-	odp_queue_t       queue;
-	odp_buffer_t      buf;
-	odp_buffer_t      tmo_buf;
-} timeout_t;
 
 typedef struct {
 	odp_spinlock_t lock;
@@ -250,6 +241,7 @@  odp_timer_tmo_t odp_timer_absolute_tmo(odp_timer_t timer, uint64_t tmo_tick,
 	uint64_t cur_tick;
 	timeout_t *new_tmo;
 	odp_buffer_t tmo_buf;
+	odp_timeout_hdr_t *tmo_hdr;
 
 	id = timer - 1;
 
@@ -273,7 +265,8 @@  odp_timer_tmo_t odp_timer_absolute_tmo(odp_timer_t timer, uint64_t tmo_tick,
 		return ODP_TIMER_TMO_INVALID;
 	}
 
-	new_tmo = (timeout_t *)odp_buffer_addr(tmo_buf);
+	tmo_hdr = odp_timeout_hdr((odp_timeout_t) tmo_buf);
+	new_tmo = &tmo_hdr->meta;
 
 	new_tmo->timer_id = id;
 	new_tmo->tick     = (int)tick;
@@ -330,3 +323,15 @@  uint64_t odp_timer_current_tick(odp_timer_t timer)
 	id = timer - 1;
 	return odp_timer.timer[id].cur_tick;
 }
+
+odp_timeout_t odp_timeout_from_buffer(odp_buffer_t buf)
+{
+	return (odp_timeout_t) buf;
+}
+
+uint64_t odp_timeout_tick(odp_timeout_t tmo)
+{
+	odp_timeout_hdr_t *tmo_hdr;
+	tmo_hdr = (odp_timeout_hdr_t *)odp_buf_to_hdr((odp_buffer_t)tmo);
+	return tmo_hdr->meta.tick;
+}