Skip to content
This repository was archived by the owner on Mar 22, 2023. It is now read-only.

Commit 3dabc13

Browse files
committed
mpsc_queue: enbale drd/helgrind tests
1 parent 61440dc commit 3dabc13

4 files changed

Lines changed: 57 additions & 5 deletions

File tree

include/libpmemobj++/detail/ringbuf.hpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,22 @@ struct ringbuf_t {
115115
space = length;
116116
end = RBUF_OFF_MAX;
117117
nworkers = max_workers;
118+
119+
/* Helgrind/Drd does not understand std::atomic */
120+
#if LIBPMEMOBJ_CPP_VG_HELGRIND_ENABLED
121+
VALGRIND_HG_DISABLE_CHECKING(&next, sizeof(next));
122+
VALGRIND_HG_DISABLE_CHECKING(&end, sizeof(end));
123+
VALGRIND_HG_DISABLE_CHECKING(&written, sizeof(written));
124+
125+
for (size_t i = 0; i < max_workers; i++) {
126+
VALGRIND_HG_DISABLE_CHECKING(
127+
&workers[i].seen_off,
128+
sizeof(workers[i].seen_off));
129+
VALGRIND_HG_DISABLE_CHECKING(
130+
&workers[i].registered,
131+
sizeof(workers[i].registered));
132+
}
133+
#endif
118134
}
119135
};
120136

include/libpmemobj++/experimental/mpsc_queue.hpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,11 @@ mpsc_queue::try_consume(Function &&f)
252252

253253
size_t offset;
254254
size_t len = ringbuf_consume(ring_buffer.get(), &offset);
255+
256+
#if LIBPMEMOBJ_CPP_VG_HELGRIND_ENABLED
257+
ANNOTATE_HAPPENS_AFTER(ring_buffer.get());
258+
#endif
259+
255260
if (len != 0) {
256261
pmem->written = offset;
257262
pop.persist(pmem->written);
@@ -264,6 +269,10 @@ mpsc_queue::try_consume(Function &&f)
264269
if (elements_to_consume)
265270
f(acc);
266271

272+
#if LIBPMEMOBJ_CPP_VG_HELGRIND_ENABLED
273+
ANNOTATE_HAPPENS_BEFORE(ring_buffer.get());
274+
#endif
275+
267276
ringbuf_release(ring_buffer.get(), len);
268277

269278
/* XXX: it would be better to call f once - hide
@@ -280,6 +289,13 @@ inline mpsc_queue::worker::worker(mpsc_queue *q)
280289
{
281290
queue = q;
282291
auto &manager = queue->get_id_manager();
292+
293+
#if LIBPMEMOBJ_CPP_VG_DRD_ENABLED
294+
ANNOTATE_BENIGN_RACE_SIZED(
295+
&manager, sizeof(std::mutex),
296+
"https://bugs.kde.org/show_bug.cgi?id=416286");
297+
#endif
298+
283299
id = manager.get();
284300

285301
assert(id < q->ring_buffer->nworkers);
@@ -330,6 +346,10 @@ mpsc_queue::worker::try_produce(size_t size, Function &&f)
330346
pmem::detail::CACHELINE_SIZE);
331347
auto offset = ringbuf_acquire(queue->ring_buffer.get(), w, req_size);
332348

349+
#if LIBPMEMOBJ_CPP_VG_HELGRIND_ENABLED
350+
ANNOTATE_HAPPENS_AFTER(queue->ring_buffer.get());
351+
#endif
352+
333353
if (offset == -1)
334354
return false;
335355

@@ -342,6 +362,10 @@ mpsc_queue::worker::try_produce(size_t size, Function &&f)
342362
store_to_log(pmem::obj::string_view(data.get(), size),
343363
queue->buf + offset);
344364

365+
#if LIBPMEMOBJ_CPP_VG_HELGRIND_ENABLED
366+
ANNOTATE_HAPPENS_BEFORE(queue->ring_buffer.get());
367+
#endif
368+
345369
ringbuf_produce(queue->ring_buffer.get(), w);
346370

347371
return true;
@@ -355,11 +379,19 @@ mpsc_queue::worker::try_produce(pmem::obj::string_view data)
355379
pmem::detail::CACHELINE_SIZE);
356380
auto offset = ringbuf_acquire(queue->ring_buffer.get(), w, req_size);
357381

382+
#if LIBPMEMOBJ_CPP_VG_HELGRIND_ENABLED
383+
ANNOTATE_HAPPENS_AFTER(queue->ring_buffer.get());
384+
#endif
385+
358386
if (offset == -1)
359387
return false;
360388

361389
store_to_log(data, queue->buf + offset);
362390

391+
#if LIBPMEMOBJ_CPP_VG_HELGRIND_ENABLED
392+
ANNOTATE_HAPPENS_BEFORE(queue->ring_buffer.get());
393+
#endif
394+
363395
ringbuf_produce(queue->ring_buffer.get(), w);
364396

365397
return true;

tests/CMakeLists.txt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -958,13 +958,12 @@ endif()
958958
################################################################################
959959
#################################### MPSC_QUEUE ################################
960960
if(TEST_MPSC_QUEUE)
961-
#Test for internal implementation of ringbuffer
961+
# Test for internal implementation of ringbuffer
962962
build_test(ringbuf mpsc_queue/ringbuf.cpp)
963-
add_test_generic(NAME ringbuf TRACERS none memcheck)
963+
add_test_generic(NAME ringbuf TRACERS none memcheck drd helgrind)
964964

965965
build_test(mpsc_queue_mt mpsc_queue/mt.cpp)
966-
# XXX: fix memcheck pmemcheck
967-
add_test_generic(NAME mpsc_queue_mt TRACERS none)
966+
add_test_generic(NAME mpsc_queue_mt TRACERS none drd helgrind memcheck pmemcheck)
968967

969968
build_test(mpsc_queue_basic mpsc_queue/basic.cpp)
970969
add_test_generic(NAME mpsc_queue_basic SCRIPT mpsc_queue/mpsc_queue_basic_0.cmake TRACERS none memcheck pmemcheck)

tests/mpsc_queue/mt.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ mt_test(pmem::obj::pool<root> pop, size_t concurrency)
4444
std::vector<std::string> values = {"xxx", "aaaaaaa", "bbbbb", "cccc"};
4545

4646
std::atomic<size_t> threads_counter(concurrency);
47+
#if LIBPMEMOBJ_CPP_VG_HELGRIND_ENABLED
48+
VALGRIND_HG_DISABLE_CHECKING(&threads_counter, sizeof(threads_counter));
49+
#endif
4750

4851
std::vector<std::string> values_on_pmem;
4952
parallel_exec(concurrency + 1, [&](size_t thread_id) {
@@ -111,7 +114,9 @@ test(int argc, char *argv[])
111114

112115
const char *path = argv[1];
113116

114-
constexpr size_t concurrency = 16;
117+
size_t concurrency = 48;
118+
if (On_valgrind)
119+
concurrency = 2;
115120

116121
pmem::obj::pool<struct root> pop;
117122

0 commit comments

Comments
 (0)