On Tue, Jan 5, 2016 at 8:42 AM, Petri Savolainen <[email protected]
> wrote:

> Removed odp_spin() and replaced usage with odp_cpu_pause().
>
> Signed-off-by: Petri Savolainen <[email protected]>
> ---
>  platform/linux-generic/Makefile.am                 |  1 -
>  platform/linux-generic/include/odp_spin_internal.h | 58
> ----------------------
>  platform/linux-generic/odp_barrier.c               |  4 +-
>  platform/linux-generic/odp_rwlock.c                |  7 ++-
>  platform/linux-generic/odp_schedule.c              |  4 +-
>  platform/linux-generic/odp_spinlock.c              |  5 +-
>  platform/linux-generic/odp_ticketlock.c            |  4 +-
>  platform/linux-generic/odp_timer.c                 | 10 ++--
>  8 files changed, 16 insertions(+), 77 deletions(-)
>  delete mode 100644 platform/linux-generic/include/odp_spin_internal.h
>
> diff --git a/platform/linux-generic/Makefile.am
> b/platform/linux-generic/Makefile.am
> index ffb4c45..9fbb3bd 100644
> --- a/platform/linux-generic/Makefile.am
> +++ b/platform/linux-generic/Makefile.am
> @@ -109,7 +109,6 @@ noinst_HEADERS = \
>                   ${srcdir}/include/odp_queue_internal.h \
>                   ${srcdir}/include/odp_schedule_internal.h \
>                   ${srcdir}/include/odp_sorted_list_internal.h \
> -                 ${srcdir}/include/odp_spin_internal.h \
>                   ${srcdir}/include/odp_timer_internal.h \
>                   ${srcdir}/include/odp_timer_wheel_internal.h \
>                   ${srcdir}/include/odp_traffic_mngr_internal.h \
> diff --git a/platform/linux-generic/include/odp_spin_internal.h
> b/platform/linux-generic/include/odp_spin_internal.h
> deleted file mode 100644
> index 29c524f..0000000
> --- a/platform/linux-generic/include/odp_spin_internal.h
> +++ /dev/null
> @@ -1,58 +0,0 @@
> -/* Copyright (c) 2013, Linaro Limited
> - * All rights reserved.
> - *
> - * SPDX-License-Identifier:     BSD-3-Clause
> - */
> -
> -
> -
> -#ifndef ODP_SPIN_INTERNAL_H_
> -#define ODP_SPIN_INTERNAL_H_
> -
> -#ifdef __cplusplus
> -extern "C" {
> -#endif
> -
> -
> -/**
> - * Spin loop for ODP internal use
> - */
> -static inline void odp_spin(void)
> -{
> -#if defined __x86_64__ || defined __i386__
> -
> -#ifdef __SSE2__
> -       __asm__ __volatile__ ("pause");
> -#else
> -       __asm__ __volatile__ ("rep; nop");
> -#endif
> -
> -#elif defined __arm__
> -
> -#if __ARM_ARCH == 7
> -       __asm__ __volatile__ ("nop");
> -       __asm__ __volatile__ ("nop");
> -       __asm__ __volatile__ ("nop");
> -       __asm__ __volatile__ ("nop");
> -#endif
> -
> -#elif defined __OCTEON__
> -
> -       __asm__ __volatile__ ("nop");
> -       __asm__ __volatile__ ("nop");
> -       __asm__ __volatile__ ("nop");
> -       __asm__ __volatile__ ("nop");
> -       __asm__ __volatile__ ("nop");
> -       __asm__ __volatile__ ("nop");
> -       __asm__ __volatile__ ("nop");
> -       __asm__ __volatile__ ("nop");
> -
> -#endif
> -}
> -
> -
> -#ifdef __cplusplus
> -}
> -#endif
> -
> -#endif
> diff --git a/platform/linux-generic/odp_barrier.c
> b/platform/linux-generic/odp_barrier.c
> index 53d83c0..0bfc0f0 100644
> --- a/platform/linux-generic/odp_barrier.c
> +++ b/platform/linux-generic/odp_barrier.c
> @@ -6,7 +6,7 @@
>
>  #include <odp/barrier.h>
>  #include <odp/sync.h>
> -#include <odp_spin_internal.h>
> +#include <odp/cpu.h>
>  #include <odp_atomic_internal.h>
>
>  void odp_barrier_init(odp_barrier_t *barrier, int count)
> @@ -43,7 +43,7 @@ void odp_barrier_wait(odp_barrier_t *barrier)
>         } else {
>                 while ((odp_atomic_load_u32(&barrier->bar) <
> barrier->count)
>                                 == wasless)
> -                       odp_spin();
> +                       odp_cpu_pause();
>

Why wouldn't you just want to change the implementation of odp_spin() to
use the pause instruction here?  These are spin lock waits but nowhere does
ODP specify that spins must be implemented inefficiently.


>         }
>
>         _ODP_FULL_BARRIER();
> diff --git a/platform/linux-generic/odp_rwlock.c
> b/platform/linux-generic/odp_rwlock.c
> index 47c15ef..0b8bb46 100644
> --- a/platform/linux-generic/odp_rwlock.c
> +++ b/platform/linux-generic/odp_rwlock.c
> @@ -8,8 +8,7 @@
>  #include <odp/atomic.h>
>  #include <odp_atomic_internal.h>
>  #include <odp/rwlock.h>
> -
> -#include <odp_spin_internal.h>
> +#include <odp/cpu.h>
>
>  void odp_rwlock_init(odp_rwlock_t *rwlock)
>  {
> @@ -25,7 +24,7 @@ void odp_rwlock_read_lock(odp_rwlock_t *rwlock)
>                 cnt = _odp_atomic_u32_load_mm(&rwlock->cnt,
> _ODP_MEMMODEL_RLX);
>                 /* waiting for read lock */
>                 if ((int32_t)cnt < 0) {
> -                       odp_spin();
> +                       odp_cpu_pause();
>                         continue;
>                 }
>                 is_locked =
> _odp_atomic_u32_cmp_xchg_strong_mm(&rwlock->cnt,
> @@ -51,7 +50,7 @@ void odp_rwlock_write_lock(odp_rwlock_t *rwlock)
>                 cnt = _odp_atomic_u32_load_mm(&rwlock->cnt,
> _ODP_MEMMODEL_RLX);
>                 /* lock acquired, wait */
>                 if (cnt != 0) {
> -                       odp_spin();
> +                       odp_cpu_pause();
>                         continue;
>                 }
>                 is_locked =
> _odp_atomic_u32_cmp_xchg_strong_mm(&rwlock->cnt,
> diff --git a/platform/linux-generic/odp_schedule.c
> b/platform/linux-generic/odp_schedule.c
> index e0fadfa..1aa60c2 100644
> --- a/platform/linux-generic/odp_schedule.c
> +++ b/platform/linux-generic/odp_schedule.c
> @@ -19,10 +19,10 @@
>  #include <odp/time.h>
>  #include <odp/spinlock.h>
>  #include <odp/hints.h>
> +#include <odp/cpu.h>
>
>  #include <odp_queue_internal.h>
>  #include <odp_packet_io_internal.h>
> -#include <odp_spin_internal.h>
>
>  odp_thrmask_t sched_mask_all;
>
> @@ -894,7 +894,7 @@ void odp_schedule_order_lock(unsigned lock_index)
>          * some events in the ordered flow need to lock.
>          */
>         while (sync != sync_out) {
> -               odp_spin();
> +               odp_cpu_pause();
>                 sync_out =
>
> odp_atomic_load_u64(&origin_qe->s.sync_out[lock_index]);
>         }
> diff --git a/platform/linux-generic/odp_spinlock.c
> b/platform/linux-generic/odp_spinlock.c
> index f165720..6a16dc4 100644
> --- a/platform/linux-generic/odp_spinlock.c
> +++ b/platform/linux-generic/odp_spinlock.c
> @@ -5,9 +5,8 @@
>   */
>
>  #include <odp/spinlock.h>
> +#include <odp/cpu.h>
>  #include <odp_atomic_internal.h>
> -#include <odp_spin_internal.h>
> -
>
>  void odp_spinlock_init(odp_spinlock_t *spinlock)
>  {
> @@ -23,7 +22,7 @@ void odp_spinlock_lock(odp_spinlock_t *spinlock)
>                  * the loop will exit when the lock becomes available
>                  * and we will retry the TAS operation above */
>                 while (_odp_atomic_flag_load(&spinlock->lock))
> -                       odp_spin();
> +                       odp_cpu_pause();
>  }
>
>
> diff --git a/platform/linux-generic/odp_ticketlock.c
> b/platform/linux-generic/odp_ticketlock.c
> index 3e2a4ec..6ab2b9a 100644
> --- a/platform/linux-generic/odp_ticketlock.c
> +++ b/platform/linux-generic/odp_ticketlock.c
> @@ -8,7 +8,7 @@
>  #include <odp/atomic.h>
>  #include <odp_atomic_internal.h>
>  #include <odp/sync.h>
> -#include <odp_spin_internal.h>
> +#include <odp/cpu.h>
>
>
>  void odp_ticketlock_init(odp_ticketlock_t *ticketlock)
> @@ -31,7 +31,7 @@ void odp_ticketlock_lock(odp_ticketlock_t *ticketlock)
>          * all stores from the previous lock owner */
>         while (ticket != _odp_atomic_u32_load_mm(&ticketlock->cur_ticket,
>                                                  _ODP_MEMMODEL_ACQ))
> -               odp_spin();
> +               odp_cpu_pause();
>  }
>
>  int odp_ticketlock_trylock(odp_ticketlock_t *tklock)
> diff --git a/platform/linux-generic/odp_timer.c
> b/platform/linux-generic/odp_timer.c
> index 5c1f8ca..b8f34fb 100644
> --- a/platform/linux-generic/odp_timer.c
> +++ b/platform/linux-generic/odp_timer.c
> @@ -33,6 +33,7 @@
>  #include <odp_atomic_internal.h>
>  #include <odp/buffer.h>
>  #include <odp_buffer_inlines.h>
> +#include <odp/cpu.h>
>  #include <odp/pool.h>
>  #include <odp_pool_internal.h>
>  #include <odp/debug.h>
> @@ -42,7 +43,6 @@
>  #include <odp_internal.h>
>  #include <odp/queue.h>
>  #include <odp/shared_memory.h>
> -#include <odp_spin_internal.h>
>  #include <odp/spinlock.h>
>  #include <odp/std_types.h>
>  #include <odp/sync.h>
> @@ -408,7 +408,7 @@ static bool timer_reset(uint32_t idx,
>                 while (_odp_atomic_flag_tas(IDX2LOCK(idx)))
>                         /* While lock is taken, spin using relaxed loads */
>                         while (_odp_atomic_flag_load(IDX2LOCK(idx)))
> -                               odp_spin();
> +                               odp_cpu_pause();
>
>                 /* Only if there is a timeout buffer can be reset the
> timer */
>                 if (odp_likely(tb->tmo_buf != ODP_BUFFER_INVALID)) {
> @@ -455,7 +455,7 @@ static bool timer_reset(uint32_t idx,
>                 while (_odp_atomic_flag_tas(IDX2LOCK(idx)))
>                         /* While lock is taken, spin using relaxed loads */
>                         while (_odp_atomic_flag_load(IDX2LOCK(idx)))
> -                               odp_spin();
> +                               odp_cpu_pause();
>
>                 /* Swap in new buffer, save any old buffer */
>                 old_buf = tb->tmo_buf;
> @@ -496,7 +496,7 @@ static odp_buffer_t timer_cancel(odp_timer_pool *tp,
>         while (_odp_atomic_flag_tas(IDX2LOCK(idx)))
>                 /* While lock is taken, spin using relaxed loads */
>                 while (_odp_atomic_flag_load(IDX2LOCK(idx)))
> -                       odp_spin();
> +                       odp_cpu_pause();
>
>         /* Update the timer state (e.g. cancel the current timeout) */
>         tb->exp_tck.v = new_state;
> @@ -550,7 +550,7 @@ static unsigned timer_expire(odp_timer_pool *tp,
> uint32_t idx, uint64_t tick)
>         while (_odp_atomic_flag_tas(IDX2LOCK(idx)))
>                 /* While lock is taken, spin using relaxed loads */
>                 while (_odp_atomic_flag_load(IDX2LOCK(idx)))
> -                       odp_spin();
> +                       odp_cpu_pause();
>         /* Proper check for timer expired */
>         exp_tck = tb->exp_tck.v;
>         if (odp_likely(exp_tck <= tick)) {
> --
> 2.6.3
>
> _______________________________________________
> 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