diff mbox

[v5,01/17] api: event: Add odp_event_t

Message ID 1422277551-16417-2-git-send-email-petri.savolainen@linaro.org
State Accepted
Commit d9a7f99587b0f498c78383a2c60d8515d1b3d444
Headers show

Commit Message

Petri Savolainen Jan. 26, 2015, 1:05 p.m. UTC
* Added odp_event.h and odp_event.c
* Added odp_event_t type and type conversion functions

Signed-off-by: Petri Savolainen <petri.savolainen@linaro.org>
---
 platform/linux-generic/Makefile.am                 |  2 +
 platform/linux-generic/include/api/odp.h           |  1 +
 platform/linux-generic/include/api/odp_buffer.h    | 34 ++++++++++---
 platform/linux-generic/include/api/odp_event.h     | 59 ++++++++++++++++++++++
 platform/linux-generic/include/api/odp_packet.h    | 21 ++++++++
 .../linux-generic/include/api/odp_platform_types.h |  6 +++
 platform/linux-generic/include/api/odp_timer.h     | 13 +++++
 platform/linux-generic/odp_buffer.c                | 10 ++++
 platform/linux-generic/odp_event.c                 | 26 ++++++++++
 platform/linux-generic/odp_packet.c                | 10 ++++
 platform/linux-generic/odp_timer.c                 |  9 ++++
 11 files changed, 185 insertions(+), 6 deletions(-)
 create mode 100644 platform/linux-generic/include/api/odp_event.h
 create mode 100644 platform/linux-generic/odp_event.c

Comments

