> -----Original Message----- > From: Stephen Hemminger <step...@networkplumber.org> > Sent: den 30 juni 2022 19:46 > To: Morten Brørup <m...@smartsharesystems.com> > Cc: Emil Berg <emil.b...@ericsson.com>; bruce.richard...@intel.com; > dev@dpdk.org; sta...@dpdk.org; bugzi...@dpdk.org; hof...@lysator.liu.se; > olivier.m...@6wind.com > Subject: Re: [PATCH v4] net: fix checksum with unaligned buffer > > On Thu, 23 Jun 2022 14:39:00 +0200 > Morten Brørup <m...@smartsharesystems.com> wrote: > > > + /* if buffer is unaligned, keeping it byte order independent */ > > + if (unlikely(unaligned)) { > > + uint16_t first = 0; > > + if (unlikely(len == 0)) > > + return 0; > > Why is length == 0 unique to unaligned case? > > > + ((unsigned char *)&first)[1] = *(const unsigned > char *)buf; > > Use a proper union instead of casting to avoid aliasing warnings. > > > + bsum += first; > > + buf = RTE_PTR_ADD(buf, 1); > > + len--; > > + } > > Many CPU's (such as x86) won't care about alignment and therefore the > extra code to handle this is not worth doing. >
x86 does care about alignment. An example is the vmovdqa instruction, where 'a' stands for 'aligned'. The description in the link below says: "When the source or destination operand is a memory operand, the operand must be aligned on a 16-byte boundary or a general-protection exception (#GP) will be generated. " https://www.felixcloutier.com/x86/movdqa:vmovdqa32:vmovdqa64 > Perhaps DPDK needs a macro (like Linux kernel) for efficient unaligned > access. > > In Linux kernel it is CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS