Skip to content

Commit f5d9ed0

Browse files
committed
Add benchmark-clobber library (#296)
1 parent 1c413d2 commit f5d9ed0

File tree

4 files changed

+44
-5
lines changed

4 files changed

+44
-5
lines changed

src/library/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
if (YDB_SDK_TESTS)
2+
add_subdirectory(benchmark)
3+
endif()
4+
15
add_subdirectory(grpc/client)
26
add_subdirectory(json_value)
37
add_subdirectory(jwt)

src/library/benchmark/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
_ydb_sdk_add_library(benchmark-clobber INTERFACE)

src/library/benchmark/clobber.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#pragma once
2+
3+
#include <util/system/compiler.h>
4+
5+
namespace NBench {
6+
7+
/**
8+
* Functions that states "I can read and write everywhere in memory".
9+
*
10+
* Use it to prevent optimizer from reordering or discarding memory writes prior
11+
* to it's call, and force memory reads after it's call.
12+
*/
13+
Y_FORCE_INLINE void Clobber() {
14+
#if defined(__GNUC__)
15+
asm volatile(""
16+
:
17+
:
18+
: "memory");
19+
#elif defined(_MSC_VER)
20+
_ReadWriteBarrier();
21+
#else
22+
// Otherwise, do nothing
23+
#endif
24+
}
25+
26+
} // namespace NBench

util/CMakeLists.txt

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -310,12 +310,7 @@ if (YDB_SDK_TESTS)
310310
system/thread_ut.cpp
311311

312312
system/types_ut.cpp
313-
314-
# TODO: add library/cpp/testing/benchmark
315-
# depends only on NBench::Clobber, that's a memory optimization barrier
316-
# system/unaligned_mem_ut.cpp
317313
system/user_ut.cpp
318-
319314
system/yassert_ut.cpp
320315
LINK_LIBRARIES
321316
yutil
@@ -324,6 +319,19 @@ if (YDB_SDK_TESTS)
324319
unit
325320
)
326321

322+
add_ydb_test(NAME util-system-unaligned_mem_ut
323+
WORKING_DIRECTORY
324+
${CMAKE_CURRENT_BINARY_DIR}/system
325+
SOURCES
326+
system/unaligned_mem_ut.cpp
327+
LINK_LIBRARIES
328+
yutil
329+
benchmark-clobber
330+
cpp-testing-unittest_main
331+
LABELS
332+
unit
333+
)
334+
327335
add_ydb_test(NAME util-system-fstat_ut
328336
WORKING_DIRECTORY
329337
${CMAKE_CURRENT_BINARY_DIR}/system

0 commit comments

Comments
 (0)