Ciprian Barbu Jan. 27, 2015, 12:09 p.m. UTC | #1
On Mon, Jan 26, 2015 at 3:05 PM, Petri Savolainen
<petri.savolainen@linaro.org> wrote:
> * Added odp_event.h and odp_event.c
> * Added odp_event_t type and type conversion functions
>
> Signed-off-by: Petri Savolainen <petri.savolainen@linaro.org>
> ---
>  platform/linux-generic/Makefile.am                 |  2 +
>  platform/linux-generic/include/api/odp.h           |  1 +
>  platform/linux-generic/include/api/odp_buffer.h    | 34 ++++++++++---
>  platform/linux-generic/include/api/odp_event.h     | 59 ++++++++++++++++++++++
>  platform/linux-generic/include/api/odp_packet.h    | 21 ++++++++
>  .../linux-generic/include/api/odp_platform_types.h |  6 +++
>  platform/linux-generic/include/api/odp_timer.h     | 13 +++++
>  platform/linux-generic/odp_buffer.c                | 10 ++++
>  platform/linux-generic/odp_event.c                 | 26 ++++++++++
>  platform/linux-generic/odp_packet.c                | 10 ++++
>  platform/linux-generic/odp_timer.c                 |  9 ++++
>  11 files changed, 185 insertions(+), 6 deletions(-)
>  create mode 100644 platform/linux-generic/include/api/odp_event.h
>  create mode 100644 platform/linux-generic/odp_event.c
>
> diff --git a/platform/linux-generic/Makefile.am b/platform/linux-generic/Makefile.am
> index a699ea6..712d75c 100644
> --- a/platform/linux-generic/Makefile.am
> +++ b/platform/linux-generic/Makefile.am
> @@ -19,6 +19,7 @@ include_HEADERS = \
>                   $(top_srcdir)/platform/linux-generic/include/api/odp_cpumask.h \
>                   $(top_srcdir)/platform/linux-generic/include/api/odp_crypto.h \
>                   $(top_srcdir)/platform/linux-generic/include/api/odp_debug.h \
> +                 $(top_srcdir)/platform/linux-generic/include/api/odp_event.h \
>                   $(top_srcdir)/platform/linux-generic/include/api/odp_hints.h \
>                   $(top_srcdir)/platform/linux-generic/include/api/odp_init.h \
>                   $(top_srcdir)/platform/linux-generic/include/api/odp_packet_flags.h \
> @@ -80,6 +81,7 @@ __LIB__libodp_la_SOURCES = \
>                            odp_classification.c \
>                            odp_cpumask.c \
>                            odp_crypto.c \
> +                          odp_event.c \
>                            odp_init.c \
>                            odp_impl.c \
>                            odp_linux.c \
> diff --git a/platform/linux-generic/include/api/odp.h b/platform/linux-generic/include/api/odp.h
> index 1cc7ce0..49357b0 100644
> --- a/platform/linux-generic/include/api/odp.h
> +++ b/platform/linux-generic/include/api/odp.h
> @@ -49,6 +49,7 @@ extern "C" {
>  #include <odp_crypto.h>
>  #include <odp_classification.h>
>  #include <odp_rwlock.h>
> +#include <odp_event.h>
>
>  #ifdef __cplusplus
>  }
> diff --git a/platform/linux-generic/include/api/odp_buffer.h b/platform/linux-generic/include/api/odp_buffer.h
> index 0670464..20036f9 100644
> --- a/platform/linux-generic/include/api/odp_buffer.h
> +++ b/platform/linux-generic/include/api/odp_buffer.h
> @@ -21,6 +21,7 @@ extern "C" {
>
>  #include <odp_std_types.h>
>  #include <odp_platform_types.h>
> +#include <odp_event.h>
>
>  /** @defgroup odp_buffer ODP BUFFER
>   *  Operations on a buffer.
> @@ -29,6 +30,28 @@ extern "C" {
>
>
>  /**
> + * Get buffer handle from event
> + *
> + * Converts an ODP_EVENT_BUFFER type event to a buffer.
> + *
> + * @param ev   Event handle
> + *
> + * @return Buffer handle
> + *
> + * @see odp_event_type()
> + */
> +odp_buffer_t odp_buffer_from_event(odp_event_t ev);
> +
> +/**
> + * Convert buffer handle to event
> + *
> + * @param buf  Buffer handle
> + *
> + * @return Event handle
> + */
> +odp_event_t odp_buffer_to_event(odp_buffer_t buf);
> +
> +/**
>   * Buffer start address
>   *
>   * @param buf      Buffer handle
> @@ -55,12 +78,11 @@ uint32_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_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 */
> +#define ODP_BUFFER_TYPE_INVALID   ODP_EVENT_TYPE_INVALID
> +#define ODP_BUFFER_TYPE_ANY       0
> +#define ODP_BUFFER_TYPE_RAW       ODP_EVENT_BUFFER
> +#define ODP_BUFFER_TYPE_PACKET    ODP_EVENT_PACKET
> +#define ODP_BUFFER_TYPE_TIMEOUT   ODP_EVENT_TIMEOUT
>
>  /**
>   * Tests if buffer is valid
> diff --git a/platform/linux-generic/include/api/odp_event.h b/platform/linux-generic/include/api/odp_event.h
> new file mode 100644
> index 0000000..209d968
> --- /dev/null
> +++ b/platform/linux-generic/include/api/odp_event.h
> @@ -0,0 +1,59 @@
> +/* Copyright (c) 2015, Linaro Limited
> + * All rights reserved.
> + *
> + * SPDX-License-Identifier:     BSD-3-Clause
> + */
> +
> +
> +/**
> + * @file
> + *
> + * ODP event
> + */
> +
> +#ifndef ODP_EVENT_H_
> +#define ODP_EVENT_H_
> +
> +#ifdef __cplusplus
> +extern "C" {
> +#endif
> +
> +
> +#include <odp_std_types.h>
> +#include <odp_platform_types.h>
> +
> +/** @defgroup odp_event ODP EVENT
> + *  Operations on an event.
> + *  @{
> + */
> +
> +
> +/**
> + * Event type
> + *
> + * @param event    Event handle
> + *
> + * @return Event type or ODP_EVENT_TYPE_INVALID
> + */
> +int odp_event_type(odp_event_t event);
> +
> +/** Invalid event type */
> +#define ODP_EVENT_TYPE_INVALID (-1)
> +/** Buffer event */
> +#define ODP_EVENT_BUFFER         1
> +/** Packet event */
> +#define ODP_EVENT_PACKET         2
> +/** Timeout event */
> +#define ODP_EVENT_TIMEOUT        3

Value 0 stands is not used, it could cause problems. Why not transform
these defines into enums and let ODP_EVENT_TYPE_INVALID be 0 ?

> +
> +
> +
> +/**
> + * @}
> + */
> +
> +#ifdef __cplusplus
> +}
> +#endif
> +
> +#endif
> diff --git a/platform/linux-generic/include/api/odp_packet.h b/platform/linux-generic/include/api/odp_packet.h
> index 920a593..92b6016 100644
> --- a/platform/linux-generic/include/api/odp_packet.h
> +++ b/platform/linux-generic/include/api/odp_packet.h
> @@ -113,6 +113,27 @@ odp_packet_t odp_packet_from_buffer(odp_buffer_t buf);
>   */
>  odp_buffer_t odp_packet_to_buffer(odp_packet_t pkt);
>
> +/**
> + * Get packet handle from event
> + *
> + * Converts an ODP_EVENT_PACKET type event to a packet.
> + *
> + * @param ev   Event handle
> + *
> + * @return Packet handle
> + *
> + * @see odp_event_type()
> + */
> +odp_packet_t odp_packet_from_event(odp_event_t ev);
> +
> +/**
> + * Convert packet handle to event
> + *
> + * @param pkt  Packet handle
> + *
> + * @return Event handle
> + */
> +odp_event_t odp_packet_to_event(odp_packet_t pkt);
>
>  /*
>   *
> diff --git a/platform/linux-generic/include/api/odp_platform_types.h b/platform/linux-generic/include/api/odp_platform_types.h
> index 6ed9e78..1d32e23 100644
> --- a/platform/linux-generic/include/api/odp_platform_types.h
> +++ b/platform/linux-generic/include/api/odp_platform_types.h
> @@ -65,6 +65,12 @@ typedef uint32_t odp_pktio_t;
>  /** odp_pktio_t value to indicate any port */
>  #define ODP_PKTIO_ANY ((odp_pktio_t)~0)
>
> +/** ODP event */
> +typedef odp_buffer_t odp_event_t;
> +
> +/** Invalid event */
> +#define ODP_EVENT_INVALID ODP_BUFFER_INVALID
> +
>  /**
>   * ODP shared memory block
>   */
> diff --git a/platform/linux-generic/include/api/odp_timer.h b/platform/linux-generic/include/api/odp_timer.h
> index 69402ef..cb17b7b 100644
> --- a/platform/linux-generic/include/api/odp_timer.h
> +++ b/platform/linux-generic/include/api/odp_timer.h
> @@ -21,6 +21,7 @@ extern "C" {
>  #include <stdlib.h>
>  #include <odp_std_types.h>
>  #include <odp_buffer.h>
> +#include <odp_event.h>
>  #include <odp_queue.h>
>
>  /** @defgroup odp_timer ODP TIMER
> @@ -310,6 +311,18 @@ int odp_timer_cancel(odp_timer_t tim, odp_buffer_t *tmo_buf);
>  odp_timeout_t odp_timeout_from_buf(odp_buffer_t buf);
>
>  /**
> + * Return timeout handle that is associated with timeout event
> + *
> + * Note: any invalid parameters will cause undefined behavior and may cause
> + * the application to abort or crash.
> + *
> + * @param buf An event of type ODP_EVENT_TIMEOUT
> + *
> + * @return timeout handle
> + */
> +odp_timeout_t odp_timeout_from_event(odp_event_t ev);
> +
> +/**
>   * Check for fresh timeout
>   * If the corresponding timer has been reset or cancelled since this timeout
>   * was enqueued, the timeout is stale (not fresh).
> diff --git a/platform/linux-generic/odp_buffer.c b/platform/linux-generic/odp_buffer.c
> index 57ba408..939332a 100644
> --- a/platform/linux-generic/odp_buffer.c
> +++ b/platform/linux-generic/odp_buffer.c
> @@ -14,6 +14,16 @@
>  #include <stdio.h>
>
>
> +odp_buffer_t odp_buffer_from_event(odp_event_t ev)
> +{
> +       return (odp_buffer_t)ev;
> +}
> +
> +odp_event_t odp_buffer_to_event(odp_buffer_t buf)
> +{
> +       return (odp_event_t)buf;
> +}
> +
>  void *odp_buffer_addr(odp_buffer_t buf)
>  {
>         odp_buffer_hdr_t *hdr = odp_buf_to_hdr(buf);
> diff --git a/platform/linux-generic/odp_event.c b/platform/linux-generic/odp_event.c
> new file mode 100644
> index 0000000..c646f42
> --- /dev/null
> +++ b/platform/linux-generic/odp_event.c
> @@ -0,0 +1,26 @@
> +/* Copyright (c) 2015, Linaro Limited
> + * All rights reserved.
> + *
> + * SPDX-License-Identifier:     BSD-3-Clause
> + */
> +
> +#include <odp_event.h>
> +#include <odp_buffer.h>
> +
> +int odp_event_type(odp_event_t event)
> +{
> +       odp_buffer_t buf;
> +
> +       buf = odp_buffer_from_event(event);
> +
> +       switch (odp_buffer_type(buf)) {
> +       case ODP_BUFFER_TYPE_RAW:
> +               return ODP_EVENT_BUFFER;
> +       case ODP_BUFFER_TYPE_PACKET:
> +               return ODP_EVENT_PACKET;
> +       case ODP_BUFFER_TYPE_TIMEOUT:
> +               return ODP_EVENT_TIMEOUT;
> +       default:
> +               return ODP_EVENT_TYPE_INVALID;
> +       }
> +}
> diff --git a/platform/linux-generic/odp_packet.c b/platform/linux-generic/odp_packet.c
> index 257abec..ebe3b55 100644
> --- a/platform/linux-generic/odp_packet.c
> +++ b/platform/linux-generic/odp_packet.c
> @@ -75,6 +75,16 @@ odp_buffer_t odp_packet_to_buffer(odp_packet_t pkt)
>         return (odp_buffer_t)pkt;
>  }
>
> +odp_packet_t odp_packet_from_event(odp_event_t ev)
> +{
> +       return (odp_packet_t)ev;
> +}
> +
> +odp_event_t odp_packet_to_event(odp_packet_t pkt)
> +{
> +       return (odp_event_t)pkt;
> +}
> +
>  /*
>   *
>   * Pointers and lengths
> diff --git a/platform/linux-generic/odp_timer.c b/platform/linux-generic/odp_timer.c
> index 3ba32a1..d926ada 100644
> --- a/platform/linux-generic/odp_timer.c
> +++ b/platform/linux-generic/odp_timer.c
> @@ -39,6 +39,7 @@
>  #include <odp_buffer_pool_internal.h>
>  #include <odp_debug.h>
>  #include <odp_debug_internal.h>
> +#include <odp_event.h>
>  #include <odp_hints.h>
>  #include <odp_internal.h>
>  #include <odp_queue.h>
> @@ -802,6 +803,14 @@ odp_timeout_t odp_timeout_from_buf(odp_buffer_t buf)
>         return (odp_timeout_t)timeout_hdr_from_buf(buf);
>  }
>
> +odp_timeout_t odp_timeout_from_event(odp_event_t ev)
> +{
> +       /* This check not mandated by the API specification */
> +       if (odp_event_type(ev) != ODP_EVENT_TIMEOUT)
> +               ODP_ABORT("Event not a timeout");
> +       return (odp_timeout_t)timeout_hdr_from_buf(odp_buffer_from_event(ev));
> +}
> +
>  int odp_timeout_fresh(odp_timeout_t tmo)
>  {
>         const odp_timeout_hdr_t *hdr = (odp_timeout_hdr_t *)tmo;
> --
> 2.2.2
>
>
> _______________________________________________
> lng-odp mailing list
> lng-odp@lists.linaro.org
> http://lists.linaro.org/mailman/listinfo/lng-odp
Bill Fischofer Jan. 27, 2015, 12:14 p.m. UTC | #2
Values of ODP abstract types are implementation defined and hence
arbitrary.  Implementations are free to define them in whatever way is most
efficient for them.

On Tue, Jan 27, 2015 at 6:09 AM, Ciprian Barbu <ciprian.barbu@linaro.org>
wrote:

> On Mon, Jan 26, 2015 at 3:05 PM, Petri Savolainen
> <petri.savolainen@linaro.org> wrote:
> > * Added odp_event.h and odp_event.c
> > * Added odp_event_t type and type conversion functions
> >
> > Signed-off-by: Petri Savolainen <petri.savolainen@linaro.org>
> > ---
> >  platform/linux-generic/Makefile.am                 |  2 +
> >  platform/linux-generic/include/api/odp.h           |  1 +
> >  platform/linux-generic/include/api/odp_buffer.h    | 34 ++++++++++---
> >  platform/linux-generic/include/api/odp_event.h     | 59
> ++++++++++++++++++++++
> >  platform/linux-generic/include/api/odp_packet.h    | 21 ++++++++
> >  .../linux-generic/include/api/odp_platform_types.h |  6 +++
> >  platform/linux-generic/include/api/odp_timer.h     | 13 +++++
> >  platform/linux-generic/odp_buffer.c                | 10 ++++
> >  platform/linux-generic/odp_event.c                 | 26 ++++++++++
> >  platform/linux-generic/odp_packet.c                | 10 ++++
> >  platform/linux-generic/odp_timer.c                 |  9 ++++
> >  11 files changed, 185 insertions(+), 6 deletions(-)
> >  create mode 100644 platform/linux-generic/include/api/odp_event.h
> >  create mode 100644 platform/linux-generic/odp_event.c
> >
> > diff --git a/platform/linux-generic/Makefile.am
> b/platform/linux-generic/Makefile.am
> > index a699ea6..712d75c 100644
> > --- a/platform/linux-generic/Makefile.am
> > +++ b/platform/linux-generic/Makefile.am
> > @@ -19,6 +19,7 @@ include_HEADERS = \
> >
>  $(top_srcdir)/platform/linux-generic/include/api/odp_cpumask.h \
> >
>  $(top_srcdir)/platform/linux-generic/include/api/odp_crypto.h \
> >
>  $(top_srcdir)/platform/linux-generic/include/api/odp_debug.h \
> > +
>  $(top_srcdir)/platform/linux-generic/include/api/odp_event.h \
> >
>  $(top_srcdir)/platform/linux-generic/include/api/odp_hints.h \
> >
>  $(top_srcdir)/platform/linux-generic/include/api/odp_init.h \
> >
>  $(top_srcdir)/platform/linux-generic/include/api/odp_packet_flags.h \
> > @@ -80,6 +81,7 @@ __LIB__libodp_la_SOURCES = \
> >                            odp_classification.c \
> >                            odp_cpumask.c \
> >                            odp_crypto.c \
> > +                          odp_event.c \
> >                            odp_init.c \
> >                            odp_impl.c \
> >                            odp_linux.c \
> > diff --git a/platform/linux-generic/include/api/odp.h
> b/platform/linux-generic/include/api/odp.h
> > index 1cc7ce0..49357b0 100644
> > --- a/platform/linux-generic/include/api/odp.h
> > +++ b/platform/linux-generic/include/api/odp.h
> > @@ -49,6 +49,7 @@ extern "C" {
> >  #include <odp_crypto.h>
> >  #include <odp_classification.h>
> >  #include <odp_rwlock.h>
> > +#include <odp_event.h>
> >
> >  #ifdef __cplusplus
> >  }
> > diff --git a/platform/linux-generic/include/api/odp_buffer.h
> b/platform/linux-generic/include/api/odp_buffer.h
> > index 0670464..20036f9 100644
> > --- a/platform/linux-generic/include/api/odp_buffer.h
> > +++ b/platform/linux-generic/include/api/odp_buffer.h
> > @@ -21,6 +21,7 @@ extern "C" {
> >
> >  #include <odp_std_types.h>
> >  #include <odp_platform_types.h>
> > +#include <odp_event.h>
> >
> >  /** @defgroup odp_buffer ODP BUFFER
> >   *  Operations on a buffer.
> > @@ -29,6 +30,28 @@ extern "C" {
> >
> >
> >  /**
> > + * Get buffer handle from event
> > + *
> > + * Converts an ODP_EVENT_BUFFER type event to a buffer.
> > + *
> > + * @param ev   Event handle
> > + *
> > + * @return Buffer handle
> > + *
> > + * @see odp_event_type()
> > + */
> > +odp_buffer_t odp_buffer_from_event(odp_event_t ev);
> > +
> > +/**
> > + * Convert buffer handle to event
> > + *
> > + * @param buf  Buffer handle
> > + *
> > + * @return Event handle
> > + */
> > +odp_event_t odp_buffer_to_event(odp_buffer_t buf);
> > +
> > +/**
> >   * Buffer start address
> >   *
> >   * @param buf      Buffer handle
> > @@ -55,12 +78,11 @@ uint32_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_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 */
> > +#define ODP_BUFFER_TYPE_INVALID   ODP_EVENT_TYPE_INVALID
> > +#define ODP_BUFFER_TYPE_ANY       0
> > +#define ODP_BUFFER_TYPE_RAW       ODP_EVENT_BUFFER
> > +#define ODP_BUFFER_TYPE_PACKET    ODP_EVENT_PACKET
> > +#define ODP_BUFFER_TYPE_TIMEOUT   ODP_EVENT_TIMEOUT
> >
> >  /**
> >   * Tests if buffer is valid
> > diff --git a/platform/linux-generic/include/api/odp_event.h
> b/platform/linux-generic/include/api/odp_event.h
> > new file mode 100644
> > index 0000000..209d968
> > --- /dev/null
> > +++ b/platform/linux-generic/include/api/odp_event.h
> > @@ -0,0 +1,59 @@
> > +/* Copyright (c) 2015, Linaro Limited
> > + * All rights reserved.
> > + *
> > + * SPDX-License-Identifier:     BSD-3-Clause
> > + */
> > +
> > +
> > +/**
> > + * @file
> > + *
> > + * ODP event
> > + */
> > +
> > +#ifndef ODP_EVENT_H_
> > +#define ODP_EVENT_H_
> > +
> > +#ifdef __cplusplus
> > +extern "C" {
> > +#endif
> > +
> > +
> > +#include <odp_std_types.h>
> > +#include <odp_platform_types.h>
> > +
> > +/** @defgroup odp_event ODP EVENT
> > + *  Operations on an event.
> > + *  @{
> > + */
> > +
> > +
> > +/**
> > + * Event type
> > + *
> > + * @param event    Event handle
> > + *
> > + * @return Event type or ODP_EVENT_TYPE_INVALID
> > + */
> > +int odp_event_type(odp_event_t event);
> > +
> > +/** Invalid event type */
> > +#define ODP_EVENT_TYPE_INVALID (-1)
> > +/** Buffer event */
> > +#define ODP_EVENT_BUFFER         1
> > +/** Packet event */
> > +#define ODP_EVENT_PACKET         2
> > +/** Timeout event */
> > +#define ODP_EVENT_TIMEOUT        3
>
> Value 0 stands is not used, it could cause problems. Why not transform
> these defines into enums and let ODP_EVENT_TYPE_INVALID be 0 ?
>
> > +
> > +
> > +
> > +/**
> > + * @}
> > + */
> > +
> > +#ifdef __cplusplus
> > +}
> > +#endif
> > +
> > +#endif
> > diff --git a/platform/linux-generic/include/api/odp_packet.h
> b/platform/linux-generic/include/api/odp_packet.h
> > index 920a593..92b6016 100644
> > --- a/platform/linux-generic/include/api/odp_packet.h
> > +++ b/platform/linux-generic/include/api/odp_packet.h
> > @@ -113,6 +113,27 @@ odp_packet_t odp_packet_from_buffer(odp_buffer_t
> buf);
> >   */
> >  odp_buffer_t odp_packet_to_buffer(odp_packet_t pkt);
> >
> > +/**
> > + * Get packet handle from event
> > + *
> > + * Converts an ODP_EVENT_PACKET type event to a packet.
> > + *
> > + * @param ev   Event handle
> > + *
> > + * @return Packet handle
> > + *
> > + * @see odp_event_type()
> > + */
> > +odp_packet_t odp_packet_from_event(odp_event_t ev);
> > +
> > +/**
> > + * Convert packet handle to event
> > + *
> > + * @param pkt  Packet handle
> > + *
> > + * @return Event handle
> > + */
> > +odp_event_t odp_packet_to_event(odp_packet_t pkt);
> >
> >  /*
> >   *
> > diff --git a/platform/linux-generic/include/api/odp_platform_types.h
> b/platform/linux-generic/include/api/odp_platform_types.h
> > index 6ed9e78..1d32e23 100644
> > --- a/platform/linux-generic/include/api/odp_platform_types.h
> > +++ b/platform/linux-generic/include/api/odp_platform_types.h
> > @@ -65,6 +65,12 @@ typedef uint32_t odp_pktio_t;
> >  /** odp_pktio_t value to indicate any port */
> >  #define ODP_PKTIO_ANY ((odp_pktio_t)~0)
> >
> > +/** ODP event */
> > +typedef odp_buffer_t odp_event_t;
> > +
> > +/** Invalid event */
> > +#define ODP_EVENT_INVALID ODP_BUFFER_INVALID
> > +
> >  /**
> >   * ODP shared memory block
> >   */
> > diff --git a/platform/linux-generic/include/api/odp_timer.h
> b/platform/linux-generic/include/api/odp_timer.h
> > index 69402ef..cb17b7b 100644
> > --- a/platform/linux-generic/include/api/odp_timer.h
> > +++ b/platform/linux-generic/include/api/odp_timer.h
> > @@ -21,6 +21,7 @@ extern "C" {
> >  #include <stdlib.h>
> >  #include <odp_std_types.h>
> >  #include <odp_buffer.h>
> > +#include <odp_event.h>
> >  #include <odp_queue.h>
> >
> >  /** @defgroup odp_timer ODP TIMER
> > @@ -310,6 +311,18 @@ int odp_timer_cancel(odp_timer_t tim, odp_buffer_t
> *tmo_buf);
> >  odp_timeout_t odp_timeout_from_buf(odp_buffer_t buf);
> >
> >  /**
> > + * Return timeout handle that is associated with timeout event
> > + *
> > + * Note: any invalid parameters will cause undefined behavior and may
> cause
> > + * the application to abort or crash.
> > + *
> > + * @param buf An event of type ODP_EVENT_TIMEOUT
> > + *
> > + * @return timeout handle
> > + */
> > +odp_timeout_t odp_timeout_from_event(odp_event_t ev);
> > +
> > +/**
> >   * Check for fresh timeout
> >   * If the corresponding timer has been reset or cancelled since this
> timeout
> >   * was enqueued, the timeout is stale (not fresh).
> > diff --git a/platform/linux-generic/odp_buffer.c
> b/platform/linux-generic/odp_buffer.c
> > index 57ba408..939332a 100644
> > --- a/platform/linux-generic/odp_buffer.c
> > +++ b/platform/linux-generic/odp_buffer.c
> > @@ -14,6 +14,16 @@
> >  #include <stdio.h>
> >
> >
> > +odp_buffer_t odp_buffer_from_event(odp_event_t ev)
> > +{
> > +       return (odp_buffer_t)ev;
> > +}
> > +
> > +odp_event_t odp_buffer_to_event(odp_buffer_t buf)
> > +{
> > +       return (odp_event_t)buf;
> > +}
> > +
> >  void *odp_buffer_addr(odp_buffer_t buf)
> >  {
> >         odp_buffer_hdr_t *hdr = odp_buf_to_hdr(buf);
> > diff --git a/platform/linux-generic/odp_event.c
> b/platform/linux-generic/odp_event.c
> > new file mode 100644
> > index 0000000..c646f42
> > --- /dev/null
> > +++ b/platform/linux-generic/odp_event.c
> > @@ -0,0 +1,26 @@
> > +/* Copyright (c) 2015, Linaro Limited
> > + * All rights reserved.
> > + *
> > + * SPDX-License-Identifier:     BSD-3-Clause
> > + */
> > +
> > +#include <odp_event.h>
> > +#include <odp_buffer.h>
> > +
> > +int odp_event_type(odp_event_t event)
> > +{
> > +       odp_buffer_t buf;
> > +
> > +       buf = odp_buffer_from_event(event);
> > +
> > +       switch (odp_buffer_type(buf)) {
> > +       case ODP_BUFFER_TYPE_RAW:
> > +               return ODP_EVENT_BUFFER;
> > +       case ODP_BUFFER_TYPE_PACKET:
> > +               return ODP_EVENT_PACKET;
> > +       case ODP_BUFFER_TYPE_TIMEOUT:
> > +               return ODP_EVENT_TIMEOUT;
> > +       default:
> > +               return ODP_EVENT_TYPE_INVALID;
> > +       }
> > +}
> > diff --git a/platform/linux-generic/odp_packet.c
> b/platform/linux-generic/odp_packet.c
> > index 257abec..ebe3b55 100644
> > --- a/platform/linux-generic/odp_packet.c
> > +++ b/platform/linux-generic/odp_packet.c
> > @@ -75,6 +75,16 @@ odp_buffer_t odp_packet_to_buffer(odp_packet_t pkt)
> >         return (odp_buffer_t)pkt;
> >  }
> >
> > +odp_packet_t odp_packet_from_event(odp_event_t ev)
> > +{
> > +       return (odp_packet_t)ev;
> > +}
> > +
> > +odp_event_t odp_packet_to_event(odp_packet_t pkt)
> > +{
> > +       return (odp_event_t)pkt;
> > +}
> > +
> >  /*
> >   *
> >   * Pointers and lengths
> > diff --git a/platform/linux-generic/odp_timer.c
> b/platform/linux-generic/odp_timer.c
> > index 3ba32a1..d926ada 100644
> > --- a/platform/linux-generic/odp_timer.c
> > +++ b/platform/linux-generic/odp_timer.c
> > @@ -39,6 +39,7 @@
> >  #include <odp_buffer_pool_internal.h>
> >  #include <odp_debug.h>
> >  #include <odp_debug_internal.h>
> > +#include <odp_event.h>
> >  #include <odp_hints.h>
> >  #include <odp_internal.h>
> >  #include <odp_queue.h>
> > @@ -802,6 +803,14 @@ odp_timeout_t odp_timeout_from_buf(odp_buffer_t buf)
> >         return (odp_timeout_t)timeout_hdr_from_buf(buf);
> >  }
> >
> > +odp_timeout_t odp_timeout_from_event(odp_event_t ev)
> > +{
> > +       /* This check not mandated by the API specification */
> > +       if (odp_event_type(ev) != ODP_EVENT_TIMEOUT)
> > +               ODP_ABORT("Event not a timeout");
> > +       return
> (odp_timeout_t)timeout_hdr_from_buf(odp_buffer_from_event(ev));
> > +}
> > +
> >  int odp_timeout_fresh(odp_timeout_t tmo)
> >  {
> >         const odp_timeout_hdr_t *hdr = (odp_timeout_hdr_t *)tmo;
> > --
> > 2.2.2
> >
> >
> > _______________________________________________
> > lng-odp mailing list
> > lng-odp@lists.linaro.org
> > http://lists.linaro.org/mailman/listinfo/lng-odp
>
> _______________________________________________
> lng-odp mailing list
> lng-odp@lists.linaro.org
> http://lists.linaro.org/mailman/listinfo/lng-odp
>
Ciprian Barbu Jan. 27, 2015, 12:21 p.m. UTC | #3
On Tue, Jan 27, 2015 at 2:14 PM, Bill Fischofer
<bill.fischofer@linaro.org> wrote:
> Values of ODP abstract types are implementation defined and hence arbitrary.
> Implementations are free to define them in whatever way is most efficient
> for them.

The question was not about efficiency, enums should be just as
efficient, I was trying to point out a possible problem. When an event
will be used in an application inside a structure it will most likely
be memset to 0, it makes more sense to have ODP_EVENT_TYPE_INVALID.

>
> On Tue, Jan 27, 2015 at 6:09 AM, Ciprian Barbu <ciprian.barbu@linaro.org>
> wrote:
>>
>> On Mon, Jan 26, 2015 at 3:05 PM, Petri Savolainen
>> <petri.savolainen@linaro.org> wrote:
>> > * Added odp_event.h and odp_event.c
>> > * Added odp_event_t type and type conversion functions
>> >
>> > Signed-off-by: Petri Savolainen <petri.savolainen@linaro.org>
>> > ---
>> >  platform/linux-generic/Makefile.am                 |  2 +
>> >  platform/linux-generic/include/api/odp.h           |  1 +
>> >  platform/linux-generic/include/api/odp_buffer.h    | 34 ++++++++++---
>> >  platform/linux-generic/include/api/odp_event.h     | 59
>> > ++++++++++++++++++++++
>> >  platform/linux-generic/include/api/odp_packet.h    | 21 ++++++++
>> >  .../linux-generic/include/api/odp_platform_types.h |  6 +++
>> >  platform/linux-generic/include/api/odp_timer.h     | 13 +++++
>> >  platform/linux-generic/odp_buffer.c                | 10 ++++
>> >  platform/linux-generic/odp_event.c                 | 26 ++++++++++
>> >  platform/linux-generic/odp_packet.c                | 10 ++++
>> >  platform/linux-generic/odp_timer.c                 |  9 ++++
>> >  11 files changed, 185 insertions(+), 6 deletions(-)
>> >  create mode 100644 platform/linux-generic/include/api/odp_event.h
>> >  create mode 100644 platform/linux-generic/odp_event.c
>> >
>> > diff --git a/platform/linux-generic/Makefile.am
>> > b/platform/linux-generic/Makefile.am
>> > index a699ea6..712d75c 100644
>> > --- a/platform/linux-generic/Makefile.am
>> > +++ b/platform/linux-generic/Makefile.am
>> > @@ -19,6 +19,7 @@ include_HEADERS = \
>> >
>> > $(top_srcdir)/platform/linux-generic/include/api/odp_cpumask.h \
>> >
>> > $(top_srcdir)/platform/linux-generic/include/api/odp_crypto.h \
>> >
>> > $(top_srcdir)/platform/linux-generic/include/api/odp_debug.h \
>> > +
>> > $(top_srcdir)/platform/linux-generic/include/api/odp_event.h \
>> >
>> > $(top_srcdir)/platform/linux-generic/include/api/odp_hints.h \
>> >
>> > $(top_srcdir)/platform/linux-generic/include/api/odp_init.h \
>> >
>> > $(top_srcdir)/platform/linux-generic/include/api/odp_packet_flags.h \
>> > @@ -80,6 +81,7 @@ __LIB__libodp_la_SOURCES = \
>> >                            odp_classification.c \
>> >                            odp_cpumask.c \
>> >                            odp_crypto.c \
>> > +                          odp_event.c \
>> >                            odp_init.c \
>> >                            odp_impl.c \
>> >                            odp_linux.c \
>> > diff --git a/platform/linux-generic/include/api/odp.h
>> > b/platform/linux-generic/include/api/odp.h
>> > index 1cc7ce0..49357b0 100644
>> > --- a/platform/linux-generic/include/api/odp.h
>> > +++ b/platform/linux-generic/include/api/odp.h
>> > @@ -49,6 +49,7 @@ extern "C" {
>> >  #include <odp_crypto.h>
>> >  #include <odp_classification.h>
>> >  #include <odp_rwlock.h>
>> > +#include <odp_event.h>
>> >
>> >  #ifdef __cplusplus
>> >  }
>> > diff --git a/platform/linux-generic/include/api/odp_buffer.h
>> > b/platform/linux-generic/include/api/odp_buffer.h
>> > index 0670464..20036f9 100644
>> > --- a/platform/linux-generic/include/api/odp_buffer.h
>> > +++ b/platform/linux-generic/include/api/odp_buffer.h
>> > @@ -21,6 +21,7 @@ extern "C" {
>> >
>> >  #include <odp_std_types.h>
>> >  #include <odp_platform_types.h>
>> > +#include <odp_event.h>
>> >
>> >  /** @defgroup odp_buffer ODP BUFFER
>> >   *  Operations on a buffer.
>> > @@ -29,6 +30,28 @@ extern "C" {
>> >
>> >
>> >  /**
>> > + * Get buffer handle from event
>> > + *
>> > + * Converts an ODP_EVENT_BUFFER type event to a buffer.
>> > + *
>> > + * @param ev   Event handle
>> > + *
>> > + * @return Buffer handle
>> > + *
>> > + * @see odp_event_type()
>> > + */
>> > +odp_buffer_t odp_buffer_from_event(odp_event_t ev);
>> > +
>> > +/**
>> > + * Convert buffer handle to event
>> > + *
>> > + * @param buf  Buffer handle
>> > + *
>> > + * @return Event handle
>> > + */
>> > +odp_event_t odp_buffer_to_event(odp_buffer_t buf);
>> > +
>> > +/**
>> >   * Buffer start address
>> >   *
>> >   * @param buf      Buffer handle
>> > @@ -55,12 +78,11 @@ uint32_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_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 */
>> > +#define ODP_BUFFER_TYPE_INVALID   ODP_EVENT_TYPE_INVALID
>> > +#define ODP_BUFFER_TYPE_ANY       0
>> > +#define ODP_BUFFER_TYPE_RAW       ODP_EVENT_BUFFER
>> > +#define ODP_BUFFER_TYPE_PACKET    ODP_EVENT_PACKET
>> > +#define ODP_BUFFER_TYPE_TIMEOUT   ODP_EVENT_TIMEOUT
>> >
>> >  /**
>> >   * Tests if buffer is valid
>> > diff --git a/platform/linux-generic/include/api/odp_event.h
>> > b/platform/linux-generic/include/api/odp_event.h
>> > new file mode 100644
>> > index 0000000..209d968
>> > --- /dev/null
>> > +++ b/platform/linux-generic/include/api/odp_event.h
>> > @@ -0,0 +1,59 @@
>> > +/* Copyright (c) 2015, Linaro Limited
>> > + * All rights reserved.
>> > + *
>> > + * SPDX-License-Identifier:     BSD-3-Clause
>> > + */
>> > +
>> > +
>> > +/**
>> > + * @file
>> > + *
>> > + * ODP event
>> > + */
>> > +
>> > +#ifndef ODP_EVENT_H_
>> > +#define ODP_EVENT_H_
>> > +
>> > +#ifdef __cplusplus
>> > +extern "C" {
>> > +#endif
>> > +
>> > +
>> > +#include <odp_std_types.h>
>> > +#include <odp_platform_types.h>
>> > +
>> > +/** @defgroup odp_event ODP EVENT
>> > + *  Operations on an event.
>> > + *  @{
>> > + */
>> > +
>> > +
>> > +/**
>> > + * Event type
>> > + *
>> > + * @param event    Event handle
>> > + *
>> > + * @return Event type or ODP_EVENT_TYPE_INVALID
>> > + */
>> > +int odp_event_type(odp_event_t event);
>> > +
>> > +/** Invalid event type */
>> > +#define ODP_EVENT_TYPE_INVALID (-1)
>> > +/** Buffer event */
>> > +#define ODP_EVENT_BUFFER         1
>> > +/** Packet event */
>> > +#define ODP_EVENT_PACKET         2
>> > +/** Timeout event */
>> > +#define ODP_EVENT_TIMEOUT        3
>>
>> Value 0 stands is not used, it could cause problems. Why not transform
>> these defines into enums and let ODP_EVENT_TYPE_INVALID be 0 ?
>>
>> > +
>> > +
>> > +
>> > +/**
>> > + * @}
>> > + */
>> > +
>> > +#ifdef __cplusplus
>> > +}
>> > +#endif
>> > +
>> > +#endif
>> > diff --git a/platform/linux-generic/include/api/odp_packet.h
>> > b/platform/linux-generic/include/api/odp_packet.h
>> > index 920a593..92b6016 100644
>> > --- a/platform/linux-generic/include/api/odp_packet.h
>> > +++ b/platform/linux-generic/include/api/odp_packet.h
>> > @@ -113,6 +113,27 @@ odp_packet_t odp_packet_from_buffer(odp_buffer_t
>> > buf);
>> >   */
>> >  odp_buffer_t odp_packet_to_buffer(odp_packet_t pkt);
>> >
>> > +/**
>> > + * Get packet handle from event
>> > + *
>> > + * Converts an ODP_EVENT_PACKET type event to a packet.
>> > + *
>> > + * @param ev   Event handle
>> > + *
>> > + * @return Packet handle
>> > + *
>> > + * @see odp_event_type()
>> > + */
>> > +odp_packet_t odp_packet_from_event(odp_event_t ev);
>> > +
>> > +/**
>> > + * Convert packet handle to event
>> > + *
>> > + * @param pkt  Packet handle
>> > + *
>> > + * @return Event handle
>> > + */
>> > +odp_event_t odp_packet_to_event(odp_packet_t pkt);
>> >
>> >  /*
>> >   *
>> > diff --git a/platform/linux-generic/include/api/odp_platform_types.h
>> > b/platform/linux-generic/include/api/odp_platform_types.h
>> > index 6ed9e78..1d32e23 100644
>> > --- a/platform/linux-generic/include/api/odp_platform_types.h
>> > +++ b/platform/linux-generic/include/api/odp_platform_types.h
>> > @@ -65,6 +65,12 @@ typedef uint32_t odp_pktio_t;
>> >  /** odp_pktio_t value to indicate any port */
>> >  #define ODP_PKTIO_ANY ((odp_pktio_t)~0)
>> >
>> > +/** ODP event */
>> > +typedef odp_buffer_t odp_event_t;
>> > +
>> > +/** Invalid event */
>> > +#define ODP_EVENT_INVALID ODP_BUFFER_INVALID
>> > +
>> >  /**
>> >   * ODP shared memory block
>> >   */
>> > diff --git a/platform/linux-generic/include/api/odp_timer.h
>> > b/platform/linux-generic/include/api/odp_timer.h
>> > index 69402ef..cb17b7b 100644
>> > --- a/platform/linux-generic/include/api/odp_timer.h
>> > +++ b/platform/linux-generic/include/api/odp_timer.h
>> > @@ -21,6 +21,7 @@ extern "C" {
>> >  #include <stdlib.h>
>> >  #include <odp_std_types.h>
>> >  #include <odp_buffer.h>
>> > +#include <odp_event.h>
>> >  #include <odp_queue.h>
>> >
>> >  /** @defgroup odp_timer ODP TIMER
>> > @@ -310,6 +311,18 @@ int odp_timer_cancel(odp_timer_t tim, odp_buffer_t
>> > *tmo_buf);
>> >  odp_timeout_t odp_timeout_from_buf(odp_buffer_t buf);
>> >
>> >  /**
>> > + * Return timeout handle that is associated with timeout event
>> > + *
>> > + * Note: any invalid parameters will cause undefined behavior and may
>> > cause
>> > + * the application to abort or crash.
>> > + *
>> > + * @param buf An event of type ODP_EVENT_TIMEOUT
>> > + *
>> > + * @return timeout handle
>> > + */
>> > +odp_timeout_t odp_timeout_from_event(odp_event_t ev);
>> > +
>> > +/**
>> >   * Check for fresh timeout
>> >   * If the corresponding timer has been reset or cancelled since this
>> > timeout
>> >   * was enqueued, the timeout is stale (not fresh).
>> > diff --git a/platform/linux-generic/odp_buffer.c
>> > b/platform/linux-generic/odp_buffer.c
>> > index 57ba408..939332a 100644
>> > --- a/platform/linux-generic/odp_buffer.c
>> > +++ b/platform/linux-generic/odp_buffer.c
>> > @@ -14,6 +14,16 @@
>> >  #include <stdio.h>
>> >
>> >
>> > +odp_buffer_t odp_buffer_from_event(odp_event_t ev)
>> > +{
>> > +       return (odp_buffer_t)ev;
>> > +}
>> > +
>> > +odp_event_t odp_buffer_to_event(odp_buffer_t buf)
>> > +{
>> > +       return (odp_event_t)buf;
>> > +}
>> > +
>> >  void *odp_buffer_addr(odp_buffer_t buf)
>> >  {
>> >         odp_buffer_hdr_t *hdr = odp_buf_to_hdr(buf);
>> > diff --git a/platform/linux-generic/odp_event.c
>> > b/platform/linux-generic/odp_event.c
>> > new file mode 100644
>> > index 0000000..c646f42
>> > --- /dev/null
>> > +++ b/platform/linux-generic/odp_event.c
>> > @@ -0,0 +1,26 @@
>> > +/* Copyright (c) 2015, Linaro Limited
>> > + * All rights reserved.
>> > + *
>> > + * SPDX-License-Identifier:     BSD-3-Clause
>> > + */
>> > +
>> > +#include <odp_event.h>
>> > +#include <odp_buffer.h>
>> > +
>> > +int odp_event_type(odp_event_t event)
>> > +{
>> > +       odp_buffer_t buf;
>> > +
>> > +       buf = odp_buffer_from_event(event);
>> > +
>> > +       switch (odp_buffer_type(buf)) {
>> > +       case ODP_BUFFER_TYPE_RAW:
>> > +               return ODP_EVENT_BUFFER;
>> > +       case ODP_BUFFER_TYPE_PACKET:
>> > +               return ODP_EVENT_PACKET;
>> > +       case ODP_BUFFER_TYPE_TIMEOUT:
>> > +               return ODP_EVENT_TIMEOUT;
>> > +       default:
>> > +               return ODP_EVENT_TYPE_INVALID;
>> > +       }
>> > +}
>> > diff --git a/platform/linux-generic/odp_packet.c
>> > b/platform/linux-generic/odp_packet.c
>> > index 257abec..ebe3b55 100644
>> > --- a/platform/linux-generic/odp_packet.c
>> > +++ b/platform/linux-generic/odp_packet.c
>> > @@ -75,6 +75,16 @@ odp_buffer_t odp_packet_to_buffer(odp_packet_t pkt)
>> >         return (odp_buffer_t)pkt;
>> >  }
>> >
>> > +odp_packet_t odp_packet_from_event(odp_event_t ev)
>> > +{
>> > +       return (odp_packet_t)ev;
>> > +}
>> > +
>> > +odp_event_t odp_packet_to_event(odp_packet_t pkt)
>> > +{
>> > +       return (odp_event_t)pkt;
>> > +}
>> > +
>> >  /*
>> >   *
>> >   * Pointers and lengths
>> > diff --git a/platform/linux-generic/odp_timer.c
>> > b/platform/linux-generic/odp_timer.c
>> > index 3ba32a1..d926ada 100644
>> > --- a/platform/linux-generic/odp_timer.c
>> > +++ b/platform/linux-generic/odp_timer.c
>> > @@ -39,6 +39,7 @@
>> >  #include <odp_buffer_pool_internal.h>
>> >  #include <odp_debug.h>
>> >  #include <odp_debug_internal.h>
>> > +#include <odp_event.h>
>> >  #include <odp_hints.h>
>> >  #include <odp_internal.h>
>> >  #include <odp_queue.h>
>> > @@ -802,6 +803,14 @@ odp_timeout_t odp_timeout_from_buf(odp_buffer_t
>> > buf)
>> >         return (odp_timeout_t)timeout_hdr_from_buf(buf);
>> >  }
>> >
>> > +odp_timeout_t odp_timeout_from_event(odp_event_t ev)
>> > +{
>> > +       /* This check not mandated by the API specification */
>> > +       if (odp_event_type(ev) != ODP_EVENT_TIMEOUT)
>> > +               ODP_ABORT("Event not a timeout");
>> > +       return
>> > (odp_timeout_t)timeout_hdr_from_buf(odp_buffer_from_event(ev));
>> > +}
>> > +
>> >  int odp_timeout_fresh(odp_timeout_t tmo)
>> >  {
>> >         const odp_timeout_hdr_t *hdr = (odp_timeout_hdr_t *)tmo;
>> > --
>> > 2.2.2
>> >
>> >
>> > _______________________________________________
>> > lng-odp mailing list
>> > lng-odp@lists.linaro.org
>> > http://lists.linaro.org/mailman/listinfo/lng-odp
>>
>> _______________________________________________
>> lng-odp mailing list
>> lng-odp@lists.linaro.org
>> http://lists.linaro.org/mailman/listinfo/lng-odp
>
>
Ola Liljedahl Jan. 27, 2015, 12:52 p.m. UTC | #4
On 27 January 2015 at 13:09, Ciprian Barbu <ciprian.barbu@linaro.org> wrote:
> On Mon, Jan 26, 2015 at 3:05 PM, Petri Savolainen
> <petri.savolainen@linaro.org> wrote:
>> * Added odp_event.h and odp_event.c
>> * Added odp_event_t type and type conversion functions
>>
>> Signed-off-by: Petri Savolainen <petri.savolainen@linaro.org>
>> ---
>>  platform/linux-generic/Makefile.am                 |  2 +
>>  platform/linux-generic/include/api/odp.h           |  1 +
>>  platform/linux-generic/include/api/odp_buffer.h    | 34 ++++++++++---
>>  platform/linux-generic/include/api/odp_event.h     | 59 ++++++++++++++++++++++
>>  platform/linux-generic/include/api/odp_packet.h    | 21 ++++++++
>>  .../linux-generic/include/api/odp_platform_types.h |  6 +++
>>  platform/linux-generic/include/api/odp_timer.h     | 13 +++++
>>  platform/linux-generic/odp_buffer.c                | 10 ++++
>>  platform/linux-generic/odp_event.c                 | 26 ++++++++++
>>  platform/linux-generic/odp_packet.c                | 10 ++++
>>  platform/linux-generic/odp_timer.c                 |  9 ++++
>>  11 files changed, 185 insertions(+), 6 deletions(-)
>>  create mode 100644 platform/linux-generic/include/api/odp_event.h
>>  create mode 100644 platform/linux-generic/odp_event.c
>>
>> diff --git a/platform/linux-generic/Makefile.am b/platform/linux-generic/Makefile.am
>> index a699ea6..712d75c 100644
>> --- a/platform/linux-generic/Makefile.am
>> +++ b/platform/linux-generic/Makefile.am
>> @@ -19,6 +19,7 @@ include_HEADERS = \
>>                   $(top_srcdir)/platform/linux-generic/include/api/odp_cpumask.h \
>>                   $(top_srcdir)/platform/linux-generic/include/api/odp_crypto.h \
>>                   $(top_srcdir)/platform/linux-generic/include/api/odp_debug.h \
>> +                 $(top_srcdir)/platform/linux-generic/include/api/odp_event.h \
>>                   $(top_srcdir)/platform/linux-generic/include/api/odp_hints.h \
>>                   $(top_srcdir)/platform/linux-generic/include/api/odp_init.h \
>>                   $(top_srcdir)/platform/linux-generic/include/api/odp_packet_flags.h \
>> @@ -80,6 +81,7 @@ __LIB__libodp_la_SOURCES = \
>>                            odp_classification.c \
>>                            odp_cpumask.c \
>>                            odp_crypto.c \
>> +                          odp_event.c \
>>                            odp_init.c \
>>                            odp_impl.c \
>>                            odp_linux.c \
>> diff --git a/platform/linux-generic/include/api/odp.h b/platform/linux-generic/include/api/odp.h
>> index 1cc7ce0..49357b0 100644
>> --- a/platform/linux-generic/include/api/odp.h
>> +++ b/platform/linux-generic/include/api/odp.h
>> @@ -49,6 +49,7 @@ extern "C" {
>>  #include <odp_crypto.h>
>>  #include <odp_classification.h>
>>  #include <odp_rwlock.h>
>> +#include <odp_event.h>
>>
>>  #ifdef __cplusplus
>>  }
>> diff --git a/platform/linux-generic/include/api/odp_buffer.h b/platform/linux-generic/include/api/odp_buffer.h
>> index 0670464..20036f9 100644
>> --- a/platform/linux-generic/include/api/odp_buffer.h
>> +++ b/platform/linux-generic/include/api/odp_buffer.h
>> @@ -21,6 +21,7 @@ extern "C" {
>>
>>  #include <odp_std_types.h>
>>  #include <odp_platform_types.h>
>> +#include <odp_event.h>
>>
>>  /** @defgroup odp_buffer ODP BUFFER
>>   *  Operations on a buffer.
>> @@ -29,6 +30,28 @@ extern "C" {
>>
>>
>>  /**
>> + * Get buffer handle from event
>> + *
>> + * Converts an ODP_EVENT_BUFFER type event to a buffer.
>> + *
>> + * @param ev   Event handle
>> + *
>> + * @return Buffer handle
>> + *
>> + * @see odp_event_type()
>> + */
>> +odp_buffer_t odp_buffer_from_event(odp_event_t ev);
>> +
>> +/**
>> + * Convert buffer handle to event
>> + *
>> + * @param buf  Buffer handle
>> + *
>> + * @return Event handle
>> + */
>> +odp_event_t odp_buffer_to_event(odp_buffer_t buf);
>> +
>> +/**
>>   * Buffer start address
>>   *
>>   * @param buf      Buffer handle
>> @@ -55,12 +78,11 @@ uint32_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_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 */
>> +#define ODP_BUFFER_TYPE_INVALID   ODP_EVENT_TYPE_INVALID
>> +#define ODP_BUFFER_TYPE_ANY       0
>> +#define ODP_BUFFER_TYPE_RAW       ODP_EVENT_BUFFER
>> +#define ODP_BUFFER_TYPE_PACKET    ODP_EVENT_PACKET
>> +#define ODP_BUFFER_TYPE_TIMEOUT   ODP_EVENT_TIMEOUT
>>
>>  /**
>>   * Tests if buffer is valid
>> diff --git a/platform/linux-generic/include/api/odp_event.h b/platform/linux-generic/include/api/odp_event.h
>> new file mode 100644
>> index 0000000..209d968
>> --- /dev/null
>> +++ b/platform/linux-generic/include/api/odp_event.h
>> @@ -0,0 +1,59 @@
>> +/* Copyright (c) 2015, Linaro Limited
>> + * All rights reserved.
>> + *
>> + * SPDX-License-Identifier:     BSD-3-Clause
>> + */
>> +
>> +
>> +/**
>> + * @file
>> + *
>> + * ODP event
>> + */
>> +
>> +#ifndef ODP_EVENT_H_
>> +#define ODP_EVENT_H_
>> +
>> +#ifdef __cplusplus
>> +extern "C" {
>> +#endif
>> +
>> +
>> +#include <odp_std_types.h>
>> +#include <odp_platform_types.h>
>> +
>> +/** @defgroup odp_event ODP EVENT
>> + *  Operations on an event.
>> + *  @{
>> + */
>> +
>> +
>> +/**
>> + * Event type
>> + *
>> + * @param event    Event handle
>> + *
>> + * @return Event type or ODP_EVENT_TYPE_INVALID
>> + */
>> +int odp_event_type(odp_event_t event);
>> +
>> +/** Invalid event type */
>> +#define ODP_EVENT_TYPE_INVALID (-1)
>> +/** Buffer event */
>> +#define ODP_EVENT_BUFFER         1
>> +/** Packet event */
>> +#define ODP_EVENT_PACKET         2
>> +/** Timeout event */
>> +#define ODP_EVENT_TIMEOUT        3
>
> Value 0 stands is not used, it could cause problems.
I also prefer enumerations to start from 0 but why could this cause problems?
Are the actual values used for the event types part of the specified
API or could that change with implementations?
Using small integers is inviting the application to use it as an index
into an array which would not work if some implementation started to
use a different range of values. So I think we in practice have set
the values in stone here.

> Why not transform
> these defines into enums and let ODP_EVENT_TYPE_INVALID be 0 ?
There is no use AFAIK of ODP_EVENT_TYPE_INVALID. You cannot specify
this when creating an event pool and you cannot get this value back
when interrogating the type of an existing pool or event. Passing an
invalid pool handle to e.g. odp_pool_info() should return an error
code (e.g. -1) and passing an invalid event handle to odp_event_type()
is invoking undefined behavior (because checking the handle for
validity in this performance critical function is not a good idea).


>
>> +
>> +
>> +
>> +/**
>> + * @}
>> + */
>> +
>> +#ifdef __cplusplus
>> +}
>> +#endif
>> +
>> +#endif
>> diff --git a/platform/linux-generic/include/api/odp_packet.h b/platform/linux-generic/include/api/odp_packet.h
>> index 920a593..92b6016 100644
>> --- a/platform/linux-generic/include/api/odp_packet.h
>> +++ b/platform/linux-generic/include/api/odp_packet.h
>> @@ -113,6 +113,27 @@ odp_packet_t odp_packet_from_buffer(odp_buffer_t buf);
>>   */
>>  odp_buffer_t odp_packet_to_buffer(odp_packet_t pkt);
>>
>> +/**
>> + * Get packet handle from event
>> + *
>> + * Converts an ODP_EVENT_PACKET type event to a packet.
>> + *
>> + * @param ev   Event handle
>> + *
>> + * @return Packet handle
>> + *
>> + * @see odp_event_type()
>> + */
>> +odp_packet_t odp_packet_from_event(odp_event_t ev);
>> +
>> +/**
>> + * Convert packet handle to event
>> + *
>> + * @param pkt  Packet handle
>> + *
>> + * @return Event handle
>> + */
>> +odp_event_t odp_packet_to_event(odp_packet_t pkt);
>>
>>  /*
>>   *
>> diff --git a/platform/linux-generic/include/api/odp_platform_types.h b/platform/linux-generic/include/api/odp_platform_types.h
>> index 6ed9e78..1d32e23 100644
>> --- a/platform/linux-generic/include/api/odp_platform_types.h
>> +++ b/platform/linux-generic/include/api/odp_platform_types.h
>> @@ -65,6 +65,12 @@ typedef uint32_t odp_pktio_t;
>>  /** odp_pktio_t value to indicate any port */
>>  #define ODP_PKTIO_ANY ((odp_pktio_t)~0)
>>
>> +/** ODP event */
>> +typedef odp_buffer_t odp_event_t;
>> +
>> +/** Invalid event */
>> +#define ODP_EVENT_INVALID ODP_BUFFER_INVALID
>> +
>>  /**
>>   * ODP shared memory block
>>   */
>> diff --git a/platform/linux-generic/include/api/odp_timer.h b/platform/linux-generic/include/api/odp_timer.h
>> index 69402ef..cb17b7b 100644
>> --- a/platform/linux-generic/include/api/odp_timer.h
>> +++ b/platform/linux-generic/include/api/odp_timer.h
>> @@ -21,6 +21,7 @@ extern "C" {
>>  #include <stdlib.h>
>>  #include <odp_std_types.h>
>>  #include <odp_buffer.h>
>> +#include <odp_event.h>
>>  #include <odp_queue.h>
>>
>>  /** @defgroup odp_timer ODP TIMER
>> @@ -310,6 +311,18 @@ int odp_timer_cancel(odp_timer_t tim, odp_buffer_t *tmo_buf);
>>  odp_timeout_t odp_timeout_from_buf(odp_buffer_t buf);
>>
>>  /**
>> + * Return timeout handle that is associated with timeout event
>> + *
>> + * Note: any invalid parameters will cause undefined behavior and may cause
>> + * the application to abort or crash.
>> + *
>> + * @param buf An event of type ODP_EVENT_TIMEOUT
>> + *
>> + * @return timeout handle
>> + */
>> +odp_timeout_t odp_timeout_from_event(odp_event_t ev);
>> +
>> +/**
>>   * Check for fresh timeout
>>   * If the corresponding timer has been reset or cancelled since this timeout
>>   * was enqueued, the timeout is stale (not fresh).
>> diff --git a/platform/linux-generic/odp_buffer.c b/platform/linux-generic/odp_buffer.c
>> index 57ba408..939332a 100644
>> --- a/platform/linux-generic/odp_buffer.c
>> +++ b/platform/linux-generic/odp_buffer.c
>> @@ -14,6 +14,16 @@
>>  #include <stdio.h>
>>
>>
>> +odp_buffer_t odp_buffer_from_event(odp_event_t ev)
>> +{
>> +       return (odp_buffer_t)ev;
>> +}
>> +
>> +odp_event_t odp_buffer_to_event(odp_buffer_t buf)
>> +{
>> +       return (odp_event_t)buf;
>> +}
>> +
>>  void *odp_buffer_addr(odp_buffer_t buf)
>>  {
>>         odp_buffer_hdr_t *hdr = odp_buf_to_hdr(buf);
>> diff --git a/platform/linux-generic/odp_event.c b/platform/linux-generic/odp_event.c
>> new file mode 100644
>> index 0000000..c646f42
>> --- /dev/null
>> +++ b/platform/linux-generic/odp_event.c
>> @@ -0,0 +1,26 @@
>> +/* Copyright (c) 2015, Linaro Limited
>> + * All rights reserved.
>> + *
>> + * SPDX-License-Identifier:     BSD-3-Clause
>> + */
>> +
>> +#include <odp_event.h>
>> +#include <odp_buffer.h>
>> +
>> +int odp_event_type(odp_event_t event)
>> +{
>> +       odp_buffer_t buf;
>> +
>> +       buf = odp_buffer_from_event(event);
>> +
>> +       switch (odp_buffer_type(buf)) {
>> +       case ODP_BUFFER_TYPE_RAW:
>> +               return ODP_EVENT_BUFFER;
>> +       case ODP_BUFFER_TYPE_PACKET:
>> +               return ODP_EVENT_PACKET;
>> +       case ODP_BUFFER_TYPE_TIMEOUT:
>> +               return ODP_EVENT_TIMEOUT;
>> +       default:
>> +               return ODP_EVENT_TYPE_INVALID;
>> +       }
>> +}
>> diff --git a/platform/linux-generic/odp_packet.c b/platform/linux-generic/odp_packet.c
>> index 257abec..ebe3b55 100644
>> --- a/platform/linux-generic/odp_packet.c
>> +++ b/platform/linux-generic/odp_packet.c
>> @@ -75,6 +75,16 @@ odp_buffer_t odp_packet_to_buffer(odp_packet_t pkt)
>>         return (odp_buffer_t)pkt;
>>  }
>>
>> +odp_packet_t odp_packet_from_event(odp_event_t ev)
>> +{
>> +       return (odp_packet_t)ev;
>> +}
>> +
>> +odp_event_t odp_packet_to_event(odp_packet_t pkt)
>> +{
>> +       return (odp_event_t)pkt;
>> +}
>> +
>>  /*
>>   *
>>   * Pointers and lengths
>> diff --git a/platform/linux-generic/odp_timer.c b/platform/linux-generic/odp_timer.c
>> index 3ba32a1..d926ada 100644
>> --- a/platform/linux-generic/odp_timer.c
>> +++ b/platform/linux-generic/odp_timer.c
>> @@ -39,6 +39,7 @@
>>  #include <odp_buffer_pool_internal.h>
>>  #include <odp_debug.h>
>>  #include <odp_debug_internal.h>
>> +#include <odp_event.h>
>>  #include <odp_hints.h>
>>  #include <odp_internal.h>
>>  #include <odp_queue.h>
>> @@ -802,6 +803,14 @@ odp_timeout_t odp_timeout_from_buf(odp_buffer_t buf)
>>         return (odp_timeout_t)timeout_hdr_from_buf(buf);
>>  }
>>
>> +odp_timeout_t odp_timeout_from_event(odp_event_t ev)
>> +{
>> +       /* This check not mandated by the API specification */
>> +       if (odp_event_type(ev) != ODP_EVENT_TIMEOUT)
>> +               ODP_ABORT("Event not a timeout");
>> +       return (odp_timeout_t)timeout_hdr_from_buf(odp_buffer_from_event(ev));
>> +}
>> +
>>  int odp_timeout_fresh(odp_timeout_t tmo)
>>  {
>>         const odp_timeout_hdr_t *hdr = (odp_timeout_hdr_t *)tmo;
>> --
>> 2.2.2
>>
>>
>> _______________________________________________
>> lng-odp mailing list
>> lng-odp@lists.linaro.org
>> http://lists.linaro.org/mailman/listinfo/lng-odp
>
> _______________________________________________
> lng-odp mailing list
> lng-odp@lists.linaro.org
> http://lists.linaro.org/mailman/listinfo/lng-odp
diff mbox

Patch

diff --git a/platform/linux-generic/Makefile.am b/platform/linux-generic/Makefile.am
index a699ea6..712d75c 100644
--- a/platform/linux-generic/Makefile.am
+++ b/platform/linux-generic/Makefile.am
@@ -19,6 +19,7 @@  include_HEADERS = \
 		  $(top_srcdir)/platform/linux-generic/include/api/odp_cpumask.h \
 		  $(top_srcdir)/platform/linux-generic/include/api/odp_crypto.h \
 		  $(top_srcdir)/platform/linux-generic/include/api/odp_debug.h \
+		  $(top_srcdir)/platform/linux-generic/include/api/odp_event.h \
 		  $(top_srcdir)/platform/linux-generic/include/api/odp_hints.h \
 		  $(top_srcdir)/platform/linux-generic/include/api/odp_init.h \
 		  $(top_srcdir)/platform/linux-generic/include/api/odp_packet_flags.h \
@@ -80,6 +81,7 @@  __LIB__libodp_la_SOURCES = \
 			   odp_classification.c \
 			   odp_cpumask.c \
 			   odp_crypto.c \
+			   odp_event.c \
 			   odp_init.c \
 			   odp_impl.c \
 			   odp_linux.c \
diff --git a/platform/linux-generic/include/api/odp.h b/platform/linux-generic/include/api/odp.h
index 1cc7ce0..49357b0 100644
--- a/platform/linux-generic/include/api/odp.h
+++ b/platform/linux-generic/include/api/odp.h
@@ -49,6 +49,7 @@  extern "C" {
 #include <odp_crypto.h>
 #include <odp_classification.h>
 #include <odp_rwlock.h>
+#include <odp_event.h>
 
 #ifdef __cplusplus
 }
diff --git a/platform/linux-generic/include/api/odp_buffer.h b/platform/linux-generic/include/api/odp_buffer.h
index 0670464..20036f9 100644
--- a/platform/linux-generic/include/api/odp_buffer.h
+++ b/platform/linux-generic/include/api/odp_buffer.h
@@ -21,6 +21,7 @@  extern "C" {
 
 #include <odp_std_types.h>
 #include <odp_platform_types.h>
+#include <odp_event.h>
 
 /** @defgroup odp_buffer ODP BUFFER
  *  Operations on a buffer.
@@ -29,6 +30,28 @@  extern "C" {
 
 
 /**
+ * Get buffer handle from event
+ *
+ * Converts an ODP_EVENT_BUFFER type event to a buffer.
+ *
+ * @param ev   Event handle
+ *
+ * @return Buffer handle
+ *
+ * @see odp_event_type()
+ */
+odp_buffer_t odp_buffer_from_event(odp_event_t ev);
+
+/**
+ * Convert buffer handle to event
+ *
+ * @param buf  Buffer handle
+ *
+ * @return Event handle
+ */
+odp_event_t odp_buffer_to_event(odp_buffer_t buf);
+
+/**
  * Buffer start address
  *
  * @param buf      Buffer handle
@@ -55,12 +78,11 @@  uint32_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_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 */
+#define ODP_BUFFER_TYPE_INVALID   ODP_EVENT_TYPE_INVALID
+#define ODP_BUFFER_TYPE_ANY       0
+#define ODP_BUFFER_TYPE_RAW       ODP_EVENT_BUFFER
+#define ODP_BUFFER_TYPE_PACKET    ODP_EVENT_PACKET
+#define ODP_BUFFER_TYPE_TIMEOUT   ODP_EVENT_TIMEOUT
 
 /**
  * Tests if buffer is valid
diff --git a/platform/linux-generic/include/api/odp_event.h b/platform/linux-generic/include/api/odp_event.h
new file mode 100644
index 0000000..209d968
--- /dev/null
+++ b/platform/linux-generic/include/api/odp_event.h
@@ -0,0 +1,59 @@ 
+/* Copyright (c) 2015, Linaro Limited
+ * All rights reserved.
+ *
+ * SPDX-License-Identifier:     BSD-3-Clause
+ */
+
+
+/**
+ * @file
+ *
+ * ODP event
+ */
+
+#ifndef ODP_EVENT_H_
+#define ODP_EVENT_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+#include <odp_std_types.h>
+#include <odp_platform_types.h>
+
+/** @defgroup odp_event ODP EVENT
+ *  Operations on an event.
+ *  @{
+ */
+
+
+/**
+ * Event type
+ *
+ * @param event    Event handle
+ *
+ * @return Event type or ODP_EVENT_TYPE_INVALID
+ */
+int odp_event_type(odp_event_t event);
+
+/** Invalid event type */
+#define ODP_EVENT_TYPE_INVALID (-1)
+/** Buffer event */
+#define ODP_EVENT_BUFFER         1
+/** Packet event */
+#define ODP_EVENT_PACKET         2
+/** Timeout event */
+#define ODP_EVENT_TIMEOUT        3
+
+
+
+/**
+ * @}
+ */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/platform/linux-generic/include/api/odp_packet.h b/platform/linux-generic/include/api/odp_packet.h
index 920a593..92b6016 100644
--- a/platform/linux-generic/include/api/odp_packet.h
+++ b/platform/linux-generic/include/api/odp_packet.h
@@ -113,6 +113,27 @@  odp_packet_t odp_packet_from_buffer(odp_buffer_t buf);
  */
 odp_buffer_t odp_packet_to_buffer(odp_packet_t pkt);
 
+/**
+ * Get packet handle from event
+ *
+ * Converts an ODP_EVENT_PACKET type event to a packet.
+ *
+ * @param ev   Event handle
+ *
+ * @return Packet handle
+ *
+ * @see odp_event_type()
+ */
+odp_packet_t odp_packet_from_event(odp_event_t ev);
+
+/**
+ * Convert packet handle to event
+ *
+ * @param pkt  Packet handle
+ *
+ * @return Event handle
+ */
+odp_event_t odp_packet_to_event(odp_packet_t pkt);
 
 /*
  *
diff --git a/platform/linux-generic/include/api/odp_platform_types.h b/platform/linux-generic/include/api/odp_platform_types.h
index 6ed9e78..1d32e23 100644
--- a/platform/linux-generic/include/api/odp_platform_types.h
+++ b/platform/linux-generic/include/api/odp_platform_types.h
@@ -65,6 +65,12 @@  typedef uint32_t odp_pktio_t;
 /** odp_pktio_t value to indicate any port */
 #define ODP_PKTIO_ANY ((odp_pktio_t)~0)
 
+/** ODP event */
+typedef odp_buffer_t odp_event_t;
+
+/** Invalid event */
+#define ODP_EVENT_INVALID ODP_BUFFER_INVALID
+
 /**
  * ODP shared memory block
  */
diff --git a/platform/linux-generic/include/api/odp_timer.h b/platform/linux-generic/include/api/odp_timer.h
index 69402ef..cb17b7b 100644
--- a/platform/linux-generic/include/api/odp_timer.h
+++ b/platform/linux-generic/include/api/odp_timer.h
@@ -21,6 +21,7 @@  extern "C" {
 #include <stdlib.h>
 #include <odp_std_types.h>
 #include <odp_buffer.h>
+#include <odp_event.h>
 #include <odp_queue.h>
 
 /** @defgroup odp_timer ODP TIMER
@@ -310,6 +311,18 @@  int odp_timer_cancel(odp_timer_t tim, odp_buffer_t *tmo_buf);
 odp_timeout_t odp_timeout_from_buf(odp_buffer_t buf);
 
 /**
+ * Return timeout handle that is associated with timeout event
+ *
+ * Note: any invalid parameters will cause undefined behavior and may cause
+ * the application to abort or crash.
+ *
+ * @param buf An event of type ODP_EVENT_TIMEOUT
+ *
+ * @return timeout handle
+ */
+odp_timeout_t odp_timeout_from_event(odp_event_t ev);
+
+/**
  * Check for fresh timeout
  * If the corresponding timer has been reset or cancelled since this timeout
  * was enqueued, the timeout is stale (not fresh).
diff --git a/platform/linux-generic/odp_buffer.c b/platform/linux-generic/odp_buffer.c
index 57ba408..939332a 100644
--- a/platform/linux-generic/odp_buffer.c
+++ b/platform/linux-generic/odp_buffer.c
@@ -14,6 +14,16 @@ 
 #include <stdio.h>
 
 
+odp_buffer_t odp_buffer_from_event(odp_event_t ev)
+{
+	return (odp_buffer_t)ev;
+}
+
+odp_event_t odp_buffer_to_event(odp_buffer_t buf)
+{
+	return (odp_event_t)buf;
+}
+
 void *odp_buffer_addr(odp_buffer_t buf)
 {
 	odp_buffer_hdr_t *hdr = odp_buf_to_hdr(buf);
diff --git a/platform/linux-generic/odp_event.c b/platform/linux-generic/odp_event.c
new file mode 100644
index 0000000..c646f42
--- /dev/null
+++ b/platform/linux-generic/odp_event.c
@@ -0,0 +1,26 @@ 
+/* Copyright (c) 2015, Linaro Limited
+ * All rights reserved.
+ *
+ * SPDX-License-Identifier:     BSD-3-Clause
+ */
+
+#include <odp_event.h>
+#include <odp_buffer.h>
+
+int odp_event_type(odp_event_t event)
+{
+	odp_buffer_t buf;
+
+	buf = odp_buffer_from_event(event);
+
+	switch (odp_buffer_type(buf)) {
+	case ODP_BUFFER_TYPE_RAW:
+		return ODP_EVENT_BUFFER;
+	case ODP_BUFFER_TYPE_PACKET:
+		return ODP_EVENT_PACKET;
+	case ODP_BUFFER_TYPE_TIMEOUT:
+		return ODP_EVENT_TIMEOUT;
+	default:
+		return ODP_EVENT_TYPE_INVALID;
+	}
+}
diff --git a/platform/linux-generic/odp_packet.c b/platform/linux-generic/odp_packet.c
index 257abec..ebe3b55 100644
--- a/platform/linux-generic/odp_packet.c
+++ b/platform/linux-generic/odp_packet.c
@@ -75,6 +75,16 @@  odp_buffer_t odp_packet_to_buffer(odp_packet_t pkt)
 	return (odp_buffer_t)pkt;
 }
 
+odp_packet_t odp_packet_from_event(odp_event_t ev)
+{
+	return (odp_packet_t)ev;
+}
+
+odp_event_t odp_packet_to_event(odp_packet_t pkt)
+{
+	return (odp_event_t)pkt;
+}
+
 /*
  *
  * Pointers and lengths
diff --git a/platform/linux-generic/odp_timer.c b/platform/linux-generic/odp_timer.c
index 3ba32a1..d926ada 100644
--- a/platform/linux-generic/odp_timer.c
+++ b/platform/linux-generic/odp_timer.c
@@ -39,6 +39,7 @@ 
 #include <odp_buffer_pool_internal.h>
 #include <odp_debug.h>
 #include <odp_debug_internal.h>
+#include <odp_event.h>
 #include <odp_hints.h>
 #include <odp_internal.h>
 #include <odp_queue.h>
@@ -802,6 +803,14 @@  odp_timeout_t odp_timeout_from_buf(odp_buffer_t buf)
 	return (odp_timeout_t)timeout_hdr_from_buf(buf);
 }
 
+odp_timeout_t odp_timeout_from_event(odp_event_t ev)
+{
+	/* This check not mandated by the API specification */
+	if (odp_event_type(ev) != ODP_EVENT_TIMEOUT)
+		ODP_ABORT("Event not a timeout");
+	return (odp_timeout_t)timeout_hdr_from_buf(odp_buffer_from_event(ev));
+}
+
 int odp_timeout_fresh(odp_timeout_t tmo)
 {
 	const odp_timeout_hdr_t *hdr = (odp_timeout_hdr_t *)tmo;