From e0c76911b3809ef3a32f45d0d947af70c365a01d Mon Sep 17 00:00:00 2001 From: xie xingguo Date: Wed, 28 Mar 2018 14:08:16 +0800 Subject: [PATCH 1/2] intarith: kill P2* macros These macros are originally introduced in https://github.com/ceph/ceph/pull/10128 and get replaced by https://github.com/ceph/ceph/pull/19913. Signed-off-by: xie xingguo --- src/include/intarith.h | 34 ++++++++++++---------------------- src/os/bluestore/BlueStore.h | 2 +- src/test/test_intarith.cc | 24 ++++++++++++------------ 3 files changed, 25 insertions(+), 35 deletions(-) diff --git a/src/include/intarith.h b/src/include/intarith.h index b2fb849db31..e08cbc0e4f2 100644 --- a/src/include/intarith.h +++ b/src/include/intarith.h @@ -46,29 +46,25 @@ constexpr inline std::make_unsigned_t> shift_round_up(T } /* - * Macro to determine if value is a power of 2 + * Wrapper to determine if value is a power of 2 */ -#define ISP2(x) (((x) & ((x) - 1)) == 0) - template constexpr inline bool isp2(T x) { return (x & (x - 1)) == 0; } /* - * Macros for various sorts of alignment and rounding. The "align" must + * Wrappers for various sorts of alignment and rounding. The "align" must * be a power of 2. Often times it is a block, sector, or page. */ /* * return x rounded down to an align boundary - * eg, P2ALIGN(1200, 1024) == 1024 (1*align) - * eg, P2ALIGN(1024, 1024) == 1024 (1*align) - * eg, P2ALIGN(0x1234, 0x100) == 0x1200 (0x12*align) - * eg, P2ALIGN(0x5600, 0x100) == 0x5600 (0x56*align) + * eg, p2align(1200, 1024) == 1024 (1*align) + * eg, p2align(1024, 1024) == 1024 (1*align) + * eg, p2align(0x1234, 0x100) == 0x1200 (0x12*align) + * eg, p2align(0x5600, 0x100) == 0x5600 (0x56*align) */ -#define P2ALIGN(x, align) ((x) & -(align)) - template constexpr inline std::make_unsigned_t> p2align(T x, U align) { return x & -align; @@ -76,11 +72,9 @@ constexpr inline std::make_unsigned_t> p2align(T x, U a /* * return x % (mod) align - * eg, P2PHASE(0x1234, 0x100) == 0x34 (x-0x12*align) - * eg, P2PHASE(0x5600, 0x100) == 0x00 (x-0x56*align) + * eg, p2phase(0x1234, 0x100) == 0x34 (x-0x12*align) + * eg, p2phase(0x5600, 0x100) == 0x00 (x-0x56*align) */ -#define P2PHASE(x, align) ((x) & ((align) - 1)) - template constexpr inline std::make_unsigned_t> p2phase(T x, U align) { return x & (align - 1); @@ -89,11 +83,9 @@ constexpr inline std::make_unsigned_t> p2phase(T x, U a /* * return how much space is left in this block (but if it's perfectly * aligned, return 0). - * eg, P2NPHASE(0x1234, 0x100) == 0xcc (0x13*align-x) - * eg, P2NPHASE(0x5600, 0x100) == 0x00 (0x56*align-x) + * eg, p2nphase(0x1234, 0x100) == 0xcc (0x13*align-x) + * eg, p2nphase(0x5600, 0x100) == 0x00 (0x56*align-x) */ -#define P2NPHASE(x, align) (-(x) & ((align) - 1)) - template constexpr inline std::make_unsigned_t> p2nphase(T x, U align) { return -x & (align - 1); @@ -101,11 +93,9 @@ constexpr inline std::make_unsigned_t> p2nphase(T x, U /* * return x rounded up to an align boundary - * eg, P2ROUNDUP(0x1234, 0x100) == 0x1300 (0x13*align) - * eg, P2ROUNDUP(0x5600, 0x100) == 0x5600 (0x56*align) + * eg, p2roundup(0x1234, 0x100) == 0x1300 (0x13*align) + * eg, p2roundup(0x5600, 0x100) == 0x5600 (0x56*align) */ -#define P2ROUNDUP(x, align) (-(-(x) & -(align))) - template constexpr inline std::make_unsigned_t> p2roundup(T x, U align) { return (-(-(x) & -(align))); diff --git a/src/os/bluestore/BlueStore.h b/src/os/bluestore/BlueStore.h index f0b6bc00e9d..da993a8a908 100644 --- a/src/os/bluestore/BlueStore.h +++ b/src/os/bluestore/BlueStore.h @@ -2716,7 +2716,7 @@ public: granularity = ROUND_UP_TO(granularity, min_alloc_size); } - uint64_t entries = P2ROUNDUP(total, granularity) / granularity; + uint64_t entries = p2roundup(total, granularity) / granularity; collections_bfs.resize(entries, bloom_filter(BLOOM_FILTER_SALT_COUNT, BLOOM_FILTER_TABLE_SIZE, diff --git a/src/test/test_intarith.cc b/src/test/test_intarith.cc index ad4487a870a..239222046e3 100644 --- a/src/test/test_intarith.cc +++ b/src/test/test_intarith.cc @@ -63,20 +63,20 @@ TEST(intarith, ctz) { } TEST(intarith, p2family) { - ASSERT_TRUE(ISP2(0x100)); - ASSERT_FALSE(ISP2(0x1234)); + ASSERT_TRUE(isp2(0x100)); + ASSERT_FALSE(isp2(0x1234)); - ASSERT_EQ(1024, P2ALIGN(1200, 1024)); - ASSERT_EQ(1024, P2ALIGN(1024, 1024)); - ASSERT_EQ(0x1200, P2ALIGN(0x1234, 0x100)); - ASSERT_EQ(0x5600, P2ALIGN(0x5600, 0x100)); + ASSERT_EQ(1024, p2align(1200, 1024)); + ASSERT_EQ(1024, p2align(1024, 1024)); + ASSERT_EQ(0x1200, p2align(0x1234, 0x100)); + ASSERT_EQ(0x5600, p2align(0x5600, 0x100)); - ASSERT_EQ(0x34, P2PHASE(0x1234, 0x100)); - ASSERT_EQ(0x00, P2PHASE(0x5600, 0x100)); + ASSERT_EQ(0x34, p2phase(0x1234, 0x100)); + ASSERT_EQ(0x00, p2phase(0x5600, 0x100)); - ASSERT_EQ(0xcc, P2NPHASE(0x1234, 0x100)); - ASSERT_EQ(0x00, P2NPHASE(0x5600, 0x100)); + ASSERT_EQ(0xcc, p2nphase(0x1234, 0x100)); + ASSERT_EQ(0x00, p2nphase(0x5600, 0x100)); - ASSERT_EQ(0x1300, P2ROUNDUP(0x1234, 0x100)); - ASSERT_EQ(0x5600, P2ROUNDUP(0x5600, 0x100)); + ASSERT_EQ(0x1300, p2roundup(0x1234, 0x100)); + ASSERT_EQ(0x5600, p2roundup(0x5600, 0x100)); } From 955d79c6e07c1834e6381a8c00accb3f5319f8c3 Mon Sep 17 00:00:00 2001 From: xie xingguo Date: Wed, 28 Mar 2018 14:19:49 +0800 Subject: [PATCH 2/2] intarith: get rid of ROUND_UP* macros Signed-off-by: xie xingguo --- src/include/intarith.h | 12 ------------ src/os/bluestore/BlueStore.h | 4 ++-- 2 files changed, 2 insertions(+), 14 deletions(-) diff --git a/src/include/intarith.h b/src/include/intarith.h index e08cbc0e4f2..242056e216f 100644 --- a/src/include/intarith.h +++ b/src/include/intarith.h @@ -17,29 +17,17 @@ #include -#ifndef DIV_ROUND_UP -#define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d)) -#endif - template constexpr inline std::make_unsigned_t> div_round_up(T n, U d) { return (n + d - 1) / d; } -#ifndef ROUND_UP_TO -#define ROUND_UP_TO(n, d) ((n)%(d) ? ((n)+(d)-(n)%(d)) : (n)) -#endif - template constexpr inline std::make_unsigned_t> round_up_to(T n, U d) { return (n % d ? (n + d - n % d) : n); } -#ifndef SHIFT_ROUND_UP -#define SHIFT_ROUND_UP(x,y) (((x)+(1<<(y))-1) >> (y)) -#endif - template constexpr inline std::make_unsigned_t> shift_round_up(T x, U y) { return (x + (1 << y) - 1) >> y; diff --git a/src/os/bluestore/BlueStore.h b/src/os/bluestore/BlueStore.h index da993a8a908..d31d8220b12 100644 --- a/src/os/bluestore/BlueStore.h +++ b/src/os/bluestore/BlueStore.h @@ -2707,13 +2707,13 @@ public: assert(min_alloc_size && isp2(min_alloc_size)); assert(mem_cap); - total = ROUND_UP_TO(total, min_alloc_size); + total = round_up_to(total, min_alloc_size); granularity = total * BLOOM_FILTER_TABLE_SIZE * 2 / mem_cap; if (!granularity) { granularity = min_alloc_size; } else { - granularity = ROUND_UP_TO(granularity, min_alloc_size); + granularity = round_up_to(granularity, min_alloc_size); } uint64_t entries = p2roundup(total, granularity) / granularity;