From b265ed2955570c17b954270e6a1449637790e9b8 Mon Sep 17 00:00:00 2001 From: Radoslaw Zarzynski Date: Fri, 9 Feb 2018 16:19:10 +0100 Subject: [PATCH] core: hint the dout()'s message crafting as a cold code. The idea is to: 1. Do not put the dout()'s crafting stuff on the hot, fall-through path. Cheapest branches are those that are forward and never taken. 2. Move it to separated sections placed far away from the main path to be more friendly to ICache and ITLB. That is, dout_impl constructs a function now. Signed-off-by: Radoslaw Zarzynski --- src/common/compiler_extensions.h | 6 ++++++ src/common/dout.h | 7 +++++-- src/common/likely.h | 4 ++-- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/common/compiler_extensions.h b/src/common/compiler_extensions.h index 2fd8f5c2d1367..64bad194038d7 100644 --- a/src/common/compiler_extensions.h +++ b/src/common/compiler_extensions.h @@ -22,9 +22,15 @@ #ifdef __GNUC__ // GCC #define WARN_UNUSED_RESULT __attribute__((warn_unused_result)) + +#define HINT_COLD_CODE __attribute__((cold)) +#define HINT_NO_INLINE __attribute__((noinline)) #else // some other compiler - just make it a no-op #define WARN_UNUSED_RESULT + +#define HINT_COLD_CODE +#define HINT_NO_INLINE #endif #endif diff --git a/src/common/dout.h b/src/common/dout.h index 085773d74a967..5fb93e9030fc8 100644 --- a/src/common/dout.h +++ b/src/common/dout.h @@ -20,6 +20,7 @@ #include "global/global_context.h" #include "common/config.h" +#include "common/compiler_extensions.h" #include "common/likely.h" #include "common/Clock.h" #include "log/Log.h" @@ -78,7 +79,8 @@ struct is_dynamic> : public std::true_type {}; } \ }(cct); \ \ - if (should_gather) { \ + if (unlikely(should_gather)) { \ + [&]() HINT_NO_INLINE HINT_COLD_CODE { \ static size_t _log_exp_length = 80; \ ceph::logging::Entry *_dout_e = \ cct->_log->create_entry(v, sub, &_log_exp_length); \ @@ -108,7 +110,8 @@ struct is_dynamic> : public std::true_type {}; // /usr/include/assert.h clobbers our fancier version. #define dendl_impl std::flush; \ _ASSERT_H->_log->submit_entry(_dout_e); \ - } \ + }(); \ + } \ } while (0) #define dendl dendl_impl diff --git a/src/common/likely.h b/src/common/likely.h index e8146a3f69eb0..f3696bfb026fd 100644 --- a/src/common/likely.h +++ b/src/common/likely.h @@ -18,7 +18,7 @@ /* * Likely / Unlikely macros */ -#define likely(x) __builtin_expect((x),1) -#define unlikely(x) __builtin_expect((x),0) +#define likely(x) __builtin_expect((const bool)(x),1) +#define unlikely(x) __builtin_expect((const bool)(x),0) #endif -- 2.39.5