[dpdk-dev] [PATCH v3 2/4] kni: fix kni fifo synchronization

Stephen Hemminger stephen at networkplumber.org
Mon Oct 8 23:53:08 CEST 2018


On Mon,  8 Oct 2018 17:11:44 +0800
Phil Yang <phil.yang at arm.com> wrote:

> diff --git a/lib/librte_kni/rte_kni_fifo.h b/lib/librte_kni/rte_kni_fifo.h
> index ac26a8c..70ac14e 100644
> --- a/lib/librte_kni/rte_kni_fifo.h
> +++ b/lib/librte_kni/rte_kni_fifo.h
> @@ -28,8 +28,9 @@ kni_fifo_put(struct rte_kni_fifo *fifo, void **data, unsigned num)
>  {
>  	unsigned i = 0;
>  	unsigned fifo_write = fifo->write;
> -	unsigned fifo_read = fifo->read;
>  	unsigned new_write = fifo_write;
> +	rte_smp_rmb();
> +	unsigned fifo_read = fifo->read;
>  

The patch makes sense, but this function should be changed to match kernel code style.
That means no declarations after initial block, and use 'unsigned int' rather than 'unsigned'

Also. why is i initialized? Best practice now is to not do gratitious initialization
since it defeats compiler checks for accidental  use of uninitialized variables.

What makes sense is something like:

kni_fifo_put(struct rte_kni_fifo *fifo, void **data, unsigned num)
{
	unsigned int i, fifo_read, fifo_write, new_write;

	fifo_write = fifo->write;
	new_write = fifo_write;
	rte_smb_rmb();
	fifo_read = fifo->read;

Sorry, blaming you for issues which are inherited from original KNI code.
Maybe someone should run kernel checkpatch (not DPDK checkpatch) on it and fix those.


More information about the dev mailing list