Skip to content

C11 atomics backport - #664

Merged
davidtgoldblatt merged 2 commits into
jemalloc:devfrom
davidtgoldblatt:atomics
Mar 3, 2017
Merged

davidtgoldblatt merged 2 commits into
jemalloc:devfrom
davidtgoldblatt:atomics

Conversation

@davidtgoldblatt

Copy link
Copy Markdown
Contributor

2 commits:

  • One that stops us from #define-ing away "inline" (which isn't used elsewhere in the codebase, so this is a no-op).
  • A C11 atomics backport.

The only API change for these atomics vs. C11 atomics is that C11 has two versions of every function:
atomic_store(dest, val);
and
atomic_store_explicit(dest, val, memory_order);
with the former giving sequential consistency, and the latter allowing more complicated ordering decisions.

I figured we'll always care enough about performance and specificity to prefer explicit ordering, so these only define the latter, and drop the _explicit suffix, so that we always have to specify the memory order. I could be persuaded that we should include both versions of every function, though.

Ideas for better testing strategies are appreciated. I'm thinking about setting up QEMU bots for ARM and POWER.

In the long term, we'll transition to C99-style inline semantics.  In the
short-term, this will allow both styles to coexist without breaking one another.
@davidtgoldblatt

Copy link
Copy Markdown
Contributor Author

Hmm, none of my testing hit the C++14 case, and stdatomic.h can't even be #include'd without error. I'll make C11-atomics the option of last resort.

@davidtgoldblatt
davidtgoldblatt force-pushed the atomics branch 2 times, most recently from a3ea3f0 to 54c0771 Compare March 1, 2017 00:29
@davidlt

davidlt commented Mar 1, 2017

Copy link
Copy Markdown

This seems to solve my problems compiling jemalloc (dev, 379dd44) on aarch64, CentOS 7.3, GCC 7.0.1.

To get it compiling on 379dd44 I had to add:

diff --git a/src/jemalloc_cpp.cpp b/src/jemalloc_cpp.cpp
index 9692b5b..0e3a5fe 100644
--- a/src/jemalloc_cpp.cpp
+++ b/src/jemalloc_cpp.cpp
@@ -1,5 +1,8 @@
 #include <mutex>
 #include <new>
+#include <atomic>
+
+using namespace std;

 #define JEMALLOC_CPP_CPP_
 #include "jemalloc/internal/jemalloc_internal.h"

@jasone jasone left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks really good overall. There are lots of niggly details that I'm just assuming you got right, especially with regard to memory ordering.

In summary:
s/implementationd/implementations/

The AppVeyor build logs suggest there are missing casts. Once you have that sorted out along with the various style nits, I'll pull the diff and give it one more look in a text editor.

#elif defined(JEMALLOC_C11_ATOMICS)
# include "jemalloc/internal/atomic_c11.h"
#else
# error "Don't have atomics implemented on this platform."

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quotes are unnecessary around #error args. We aren't currently consistent about this, but I try to omit the quotes on new code.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This broke with one of the compilers I tested on because of the apostrophe.

Comment thread include/jemalloc/internal/atomic.h Outdated
* counterparts of the C11 atomic functions for type, as so:
* JEMALLOC_GENERATE_ATOMICS(int *, pi, 3);
* and then write things like:
* int* some_ptr;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style nit (here and one more below): int *some_ptr

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Comment thread include/jemalloc/internal/atomic.h Outdated
* In order to let us transition atomics usage piecemeal (and reason locally
* about memory orders), we'll support the previous API for a while.
*/
#define JEMALLOC_GENERATE_COMPATABILITY_ATOMICS(type, short_type) \

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something looks weird with regard to the tab-aligned (?) backslash continuation throughout this diff.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this is github formatting things weirdly. These were all done via vim macro to insert spaces up to virtcol 80, assuming a tab is exactly 8 characters wide.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, so the style for multi-line macro definitions is to use tabs rather than spaces to put the continuation character at column 72.

@davidtgoldblatt davidtgoldblatt Mar 2, 2017 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Recording the vimscript incantation here so I don't forget how to do it later:

s@\s*\\$@\=repeat('^I', (80-virtcol('.'))/8).'\'@

