@ -22,6 +22,11 @@
# define ROCKSDB_FIELD_UNUSED
# define ROCKSDB_FIELD_UNUSED
# endif // __clang__
# endif // __clang__
# ifndef STRINGIFY
# define STRINGIFY(x) #x
# define TOSTRING(x) STRINGIFY(x)
# endif
namespace rocksdb {
namespace rocksdb {
enum TickersInternal : uint32_t {
enum TickersInternal : uint32_t {
@ -35,7 +40,7 @@ enum HistogramsInternal : uint32_t {
} ;
} ;
class StatisticsImpl : public Statistics {
class ALIGN_AS ( CACHE_LINE_SIZE ) StatisticsImpl : public Statistics {
public :
public :
StatisticsImpl ( std : : shared_ptr < Statistics > stats ,
StatisticsImpl ( std : : shared_ptr < Statistics > stats ,
bool enable_internal_stats ) ;
bool enable_internal_stats ) ;
@ -69,17 +74,23 @@ class StatisticsImpl : public Statistics {
// cores can never share the same cache line.
// cores can never share the same cache line.
//
//
// Alignment attributes expand to nothing depending on the platform
// Alignment attributes expand to nothing depending on the platform
struct StatisticsData {
struct ALIGN_AS ( CACHE_LINE_SIZE ) StatisticsData {
std : : atomic_uint_fast64_t tickers_ [ INTERNAL_TICKER_ENUM_MAX ] = { { 0 } } ;
std : : atomic_uint_fast64_t tickers_ [ INTERNAL_TICKER_ENUM_MAX ] = { { 0 } } ;
HistogramImpl histograms_ [ INTERNAL_HISTOGRAM_ENUM_MAX ] ;
HistogramImpl histograms_ [ INTERNAL_HISTOGRAM_ENUM_MAX ] ;
# ifndef HAVE_ALIGNED_NEW
char
char
padding [ ( CACHE_LINE_SIZE -
padding [ ( CACHE_LINE_SIZE -
( INTERNAL_TICKER_ENUM_MAX * sizeof ( std : : atomic_uint_fast64_t ) +
( INTERNAL_TICKER_ENUM_MAX * sizeof ( std : : atomic_uint_fast64_t ) +
INTERNAL_HISTOGRAM_ENUM_MAX * sizeof ( HistogramImpl ) ) %
INTERNAL_HISTOGRAM_ENUM_MAX * sizeof ( HistogramImpl ) ) %
CACHE_LINE_SIZE ) ] ROCKSDB_FIELD_UNUSED ;
CACHE_LINE_SIZE ) ] ROCKSDB_FIELD_UNUSED ;
# endif
void * operator new ( size_t s ) { return port : : cacheline_aligned_alloc ( s ) ; }
void * operator new [ ] ( size_t s ) { return port : : cacheline_aligned_alloc ( s ) ; }
void operator delete ( void * p ) { port : : cacheline_aligned_free ( p ) ; }
void operator delete [ ] ( void * p ) { port : : cacheline_aligned_free ( p ) ; }
} ;
} ;
static_assert ( sizeof ( StatisticsData ) % 64 = = 0 , " Expected 64-byte aligned " ) ;
static_assert ( sizeof ( StatisticsData ) % CACHE_LINE_SIZE = = 0 , " Expected " TOSTRING ( CACHE_LINE_SIZE ) " -byte aligned " ) ;
CoreLocalArray < StatisticsData > per_core_stats_ ;
CoreLocalArray < StatisticsData > per_core_stats_ ;