[dpdk-dev] [PATCH v5 1/2] eal/ticketlock: ticket based to improve fairness
Jerin Jacob Kollanukkaran
jerinj at marvell.com
Wed Mar 13 10:41:14 CET 2019
On Mon, 2019-03-11 at 13:52 +0800, Joyce Kong wrote:
> The spinlock implementation is unfair, some threads may take locks
> aggressively while leaving the other threads starving for long time.
>
> This patch introduces ticketlock which gives each waiting thread a
> ticket and they can take the lock one by one. First come, first
> serviced.
> This avoids starvation for too long time and is more predictable.
>
> Suggested-by: Jerin Jacob <jerinj at marvell.com>
> Signed-off-by: Joyce kong <joyce.kong at arm.com>
> Reviewed-by: Gavin Hu <gavin.hu at arm.com>
> Reviewed-by: Ola Liljedahl <ola.liljedahl at arm.com>
> Reviewed-by: Honnappa Nagarahalli <honnappa.nagarahalli at arm.com>
> ---
> +static inline __rte_experimental int
> +rte_ticketlock_trylock(rte_ticketlock_t *tl)
> +{
> + unsigned int next = __atomic_load_n(&tl->next,
> __ATOMIC_RELAXED);
> + unsigned int cur = __atomic_load_n(&tl->current,
> __ATOMIC_RELAXED);
> + if (next == cur) {
> + if (__atomic_compare_exchange_n(&tl->next, &next,
> next+1,
> + 0, __ATOMIC_ACQUIRE, __ATOMIC_RELAXED))
gcc 8.2 emits the following compilation error.
/export/dpdk.org/build/include/generic/rte_ticketlock.h:93:46: error:
incompatible pointer types passing 'unsigned int *' to parameter of
type 'uint16_t *' (aka 'unsigned short *') [-Werror,-Wincompatible-
pointer-types]
if (__atomic_compare_exchange_n(&tl->next, &next,
next+1,
> + return 1;
> + }
> +
> + return 0;
> +}
> +
>
More information about the dev
mailing list