diff --git a/src/library/CMakeLists.txt b/src/library/CMakeLists.txt index 96fed21fca..a1f8aeb527 100644 --- a/src/library/CMakeLists.txt +++ b/src/library/CMakeLists.txt @@ -1,3 +1,7 @@ +if (YDB_SDK_TESTS) + add_subdirectory(benchmark) +endif() + add_subdirectory(grpc/client) add_subdirectory(json_value) add_subdirectory(jwt) diff --git a/src/library/benchmark/CMakeLists.txt b/src/library/benchmark/CMakeLists.txt new file mode 100644 index 0000000000..90a15166bf --- /dev/null +++ b/src/library/benchmark/CMakeLists.txt @@ -0,0 +1 @@ +_ydb_sdk_add_library(benchmark-clobber INTERFACE) diff --git a/src/library/benchmark/clobber.h b/src/library/benchmark/clobber.h new file mode 100644 index 0000000000..f8ce28a3f1 --- /dev/null +++ b/src/library/benchmark/clobber.h @@ -0,0 +1,26 @@ +#pragma once + +#include + +namespace NBench { + +/** + * Functions that states "I can read and write everywhere in memory". + * + * Use it to prevent optimizer from reordering or discarding memory writes prior + * to it's call, and force memory reads after it's call. + */ +Y_FORCE_INLINE void Clobber() { +#if defined(__GNUC__) + asm volatile("" + : + : + : "memory"); +#elif defined(_MSC_VER) + _ReadWriteBarrier(); +#else + // Otherwise, do nothing +#endif +} + +} // namespace NBench diff --git a/util/CMakeLists.txt b/util/CMakeLists.txt index a4bddaca3f..994e5163a2 100644 --- a/util/CMakeLists.txt +++ b/util/CMakeLists.txt @@ -310,12 +310,7 @@ if (YDB_SDK_TESTS) system/thread_ut.cpp system/types_ut.cpp - - # TODO: add library/cpp/testing/benchmark - # depends only on NBench::Clobber, that's a memory optimization barrier - # system/unaligned_mem_ut.cpp system/user_ut.cpp - system/yassert_ut.cpp LINK_LIBRARIES yutil @@ -324,6 +319,19 @@ if (YDB_SDK_TESTS) unit ) + add_ydb_test(NAME util-system-unaligned_mem_ut + WORKING_DIRECTORY + ${CMAKE_CURRENT_BINARY_DIR}/system + SOURCES + system/unaligned_mem_ut.cpp + LINK_LIBRARIES + yutil + benchmark-clobber + cpp-testing-unittest_main + LABELS + unit + ) + add_ydb_test(NAME util-system-fstat_ut WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/system diff --git a/util/system/unaligned_mem_ut.cpp b/util/system/unaligned_mem_ut.cpp index 9de3f3e931..ac135752aa 100644 --- a/util/system/unaligned_mem_ut.cpp +++ b/util/system/unaligned_mem_ut.cpp @@ -1,6 +1,6 @@ #include "unaligned_mem.h" -#include +#include #include #include