[Libguestfs] [PATCH libnbd] lib: Use GCC hints to move debug and error handling code out of hot paths.
Eric Blake
eblake at redhat.com
Mon Nov 4 19:31:50 UTC 2019
On 11/2/19 4:24 PM, Richard W.M. Jones wrote:
> ---
> generator/generator | 6 +++---
> lib/crypto.c | 2 +-
> lib/internal.h | 14 +++++++++++++-
> 3 files changed, 17 insertions(+), 5 deletions(-)
>
> +++ b/lib/internal.h
> @@ -40,6 +40,18 @@
> #include "states.h"
> #include "unlocked.h"
>
> +/* Define unlikely macro, but only for GCC. These are used to move
> + * debug and error handling code out of hot paths, making the hot path
> + * into common functions use less instruction cache.
> + */
> +#if defined(__GNUC__)
> +#define unlikely(x) __builtin_expect (!!(x), 0)
> +#define if_debug(h) if (unlikely ((h)->debug))
> +#else
> +#define unlikely(x) (x)
> +#define if_debug(h) if ((h)->debug)
> +#endif
Same question about applicability to clang as for nbdkit, otherwise
looks fine.
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3226
Virtualization: qemu.org | libvirt.org
More information about the Libguestfs
mailing list