Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #296 Fix util/system/unaligned_mem_ut #309

Merged
merged 2 commits into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/library/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
if (YDB_SDK_TESTS)
add_subdirectory(benchmark)
endif()

add_subdirectory(grpc/client)
add_subdirectory(json_value)
add_subdirectory(jwt)
Expand Down
1 change: 1 addition & 0 deletions src/library/benchmark/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
_ydb_sdk_add_library(benchmark-clobber INTERFACE)
26 changes: 26 additions & 0 deletions src/library/benchmark/clobber.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#pragma once

#include <util/system/compiler.h>

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
18 changes: 13 additions & 5 deletions util/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion util/system/unaligned_mem_ut.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "unaligned_mem.h"

#include <library/cpp/testing/benchmark/bench.h>
#include <src/library/benchmark/clobber.h>
#include <library/cpp/testing/unittest/registar.h>

#include <util/system/compiler.h>
Expand Down
Loading