[dpdk-dev] [PATCH v2 4/7] vhost: do not use rte_memcpy for virtio_hdr copy

Stephen Hemminger stephen at networkplumber.org
Mon Mar 7 05:20:00 CET 2016


On Thu, 18 Feb 2016 21:49:09 +0800
Yuanhan Liu <yuanhan.liu at linux.intel.com> wrote:

> +static inline void
> +copy_virtio_net_hdr(struct vhost_virtqueue *vq, uint64_t desc_addr,
> +		    struct virtio_net_hdr_mrg_rxbuf hdr)
> +{
> +	if (vq->vhost_hlen == sizeof(struct virtio_net_hdr_mrg_rxbuf)) {
> +		*(struct virtio_net_hdr_mrg_rxbuf *)(uintptr_t)desc_addr = hdr;
> +	} else {
> +		*(struct virtio_net_hdr *)(uintptr_t)desc_addr = hdr.hdr;
> +	}
> +}
> +

Don't use {} around single statements.
Since you are doing all this casting, why not just use regular old memcpy
which will be inlined by Gcc  into same instructions anyway.
And since are always casting the desc_addr, why not pass a type that
doesn't need the additional cast (like void *)


More information about the dev mailing list