[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:58:12 CET 2019
> -----Original Message-----
> From: Jerin Jacob Kollanukkaran <jerinj at marvell.com>
> Sent: Wednesday, March 13, 2019 11:36 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>
> > ---
> > diff --git a/MAINTAINERS b/MAINTAINERS index 097cfb4..12a091f 100644
> > --- a/MAINTAINERS
> > +++ b/MAINTAINERS
> > @@ -210,6 +210,10 @@ M: Cristian Dumitrescu <
> > cristian.dumitrescu at intel.com>
> > F: lib/librte_eal/common/include/rte_bitmap.h
> > F: app/test/test_bitmap.c
> >
> > +Ticketlock
> > +M: Joyce Kong <joyce.kong at arm.com>
> > +F: lib/librte_eal/common/include/generic/rte_ticketlock.h
>
>
> Add F: app/test/test_ticketlock.c in the next patch
>
Done in V6.
> >
> > +#include <rte_lcore.h>
> > +#include <rte_common.h>
> > +#include <rte_pause.h>
>
> Sort the header in alphabetical order.
>
Done in v6.
> > +
> > +/**
> > + * The rte_ticketlock_t type.
> > + */
> > +typedef struct {
> > + uint16_t current;
> > + uint16_t next;
> > +} rte_ticketlock_t;
> > +
> >
> > +
> > +/**
> > + * Take the ticketlock.
> > + *
> > + * @param tl
> > + * A pointer to the ticketlock.
> > + */
> > +static inline __rte_experimental void
> > +rte_ticketlock_lock(rte_ticketlock_t *tl) {
> > + unsigned int me = __atomic_fetch_add(&tl->next, 1,
>
> If current, next is uint16_t why "me" as unsigned int.
>
Change "me" to uint16_t to match current and next in v6.
> > __ATOMIC_RELAXED);
> > + while (__atomic_load_n(&tl->current, __ATOMIC_ACQUIRE) != me)
> > + rte_pause();
> > +}
> > +
> > +/**
> > + * Release the ticketlock.
> > + *
> > + * @param tl
> > + * A pointer to the ticketlock.
> > + */
> > +static inline __rte_experimental void
> > +rte_ticketlock_unlock(rte_ticketlock_t *tl) {
> > + unsigned int i = __atomic_load_n(&tl->current,
> > __ATOMIC_RELAXED);
> > + i++;
>
> You can save this line by making
> __atomic_store_n(&tl->current, i + 1, __ATOMIC_RELEASE);
>
Done in V6.
> The code looks good. Please check the above comments and earlier reported
> compilation issue with clang 7.1
>
More information about the dev
mailing list