On Fri, Sep 11, 2015 at 7:55 AM, Petri Savolainen <
[email protected]> wrote:

> New thread API call odp_thread_count_max() replaces the
> preprocessor macro in the API. A macro is still used
> internally.
>
> Signed-off-by: Petri Savolainen <[email protected]>
> ---
>  include/odp/api/config.h                           |  5 ---
>  .../linux-generic/include/odp/plat/cpumask_types.h |  3 +-
>  .../include/odp/plat/rwlock_recursive_types.h      |  4 +--
>  .../linux-generic/include/odp_buffer_internal.h    |  3 +-
>  .../linux-generic/include/odp_config_internal.h    | 29 ++++++++++++++++
>  platform/linux-generic/odp_thread.c                |  9 ++---
>  platform/linux-generic/odp_thrmask.c               |  4 +--
>  test/performance/odp_pktio_perf.c                  | 40
> +++++++++++++++++++---
>  test/validation/thread/thread.c                    |  2 +-
>  9 files changed, 78 insertions(+), 21 deletions(-)
>  create mode 100644 platform/linux-generic/include/odp_config_internal.h
>
> diff --git a/include/odp/api/config.h b/include/odp/api/config.h
> index 302eaf5..bf88be8 100644
> --- a/include/odp/api/config.h
> +++ b/include/odp/api/config.h
> @@ -24,11 +24,6 @@ extern "C" {
>   */
>
>  /**
> - * Maximum number of threads
> - */
> -#define ODP_CONFIG_MAX_THREADS  128
> -
> -/**
>   * Maximum number of pools
>   */
>  #define ODP_CONFIG_POOLS        16
> diff --git a/platform/linux-generic/include/odp/plat/cpumask_types.h
> b/platform/linux-generic/include/odp/plat/cpumask_types.h
> index 6fba832..d3bf988 100644
> --- a/platform/linux-generic/include/odp/plat/cpumask_types.h
> +++ b/platform/linux-generic/include/odp/plat/cpumask_types.h
> @@ -23,11 +23,12 @@ extern "C" {
>   */
>
>  #include <odp/std_types.h>
> +#include <odp_config_internal.h>
>
>  /**
>   * Minimum size of output buffer for odp_cpumask_to_str()
>   */
> -#define ODP_CPUMASK_STR_SIZE ((ODP_CONFIG_MAX_THREADS + 3) / 4 + 3)
> +#define ODP_CPUMASK_STR_SIZE ((__ODP_CONFIG_MAX_THREADS + 3) / 4 + 3)
>
>  /**
>   * CPU mask
> diff --git
> a/platform/linux-generic/include/odp/plat/rwlock_recursive_types.h
> b/platform/linux-generic/include/odp/plat/rwlock_recursive_types.h
> index 9e220f5..0e20b40 100644
> --- a/platform/linux-generic/include/odp/plat/rwlock_recursive_types.h
> +++ b/platform/linux-generic/include/odp/plat/rwlock_recursive_types.h
> @@ -19,7 +19,7 @@ extern "C" {
>
>  #include <odp/rwlock.h>
>  #include <odp/std_types.h>
> -#include <odp/config.h>
> +#include <odp_config_internal.h>
>
>  /**
>   * @internal
> @@ -29,7 +29,7 @@ struct odp_rwlock_recursive_s {
>         odp_rwlock_t lock;                       /**< the lock */
>         int wr_owner;                            /**< write owner thread */
>         uint32_t wr_cnt;                         /**< write recursion
> count */
> -       uint8_t  rd_cnt[ODP_CONFIG_MAX_THREADS]; /**< read recursion count
> */
> +       uint8_t  rd_cnt[__ODP_CONFIG_MAX_THREADS]; /**< read recursion
> count */
>  };
>
>  /** @addtogroup odp_synchronizers
> diff --git a/platform/linux-generic/include/odp_buffer_internal.h
> b/platform/linux-generic/include/odp_buffer_internal.h
> index 4cacca1..7671ea7 100644
> --- a/platform/linux-generic/include/odp_buffer_internal.h
> +++ b/platform/linux-generic/include/odp_buffer_internal.h
> @@ -30,6 +30,7 @@ extern "C" {
>  #include <odp/thread.h>
>  #include <odp/event.h>
>  #include <odp_forward_typedefs_internal.h>
> +#include <odp_config_internal.h>
>
>  #define ODP_BITSIZE(x) \
>         ((x) <=     2 ?  1 : \
> @@ -143,7 +144,7 @@ struct odp_buffer_hdr_t {
>
>  /** @internal Compile time assert that the
>   * allocator field can handle any allocator id*/
> -_ODP_STATIC_ASSERT(INT16_MAX >= ODP_CONFIG_MAX_THREADS,
> +_ODP_STATIC_ASSERT(INT16_MAX >= __ODP_CONFIG_MAX_THREADS,
>                    "ODP_BUFFER_HDR_T__ALLOCATOR__SIZE_ERROR");
>
>  typedef struct odp_buffer_hdr_stride {
> diff --git a/platform/linux-generic/include/odp_config_internal.h
> b/platform/linux-generic/include/odp_config_internal.h
> new file mode 100644
> index 0000000..c60ec66
> --- /dev/null
> +++ b/platform/linux-generic/include/odp_config_internal.h
> @@ -0,0 +1,29 @@
> +/* Copyright (c) 2015, Linaro Limited
> + * All rights reserved.
> + *
> + * SPDX-License-Identifier:     BSD-3-Clause
> + */
> +
> +/**
> + * @file
> + *
> + * Linux-generic platform internal configuration
> + */
> +
> +#ifndef ODP_INTERNAL_CONFIG_H_
> +#define ODP_INTERNAL_CONFIG_H_
>

The file is named odp_config_internal so shouldn't this be
ODP_CONFIG_INTERNAL_H_ ?


> +
> +#ifdef __cplusplus
> +extern "C" {
> +#endif
> +
> +/**
> + * Maximum number of threads
> + */
> +#define __ODP_CONFIG_MAX_THREADS  128
>

We've been using one leading underscore for internal APIs.  Should we be
consistent here for internal constants?


> +
> +#ifdef __cplusplus
> +}
> +#endif
> +
> +#endif
> diff --git a/platform/linux-generic/odp_thread.c
> b/platform/linux-generic/odp_thread.c
> index a8ce133..8acf647 100644
> --- a/platform/linux-generic/odp_thread.c
> +++ b/platform/linux-generic/odp_thread.c
> @@ -18,6 +18,7 @@
>  #include <odp/shared_memory.h>
>  #include <odp/align.h>
>  #include <odp/cpu.h>
> +#include <odp_config_internal.h>
>
>  #include <string.h>
>  #include <stdio.h>
> @@ -31,7 +32,7 @@ typedef struct {
>
>
>  typedef struct {
> -       thread_state_t thr[ODP_CONFIG_MAX_THREADS];
> +       thread_state_t thr[__ODP_CONFIG_MAX_THREADS];
>         union {
>                 /* struct order must be kept in sync with schedule_types.h
> */
>                 struct {
> @@ -101,10 +102,10 @@ static int alloc_id(odp_thread_type_t type)
>         int thr;
>         odp_thrmask_t *all = &thread_globals->all;
>
> -       if (thread_globals->num >= ODP_CONFIG_MAX_THREADS)
> +       if (thread_globals->num >= __ODP_CONFIG_MAX_THREADS)
>                 return -1;
>
> -       for (thr = 0; thr < ODP_CONFIG_MAX_THREADS; thr++) {
> +       for (thr = 0; thr < __ODP_CONFIG_MAX_THREADS; thr++) {
>                 if (odp_thrmask_isset(all, thr) == 0) {
>                         odp_thrmask_set(all, thr);
>
> @@ -128,7 +129,7 @@ static int free_id(int thr)
>  {
>         odp_thrmask_t *all = &thread_globals->all;
>
> -       if (thr < 0 || thr >= ODP_CONFIG_MAX_THREADS)
> +       if (thr < 0 || thr >= __ODP_CONFIG_MAX_THREADS)
>                 return -1;
>
>         if (odp_thrmask_isset(all, thr) == 0)
> diff --git a/platform/linux-generic/odp_thrmask.c
> b/platform/linux-generic/odp_thrmask.c
> index d10bbf1..d8cf261 100644
> --- a/platform/linux-generic/odp_thrmask.c
> +++ b/platform/linux-generic/odp_thrmask.c
> @@ -9,11 +9,11 @@
>  #endif
>  #include <sched.h>
>
> -#include <odp/config.h>
> +#include <odp_config_internal.h>
>  #include <odp/thrmask.h>
>  #include <odp/cpumask.h>
>
> -#if CPU_SETSIZE < ODP_CONFIG_MAX_THREADS
> +#if CPU_SETSIZE < __ODP_CONFIG_MAX_THREADS
>  #error Thread mask does not fit all thread IDs
>  #endif
>
> diff --git a/test/performance/odp_pktio_perf.c
> b/test/performance/odp_pktio_perf.c
> index 709becf..185375e 100644
> --- a/test/performance/odp_pktio_perf.c
> +++ b/test/performance/odp_pktio_perf.c
> @@ -121,10 +121,12 @@ typedef struct {
>         odp_barrier_t tx_barrier;
>         odp_pktio_t pktio_tx;
>         odp_pktio_t pktio_rx;
> -       pkt_rx_stats_t rx_stats[ODP_CONFIG_MAX_THREADS];
> -       pkt_tx_stats_t tx_stats[ODP_CONFIG_MAX_THREADS];
> +       pkt_rx_stats_t *rx_stats;
> +       pkt_tx_stats_t *tx_stats;
>         uint8_t src_mac[ODPH_ETHADDR_LEN];
>         uint8_t dst_mac[ODPH_ETHADDR_LEN];
> +       uint32_t rx_stats_size;
> +       uint32_t tx_stats_size;
>  } test_globals_t;
>
>  /* Status of max rate search */
> @@ -468,7 +470,7 @@ static int process_results(uint64_t expected_tx_cnt,
>         char str[512];
>         int len = 0;
>
> -       for (i = 0; i < ODP_CONFIG_MAX_THREADS; ++i) {
> +       for (i = 0; i < odp_thread_count_max(); ++i) {
>                 rx_pkts += gbl_args->rx_stats[i].s.rx_cnt;
>                 tx_pkts += gbl_args->tx_stats[i].s.tx_cnt;
>         }
> @@ -610,8 +612,8 @@ static int run_test_single(odp_cpumask_t *thd_mask_tx,
>         odp_atomic_store_u32(&shutdown, 0);
>
>         memset(thd_tbl, 0, sizeof(thd_tbl));
> -       memset(&gbl_args->rx_stats, 0, sizeof(gbl_args->rx_stats));
> -       memset(&gbl_args->tx_stats, 0, sizeof(gbl_args->tx_stats));
> +       memset(gbl_args->rx_stats, 0, gbl_args->rx_stats_size);
> +       memset(gbl_args->tx_stats, 0, gbl_args->tx_stats_size);
>
>         expected_tx_cnt = status->pps_curr * gbl_args->args.duration;
>
> @@ -989,6 +991,7 @@ int main(int argc, char **argv)
>  {
>         int ret;
>         odp_shm_t shm;
> +       int max_thrs;
>
>         if (odp_init_global(NULL, NULL) != 0)
>                 LOG_ABORT("Failed global init.\n");
> @@ -1003,6 +1006,33 @@ int main(int argc, char **argv)
>                 LOG_ABORT("Shared memory reserve failed.\n");
>         memset(gbl_args, 0, sizeof(test_globals_t));
>
> +       max_thrs = odp_thread_count_max();
> +
> +       gbl_args->rx_stats_size = max_thrs * sizeof(pkt_rx_stats_t);
> +       gbl_args->tx_stats_size = max_thrs * sizeof(pkt_tx_stats_t);
> +
> +       shm = odp_shm_reserve("test_globals.rx_stats",
> +                             gbl_args->rx_stats_size,
> +                             ODP_CACHE_LINE_SIZE, 0);
> +
> +       gbl_args->rx_stats = odp_shm_addr(shm);
> +
> +       if (gbl_args->rx_stats == NULL)
> +               LOG_ABORT("Shared memory reserve failed.\n");
> +
> +       memset(gbl_args->rx_stats, 0, gbl_args->rx_stats_size);
> +
> +       shm = odp_shm_reserve("test_globals.tx_stats",
> +                             gbl_args->tx_stats_size,
> +                             ODP_CACHE_LINE_SIZE, 0);
> +
> +       gbl_args->tx_stats = odp_shm_addr(shm);
> +
> +       if (gbl_args->tx_stats == NULL)
> +               LOG_ABORT("Shared memory reserve failed.\n");
> +
> +       memset(gbl_args->tx_stats, 0, gbl_args->tx_stats_size);
> +
>         parse_args(argc, argv, &gbl_args->args);
>
>         ret = test_init();
> diff --git a/test/validation/thread/thread.c
> b/test/validation/thread/thread.c
> index d4f3ee0..093e688 100644
> --- a/test/validation/thread/thread.c
> +++ b/test/validation/thread/thread.c
> @@ -74,7 +74,7 @@ void thread_test_odp_thrmask_worker(void)
>         ret = odp_thrmask_worker(&mask);
>         CU_ASSERT(ret == odp_thrmask_count(&mask));
>         CU_ASSERT(ret == args.numthrds);
> -       CU_ASSERT(ret <= ODP_CONFIG_MAX_THREADS);
> +       CU_ASSERT(ret <= odp_thread_count_max());
>
>         /* allow thread(s) to exit */
>         odp_barrier_wait(&bar_exit);
> --
> 2.5.1
>
> _______________________________________________
> lng-odp mailing list
> [email protected]
> https://lists.linaro.org/mailman/listinfo/lng-odp
>
_______________________________________________
lng-odp mailing list
[email protected]
https://lists.linaro.org/mailman/listinfo/lng-odp

Reply via email to