cpp atomic: define to 1 which is saner

This commit is contained in:
Ciro Santilli 六四事件 法轮功
2019-11-15 00:00:00 +00:00
parent 175b0e3d50
commit d82e47e9d2
9 changed files with 20 additions and 18 deletions

View File

@@ -11097,6 +11097,8 @@ dhrystone
===== BST vs heap vs hashmap ===== BST vs heap vs hashmap
TODO: move benchmark graph from link:userland/cpp/bst_vs_heap_vs_hashmap.cpp[] to link:userland/algorithm/set[].
The following benchmark setup works both: The following benchmark setup works both:
* on host through timers + https://stackoverflow.com/questions/51952471/why-do-i-get-a-constant-instead-of-logarithmic-curve-for-an-insert-time-benchmar/51953081#51953081[granule] * on host through timers + https://stackoverflow.com/questions/51952471/why-do-i-get-a-constant-instead-of-logarithmic-curve-for-an-insert-time-benchmar/51953081#51953081[granule]

View File

@@ -1,2 +1,2 @@
#define LKMC_USERLAND_ATOMIC_AARCH64_ADD #define LKMC_USERLAND_ATOMIC_AARCH64_ADD 1
#include "main.hpp" #include "main.hpp"

View File

@@ -1,2 +1,2 @@
#define LKMC_USERLAND_ATOMIC_AARCH64_LDADD #define LKMC_USERLAND_ATOMIC_AARCH64_LDADD 1
#include "main.hpp" #include "main.hpp"

View File

@@ -1,2 +1,2 @@
#define LKMC_USERLAND_ATOMIC_FAIL #define LKMC_USERLAND_ATOMIC_FAIL 1
#include "main.hpp" #include "main.hpp"

View File

@@ -10,29 +10,29 @@
size_t niters; size_t niters;
#if defined(LKMC_USERLAND_ATOMIC_STD_ATOMIC) #if LKMC_USERLAND_ATOMIC_STD_ATOMIC
std::atomic_ulong global(0); std::atomic_ulong global(0);
#else #else
uint64_t global = 0; uint64_t global = 0;
#endif #endif
#if defined(LKMC_USERLAND_ATOMIC_MUTEX) #if LKMC_USERLAND_ATOMIC_MUTEX
std::mutex mutex; std::mutex mutex;
#endif #endif
void threadMain() { void threadMain() {
for (size_t i = 0; i < niters; ++i) { for (size_t i = 0; i < niters; ++i) {
#if defined(LKMC_USERLAND_ATOMIC_MUTEX) #if LKMC_USERLAND_ATOMIC_MUTEX
mutex.lock(); mutex.lock();
#endif #endif
#if defined(LKMC_USERLAND_ATOMIC_X86_64_INC) #if LKMC_USERLAND_ATOMIC_X86_64_INC
__asm__ __volatile__ ( __asm__ __volatile__ (
"incq %0;" "incq %0;"
: "+g" (global) : "+g" (global)
: :
: :
); );
#elif defined(LKMC_USERLAND_ATOMIC_X86_64_LOCK_INC) #elif LKMC_USERLAND_ATOMIC_X86_64_LOCK_INC
// https://cirosantilli.com/linux-kernel-module-cheat#x86-lock-prefix // https://cirosantilli.com/linux-kernel-module-cheat#x86-lock-prefix
__asm__ __volatile__ ( __asm__ __volatile__ (
"lock;" "lock;"
@@ -41,14 +41,14 @@ void threadMain() {
: :
: :
); );
#elif defined(LKMC_USERLAND_ATOMIC_AARCH64_ADD) #elif LKMC_USERLAND_ATOMIC_AARCH64_ADD
__asm__ __volatile__ ( __asm__ __volatile__ (
"add %0, %0, 1;" "add %0, %0, 1;"
: "+r" (global) : "+r" (global)
: :
: :
); );
#elif defined(LKMC_USERLAND_ATOMIC_AARCH64_LDADD) #elif LKMC_USERLAND_ATOMIC_AARCH64_LDADD
// https://cirosantilli.com/linux-kernel-module-cheat#arm-lse // https://cirosantilli.com/linux-kernel-module-cheat#arm-lse
__asm__ __volatile__ ( __asm__ __volatile__ (
"ldadd %[inc], xzr, [%[addr]];" "ldadd %[inc], xzr, [%[addr]];"
@@ -60,7 +60,7 @@ void threadMain() {
#else #else
global++; global++;
#endif #endif
#if defined(LKMC_USERLAND_ATOMIC_MUTEX) #if LKMC_USERLAND_ATOMIC_MUTEX
mutex.unlock(); mutex.unlock();
#endif #endif
#if 0 #if 0
@@ -88,9 +88,9 @@ int main(int argc, char **argv) {
for (size_t i = 0; i < nthreads; ++i) for (size_t i = 0; i < nthreads; ++i)
threads[i].join(); threads[i].join();
uint64_t expect = nthreads * niters; uint64_t expect = nthreads * niters;
#if defined(LKMC_USERLAND_ATOMIC_FAIL) || \ #if LKMC_USERLAND_ATOMIC_FAIL || \
defined(LKMC_USERLAND_ATOMIC_X86_64_INC) || \ LKMC_USERLAND_ATOMIC_X86_64_INC || \
defined(LKMC_USERLAND_ATOMIC_AARCH64_INC) LKMC_USERLAND_ATOMIC_AARCH64_INC
// These fail, so we just print the outcomes. // These fail, so we just print the outcomes.
std::cout << "expect " << expect << std::endl; std::cout << "expect " << expect << std::endl;
std::cout << "global " << global << std::endl; std::cout << "global " << global << std::endl;

View File

@@ -1,2 +1,2 @@
#define LKMC_USERLAND_ATOMIC_MUTEX #define LKMC_USERLAND_ATOMIC_MUTEX 1
#include "main.hpp" #include "main.hpp"

View File

@@ -1,2 +1,2 @@
#define LKMC_USERLAND_ATOMIC_STD_ATOMIC #define LKMC_USERLAND_ATOMIC_STD_ATOMIC 1
#include "main.hpp" #include "main.hpp"

View File

@@ -1,2 +1,2 @@
#define LKMC_USERLAND_ATOMIC_X86_64_INC #define LKMC_USERLAND_ATOMIC_X86_64_INC 1
#include "main.hpp" #include "main.hpp"

View File

@@ -1,2 +1,2 @@
#define LKMC_USERLAND_ATOMIC_X86_64_LOCK_INC #define LKMC_USERLAND_ATOMIC_X86_64_LOCK_INC 1
#include "main.hpp" #include "main.hpp"