Re: [lng-odp] [PATCH] linux-generic: timer: use plain buffers for timeouts

2015-06-22 Thread Ivan Khoronzhuk

Hi Ola,

Maybe I'm wrong, but let me try to explain change in question.

The main reason in this change is the lack of possibility to convert 
buf_hdr to
buf_handle. The function odp_timeout_to_event requires this conversion. 
By and
large it's not required the tmo_handle to be the tmo_header for 
linux-generic.
It can be tmo_handle = buf_handle. In this case odp_timeout_to_event can 
avoid
buf_hdr - buf_handle conversion. After what it can be reused for 
keystone or

other platforms that avoid buffer header to handle conversion.

The second reason is function _odp_buffer_type(), On linux-generic 
buffer header

holds a field for event type, in Keysonte, the h/w descriptor contains field
for event type. So there is no reason to save it twice, in h/w 
descriptor and
in buffer header. In keystone h/w descriptor = event handle. Holding 
event type

in event is more logical. And Taras, probably, wanted to avoid implementing
it's own _odp_buffet_type and replaced it on odp_event_type.

Why this is problematic to implement on Kestone platform?
It's not a problem, it's redundancy.
From what I see, buf_handle = h/w descriptor pointer. H/w descriptor 
contains

enough fields to hold buffer information, that's why actual buffer header is
empty for now. It doesn't hold handle and event type, so it cannot be easily
converted. Currently, there is no reason it this, especially if timeout 
handle

can be equal to buffer handle.

Am I right, Taras?

But it's not a problem to add link on handle to buffer header, but why?


On 01.06.15 15:12, Ola Liljedahl wrote:

If I understand your patch correctly, a timeout event is really a buffer
with the timeout-specific header stored just after the buffer header (as
before). You don't change the definition of odp_timeout_hdr_t and the
implementation of odp_timeout_hdr(odp_buffer_t buf) has just moved from
odp_timer_internal.h to odp_timer.c where is renamed
to timeout_hdr_from_buf(). There is also a new
function timeout_hdr(odp_timeout_t tmo) which helps with the conversion
from timeout to timeout header.

So you essential change seems to make the timeout event handle the same
as a buffer event handle and not necessarily a pointer (as in the
original code). I don't see why this is an important change (from a
portability or structural point of view), can you please explain this?

-- Ola



On 31 May 2015 at 08:50, Taras Kondratiuk taras.kondrat...@linaro.org
mailto:taras.kondrat...@linaro.org wrote:

On 05/29/2015 07:26 AM, Ola Liljedahl wrote:
 On 13 May 2015 at 17:31, Ola Liljedahl ola.liljed...@linaro.org 
mailto:ola.liljed...@linaro.org
 mailto:ola.liljed...@linaro.org mailto:ola.liljed...@linaro.org 
wrote:

 On 13 May 2015 at 12:19, Maxim Uvarov maxim.uva...@linaro.org 
mailto:maxim.uva...@linaro.org
 mailto:maxim.uva...@linaro.org mailto:maxim.uva...@linaro.org 
wrote:

 Patch looks good. Validation test passed. Need one more review.

 Thanks. I did this primarily for KS2 being able to use the
 linux-generic timer implementation without any changes. I am waiting
 for Taras to verify this.

 Well it seems now that Taras is not going to verify that this patch
 solves his problems on KS2. I like the patch anyway and would like to
 see it merged. Any reviewers?

Sorry for a long delay.
I had a slightly different approach in mind.

8-
From: Taras Kondratiuk taras.kondrat...@linaro.org
mailto:taras.kondrat...@linaro.org
Date: Sat, 30 May 2015 23:26:19 -0700
Subject: [PATCH] linux-generic: timer: convert odp_timeout_t to event

Signed-off-by: Taras Kondratiuk taras.kondrat...@linaro.org
mailto:taras.kondrat...@linaro.org
---
  .../linux-generic/include/odp/plat/timer_types.h   |  8 --
  .../linux-generic/include/odp_timer_internal.h |  8 --
  platform/linux-generic/odp_timer.c | 31
--
  3 files changed, 23 insertions(+), 24 deletions(-)

