[PATCH v9] eal: add seqlock

Morten Brørup mb at smartsharesystems.com
Wed Jun 1 08:07:50 CEST 2022


> From: Stephen Hemminger [mailto:stephen at networkplumber.org]
> Sent: Wednesday, 1 June 2022 00.46
> 
> On Mon, 23 May 2022 16:23:46 +0200
> Mattias Rönnblom <mattias.ronnblom at ericsson.com> wrote:
> 
> > +/**
> > + * The RTE seqcount type.
> > + */
> > +typedef struct {
> > +	uint32_t sn; /**< A sequence number for the protected data. */
> > +} rte_seqcount_t;
> 
> Don't need structure for only one element.
> 
> typedef uint32_t rte_seqcount_t;

Agree. The rte_seqcount_t type is not going to evolve in any way, so it should be safe not wrapping it into a structure.

> +	if (unlikely(begin_sn != end_sn))
> +		return true;
> +
> +	return false;
> 
> Prefer to avoid conditional if possible (compiler will optimize it as):
> 
>         return begin_sn == end_sn;

Typo: return begin_sn != end_sn;

Please keep the unlikely() hint, which could also be added to Stephen's variant.

Considering the comments in the source code related to this comparison, Mattias' version seems more readable. And I suppose the compiler is able to generate optimized code for both.



More information about the dev mailing list