#include <turf/Thread.h>
#include <turf/Mutex.h>
#include <turf/RaceDetector.h>
-#include <unordered_map>
#include <vector>
namespace junction {
class MapAdapter {
public:
- static TURF_CONSTEXPR const char* MapName = "CDS CuckooMap";
+ static TURF_CONSTEXPR const char* getMapName() { return "CDS CuckooMap"; }
cds::gc::HP* m_hpGC;
class MapAdapter {
public:
- static TURF_CONSTEXPR const char* MapName = "CDS MichaelKVList";
+ static TURF_CONSTEXPR const char* getMapName() { return "CDS MichaelKVList"; }
cds::gc::HP* m_hpGC;
class MapAdapter {
public:
- static TURF_CONSTEXPR const char* MapName = "Junction Crude map";
+ static TURF_CONSTEXPR const char* getMapName() { return "Junction Crude map"; }
MapAdapter(ureg) {
}
class MapAdapter {
public:
- static TURF_CONSTEXPR const char* MapName = "Folly AtomicHashMap";
+ static TURF_CONSTEXPR const char* getMapName() { return "Folly AtomicHashMap"; }
MapAdapter(ureg) {
}
class MapAdapter {
public:
- static TURF_CONSTEXPR const char* MapName = "Junction Grampa map";
+ static TURF_CONSTEXPR const char* getMapName() { return "Junction Grampa map"; }
MapAdapter(ureg) {
}
class MapAdapter {
public:
- static TURF_CONSTEXPR const char* MapName = "Junction Leapfrog map";
+ static TURF_CONSTEXPR const char* getMapName() { return "Junction Leapfrog map"; }
MapAdapter(ureg) {
}
class MapAdapter {
public:
- static TURF_CONSTEXPR const char* MapName = "Single + RWLock";
+ static TURF_CONSTEXPR const char* getMapName() { return "Single + RWLock"; }
MapAdapter(ureg) {
}
class MapAdapter {
public:
- static TURF_CONSTEXPR const char* MapName = "libcuckoo cuckoohash_map";
+ static TURF_CONSTEXPR const char* getMapName() { return "libcuckoo cuckoohash_map"; }
MapAdapter(ureg) {
}
class MapAdapter {
public:
- static TURF_CONSTEXPR const char* MapName = "Junction Linear map";
+ static TURF_CONSTEXPR const char* getMapName() { return "Junction Linear map"; }
MapAdapter(ureg) {
}
class MapAdapter {
public:
- static TURF_CONSTEXPR const char* MapName = "Single + Mutex";
+ static TURF_CONSTEXPR const char* getMapName() { return "Single + Mutex"; }
MapAdapter(ureg) {
}
class MapAdapter {
public:
- static TURF_CONSTEXPR const char* MapName = "Single + RWLock";
+ static TURF_CONSTEXPR const char* getMapName() { return "Single + RWLock"; }
MapAdapter(ureg) {
}
class MapAdapter {
public:
- static TURF_CONSTEXPR const char* MapName = "nbds hashtable_t";
+ static TURF_CONSTEXPR const char* getMapName() { return "nbds hashtable_t"; }
MapAdapter(ureg) {
}
class MapAdapter {
public:
- static TURF_CONSTEXPR const char* MapName = "Null";
+ static TURF_CONSTEXPR const char* getMapName() { return "Null"; }
MapAdapter(ureg) {
}
class MapAdapter {
public:
- static TURF_CONSTEXPR const char* MapName = "std::map + std::mutex";
+ static TURF_CONSTEXPR const char* getMapName() { return "std::map + std::mutex"; }
MapAdapter(ureg) {
}
class MapAdapter {
public:
- static TURF_CONSTEXPR const char* MapName = "Intel TBB concurrent_hash_map";
+ static TURF_CONSTEXPR const char* getMapName() { return "Intel TBB concurrent_hash_map"; }
MapAdapter(ureg) {
}
class MapAdapter {
public:
- static TURF_CONSTEXPR const char* MapName = "Tervel HashMap";
+ static TURF_CONSTEXPR const char* getMapName() { return "Tervel HashMap"; }
tervel::Tervel m_tervel;
TestEnvironment() : numThreads(dispatcher.getNumPhysicalCores()), adapter(numThreads) {
TURF_ASSERT(numThreads > 0);
for (ureg t = 0; t < numThreads; t++)
- threads.emplace_back(adapter, t);
+ threads.push_back(MapAdapter::ThreadContext(adapter, t));
dispatcher.kickMulti(&MapAdapter::ThreadContext::registerThread, &threads[0], threads.size());
}
#include <junction/extra/MapAdapter.h>
#include <algorithm>
#include <vector>
+#include <stdio.h>
using namespace turf::intTypes;
typedef junction::extra::MapAdapter MapAdapter;
class ThreadState {
public:
- SharedState& m_shared;
+ SharedState* m_shared;
MapAdapter::ThreadContext m_threadCtx;
ureg m_threadIndex;
u32 m_rangeLo;
Stats m_stats;
- ThreadState(SharedState& shared, ureg threadIndex, u32 rangeLo, u32 rangeHi)
- : m_shared(shared), m_threadCtx(shared.adapter, threadIndex) {
+ ThreadState(SharedState* shared, ureg threadIndex, u32 rangeLo, u32 rangeHi)
+ : m_shared(shared), m_threadCtx(shared->adapter, threadIndex) {
m_threadIndex = threadIndex;
m_rangeLo = rangeLo;
m_rangeHi = rangeHi;
void initialPopulate() {
TURF_ASSERT(m_addIndex == m_removeIndex);
- MapAdapter::Map* map = m_shared.map;
- for (ureg i = 0; i < m_shared.numKeysPerThread; i++) {
+ MapAdapter::Map* map = m_shared->map;
+ for (ureg i = 0; i < m_shared->numKeysPerThread; i++) {
u32 key = m_addIndex * Prime;
map->assign(key, (void*) (key & ~uptr(3)));
if (++m_addIndex == m_rangeHi)
}
void run() {
- MapAdapter::Map* map = m_shared.map;
+ MapAdapter::Map* map = m_shared->map;
turf::CPUTimer::Converter converter;
- Delay delay(m_shared.delayFactor);
+ Delay delay(m_shared->delayFactor);
Stats stats;
ureg lookupIndex = m_rangeLo;
- ureg remaining = m_shared.itersPerChunk;
+ ureg remaining = m_shared->itersPerChunk;
if (m_threadIndex == 0)
- m_shared.spinKicker.kick(m_shared.numThreads - 1);
+ m_shared->spinKicker.kick(m_shared->numThreads - 1);
else {
remaining = ~u32(0);
- m_shared.spinKicker.waitForKick();
+ m_shared->spinKicker.waitForKick();
}
// ---------
for (; remaining > 0; remaining--) {
// Add
delay.delay(stats.workUnitsDone);
- if (m_shared.doneFlag.load(turf::Relaxed))
+ if (m_shared->doneFlag.load(turf::Relaxed))
break;
u32 key = m_addIndex * Prime;
if (key >= 2) {
// Lookup
if (s32(lookupIndex - m_removeIndex) < 0)
lookupIndex = m_removeIndex;
- for (ureg l = 0; l < m_shared.readsPerWrite; l++) {
+ for (ureg l = 0; l < m_shared->readsPerWrite; l++) {
delay.delay(stats.workUnitsDone);
- if (m_shared.doneFlag.load(turf::Relaxed))
+ if (m_shared->doneFlag.load(turf::Relaxed))
break;
key = lookupIndex * Prime;
if (key >= 2) {
// Remove
delay.delay(stats.workUnitsDone);
- if (m_shared.doneFlag.load(turf::Relaxed))
+ if (m_shared->doneFlag.load(turf::Relaxed))
break;
key = m_removeIndex * Prime;
if (key >= 2) {
// Lookup
if (s32(lookupIndex - m_removeIndex) < 0)
lookupIndex = m_removeIndex;
- for (ureg l = 0; l < m_shared.readsPerWrite; l++) {
+ for (ureg l = 0; l < m_shared->readsPerWrite; l++) {
delay.delay(stats.workUnitsDone);
- if (m_shared.doneFlag.load(turf::Relaxed))
+ if (m_shared->doneFlag.load(turf::Relaxed))
break;
key = lookupIndex * Prime;
if (key >= 2) {
}
}
if (m_threadIndex == 0)
- m_shared.doneFlag.store(1, turf::Relaxed);
+ m_shared->doneFlag.store(1, turf::Relaxed);
m_threadCtx.update();
turf::CPUTimer::Point end = turf::CPUTimer::get();
// ---------
for (ureg t = 0; t < numThreads; t++) {
u32 rangeLo = 0xffffffffu / numThreads * t + 1;
u32 rangeHi = 0xffffffffu / numThreads * (t + 1) + 1;
- threads.emplace_back(shared, t, rangeLo, rangeHi);
+ threads.push_back(ThreadState(&shared, t, rangeLo, rangeHi));
}
dispatcher.kickMulti(&ThreadState::registerThread, &threads[0], threads.size());
dispatcher.kickMulti(&ThreadState::initialPopulate, &threads[0], threads.size());
printf("{\n");
- printf("'mapType': '%s',\n", MapAdapter::MapName);
+ printf("'mapType': '%s',\n", MapAdapter::getMapName());
printf("'readsPerWrite': %d,\n", (int) readsPerWrite);
printf("'itersPerChunk': %d,\n", (int) itersPerChunk);
printf("'chunks': %d,\n", (int) chunks);
#include <junction/extra/MapAdapter.h>
#include <algorithm>
#include <vector>
+#include <stdio.h>
using namespace turf::intTypes;
typedef junction::extra::MapAdapter MapAdapter;
class ThreadState {
public:
- SharedState& m_shared;
+ SharedState* m_shared;
MapAdapter::ThreadContext m_threadCtx;
ureg m_threadIndex;
u32 m_rangeLo;
Stats m_stats;
- ThreadState(SharedState& shared, ureg threadIndex, u32 rangeLo, u32 rangeHi)
- : m_shared(shared), m_threadCtx(shared.adapter, threadIndex) {
+ ThreadState(SharedState* shared, ureg threadIndex, u32 rangeLo, u32 rangeHi)
+ : m_shared(shared), m_threadCtx(shared->adapter, threadIndex) {
m_threadIndex = threadIndex;
m_rangeLo = rangeLo;
m_rangeHi = rangeHi;
void initialPopulate() {
TURF_ASSERT(m_addIndex == m_removeIndex);
- MapAdapter::Map* map = m_shared.map;
- for (ureg i = 0; i < m_shared.numKeysPerThread; i++) {
+ MapAdapter::Map* map = m_shared->map;
+ for (ureg i = 0; i < m_shared->numKeysPerThread; i++) {
u32 key = m_addIndex * Prime;
if (key >= 2)
map->assign(key, (void*) uptr(key));
}
void run() {
- MapAdapter::Map* map = m_shared.map;
+ MapAdapter::Map* map = m_shared->map;
turf::CPUTimer::Converter converter;
Stats stats;
ureg lookupIndex = m_rangeLo;
- ureg remaining = m_shared.itersPerChunk;
+ ureg remaining = m_shared->itersPerChunk;
if (m_threadIndex == 0)
- m_shared.spinKicker.kick(m_shared.numThreads - 1);
+ m_shared->spinKicker.kick(m_shared->numThreads - 1);
else {
remaining = ~u32(0);
- m_shared.spinKicker.waitForKick();
+ m_shared->spinKicker.waitForKick();
}
// ---------
turf::CPUTimer::Point start = turf::CPUTimer::get();
for (; remaining > 0; remaining--) {
// Add
- if (m_shared.doneFlag.load(turf::Relaxed))
+ if (m_shared->doneFlag.load(turf::Relaxed))
break;
u32 key = m_addIndex * Prime;
if (key >= 2) {
// Lookup
if (s32(lookupIndex - m_removeIndex) < 0)
lookupIndex = m_removeIndex;
- for (ureg l = 0; l < m_shared.readsPerWrite; l++) {
- if (m_shared.doneFlag.load(turf::Relaxed))
+ for (ureg l = 0; l < m_shared->readsPerWrite; l++) {
+ if (m_shared->doneFlag.load(turf::Relaxed))
break;
key = lookupIndex * Prime;
if (key >= 2) {
}
// Remove
- if (m_shared.doneFlag.load(turf::Relaxed))
+ if (m_shared->doneFlag.load(turf::Relaxed))
break;
key = m_removeIndex * Prime;
if (key >= 2) {
// Lookup
if (s32(lookupIndex - m_removeIndex) < 0)
lookupIndex = m_removeIndex;
- for (ureg l = 0; l < m_shared.readsPerWrite; l++) {
- if (m_shared.doneFlag.load(turf::Relaxed))
+ for (ureg l = 0; l < m_shared->readsPerWrite; l++) {
+ if (m_shared->doneFlag.load(turf::Relaxed))
break;
key = lookupIndex * Prime;
if (key >= 2) {
}
}
if (m_threadIndex == 0)
- m_shared.doneFlag.store(1, turf::Relaxed);
+ m_shared->doneFlag.store(1, turf::Relaxed);
m_threadCtx.update();
turf::CPUTimer::Point end = turf::CPUTimer::get();
// ---------
for (ureg t = 0; t < numCores; t++) {
u32 rangeLo = 0xffffffffu / numCores * t + 1;
u32 rangeHi = 0xffffffffu / numCores * (t + 1) + 1;
- threads.emplace_back(shared, t, rangeLo, rangeHi);
+ threads.push_back(ThreadState(&shared, t, rangeLo, rangeHi));
}
dispatcher.kickOne(0, &ThreadState::registerThread, threads[0]);
}
printf("{\n");
- printf("'mapType': '%s',\n", MapAdapter::MapName);
+ printf("'mapType': '%s',\n", MapAdapter::getMapName());
printf("'population': %d,\n", (int) (numCores * NumKeysPerThread));
printf("'readsPerWrite': %d,\n", (int) readsPerWrite);
printf("'itersPerChunk': %d,\n", (int) itersPerChunk);