From: Mathieu Desnoyers Date: Sun, 25 Sep 2016 16:31:11 +0000 (-0400) Subject: Performance: implement lttng_inline_memcpy X-Git-Tag: v2.9.0-rc1~9 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=51b8f2fa2b972e62117caa946dd3e3565b6ca4a3;p=lttng-ust.git Performance: implement lttng_inline_memcpy Because all length parameters received for serializing data coming from applications go through a callback, they are never constant, and it hurts performance to perform a call to memcpy each time. Signed-off-by: Mathieu Desnoyers --- diff --git a/libringbuffer/backend_internal.h b/libringbuffer/backend_internal.h index 90088b89..e597cf4d 100644 --- a/libringbuffer/backend_internal.h +++ b/libringbuffer/backend_internal.h @@ -592,6 +592,28 @@ int update_read_sb_index(const struct lttng_ust_lib_ring_buffer_config *config, #define inline_memcpy(dest, src, n) memcpy(dest, src, n) #endif +static inline __attribute__((always_inline)) +void lttng_inline_memcpy(void *dest, const void *src, + unsigned long len) +{ + switch (len) { + case 1: + *(uint8_t *) dest = *(const uint8_t *) src; + break; + case 2: + *(uint16_t *) dest = *(const uint16_t *) src; + break; + case 4: + *(uint32_t *) dest = *(const uint32_t *) src; + break; + case 8: + *(uint64_t *) dest = *(const uint64_t *) src; + break; + default: + inline_memcpy(dest, src, len); + } +} + /* * Use the architecture-specific memcpy implementation for constant-sized * inputs, but rely on an inline memcpy for length statically unknown. @@ -603,7 +625,7 @@ do { \ if (__builtin_constant_p(len)) \ memcpy(dest, src, __len); \ else \ - inline_memcpy(dest, src, __len); \ + lttng_inline_memcpy(dest, src, __len); \ } while (0) /*