[dpdk-dev] [PATCH v5 1/2] eal/ticketlock: ticket based to improve fairness

Joyce Kong (Arm Technology China) Joyce.Kong at arm.com
Fri Mar 15 07:57:35 CET 2019


> -----Original Message-----
> From: Jerin Jacob Kollanukkaran <jerinj at marvell.com>
> Sent: Wednesday, March 13, 2019 5:41 PM
> To: Joyce Kong (Arm Technology China) <Joyce.Kong at arm.com>;
> dev at dpdk.org
> Cc: stephen at networkplumber.org; Honnappa Nagarahalli
> <Honnappa.Nagarahalli at arm.com>; thomas at monjalon.net; nd
> <nd at arm.com>; jerin.jacob at caviumnetworks.com; Gavin Hu (Arm
> Technology China) <Gavin.Hu at arm.com>
> Subject: Re: [dpdk-dev] [PATCH v5 1/2] eal/ticketlock: ticket based to improve
> fairness
> 
> 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,
> 

Fix the error by changing next and cur from unsigned int to unint16_t in V6.


> 
> > +			return 1;
> > +	}
> > +
> > +	return 0;
> > +}
> > +
> >


More information about the dev mailing list