[Libguestfs] [PATCH nbdkit] server: Use GCC hints to move debug and error handling code out of hot paths.
Eric Blake
eblake at redhat.com
Mon Nov 4 19:30:58 UTC 2019
On 11/2/19 4:24 PM, Richard W.M. Jones wrote:
> For GCC only, define unlikely() macro. Use it on error paths to move
> code out of the hot path.
>
> In the server only, use the debug() macro (don't call nbdkit_debug
> directly). This macro checks the verbose flag and moves the call to
> nbdkit_debug out of the hot path.
> ---
> +++ b/server/internal.h
> @@ -45,6 +45,17 @@
> #include "cleanup.h"
> #include "nbd-protocol.h"
>
> +/* Define unlikely macro, but only for GCC. These are used to move
> + * debug and error handling code out of hot paths.
> + */
> +#if defined(__GNUC__)
> +#define unlikely(x) __builtin_expect (!!(x), 0)
> +#define if_verbose if (unlikely (verbose))
Doesn't clang define __GNUC__, at which point all of our supported
compilers (since we require __attribute__((cleanup)) support) also have
__builtin_expect?
> +#else
> +#define unlikely(x) (x)
> +#define if_verbose if (verbose)
> +#endif
Or put another way, this #else may be dead code, and the #if may be
unnecessary compared to just unconditionally defining unlikely() and
if_verbose.
At any rate, the changes make sense.
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3226
Virtualization: qemu.org | libvirt.org
More information about the Libguestfs
mailing list