Comment thread include/jemalloc/internal/atomic.h Outdated
ATOMIC_SEQ_CST); \
} \
/* \
* We use '3' below, since the implementation header might have used '1' and \

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe simplify by just not allowing terminating semicolons?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Comment thread include/jemalloc/internal/atomic.h Outdated
typedef struct { \
char c; \
} atomic_allow_terminating_semicolon4_##short_type

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extraneous blank line.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

case atomic_memory_order_seq_cst:
return __ATOMIC_SEQ_CST;
}
/* Can't actually happen. */

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add not_reached() here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... and, broke the build in the process. It's tricky to use a non-hermetic header from a hermetic one. What do you think about delaying until after the header refactoring?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Heh, totally fine to swap order.

#define ATOMIC_INTERLOCKED_SUFFIX_1 16
#define ATOMIC_INTERLOCKED_SUFFIX_2
#define ATOMIC_INTERLOCKED_SUFFIX_3 64

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extraneous blank line.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@@ -74,26 +74,6 @@ arena_tdata_get
arena_tdata_get_hard
arenas
arenas_tdata_cleanup

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This diff makes it so that we no longer have any non-inline library-internal functions which need name mangling, right?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, now that you mention it, no; this diff generated externally visible symbols. Fixed.

Comment thread test/unit/atomic.c Outdated
TEST_STRUCT(unsigned, u);
TEST_BEGIN(test_atomic_u) {
TEST_BODY(u, unsigned, unsigned, u, "#x");
TEST_BODY(unsigned, u);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why isn't this one INTEGER_TEST_BODY()?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, it should be. Fixed.

Comment thread test/unit/atomic.c Outdated
val = atomic_load_##ta(&atom, ATOMIC_RELAXED); \
assert_##ta##_eq(val2, val, "Exchange store invalid value"); \
\
/* Weak CAS. Spurious failures are allowed, so we loop a few times. */\

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, are we going to have intermittent test failures as a result of this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not meaningfully. This only matters for LL/SC architectures in screwy situations (e.g. taking an interrupt in between the load and store components of the CAS). This is more a theoretical possibility than a real one.

@davidtgoldblatt

Copy link
Copy Markdown
Contributor Author

The warnings about signed vs. unsigned are unfortunate, because we don't necessarily know the signed version of the type; we'd have to pass it in as another macro argument. What do you think about just pragma-ing out the warning on MSVC?

@jasone

jasone commented Mar 1, 2017

Copy link
Copy Markdown
Member

Re: the MSVC warnings, if you can get the pragma approach to work, go for it.

@davidtgoldblatt
davidtgoldblatt force-pushed the atomics branch 5 times, most recently from 696a973 to f31833c Compare March 2, 2017 22:49
@davidtgoldblatt

Copy link
Copy Markdown
Contributor Author

@davidlt, I believe the most recent version of the pull request should work on ARM if you've got a second to test. I tried it out on qemu, but in a different enough system that independent verification would be encouraging.

@davidlt

davidlt commented Mar 3, 2017

Copy link
Copy Markdown

@davidtgoldblatt I did some tests and results are below. Your PR allows it to compile, while the current tip of dev branch does not compile out of the box.

I already reported Huge Page issue: #669

I noticed that GCC 7.0.1 and --enable-prof cause one unit test to fail.

I doubt any of these are related.

I also have ability to test on ppc64le.

./configure (GCC 4.8.5, ld 2.25.1-22.base.el7, CentOS 7.3.1611 [last update 2017-03-03], kernel 4.5.0-22.el7.aarch64)

Test suite summary: pass: 36/45, skip: 8/45, fail: 1/45

=== test/unit/pages ===
test_pages_huge:test/unit/pages.c:15: Failed assertion: (pages_huge(hugepage, HUGEPAGE)) != (have_thp) --> true == true: Unexpected pages_huge() result
test_pages_huge:test/unit/pages.c:17: Failed assertion: (jet_pages_nohuge(hugepage, ((size_t)(1U << 29)))) == (false) --> true != false: Unexpected pages_nohuge() result
test_pages_huge: fail
--- pass: 0/1, skip: 0/1, fail: 1/1 ---

./configure --enable-prof (GCC 4.8.5, ld 2.25.1-22.base.el7, CentOS 7.3.1611 [last update 2017-03-03], kernel 4.5.0-22.el7.aarch64)

Test suite summary: pass: 44/46, skip: 1/46, fail: 1/46

=== test/unit/pages ===
test_pages_huge:test/unit/pages.c:15: Failed assertion: (pages_huge(hugepage, HUGEPAGE)) != (have_thp) --> true == true: Unexpected pages_huge() result
test_pages_huge:test/unit/pages.c:17: Failed assertion: (jet_pages_nohuge(hugepage, ((size_t)(1U << 29)))) == (false) --> true != false: Unexpected pages_nohuge() result
test_pages_huge: fail
--- pass: 0/1, skip: 0/1, fail: 1/1 ---

./configure CC="gcc" CXX="g++" (GCC 7.0.1 [20170225], ld 2.27, CentOS 7.3.1611 [last update 2017-03-03], kernel 4.5.0-22.el7.aarch64)

Test suite summary: pass: 36/45, skip: 8/45, fail: 1/45

=== test/unit/pages ===
test_pages_huge:test/unit/pages.c:15: Failed assertion: (pages_huge(hugepage, HUGEPAGE)) != (have_thp) --> true == true: Unexpected pages_huge() result
test_pages_huge:test/unit/pages.c:17: Failed assertion: (jet_pages_nohuge(hugepage, ((size_t)(1U << 29)))) == (false) --> true != false: Unexpected pages_nohuge() result
test_pages_huge: fail
--- pass: 0/1, skip: 0/1, fail: 1/1 ---

./configure --enable-prof CC="gcc" CXX="g++" (GCC 7.0.1 [20170225], ld 2.27, CentOS 7.3.1611 [last update 2017-03-03], kernel 4.5.0-22.el7.aarch64)

Test suite summary: pass: 43/46, skip: 1/46, fail: 2/46

=== test/unit/pages ===
test_pages_huge:test/unit/pages.c:15: Failed assertion: (pages_huge(hugepage, HUGEPAGE)) != (have_thp) --> true == true: Unexpected pages_huge() result
test_pages_huge:test/unit/pages.c:17: Failed assertion: (jet_pages_nohuge(hugepage, ((size_t)(1U << 29)))) == (false) --> true != false: Unexpected pages_nohuge() result
test_pages_huge: fail
--- pass: 0/1, skip: 0/1, fail: 1/1 ---

=== test/unit/prof_accum ===
thd_start:test/unit/prof_accum.c:43: Failed assertion: (bt_count_prev+(i-i_prev)) <= (bt_count) --> 6 > 1: Expected larger backtrace count increase
thd_start:test/unit/prof_accum.c:43: Failed assertion: (bt_count_prev+(i-i_prev)) <= (bt_count) --> 6 > 1: Expected larger backtrace count increase
thd_start:test/unit/prof_accum.c:43: Failed assertion: (bt_count_prev+(i-i_prev)) <= (bt_count) --> 6 > 1: Expected larger backtrace count increase
thd_start:test/unit/prof_accum.c:43: Failed assertion: (bt_count_prev+(i-i_prev)) <= (bt_count) --> 6 > 1: Expected larger backtrace count increase
thd_start:test/unit/prof_accum.c:43: Failed assertion: (bt_count_prev+(i-i_prev)) <= (bt_count) --> 6 > 1: Expected larger backtrace count increase
thd_start:test/unit/prof_accum.c:43: Failed assertion: (bt_count_prev+(i-i_prev)) <= (bt_count) --> 6 > 1: Expected larger backtrace count increase
thd_start:test/unit/prof_accum.c:43: Failed assertion: (bt_count_prev+(i-i_prev)) <= (bt_count) --> 6 > 1: Expected larger backtrace count increase
thd_start:test/unit/prof_accum.c:43: Failed assertion: (bt_count_prev+(i-i_prev)) <= (bt_count) --> 6 > 1: Expected larger backtrace count increase
thd_start:test/unit/prof_accum.c:43: Failed assertion: (bt_count_prev+(i-i_prev)) <= (bt_count) --> 6 > 1: Expected larger backtrace count increase
thd_start:test/unit/prof_accum.c:43: Failed assertion: (bt_count_prev+(i-i_prev)) <= (bt_count) --> 6 > 1: Expected larger backtrace count increase
thd_start:test/unit/prof_accum.c:43: Failed assertion: (bt_count_prev+(i-i_prev)) <= (bt_count) --> 6 > 1: Expected larger backtrace count increase
thd_start:test/unit/prof_accum.c:43: Failed assertion: (bt_count_prev+(i-i_prev)) <= (bt_count) --> 6 > 1: Expected larger backtrace count increase
thd_start:test/unit/prof_accum.c:43: Failed assertion: (bt_count_prev+(i-i_prev)) <= (bt_count) --> 6 > 1: Expected larger backtrace count increase
thd_start:test/unit/prof_accum.c:43: Failed assertion: (bt_count_prev+(i-i_prev)) <= (bt_count) --> 6 > 1: Expected larger backtrace count increase
thd_start:test/unit/prof_accum.c:43: Failed assertion: (bt_count_prev+(i-i_prev)) <= (bt_count) --> 6 > 1: Expected larger backtrace count increase
thd_start:test/unit/prof_accum.c:43: Failed assertion: (bt_count_prev+(i-i_prev)) <= (bt_count) --> 6 > 1: Expected larger backtrace count increase
thd_start:test/unit/prof_accum.c:43: Failed assertion: (bt_count_prev+(i-i_prev)) <= (bt_count) --> 6 > 1: Expected larger backtrace count increase
thd_start:test/unit/prof_accum.c:43: Failed assertion: (bt_count_prev+(i-i_prev)) <= (bt_count) --> 6 > 1: Expected larger backtrace count increase
thd_start:test/unit/prof_accum.c:43: Failed assertion: (bt_count_prev+(i-i_prev)) <= (bt_count) --> 6 > 1: Expected larger backtrace count increase
thd_start:test/unit/prof_accum.c:43: Failed assertion: (bt_count_prev+(i-i_prev)) <= (bt_count) --> 6 > 1: Expected larger backtrace count increase
thd_start:test/unit/prof_accum.c:43: Failed assertion: (bt_count_prev+(i-i_prev)) <= (bt_count) --> 6 > 1: Expected larger backtrace count increase
thd_start:test/unit/prof_accum.c:43: Failed assertion: (bt_count_prev+(i-i_prev)) <= (bt_count) --> 6 > 1: Expected larger backtrace count increase
thd_start:test/unit/prof_accum.c:43: Failed assertion: (bt_count_prev+(i-i_prev)) <= (bt_count) --> 6 > 1: Expected larger backtrace count increase
thd_start:test/unit/prof_accum.c:43: Failed assertion: (bt_count_prev+(i-i_prev)) <= (bt_count) --> 6 > 1: Expected larger backtrace count increase
thd_start:test/unit/prof_accum.c:43: Failed assertion: (bt_count_prev+(i-i_prev)) <= (bt_count) --> 6 > 1: Expected larger backtrace count increase
thd_start:test/unit/prof_accum.c:43: Failed assertion: (bt_count_prev+(i-i_prev)) <= (bt_count) --> 6 > 1: Expected larger backtrace count increase
thd_start:test/unit/prof_accum.c:43: Failed assertion: (bt_count_prev+(i-i_prev)) <= (bt_count) --> 6 > 1: Expected larger backtrace count increase
thd_start:test/unit/prof_accum.c:43: Failed assertion: (bt_count_prev+(i-i_prev)) <= (bt_count) --> 6 > 1: Expected larger backtrace count increase
thd_start:test/unit/prof_accum.c:43: Failed assertion: (bt_count_prev+(i-i_prev)) <= (bt_count) --> 6 > 1: Expected larger backtrace count increase
thd_start:test/unit/prof_accum.c:43: Failed assertion: (bt_count_prev+(i-i_prev)) <= (bt_count) --> 6 > 1: Expected larger backtrace count increase
thd_start:test/unit/prof_accum.c:43: Failed assertion: (bt_count_prev+(i-i_prev)) <= (bt_count) --> 6 > 1: Expected larger backtrace count increase
thd_start:test/unit/prof_accum.c:43: Failed assertion: (bt_count_prev+(i-i_prev)) <= (bt_count) --> 6 > 1: Expected larger backtrace count increase
thd_start:test/unit/prof_accum.c:43: Failed assertion: (bt_count_prev+(i-i_prev)) <= (bt_count) --> 6 > 1: Expected larger backtrace count increase
thd_start:test/unit/prof_accum.c:43: Failed assertion: (bt_count_prev+(i-i_prev)) <= (bt_count) --> 6 > 1: Expected larger backtrace count increase
thd_start:test/unit/prof_accum.c:43: Failed assertion: (bt_count_prev+(i-i_prev)) <= (bt_count) --> 6 > 1: Expected larger backtrace count increase
thd_start:test/unit/prof_accum.c:43: Failed assertion: (bt_count_prev+(i-i_prev)) <= (bt_count) --> 6 > 1: Expected larger backtrace count increase
thd_start:test/unit/prof_accum.c:43: Failed assertion: (bt_count_prev+(i-i_prev)) <= (bt_count) --> 5 > 1: Expected larger backtrace count increase
thd_start:test/unit/prof_accum.c:43: Failed assertion: (bt_count_prev+(i-i_prev)) <= (bt_count) --> 5 > 1: Expected larger backtrace count increase
thd_start:test/unit/prof_accum.c:43: Failed assertion: (bt_count_prev+(i-i_prev)) <= (bt_count) --> 5 > 1: Expected larger backtrace count increase
thd_start:test/unit/prof_accum.c:43: Failed assertion: (bt_count_prev+(i-i_prev)) <= (bt_count) --> 5 > 1: Expected larger backtrace count increase
test_idump: fail
--- pass: 0/1, skip: 0/1, fail: 1/1 ---

./configure CC="clang" CXX="clang++" (LLVM/Clang 4.0.0 RC2, GCC 7.0.1 [20170225], ld 2.27, CentOS 7.3.1611 [last update 2017-03-03], kernel 4.5.0-22.el7.aarch64)

Test suite summary: pass: 36/45, skip: 8/45, fail: 1/45

=== test/unit/pages ===
test_pages_huge:test/unit/pages.c:15: Failed assertion: (pages_huge(hugepage, HUGEPAGE)) != (have_thp) --> true == true: Unexpected pages_huge() result
test_pages_huge:test/unit/pages.c:17: Failed assertion: (jet_pages_nohuge(hugepage, ((size_t)(1U << 29)))) == (false) --> true != false: Unexpected pages_nohuge() result
test_pages_huge: fail
--- pass: 0/1, skip: 0/1, fail: 1/1 ---

./configure --enable-prof CC="clang" CXX="clang++" (LLVM/Clang 4.0.0 RC2, GCC 7.0.1 [20170225], ld 2.27, CentOS 7.3.1611 [last update 2017-03-03], kernel 4.5.0-22.el7.aarch64)

Test suite summary: pass: 43/46, skip: 1/46, fail: 2/46

=== test/unit/pages ===
test_pages_huge:test/unit/pages.c:15: Failed assertion: (pages_huge(hugepage, HUGEPAGE)) != (have_thp) --> true == true: Unexpected pages_huge() result
test_pages_huge:test/unit/pages.c:17: Failed assertion: (jet_pages_nohuge(hugepage, ((size_t)(1U << 29)))) == (false) --> true != false: Unexpected pages_nohuge() result
test_pages_huge: fail
--- pass: 0/1, skip: 0/1, fail: 1/1 ---

=== test/unit/prof_accum ===
thd_start:test/unit/prof_accum.c:43: Failed assertion: (bt_count_prev+(i-i_prev)) <= (bt_count) --> 6 > 1: Expected larger backtrace count increase
thd_start:test/unit/prof_accum.c:43: Failed assertion: (bt_count_prev+(i-i_prev)) <= (bt_count) --> 6 > 1: Expected larger backtrace count increase
thd_start:test/unit/prof_accum.c:43: Failed assertion: (bt_count_prev+(i-i_prev)) <= (bt_count) --> 6 > 1: Expected larger backtrace count increase
thd_start:test/unit/prof_accum.c:43: Failed assertion: (bt_count_prev+(i-i_prev)) <= (bt_count) --> 6 > 1: Expected larger backtrace count increase
thd_start:test/unit/prof_accum.c:43: Failed assertion: (bt_count_prev+(i-i_prev)) <= (bt_count) --> 6 > 1: Expected larger backtrace count increase
thd_start:test/unit/prof_accum.c:43: Failed assertion: (bt_count_prev+(i-i_prev)) <= (bt_count) --> 6 > 1: Expected larger backtrace count increase
thd_start:test/unit/prof_accum.c:43: Failed assertion: (bt_count_prev+(i-i_prev)) <= (bt_count) --> 6 > 1: Expected larger backtrace count increase
thd_start:test/unit/prof_accum.c:43: Failed assertion: (bt_count_prev+(i-i_prev)) <= (bt_count) --> 6 > 1: Expected larger backtrace count increase
thd_start:test/unit/prof_accum.c:43: Failed assertion: (bt_count_prev+(i-i_prev)) <= (bt_count) --> 6 > 1: Expected larger backtrace count increase
thd_start:test/unit/prof_accum.c:43: Failed assertion: (bt_count_prev+(i-i_prev)) <= (bt_count) --> 6 > 1: Expected larger backtrace count increase
thd_start:test/unit/prof_accum.c:43: Failed assertion: (bt_count_prev+(i-i_prev)) <= (bt_count) --> 6 > 1: Expected larger backtrace count increase
thd_start:test/unit/prof_accum.c:43: Failed assertion: (bt_count_prev+(i-i_prev)) <= (bt_count) --> 6 > 1: Expected larger backtrace count increase
thd_start:test/unit/prof_accum.c:43: Failed assertion: (bt_count_prev+(i-i_prev)) <= (bt_count) --> 6 > 1: Expected larger backtrace count increase
thd_start:test/unit/prof_accum.c:43: Failed assertion: (bt_count_prev+(i-i_prev)) <= (bt_count) --> 6 > 1: Expected larger backtrace count increase
thd_start:test/unit/prof_accum.c:43: Failed assertion: (bt_count_prev+(i-i_prev)) <= (bt_count) --> 6 > 1: Expected larger backtrace count increase
thd_start:test/unit/prof_accum.c:43: Failed assertion: (bt_count_prev+(i-i_prev)) <= (bt_count) --> 6 > 1: Expected larger backtrace count increase
thd_start:test/unit/prof_accum.c:43: Failed assertion: (bt_count_prev+(i-i_prev)) <= (bt_count) --> 6 > 1: Expected larger backtrace count increase
thd_start:test/unit/prof_accum.c:43: Failed assertion: (bt_count_prev+(i-i_prev)) <= (bt_count) --> 6 > 1: Expected larger backtrace count increase
thd_start:test/unit/prof_accum.c:43: Failed assertion: (bt_count_prev+(i-i_prev)) <= (bt_count) --> 6 > 1: Expected larger backtrace count increase
thd_start:test/unit/prof_accum.c:43: Failed assertion: (bt_count_prev+(i-i_prev)) <= (bt_count) --> 6 > 1: Expected larger backtrace count increase
thd_start:test/unit/prof_accum.c:43: Failed assertion: (bt_count_prev+(i-i_prev)) <= (bt_count) --> 6 > 1: Expected larger backtrace count increase
thd_start:test/unit/prof_accum.c:43: Failed assertion: (bt_count_prev+(i-i_prev)) <= (bt_count) --> 6 > 1: Expected larger backtrace count increase
thd_start:test/unit/prof_accum.c:43: Failed assertion: (bt_count_prev+(i-i_prev)) <= (bt_count) --> 6 > 1: Expected larger backtrace count increase
thd_start:test/unit/prof_accum.c:43: Failed assertion: (bt_count_prev+(i-i_prev)) <= (bt_count) --> 6 > 1: Expected larger backtrace count increase
thd_start:test/unit/prof_accum.c:43: Failed assertion: (bt_count_prev+(i-i_prev)) <= (bt_count) --> 6 > 1: Expected larger backtrace count increase
thd_start:test/unit/prof_accum.c:43: Failed assertion: (bt_count_prev+(i-i_prev)) <= (bt_count) --> 6 > 1: Expected larger backtrace count increase
thd_start:test/unit/prof_accum.c:43: Failed assertion: (bt_count_prev+(i-i_prev)) <= (bt_count) --> 6 > 1: Expected larger backtrace count increase
thd_start:test/unit/prof_accum.c:43: Failed assertion: (bt_count_prev+(i-i_prev)) <= (bt_count) --> 6 > 1: Expected larger backtrace count increase
thd_start:test/unit/prof_accum.c:43: Failed assertion: (bt_count_prev+(i-i_prev)) <= (bt_count) --> 6 > 1: Expected larger backtrace count increase
thd_start:test/unit/prof_accum.c:43: Failed assertion: (bt_count_prev+(i-i_prev)) <= (bt_count) --> 6 > 1: Expected larger backtrace count increase
thd_start:test/unit/prof_accum.c:43: Failed assertion: (bt_count_prev+(i-i_prev)) <= (bt_count) --> 6 > 1: Expected larger backtrace count increase
thd_start:test/unit/prof_accum.c:43: Failed assertion: (bt_count_prev+(i-i_prev)) <= (bt_count) --> 6 > 1: Expected larger backtrace count increase
thd_start:test/unit/prof_accum.c:43: Failed assertion: (bt_count_prev+(i-i_prev)) <= (bt_count) --> 6 > 1: Expected larger backtrace count increase
thd_start:test/unit/prof_accum.c:43: Failed assertion: (bt_count_prev+(i-i_prev)) <= (bt_count) --> 6 > 1: Expected larger backtrace count increase
thd_start:test/unit/prof_accum.c:43: Failed assertion: (bt_count_prev+(i-i_prev)) <= (bt_count) --> 6 > 1: Expected larger backtrace count increase
thd_start:test/unit/prof_accum.c:43: Failed assertion: (bt_count_prev+(i-i_prev)) <= (bt_count) --> 6 > 1: Expected larger backtrace count increase
thd_start:test/unit/prof_accum.c:43: Failed assertion: (bt_count_prev+(i-i_prev)) <= (bt_count) --> 5 > 1: Expected larger backtrace count increase
thd_start:test/unit/prof_accum.c:43: Failed assertion: (bt_count_prev+(i-i_prev)) <= (bt_count) --> 5 > 1: Expected larger backtrace count increase
thd_start:test/unit/prof_accum.c:43: Failed assertion: (bt_count_prev+(i-i_prev)) <= (bt_count) --> 5 > 1: Expected larger backtrace count increase
thd_start:test/unit/prof_accum.c:43: Failed assertion: (bt_count_prev+(i-i_prev)) <= (bt_count) --> 5 > 1: Expected larger backtrace count increase
test_idump: fail
--- pass: 0/1, skip: 0/1, fail: 1/1 ---

This introduces a backport of C11 atomics.  It has four implementations; ranked
in order of preference, they are:
- GCC/Clang __atomic builtins
- GCC/Clang __sync builtins
- MSVC _Interlocked builtins
- C11 atomics, from <stdatomic.h>

The primary advantages are:
- Close adherence to the standard API gives us a defined memory model.
- Type safety: atomic objects are now separate types from non-atomic ones, so
  that it's impossible to mix up atomic and non-atomic updates (which is
  undefined behavior that compilers are starting to take advantage of).
- Efficiency: we can specify ordering for operations, avoiding fences and
  atomic operations on strongly ordered architectures (example:
  `atomic_write_u32(ptr, val);` involves a CAS loop, whereas
  `atomic_store(ptr, val, ATOMIC_RELEASE);` is a plain store.

This diff leaves in the current atomics API (implementing them in terms of the
backport).  This lets us transition uses over piecemeal.

Testing:
This is by nature hard to test. I've manually tested the first three options on
Linux on gcc by futzing with the #defines manually, on freebsd with gcc and
clang, on MSVC, and on OS X with clang.  All of these were x86 machines though,
and we don't have any test infrastructure set up for non-x86 platforms.

@jasone jasone left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🏆

@davidtgoldblatt

Copy link
Copy Markdown
Contributor Author

Thanks @davidlt and @jasone. The ARM profiling failures are indeed unrelated (the situations in which various forms of profiling are supported are unfortunately not really documented).

@davidtgoldblatt
davidtgoldblatt merged commit d4ac758 into jemalloc:dev Mar 3, 2017
@davidtgoldblatt
davidtgoldblatt deleted the atomics branch April 24, 2017 19:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants