On Wed, Oct 19, 2016 at 7:09 AM, Petri Savolainen <
petri.savolai...@nokia.com> wrote:

> Removed odp_pool_to_entry(), which was a duplicate of
> pool_entry_from_hdl(). Renamed odp_buf_to_hdr() to
> buf_hdl_to_hdr(), which describes more accurately the internal
> function. Inlined pool_entry(), pool_entry_from_hdl() and
> buf_hdl_to_hdr(), which are used often and also outside of
> pool.c. Renamed odp_buffer_pool_headroom() and _tailroom() to
> simply pool_headroom() and _tailroom(), since those are internal
> functions (not API as previous names hint). Also moved those
> into pool.c, since inlining is not needed for functions that are
> called only in (netmap) init phase.
>
> Signed-off-by: Petri Savolainen <petri.savolai...@nokia.com>
> ---
>  .../linux-generic/include/odp_buffer_inlines.h     |  2 -
>  .../linux-generic/include/odp_packet_internal.h    |  2 +-
>  platform/linux-generic/include/odp_pool_internal.h | 35 +++++++++++---
>  platform/linux-generic/odp_buffer.c                |  6 +--
>  platform/linux-generic/odp_packet.c                |  8 ++--
>  platform/linux-generic/odp_packet_io.c             |  2 +-
>  platform/linux-generic/odp_pool.c                  | 53
> ++++++----------------
>  platform/linux-generic/odp_queue.c                 |  4 +-
>  platform/linux-generic/odp_schedule_ordered.c      |  4 +-
>  platform/linux-generic/odp_timer.c                 |  2 +-
>  platform/linux-generic/pktio/loop.c                |  2 +-
>  platform/linux-generic/pktio/netmap.c              |  4 +-
>  platform/linux-generic/pktio/socket_mmap.c         |  2 +-
>  13 files changed, 61 insertions(+), 65 deletions(-)
>
> diff --git a/platform/linux-generic/include/odp_buffer_inlines.h
> b/platform/linux-generic/include/odp_buffer_inlines.h
> index 2f5eb88..f8688f6 100644
> --- a/platform/linux-generic/include/odp_buffer_inlines.h
> +++ b/platform/linux-generic/include/odp_buffer_inlines.h
> @@ -31,8 +31,6 @@ static inline odp_buffer_t odp_hdr_to_buf(odp_buffer_hdr_t
> *hdr)
>         return hdr->handle.handle;
>  }
>
> -odp_buffer_hdr_t *odp_buf_to_hdr(odp_buffer_t buf);
> -
>  static inline uint32_t pool_id_from_buf(odp_buffer_t buf)
>  {
>         odp_buffer_bits_t handle;
> diff --git a/platform/linux-generic/include/odp_packet_internal.h
> b/platform/linux-generic/include/odp_packet_internal.h
> index 8ad664b..48f9b26 100644
> --- a/platform/linux-generic/include/odp_packet_internal.h
> +++ b/platform/linux-generic/include/odp_packet_internal.h
> @@ -184,7 +184,7 @@ typedef struct {
>   */
>  static inline odp_packet_hdr_t *odp_packet_hdr(odp_packet_t pkt)
>  {
> -       return (odp_packet_hdr_t *)odp_buf_to_hdr((odp_buffer_t)pkt);
> +       return (odp_packet_hdr_t *)buf_hdl_to_hdr((odp_buffer_t)pkt);
>  }
>
>  static inline void copy_packet_parser_metadata(odp_packet_hdr_t *src_hdr,
> diff --git a/platform/linux-generic/include/odp_pool_internal.h
> b/platform/linux-generic/include/odp_pool_internal.h
> index 278c553..c9bf71b 100644
> --- a/platform/linux-generic/include/odp_pool_internal.h
> +++ b/platform/linux-generic/include/odp_pool_internal.h
> @@ -73,23 +73,44 @@ typedef struct pool_t {
>
>  } pool_t;
>
> -pool_t *pool_entry(uint32_t pool_idx);
> +typedef struct pool_table_t {
> +       pool_t    pool[ODP_CONFIG_POOLS];
> +       odp_shm_t shm;
> +} pool_table_t;
>
> -static inline pool_t *odp_pool_to_entry(odp_pool_t pool_hdl)
> +extern pool_table_t *pool_tbl;
> +
> +static inline pool_t *pool_entry(uint32_t pool_idx)
>  {
> -       return pool_entry(_odp_typeval(pool_hdl));
> +       return &pool_tbl->pool[pool_idx];
>  }
>
> -static inline uint32_t odp_buffer_pool_headroom(odp_pool_t pool)
> +static inline pool_t *pool_entry_from_hdl(odp_pool_t pool_hdl)
>  {
> -       return odp_pool_to_entry(pool)->headroom;
> +       return &pool_tbl->pool[_odp_typeval(pool_hdl)];
>  }
>
> -static inline uint32_t odp_buffer_pool_tailroom(odp_pool_t pool)
> +static inline odp_buffer_hdr_t *buf_hdl_to_hdr(odp_buffer_t buf)
>  {
> -       return odp_pool_to_entry(pool)->tailroom;
> +       odp_buffer_bits_t handle;
> +       uint32_t pool_id, index, block_offset;
> +       pool_t *pool;
> +       odp_buffer_hdr_t *buf_hdr;
> +
> +       handle.handle = buf;
> +       pool_id       = handle.pool_id;
> +       index         = handle.index;
> +       pool          = pool_entry(pool_id);
> +       block_offset  = index * pool->block_size;
> +
> +       buf_hdr = (odp_buffer_hdr_t *)&pool->base_addr[block_offset];
>

This requires a cast to compile with clang:

 In file included from odp_buffer.c:8:
./include/odp_pool_internal.h:106:12: error: cast from 'uint8_t *' (aka
'unsigned char *') to 'odp_buffer_hdr_t *' (aka 'struct odp_buffer_hdr_t
*') increases required alignment from 1 to 8 [-Werror,-Wcast-align]
        buf_hdr = (odp_buffer_hdr_t *)&pool->base_addr[block_offset];
                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
Makefile:859: recipe for target 'odp_buffer.lo' failed
make[1]: *** [odp_buffer.lo] Error 1

+
> +       return buf_hdr;
>  }
>
> +uint32_t pool_headroom(odp_pool_t pool);
> +uint32_t pool_tailroom(odp_pool_t pool);
> +
>  #ifdef __cplusplus
>  }
>  #endif
> diff --git a/platform/linux-generic/odp_buffer.c
> b/platform/linux-generic/odp_buffer.c
> index 0ddaf95..eed15c0 100644
> --- a/platform/linux-generic/odp_buffer.c
> +++ b/platform/linux-generic/odp_buffer.c
> @@ -26,14 +26,14 @@ odp_event_t odp_buffer_to_event(odp_buffer_t buf)
>
>  void *odp_buffer_addr(odp_buffer_t buf)
>  {
> -       odp_buffer_hdr_t *hdr = odp_buf_to_hdr(buf);
> +       odp_buffer_hdr_t *hdr = buf_hdl_to_hdr(buf);
>
>         return hdr->addr[0];
>  }
>
>  uint32_t odp_buffer_size(odp_buffer_t buf)
>  {
> -       odp_buffer_hdr_t *hdr = odp_buf_to_hdr(buf);
> +       odp_buffer_hdr_t *hdr = buf_hdl_to_hdr(buf);
>
>         return hdr->size;
>  }
> @@ -48,7 +48,7 @@ int odp_buffer_snprint(char *str, uint32_t n,
> odp_buffer_t buf)
>                 return len;
>         }
>
> -       hdr = odp_buf_to_hdr(buf);
> +       hdr = buf_hdl_to_hdr(buf);
>
>         len += snprintf(&str[len], n-len,
>                         "Buffer\n");
> diff --git a/platform/linux-generic/odp_packet.c
> b/platform/linux-generic/odp_packet.c
> index bf22443..59f0c99 100644
> --- a/platform/linux-generic/odp_packet.c
> +++ b/platform/linux-generic/odp_packet.c
> @@ -77,7 +77,7 @@ static void packet_init(pool_t *pool, odp_packet_hdr_t
> *pkt_hdr,
>  int packet_alloc_multi(odp_pool_t pool_hdl, uint32_t len,
>                        odp_packet_t pkt[], int max_num)
>  {
> -       pool_t *pool = odp_pool_to_entry(pool_hdl);
> +       pool_t *pool = pool_entry_from_hdl(pool_hdl);
>         int num, i;
>         odp_packet_hdr_t *pkt_hdrs[max_num];
>
> @@ -98,7 +98,7 @@ int packet_alloc_multi(odp_pool_t pool_hdl, uint32_t len,
>
>  odp_packet_t odp_packet_alloc(odp_pool_t pool_hdl, uint32_t len)
>  {
> -       pool_t *pool = odp_pool_to_entry(pool_hdl);
> +       pool_t *pool = pool_entry_from_hdl(pool_hdl);
>         size_t pkt_size = len ? len : pool->data_size;
>         odp_packet_t pkt;
>         odp_packet_hdr_t *pkt_hdr;
> @@ -130,7 +130,7 @@ odp_packet_t odp_packet_alloc(odp_pool_t pool_hdl,
> uint32_t len)
>  int odp_packet_alloc_multi(odp_pool_t pool_hdl, uint32_t len,
>                            odp_packet_t pkt[], int num)
>  {
> -       pool_t *pool = odp_pool_to_entry(pool_hdl);
> +       pool_t *pool = pool_entry_from_hdl(pool_hdl);
>         size_t pkt_size = len ? len : pool->data_size;
>         int count, i;
>         odp_packet_hdr_t *pkt_hdrs[num];
> @@ -173,7 +173,7 @@ void odp_packet_free_multi(const odp_packet_t pkt[],
> int num)
>  int odp_packet_reset(odp_packet_t pkt, uint32_t len)
>  {
>         odp_packet_hdr_t *const pkt_hdr = odp_packet_hdr(pkt);
> -       pool_t *pool = odp_pool_to_entry(pkt_hdr->buf_hdr.pool_hdl);
> +       pool_t *pool = pool_entry_from_hdl(pkt_hdr->buf_hdr.pool_hdl);
>
>         if (len > pool->headroom + pool->data_size + pool->tailroom)
>                 return -1;
> diff --git a/platform/linux-generic/odp_packet_io.c
> b/platform/linux-generic/odp_packet_io.c
> index 0b9939b..50798cf 100644
> --- a/platform/linux-generic/odp_packet_io.c
> +++ b/platform/linux-generic/odp_packet_io.c
> @@ -563,7 +563,7 @@ static inline int pktin_recv_buf(odp_pktin_queue_t
> queue,
>                 pkt = packets[i];
>                 pkt_hdr = odp_packet_hdr(pkt);
>                 buf = _odp_packet_to_buffer(pkt);
> -               buf_hdr = odp_buf_to_hdr(buf);
> +               buf_hdr = buf_hdl_to_hdr(buf);
>
>                 if (pkt_hdr->p.input_flags.dst_queue) {
>                         queue_entry_t *dst_queue;
> diff --git a/platform/linux-generic/odp_pool.c
> b/platform/linux-generic/odp_pool.c
> index 663b939..faea2fc 100644
> --- a/platform/linux-generic/odp_pool.c
> +++ b/platform/linux-generic/odp_pool.c
> @@ -32,18 +32,13 @@
>  ODP_STATIC_ASSERT(CONFIG_POOL_CACHE_SIZE > (2 * CACHE_BURST),
>                   "cache_burst_size_too_large_compared_to_cache_size");
>
> -typedef struct pool_table_t {
> -       pool_t    pool[ODP_CONFIG_POOLS];
> -       odp_shm_t shm;
> -} pool_table_t;
> -
>  /* Thread local variables */
>  typedef struct pool_local_t {
>         pool_cache_t *cache[ODP_CONFIG_POOLS];
>         int thr_id;
>  } pool_local_t;
>
> -static pool_table_t *pool_tbl;
> +pool_table_t *pool_tbl;
>  static __thread pool_local_t local;
>
>  static inline odp_pool_t pool_index_to_handle(uint32_t pool_idx)
> @@ -51,16 +46,6 @@ static inline odp_pool_t pool_index_to_handle(uint32_t
> pool_idx)
>         return _odp_cast_scalar(odp_pool_t, pool_idx);
>  }
>
> -pool_t *pool_entry(uint32_t pool_idx)
> -{
> -       return &pool_tbl->pool[pool_idx];
> -}
> -
> -static inline pool_t *pool_entry_from_hdl(odp_pool_t pool_hdl)
> -{
> -       return &pool_tbl->pool[_odp_typeval(pool_hdl)];
> -}
> -
>  int odp_pool_init_global(void)
>  {
>         uint32_t i;
> @@ -475,32 +460,14 @@ int odp_pool_destroy(odp_pool_t pool_hdl)
>         return 0;
>  }
>
> -odp_buffer_hdr_t *odp_buf_to_hdr(odp_buffer_t buf)
> -{
> -       odp_buffer_bits_t handle;
> -       uint32_t pool_id, index, block_offset;
> -       pool_t *pool;
> -       odp_buffer_hdr_t *buf_hdr;
> -
> -       handle.handle = buf;
> -       pool_id       = handle.pool_id;
> -       index         = handle.index;
> -       pool          = pool_entry(pool_id);
> -       block_offset  = index * pool->block_size;
> -
> -       buf_hdr = (odp_buffer_hdr_t *)&pool->base_addr[block_offset];
> -
> -       return buf_hdr;
> -}
> -
>  odp_event_type_t _odp_buffer_event_type(odp_buffer_t buf)
>  {
> -       return odp_buf_to_hdr(buf)->event_type;
> +       return buf_hdl_to_hdr(buf)->event_type;
>  }
>
>  void _odp_buffer_event_type_set(odp_buffer_t buf, int ev)
>  {
> -       odp_buf_to_hdr(buf)->event_type = ev;
> +       buf_hdl_to_hdr(buf)->event_type = ev;
>  }
>
>  void *buffer_map(odp_buffer_hdr_t *buf,
> @@ -613,7 +580,7 @@ int buffer_alloc_multi(odp_pool_t pool_hdl,
> odp_buffer_t buf[],
>                         buf[idx] = (odp_buffer_t)(uintptr_t)data[i];
>
>                         if (buf_hdr) {
> -                               buf_hdr[idx] = odp_buf_to_hdr(buf[idx]);
> +                               buf_hdr[idx] = buf_hdl_to_hdr(buf[idx]);
>                                 /* Prefetch newly allocated and soon to be
> used
>                                  * buffer headers. */
>                                 odp_prefetch(buf_hdr[idx]);
> @@ -632,7 +599,7 @@ int buffer_alloc_multi(odp_pool_t pool_hdl,
> odp_buffer_t buf[],
>
>         if (buf_hdr) {
>                 for (i = 0; i < num_ch; i++)
> -                       buf_hdr[i] = odp_buf_to_hdr(buf[i]);
> +                       buf_hdr[i] = buf_hdl_to_hdr(buf[i]);
>         }
>
>         return num_ch + num_deq;
> @@ -884,3 +851,13 @@ int odp_buffer_is_valid(odp_buffer_t buf)
>
>         return 1;
>  }
> +
> +uint32_t pool_headroom(odp_pool_t pool)
> +{
> +       return pool_entry_from_hdl(pool)->headroom;
> +}
> +
> +uint32_t pool_tailroom(odp_pool_t pool)
> +{
> +       return pool_entry_from_hdl(pool)->tailroom;
> +}
> diff --git a/platform/linux-generic/odp_queue.c
> b/platform/linux-generic/odp_queue.c
> index 8667076..a958967 100644
> --- a/platform/linux-generic/odp_queue.c
> +++ b/platform/linux-generic/odp_queue.c
> @@ -479,7 +479,7 @@ int odp_queue_enq_multi(odp_queue_t handle, const
> odp_event_t ev[], int num)
>         queue = queue_to_qentry(handle);
>
>         for (i = 0; i < num; i++)
> -               buf_hdr[i] = odp_buf_to_hdr(odp_buffer_from_event(ev[i]));
> +               buf_hdr[i] = buf_hdl_to_hdr(odp_buffer_from_event(ev[i]));
>
>         return num == 0 ? 0 : queue->s.enqueue_multi(queue, buf_hdr,
>                                                      num, SUSTAIN_ORDER);
> @@ -491,7 +491,7 @@ int odp_queue_enq(odp_queue_t handle, odp_event_t ev)
>         queue_entry_t *queue;
>
>         queue   = queue_to_qentry(handle);
> -       buf_hdr = odp_buf_to_hdr(odp_buffer_from_event(ev));
> +       buf_hdr = buf_hdl_to_hdr(odp_buffer_from_event(ev));
>
>         /* No chains via this entry */
>         buf_hdr->link = NULL;
> diff --git a/platform/linux-generic/odp_schedule_ordered.c
> b/platform/linux-generic/odp_schedule_ordered.c
> index 8412183..5574faf 100644
> --- a/platform/linux-generic/odp_schedule_ordered.c
> +++ b/platform/linux-generic/odp_schedule_ordered.c
> @@ -749,7 +749,7 @@ int release_order(void *origin_qe_ptr, uint64_t order,
>                 return -1;
>         }
>
> -       placeholder_buf_hdr = odp_buf_to_hdr(placeholder_buf);
> +       placeholder_buf_hdr = buf_hdl_to_hdr(placeholder_buf);
>
>         /* Copy info to placeholder and add it to the reorder queue */
>         placeholder_buf_hdr->origin_qe     = origin_qe;
> @@ -805,7 +805,7 @@ void cache_order_info(uint32_t queue_index)
>         uint32_t i;
>         queue_entry_t *qe = get_qentry(queue_index);
>         odp_event_t ev = sched_local.ev_stash[0];
> -       odp_buffer_hdr_t *buf_hdr = odp_buf_to_hdr(odp_buffer_
> from_event(ev));
> +       odp_buffer_hdr_t *buf_hdr = buf_hdl_to_hdr(odp_buffer_
> from_event(ev));
>
>         sched_local.origin_qe = qe;
>         sched_local.order     = buf_hdr->order;
> diff --git a/platform/linux-generic/odp_timer.c
> b/platform/linux-generic/odp_timer.c
> index 573489d..90c575f 100644
> --- a/platform/linux-generic/odp_timer.c
> +++ b/platform/linux-generic/odp_timer.c
> @@ -76,7 +76,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 *)(void *)odp_buf_to_hdr(buf);
> +       return (odp_timeout_hdr_t *)(void *)buf_hdl_to_hdr(buf);
>  }
>
>  static odp_timeout_hdr_t *timeout_hdr(odp_timeout_t tmo)
> diff --git a/platform/linux-generic/pktio/loop.c b/platform/linux-generic/
> pktio/loop.c
> index 21d7542..28dd404 100644
> --- a/platform/linux-generic/pktio/loop.c
> +++ b/platform/linux-generic/pktio/loop.c
> @@ -162,7 +162,7 @@ static int loopback_send(pktio_entry_t *pktio_entry,
> int index ODP_UNUSED,
>                 len = QUEUE_MULTI_MAX;
>
>         for (i = 0; i < len; ++i) {
> -               hdr_tbl[i] = odp_buf_to_hdr(_odp_packet_to_
> buffer(pkt_tbl[i]));
> +               hdr_tbl[i] = buf_hdl_to_hdr(_odp_packet_to_
> buffer(pkt_tbl[i]));
>                 bytes += odp_packet_len(pkt_tbl[i]);
>         }
>
> diff --git a/platform/linux-generic/pktio/netmap.c
> b/platform/linux-generic/pktio/netmap.c
> index c1cdf72..cf67741 100644
> --- a/platform/linux-generic/pktio/netmap.c
> +++ b/platform/linux-generic/pktio/netmap.c
> @@ -346,8 +346,8 @@ static int netmap_open(odp_pktio_t id ODP_UNUSED,
> pktio_entry_t *pktio_entry,
>
>         /* max frame len taking into account the l2-offset */
>         pkt_nm->max_frame_len = ODP_CONFIG_PACKET_BUF_LEN_MAX -
> -               odp_buffer_pool_headroom(pool) -
> -               odp_buffer_pool_tailroom(pool);
> +                               pool_headroom(pool) -
> +                               pool_tailroom(pool);
>
>         /* allow interface to be opened with or without the 'netmap:'
> prefix */
>         prefix = "netmap:";
> diff --git a/platform/linux-generic/pktio/socket_mmap.c
> b/platform/linux-generic/pktio/socket_mmap.c
> index bf4402a..666aae6 100644
> --- a/platform/linux-generic/pktio/socket_mmap.c
> +++ b/platform/linux-generic/pktio/socket_mmap.c
> @@ -351,7 +351,7 @@ static void mmap_fill_ring(struct ring *ring,
> odp_pool_t pool_hdl, int fanout)
>         if (pool_hdl == ODP_POOL_INVALID)
>                 ODP_ABORT("Invalid pool handle\n");
>
> -       pool = odp_pool_to_entry(pool_hdl);
> +       pool = pool_entry_from_hdl(pool_hdl);
>
>         /* Frame has to capture full packet which can fit to the pool
> block.*/
>         ring->req.tp_frame_size = (pool->data_size +
> --
> 2.8.1
>
>

Reply via email to