Received: from eggs.gnu.org ([208.118.235.92]:51398) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UIksZ-0000dM-TO for qemu-devel@nongnu.org; Thu, 21 Mar 2013 15:10:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UIksU-0001P1-SS for qemu-devel@nongnu.org; Thu, 21 Mar 2013 15:10:23 -0400 Received: from ssl.dlhnet.de ([91.198.192.8]:39045 helo=ssl.dlh.net) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UIksU-0001Os-Ix for qemu-devel@nongnu.org; Thu, 21 Mar 2013 15:10:18 -0400 Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 6.2 \(1499\)) From: Peter Lieven In-Reply-To: <514B4D90.7080007@redhat.com> Date: Thu, 21 Mar 2013 20:11:39 +0100 Content-Transfer-Encoding: quoted-printable Message-Id: <047DDAEC-FD19-4779-9966-D82CACBC86BE@kamp.de> References: <1363881457-14814-1-git-send-email-pl@kamp.de> <1363881457-14814-3-git-send-email-pl@kamp.de> <514B4D90.7080007@redhat.com> Subject: Re: [Qemu-devel] [PATCHv3 2/9] cutils: add a function to find non-zero content in a buffer List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Eric Blake Cc: kwolf@redhat.com, pbonzini@redhat.com, qemu-devel@nongnu.org Am 21.03.2013 um 19:12 schrieb Eric Blake : > On 03/21/2013 09:57 AM, Peter Lieven wrote: >> this adds buffer_find_nonzero_offset() which is a SSE2/Altives >=20 > s/Altives/Altivec/ >=20 >> optimized function that searches for non-zero content in a >> buffer. >>=20 >> due to the optimizations used in the function there are restrictions >> on buffer address and search length. the function >> can_use_buffer_find_nonzero_content() can be used to check if >> the function can be used safely. >>=20 >> Signed-off-by: Peter Lieven >> --- >> include/qemu-common.h | 3 +++ >> util/cutils.c | 50 = +++++++++++++++++++++++++++++++++++++++++++++++++ >> 2 files changed, 53 insertions(+) >=20 >> +inline bool can_use_buffer_find_nonzero_offset(const void *buf, = size_t len); >> +inline size_t buffer_find_nonzero_offset(const void *buf, size_t = len); >=20 > Ouch. It is okay to add a 'static inline' function, but then the > implementation must live in this header. Otherwise, the function must > not be inline, or you risk linker errors. Sorry, i was not aware.=20 >=20 >> +++ b/util/cutils.c >> @@ -143,6 +143,56 @@ int qemu_fdatasync(int fd) >> } >>=20 >> /* >> + * Searches for an area with non-zero content in a buffer >> + * >> + * Attention! The len must be a multiple of 8 * sizeof(VECTYPE)=20 >=20 > Should we call out BUFFER_FIND_NONZERO_OFFSET_UNROLL_FACTOR instead of = a > magic number here? But I'm okay with leaving it as-is. >=20 >> + * and addr must be a multiple of sizeof(VECTYPE) due to=20 >=20 > Trailing whitespace (here, and on several other lines). Please run = your > series through scripts/checkpatch.pl before submitting v4. thanks for the pointer. >=20 >> + * restriction of optimizations in this function. >> + *=20 >> + * can_use_buffer_find_nonzero_offset() can be used to check >> + * these requirements. >> + *=20 >> + * The return value is the offset of the non-zero area rounded >> + * down to 8 * sizeof(VECTYPE). If the buffer is all zero=20 >=20 > Same comment on this use of '8'. >=20 >> + * the return value is equal to len. >> + */ >> + >> +inline size_t buffer_find_nonzero_offset(const void *buf, size_t = len) >=20 > s/inline// (or move it to a 'static inline' definition in the .h) I would move at least the can_use_buffer_find_nonzero_offset() function completely into the header and rely the compiler inlineing buffer_find_nonzero_offset(). >=20 >> +{ >> + VECTYPE *p =3D (VECTYPE *)buf; >> + VECTYPE zero =3D ZERO_SPLAT; >> + size_t i; >> + =20 >=20 > You copied the 'Attention! ...' message from buffer_is_zero, which > currently asserts that its condition is held. Therefore, consistency > would argue that you should assert your preconditions here, even if it > adds more to the code size. But this is something where a maintainer > might have a better opinion on whether to keep the code robust with an > assert(), or whether the faster operation without sanity checking is > more appropriate (in which case a followup to remove the assert from > buffer_is_zero would make sense). I would appreciate feedback on this from the maintainers. My concern with buffer_find_nonzero_offset() is that it is used for checking = millions of 4KByte pages. buffer_is_zero is used for larger objects in the bdrv context, afaik. >=20 >> * Checks if a buffer is all zeroes >> * >> * Attention! The len must be a multiple of 4 * sizeof(long) due to >>=20 >=20 > Cleaning up whitespace is trivial; but the incorrect use of 'inline' > requires a v4. >=20 > --=20 > Eric Blake eblake redhat com +1-919-301-3266 > Libvirt virtualization library http://libvirt.org >=20