diff --git a/platform/linux-generic/include/odp/plat/timer_types.h
b/platform/linux-generic/include/odp/plat/timer_types.h
index 006683e..d987096 100644
--- a/platform/linux-generic/include/odp/plat/timer_types.h
+++ b/platform/linux-generic/include/odp/plat/timer_types.h
@@ -18,6 +18,10 @@
  extern C {
  #endif

+#include odp/std_types.h
+#include odp/plat/strong_types.h
+#include odp/plat/event_types.h
+
  /** @addtogroup odp_timer
   *  @{
   **/
@@ -32,9 +36,9 @@ typedef uint32_t odp_timer_t;

  #define ODP_TIMER_INVALID ((uint32_t)~0U)

-typedef void *odp_timeout_t;
+typedef odp_handle_t odp_timeout_t;

-#define ODP_TIMEOUT_INVALID NULL
+#define ODP_TIMEOUT_INVALID (odp_timeout_t)ODP_EVENT_INVALID

  /**
   * @}
diff --git a/platform/linux-generic/include/odp_timer_internal.h

Re: [lng-odp] [PATCH] linux-generic: timer: use plain buffers for timeouts

2015-06-01 Thread Ola Liljedahl
If I understand your patch correctly, a timeout event is really a buffer
with the timeout-specific header stored just after the buffer header (as
before). You don't change the definition of odp_timeout_hdr_t and the
implementation of odp_timeout_hdr(odp_buffer_t buf) has just moved from
odp_timer_internal.h to odp_timer.c where is renamed
to timeout_hdr_from_buf(). There is also a new
function timeout_hdr(odp_timeout_t tmo) which helps with the conversion
from timeout to timeout header.

So you essential change seems to make the timeout event handle the same as
a buffer event handle and not necessarily a pointer (as in the original
code). I don't see why this is an important change (from a portability or
structural point of view), can you please explain this?

-- Ola



On 31 May 2015 at 08:50, Taras Kondratiuk taras.kondrat...@linaro.org
wrote:

 On 05/29/2015 07:26 AM, Ola Liljedahl wrote:
  On 13 May 2015 at 17:31, Ola Liljedahl ola.liljed...@linaro.org
  mailto:ola.liljed...@linaro.org wrote:
 
  On 13 May 2015 at 12:19, Maxim Uvarov maxim.uva...@linaro.org
  mailto:maxim.uva...@linaro.org wrote:
 
  Patch looks good. Validation test passed. Need one more review.
 
  Thanks. I did this primarily for KS2 being able to use the
  linux-generic timer implementation without any changes. I am waiting
  for Taras to verify this.
 
  Well it seems now that Taras is not going to verify that this patch
  solves his problems on KS2. I like the patch anyway and would like to
  see it merged. Any reviewers?

 Sorry for a long delay.
 I had a slightly different approach in mind.

 8-
 From: Taras Kondratiuk taras.kondrat...@linaro.org
 Date: Sat, 30 May 2015 23:26:19 -0700
 Subject: [PATCH] linux-generic: timer: convert odp_timeout_t to event

 Signed-off-by: Taras Kondratiuk taras.kondrat...@linaro.org
 ---
  .../linux-generic/include/odp/plat/timer_types.h   |  8 --
  .../linux-generic/include/odp_timer_internal.h |  8 --
  platform/linux-generic/odp_timer.c | 31
 --
  3 files changed, 23 insertions(+), 24 deletions(-)

 diff --git a/platform/linux-generic/include/odp/plat/timer_types.h
 b/platform/linux-generic/include/odp/plat/timer_types.h
 index 006683e..d987096 100644
 --- a/platform/linux-generic/include/odp/plat/timer_types.h
 +++ b/platform/linux-generic/include/odp/plat/timer_types.h
 @@ -18,6 +18,10 @@
  extern C {
  #endif

 +#include odp/std_types.h
 +#include odp/plat/strong_types.h
 +#include odp/plat/event_types.h
 +
  /** @addtogroup odp_timer
   *  @{
   **/
 @@ -32,9 +36,9 @@ typedef uint32_t odp_timer_t;

  #define ODP_TIMER_INVALID ((uint32_t)~0U)

 -typedef void *odp_timeout_t;
 +typedef odp_handle_t odp_timeout_t;

 -#define ODP_TIMEOUT_INVALID NULL
 +#define ODP_TIMEOUT_INVALID (odp_timeout_t)ODP_EVENT_INVALID

  /**
   * @}
 diff --git a/platform/linux-generic/include/odp_timer_internal.h
 b/platform/linux-generic/include/odp_timer_internal.h
 index 90af62c..db379ec 100644
 --- a/platform/linux-generic/include/odp_timer_internal.h
 +++ b/platform/linux-generic/include/odp_timer_internal.h
 @@ -40,12 +40,4 @@ typedef struct odp_timeout_hdr_stride {
  } odp_timeout_hdr_stride;


 -/**
 - * Return the timeout header
 - */
 -static inline odp_timeout_hdr_t *odp_timeout_hdr(odp_buffer_t buf)
 -{
 -   return (odp_timeout_hdr_t *)odp_buf_to_hdr(buf);
 -}
 -
  #endif
 diff --git a/platform/linux-generic/odp_timer.c
 b/platform/linux-generic/odp_timer.c
 index b7cb04f..39e76e1 100644
 --- a/platform/linux-generic/odp_timer.c
 +++ b/platform/linux-generic/odp_timer.c
 @@ -80,7 +80,13 @@ static _odp_atomic_flag_t locks[NUM_LOCKS]; /* Multiple
 locks per cache line! */

  static odp_timeout_hdr_t *timeout_hdr_from_buf(odp_buffer_t buf)
  {
 -   return (odp_timeout_hdr_t *)odp_buf_to_hdr(buf);
 +   return (odp_timeout_hdr_t *)(void *)odp_buf_to_hdr(buf);
 +}
 +
 +static odp_timeout_hdr_t *timeout_hdr(odp_timeout_t tmo)
 +{
 +   odp_buffer_t buf =
 odp_buffer_from_event(odp_timeout_to_event(tmo));
 +   return timeout_hdr_from_buf(buf);
  }


  
 /**
 @@ -422,7 +428,8 @@ static bool timer_reset(uint32_t idx,
 } else {
 /* We have a new timeout buffer which replaces any old one
 */
 /* Fill in some (constant) header fields for timeout
 events */
 -   if (_odp_buffer_type(*tmo_buf) == ODP_EVENT_TIMEOUT) {
 +   if (odp_event_type(odp_buffer_to_event(*tmo_buf)) ==
 +   ODP_EVENT_TIMEOUT) {
 /* Convert from buffer to timeout hdr */
 odp_timeout_hdr_t *tmo_hdr =
 timeout_hdr_from_buf(*tmo_buf);
 @@ -567,7 +574,8 @@ static unsigned timer_expire(odp_timer_pool *tp,
 uint32_t idx, uint64_t 

Re: [lng-odp] [PATCH] linux-generic: timer: use plain buffers for timeouts

2015-05-29 Thread Ola Liljedahl
On 13 May 2015 at 17:31, Ola Liljedahl ola.liljed...@linaro.org wrote:

 On 13 May 2015 at 12:19, Maxim Uvarov maxim.uva...@linaro.org wrote:

 Patch looks good. Validation test passed. Need one more review.

 Thanks. I did this primarily for KS2 being able to use the linux-generic
 timer implementation without any changes. I am waiting for Taras to verify
 this.

Well it seems now that Taras is not going to verify that this patch solves
his problems on KS2. I like the patch anyway and would like to see it
merged. Any reviewers?

-- Ola



 -- Ola



 Thanks,
 Maxim.


 On 04/24/2015 17:10, Ola Liljedahl wrote:

 Use plain buffers for timeouts. Store the timeout header in the buffer
 data area. This simplifies re-use on other platforms where the event
 header cannot be arbitrarily defined.

 Signed-off-by: Ola Liljedahl ola.liljed...@linaro.org
 ---
 (This document/code contribution attached is provided under the terms of
 agreement LES-LTM-21309)

   platform/linux-generic/include/odp_timer_internal.h | 15
 ---
   platform/linux-generic/odp_pool.c   |  7 ---
   platform/linux-generic/odp_timer.c  | 15
 +--
   3 files changed, 25 insertions(+), 12 deletions(-)

 diff --git a/platform/linux-generic/include/odp_timer_internal.h
 b/platform/linux-generic/include/odp_timer_internal.h
 index 90af62c..a631bd0 100644
 --- a/platform/linux-generic/include/odp_timer_internal.h
 +++ b/platform/linux-generic/include/odp_timer_internal.h
 @@ -16,36 +16,45 @@
 #include odp/align.h
   #include odp/debug.h
 +#include odp_debug_internal.h
   #include odp_buffer_internal.h
   #include odp_pool_internal.h
   #include odp/timer.h
 /**
* Internal Timeout header
 + * For compatibility with buffers, we use the buffer_hdr here and
 nothing else
*/
   typedef struct {
 /* common buffer header */
 odp_buffer_hdr_t buf_hdr;
 +} odp_timeout_fakehdr_t;
   +/* The real timeout header is in a separate struct in a separate
 location */
 +typedef struct {
 /* Requested expiration time */
 uint64_t expiration;
 /* User ptr inherited from parent timer */
 void *user_ptr;
 +   /* Handle of buffer we are located in */
 +   odp_buffer_t buf;
 /* Parent timer */
 odp_timer_t timer;
   } odp_timeout_hdr_t;
 typedef struct odp_timeout_hdr_stride {
 -   uint8_t
 pad[ODP_CACHE_LINE_SIZE_ROUNDUP(sizeof(odp_timeout_hdr_t))];
 +   uint8_t
 pad[ODP_CACHE_LINE_SIZE_ROUNDUP(sizeof(odp_timeout_fakehdr_t))];
   } odp_timeout_hdr_stride;
   /**
* Return the timeout header
*/
 -static inline odp_timeout_hdr_t *odp_timeout_hdr(odp_buffer_t buf)
 +static inline odp_timeout_hdr_t *odp_timeout_hdr_from_buf(odp_buffer_t
 buf)
   {
 -   return (odp_timeout_hdr_t *)odp_buf_to_hdr(buf);
 +   /* The real timeout header is stored in the buffer data */
 +   ODP_ASSERT(odp_buffer_size(buf) == sizeof(odp_timeout_hdr_t));
 +   return (odp_timeout_hdr_t *)odp_buffer_addr(buf);
   }
 #endif
 diff --git a/platform/linux-generic/odp_pool.c
 b/platform/linux-generic/odp_pool.c
 index bf49623..fc10aa4 100644
 --- a/platform/linux-generic/odp_pool.c
 +++ b/platform/linux-generic/odp_pool.c
 @@ -32,7 +32,7 @@
   typedef union buffer_type_any_u {
 odp_buffer_hdr_t  buf;
 odp_packet_hdr_t  pkt;
 -   odp_timeout_hdr_t tmo;
 +   odp_timeout_fakehdr_t tmo;
   } odp_anybuf_t;
 _ODP_STATIC_ASSERT((sizeof(union buffer_type_any_u) % 8) == 0,
 @@ -148,7 +148,8 @@ odp_pool_t odp_pool_create(const char *name,
 /* Default size and align for timeouts */
 if (params-type == ODP_POOL_TIMEOUT) {
 -   params-buf.size  = 0; /* tmo.__res1 */
 +   /* The real timeout header is stored in the buffer */
 +   params-buf.size  = sizeof(odp_timeout_hdr_t); /*
 tmo.__res1 */
 params-buf.align = 0; /* tmo.__res2 */
 }
   @@ -226,7 +227,7 @@ odp_pool_t odp_pool_create(const char *name,
 break;
 case ODP_POOL_TIMEOUT:
 -   blk_size = 0;
 +   blk_size = params-buf.size;
 buf_num = params-tmo.num;
 buf_stride = sizeof(odp_timeout_hdr_stride);
 break;
 diff --git a/platform/linux-generic/odp_timer.c
 b/platform/linux-generic/odp_timer.c
 index e5391dc..1922f94 100644
 --- a/platform/linux-generic/odp_timer.c
 +++ b/platform/linux-generic/odp_timer.c
 @@ -78,7 +78,7 @@ static _odp_atomic_flag_t locks[NUM_LOCKS]; /*
 Multiple locks per cache line! */
 static odp_timeout_hdr_t *timeout_hdr_from_buf(odp_buffer_t buf)
   {
 -   return (odp_timeout_hdr_t *)odp_buf_to_hdr(buf);
 +   return odp_timeout_hdr_from_buf(buf);
   }

 /**
 @@ -820,8 +820,7 @@ odp_timeout_t odp_timeout_from_event(odp_event_t ev)
   odp_event_t 

Re: [lng-odp] [PATCH] linux-generic: timer: use plain buffers for timeouts

2015-05-13 Thread Maxim Uvarov

Patch looks good. Validation test passed. Need one more review.

Thanks,
Maxim.

On 04/24/2015 17:10, Ola Liljedahl wrote:

Use plain buffers for timeouts. Store the timeout header in the buffer
data area. This simplifies re-use on other platforms where the event
header cannot be arbitrarily defined.

Signed-off-by: Ola Liljedahl ola.liljed...@linaro.org
---
(This document/code contribution attached is provided under the terms of
agreement LES-LTM-21309)

  platform/linux-generic/include/odp_timer_internal.h | 15 ---
  platform/linux-generic/odp_pool.c   |  7 ---
  platform/linux-generic/odp_timer.c  | 15 +--
  3 files changed, 25 insertions(+), 12 deletions(-)

diff --git a/platform/linux-generic/include/odp_timer_internal.h 
b/platform/linux-generic/include/odp_timer_internal.h
index 90af62c..a631bd0 100644
--- a/platform/linux-generic/include/odp_timer_internal.h
+++ b/platform/linux-generic/include/odp_timer_internal.h
@@ -16,36 +16,45 @@
  
  #include odp/align.h

  #include odp/debug.h
+#include odp_debug_internal.h
  #include odp_buffer_internal.h
  #include odp_pool_internal.h
  #include odp/timer.h
  
  /**

   * Internal Timeout header
+ * For compatibility with buffers, we use the buffer_hdr here and nothing else
   */
  typedef struct {
/* common buffer header */
odp_buffer_hdr_t buf_hdr;
+} odp_timeout_fakehdr_t;
  
+/* The real timeout header is in a separate struct in a separate location */

+typedef struct {
/* Requested expiration time */
uint64_t expiration;
/* User ptr inherited from parent timer */
void *user_ptr;
+   /* Handle of buffer we are located in */
+   odp_buffer_t buf;
/* Parent timer */
odp_timer_t timer;
  } odp_timeout_hdr_t;
  
  typedef struct odp_timeout_hdr_stride {

-   uint8_t pad[ODP_CACHE_LINE_SIZE_ROUNDUP(sizeof(odp_timeout_hdr_t))];
+   uint8_t pad[ODP_CACHE_LINE_SIZE_ROUNDUP(sizeof(odp_timeout_fakehdr_t))];
  } odp_timeout_hdr_stride;
  
  
  /**

   * Return the timeout header
   */
-static inline odp_timeout_hdr_t *odp_timeout_hdr(odp_buffer_t buf)
+static inline odp_timeout_hdr_t *odp_timeout_hdr_from_buf(odp_buffer_t buf)
  {
-   return (odp_timeout_hdr_t *)odp_buf_to_hdr(buf);
+   /* The real timeout header is stored in the buffer data */
+   ODP_ASSERT(odp_buffer_size(buf) == sizeof(odp_timeout_hdr_t));
+   return (odp_timeout_hdr_t *)odp_buffer_addr(buf);
  }
  
  #endif

diff --git a/platform/linux-generic/odp_pool.c 
b/platform/linux-generic/odp_pool.c
index bf49623..fc10aa4 100644
--- a/platform/linux-generic/odp_pool.c
+++ b/platform/linux-generic/odp_pool.c
@@ -32,7 +32,7 @@
  typedef union buffer_type_any_u {
odp_buffer_hdr_t  buf;
odp_packet_hdr_t  pkt;
-   odp_timeout_hdr_t tmo;
+   odp_timeout_fakehdr_t tmo;
  } odp_anybuf_t;
  
  _ODP_STATIC_ASSERT((sizeof(union buffer_type_any_u) % 8) == 0,

@@ -148,7 +148,8 @@ odp_pool_t odp_pool_create(const char *name,
  
  	/* Default size and align for timeouts */

if (params-type == ODP_POOL_TIMEOUT) {
-   params-buf.size  = 0; /* tmo.__res1 */
+   /* The real timeout header is stored in the buffer */
+   params-buf.size  = sizeof(odp_timeout_hdr_t); /* tmo.__res1 */
params-buf.align = 0; /* tmo.__res2 */
}
  
@@ -226,7 +227,7 @@ odp_pool_t odp_pool_create(const char *name,

break;
  
  	case ODP_POOL_TIMEOUT:

-   blk_size = 0;
+   blk_size = params-buf.size;
buf_num = params-tmo.num;
buf_stride = sizeof(odp_timeout_hdr_stride);
break;
diff --git a/platform/linux-generic/odp_timer.c 
b/platform/linux-generic/odp_timer.c
index e5391dc..1922f94 100644
--- a/platform/linux-generic/odp_timer.c
+++ b/platform/linux-generic/odp_timer.c
@@ -78,7 +78,7 @@ static _odp_atomic_flag_t locks[NUM_LOCKS]; /* Multiple locks 
per cache line! */
  
  static odp_timeout_hdr_t *timeout_hdr_from_buf(odp_buffer_t buf)

  {
-   return (odp_timeout_hdr_t *)odp_buf_to_hdr(buf);
+   return odp_timeout_hdr_from_buf(buf);
  }
  
  /**

@@ -820,8 +820,7 @@ odp_timeout_t odp_timeout_from_event(odp_event_t ev)
  odp_event_t odp_timeout_to_event(odp_timeout_t tmo)
  {
odp_timeout_hdr_t *tmo_hdr = (odp_timeout_hdr_t *)tmo;
-   odp_buffer_t buf = odp_hdr_to_buf(tmo_hdr-buf_hdr);
-   return odp_buffer_to_event(buf);
+   return odp_buffer_to_event(tmo_hdr-buf);
  }
  
  int odp_timeout_fresh(odp_timeout_t tmo)

@@ -857,16 +856,20 @@ void *odp_timeout_user_ptr(odp_timeout_t tmo)
  
  odp_timeout_t odp_timeout_alloc(odp_pool_t pool)

  {
+   odp_timeout_hdr_t *tmo_hdr;
odp_buffer_t buf = odp_buffer_alloc(pool);
if (odp_unlikely(buf == ODP_BUFFER_INVALID))
return 

Re: [lng-odp] [PATCH] linux-generic: timer: use plain buffers for timeouts

2015-05-13 Thread Ola Liljedahl
On 13 May 2015 at 12:19, Maxim Uvarov maxim.uva...@linaro.org wrote:

 Patch looks good. Validation test passed. Need one more review.

Thanks. I did this primarily for KS2 being able to use the linux-generic
timer implementation without any changes. I am waiting for Taras to verify
this.

-- Ola



 Thanks,
 Maxim.


 On 04/24/2015 17:10, Ola Liljedahl wrote:

 Use plain buffers for timeouts. Store the timeout header in the buffer
 data area. This simplifies re-use on other platforms where the event
 header cannot be arbitrarily defined.

 Signed-off-by: Ola Liljedahl ola.liljed...@linaro.org
 ---
 (This document/code contribution attached is provided under the terms of
 agreement LES-LTM-21309)

   platform/linux-generic/include/odp_timer_internal.h | 15 ---
   platform/linux-generic/odp_pool.c   |  7 ---
   platform/linux-generic/odp_timer.c  | 15 +--
   3 files changed, 25 insertions(+), 12 deletions(-)

 diff --git a/platform/linux-generic/include/odp_timer_internal.h
 b/platform/linux-generic/include/odp_timer_internal.h
 index 90af62c..a631bd0 100644
 --- a/platform/linux-generic/include/odp_timer_internal.h
 +++ b/platform/linux-generic/include/odp_timer_internal.h
 @@ -16,36 +16,45 @@
 #include odp/align.h
   #include odp/debug.h
 +#include odp_debug_internal.h
   #include odp_buffer_internal.h
   #include odp_pool_internal.h
   #include odp/timer.h
 /**
* Internal Timeout header
 + * For compatibility with buffers, we use the buffer_hdr here and
 nothing else
*/
   typedef struct {
 /* common buffer header */
 odp_buffer_hdr_t buf_hdr;
 +} odp_timeout_fakehdr_t;
   +/* The real timeout header is in a separate struct in a separate
 location */
 +typedef struct {
 /* Requested expiration time */
 uint64_t expiration;
 /* User ptr inherited from parent timer */
 void *user_ptr;
 +   /* Handle of buffer we are located in */
 +   odp_buffer_t buf;
 /* Parent timer */
 odp_timer_t timer;
   } odp_timeout_hdr_t;
 typedef struct odp_timeout_hdr_stride {
 -   uint8_t
 pad[ODP_CACHE_LINE_SIZE_ROUNDUP(sizeof(odp_timeout_hdr_t))];
 +   uint8_t
 pad[ODP_CACHE_LINE_SIZE_ROUNDUP(sizeof(odp_timeout_fakehdr_t))];
   } odp_timeout_hdr_stride;
   /**
* Return the timeout header
*/
 -static inline odp_timeout_hdr_t *odp_timeout_hdr(odp_buffer_t buf)
 +static inline odp_timeout_hdr_t *odp_timeout_hdr_from_buf(odp_buffer_t
 buf)
   {
 -   return (odp_timeout_hdr_t *)odp_buf_to_hdr(buf);
 +   /* The real timeout header is stored in the buffer data */
 +   ODP_ASSERT(odp_buffer_size(buf) == sizeof(odp_timeout_hdr_t));
 +   return (odp_timeout_hdr_t *)odp_buffer_addr(buf);
   }
 #endif
 diff --git a/platform/linux-generic/odp_pool.c
 b/platform/linux-generic/odp_pool.c
 index bf49623..fc10aa4 100644
 --- a/platform/linux-generic/odp_pool.c
 +++ b/platform/linux-generic/odp_pool.c
 @@ -32,7 +32,7 @@
   typedef union buffer_type_any_u {
 odp_buffer_hdr_t  buf;
 odp_packet_hdr_t  pkt;
 -   odp_timeout_hdr_t tmo;
 +   odp_timeout_fakehdr_t tmo;
   } odp_anybuf_t;
 _ODP_STATIC_ASSERT((sizeof(union buffer_type_any_u) % 8) == 0,
 @@ -148,7 +148,8 @@ odp_pool_t odp_pool_create(const char *name,
 /* Default size and align for timeouts */
 if (params-type == ODP_POOL_TIMEOUT) {
 -   params-buf.size  = 0; /* tmo.__res1 */
 +   /* The real timeout header is stored in the buffer */
 +   params-buf.size  = sizeof(odp_timeout_hdr_t); /*
 tmo.__res1 */
 params-buf.align = 0; /* tmo.__res2 */
 }
   @@ -226,7 +227,7 @@ odp_pool_t odp_pool_create(const char *name,
 break;
 case ODP_POOL_TIMEOUT:
 -   blk_size = 0;
 +   blk_size = params-buf.size;
 buf_num = params-tmo.num;
 buf_stride = sizeof(odp_timeout_hdr_stride);
 break;
 diff --git a/platform/linux-generic/odp_timer.c
 b/platform/linux-generic/odp_timer.c
 index e5391dc..1922f94 100644
 --- a/platform/linux-generic/odp_timer.c
 +++ b/platform/linux-generic/odp_timer.c
 @@ -78,7 +78,7 @@ static _odp_atomic_flag_t locks[NUM_LOCKS]; /* Multiple
 locks per cache line! */
 static odp_timeout_hdr_t *timeout_hdr_from_buf(odp_buffer_t buf)
   {
 -   return (odp_timeout_hdr_t *)odp_buf_to_hdr(buf);
 +   return odp_timeout_hdr_from_buf(buf);
   }

 /**
 @@ -820,8 +820,7 @@ odp_timeout_t odp_timeout_from_event(odp_event_t ev)
   odp_event_t odp_timeout_to_event(odp_timeout_t tmo)
   {
 odp_timeout_hdr_t *tmo_hdr = (odp_timeout_hdr_t *)tmo;
 -   odp_buffer_t buf = odp_hdr_to_buf(tmo_hdr-buf_hdr);
 -   return odp_buffer_to_event(buf);
 +   return odp_buffer_to_event(tmo_hdr-buf);
   }
 int 

[lng-odp] [PATCH] linux-generic: timer: use plain buffers for timeouts

2015-04-24 Thread Ola Liljedahl
Use plain buffers for timeouts. Store the timeout header in the buffer
data area. This simplifies re-use on other platforms where the event
header cannot be arbitrarily defined.

Signed-off-by: Ola Liljedahl ola.liljed...@linaro.org
---
(This document/code contribution attached is provided under the terms of
agreement LES-LTM-21309)

 platform/linux-generic/include/odp_timer_internal.h | 15 ---
 platform/linux-generic/odp_pool.c   |  7 ---
 platform/linux-generic/odp_timer.c  | 15 +--
 3 files changed, 25 insertions(+), 12 deletions(-)

diff --git a/platform/linux-generic/include/odp_timer_internal.h 
b/platform/linux-generic/include/odp_timer_internal.h
index 90af62c..a631bd0 100644
--- a/platform/linux-generic/include/odp_timer_internal.h
+++ b/platform/linux-generic/include/odp_timer_internal.h
@@ -16,36 +16,45 @@
 
 #include odp/align.h
 #include odp/debug.h
+#include odp_debug_internal.h
 #include odp_buffer_internal.h
 #include odp_pool_internal.h
 #include odp/timer.h
 
 /**
  * Internal Timeout header
+ * For compatibility with buffers, we use the buffer_hdr here and nothing else
  */
 typedef struct {
/* common buffer header */
odp_buffer_hdr_t buf_hdr;
+} odp_timeout_fakehdr_t;
 
+/* The real timeout header is in a separate struct in a separate location */
+typedef struct {
/* Requested expiration time */
uint64_t expiration;
/* User ptr inherited from parent timer */
void *user_ptr;
+   /* Handle of buffer we are located in */
+   odp_buffer_t buf;
/* Parent timer */
odp_timer_t timer;
 } odp_timeout_hdr_t;
 
 typedef struct odp_timeout_hdr_stride {
-   uint8_t pad[ODP_CACHE_LINE_SIZE_ROUNDUP(sizeof(odp_timeout_hdr_t))];
+   uint8_t pad[ODP_CACHE_LINE_SIZE_ROUNDUP(sizeof(odp_timeout_fakehdr_t))];
 } odp_timeout_hdr_stride;
 
 
 /**
  * Return the timeout header
  */
-static inline odp_timeout_hdr_t *odp_timeout_hdr(odp_buffer_t buf)
+static inline odp_timeout_hdr_t *odp_timeout_hdr_from_buf(odp_buffer_t buf)
 {
-   return (odp_timeout_hdr_t *)odp_buf_to_hdr(buf);
+   /* The real timeout header is stored in the buffer data */
+   ODP_ASSERT(odp_buffer_size(buf) == sizeof(odp_timeout_hdr_t));
+   return (odp_timeout_hdr_t *)odp_buffer_addr(buf);
 }
 
 #endif
diff --git a/platform/linux-generic/odp_pool.c 
b/platform/linux-generic/odp_pool.c
index bf49623..fc10aa4 100644
--- a/platform/linux-generic/odp_pool.c
+++ b/platform/linux-generic/odp_pool.c
@@ -32,7 +32,7 @@
 typedef union buffer_type_any_u {
odp_buffer_hdr_t  buf;
odp_packet_hdr_t  pkt;
-   odp_timeout_hdr_t tmo;
+   odp_timeout_fakehdr_t tmo;
 } odp_anybuf_t;
 
 _ODP_STATIC_ASSERT((sizeof(union buffer_type_any_u) % 8) == 0,
@@ -148,7 +148,8 @@ odp_pool_t odp_pool_create(const char *name,
 
/* Default size and align for timeouts */
if (params-type == ODP_POOL_TIMEOUT) {
-   params-buf.size  = 0; /* tmo.__res1 */
+   /* The real timeout header is stored in the buffer */
+   params-buf.size  = sizeof(odp_timeout_hdr_t); /* tmo.__res1 */
params-buf.align = 0; /* tmo.__res2 */
}
 
@@ -226,7 +227,7 @@ odp_pool_t odp_pool_create(const char *name,
break;
 
case ODP_POOL_TIMEOUT:
-   blk_size = 0;
+   blk_size = params-buf.size;
buf_num = params-tmo.num;
buf_stride = sizeof(odp_timeout_hdr_stride);
break;
diff --git a/platform/linux-generic/odp_timer.c 
b/platform/linux-generic/odp_timer.c
index e5391dc..1922f94 100644
--- a/platform/linux-generic/odp_timer.c
+++ b/platform/linux-generic/odp_timer.c
@@ -78,7 +78,7 @@ static _odp_atomic_flag_t locks[NUM_LOCKS]; /* Multiple locks 
per cache line! */
 
 static odp_timeout_hdr_t *timeout_hdr_from_buf(odp_buffer_t buf)
 {
-   return (odp_timeout_hdr_t *)odp_buf_to_hdr(buf);
+   return odp_timeout_hdr_from_buf(buf);
 }
 
 /**
@@ -820,8 +820,7 @@ odp_timeout_t odp_timeout_from_event(odp_event_t ev)
 odp_event_t odp_timeout_to_event(odp_timeout_t tmo)
 {
odp_timeout_hdr_t *tmo_hdr = (odp_timeout_hdr_t *)tmo;
-   odp_buffer_t buf = odp_hdr_to_buf(tmo_hdr-buf_hdr);
-   return odp_buffer_to_event(buf);
+   return odp_buffer_to_event(tmo_hdr-buf);
 }
 
 int odp_timeout_fresh(odp_timeout_t tmo)
@@ -857,16 +856,20 @@ void *odp_timeout_user_ptr(odp_timeout_t tmo)
 
 odp_timeout_t odp_timeout_alloc(odp_pool_t pool)
 {
+   odp_timeout_hdr_t *tmo_hdr;
odp_buffer_t buf = odp_buffer_alloc(pool);
if (odp_unlikely(buf == ODP_BUFFER_INVALID))
return ODP_TIMEOUT_INVALID;
-   return odp_timeout_from_event(odp_buffer_to_event(buf));
+   tmo_hdr = timeout_hdr_from_buf(buf);
+   /* Must save buffer handle in timeout header for