Commit 8bf79388 authored by Chad Austin's avatar Chad Austin Committed by Facebook Github Bot

enable SharedMutex benchmarks on macOS

Summary:
Instead of using a Linux-specific API for random numbers, use
std::minstd_rand. It's not precisely identical, but probably
sufficient for these tests.

Reviewed By: yfeldblum

Differential Revision: D20039048

fbshipit-source-id: 5ace1a0552f995a48b37e4fa2209394f1b28ca84
parent 8583f02b
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include <folly/SharedMutex.h> #include <folly/SharedMutex.h>
#include <stdlib.h> #include <stdlib.h>
#include <random>
#include <thread> #include <thread>
#include <vector> #include <vector>
...@@ -664,8 +665,9 @@ static void runMixed( ...@@ -664,8 +665,9 @@ static void runMixed(
BENCHMARK_SUSPEND { BENCHMARK_SUSPEND {
for (size_t t = 0; t < numThreads; ++t) { for (size_t t = 0; t < numThreads; ++t) {
threads[t] = DSched::thread([&, t, numThreads] { threads[t] = DSched::thread([&, t, numThreads] {
struct drand48_data buffer; std::minstd_rand engine;
srand48_r(t, &buffer); engine.seed(t);
long writeThreshold = writeFraction * 0x7fffffff; long writeThreshold = writeFraction * 0x7fffffff;
Lock privateLock; Lock privateLock;
Lock* lock = useSeparateLocks ? &privateLock : &(padded.globalLock); Lock* lock = useSeparateLocks ? &privateLock : &(padded.globalLock);
...@@ -674,8 +676,7 @@ static void runMixed( ...@@ -674,8 +676,7 @@ static void runMixed(
this_thread::yield(); this_thread::yield();
} }
for (size_t op = t; op < numOps; op += numThreads) { for (size_t op = t; op < numOps; op += numThreads) {
long randVal; long randVal = engine();
lrand48_r(&buffer, &randVal);
bool writeOp = randVal < writeThreshold; bool writeOp = randVal < writeThreshold;
if (writeOp) { if (writeOp) {
locker.lock(lock); locker.lock(lock);
...@@ -801,8 +802,8 @@ static void runAllAndValidate(size_t numOps, size_t numThreads) { ...@@ -801,8 +802,8 @@ static void runAllAndValidate(size_t numOps, size_t numThreads) {
BENCHMARK_SUSPEND { BENCHMARK_SUSPEND {
for (size_t t = 0; t < numThreads; ++t) { for (size_t t = 0; t < numThreads; ++t) {
threads[t] = DSched::thread([&, t, numThreads] { threads[t] = DSched::thread([&, t, numThreads] {
struct drand48_data buffer; std::minstd_rand engine;
srand48_r(t, &buffer); engine.seed(t);
bool exclusive = false; bool exclusive = false;
bool upgrade = false; bool upgrade = false;
...@@ -818,8 +819,7 @@ static void runAllAndValidate(size_t numOps, size_t numThreads) { ...@@ -818,8 +819,7 @@ static void runAllAndValidate(size_t numOps, size_t numThreads) {
} }
for (size_t op = t; op < numOps; op += numThreads) { for (size_t op = t; op < numOps; op += numThreads) {
// randVal in [0,1000) // randVal in [0,1000)
long randVal; long randVal = engine();
lrand48_r(&buffer, &randVal);
randVal = (long)((randVal * (uint64_t)1000) / 0x7fffffff); randVal = (long)((randVal * (uint64_t)1000) / 0x7fffffff);
// make as many assertions as possible about the global state // make as many assertions as possible about the global state
...@@ -1216,15 +1216,14 @@ static void runRemoteUnlock( ...@@ -1216,15 +1216,14 @@ static void runRemoteUnlock(
} }
// else we're a sender // else we're a sender
struct drand48_data buffer; std::minstd_rand engine;
srand48_r(t, &buffer); engine.seed(t);
while (!goPtr->load()) { while (!goPtr->load()) {
this_thread::yield(); this_thread::yield();
} }
for (size_t op = t; op < numOps; op += numSendingThreads) { for (size_t op = t; op < numOps; op += numSendingThreads) {
long unscaledRandVal; long unscaledRandVal = engine();
lrand48_r(&buffer, &unscaledRandVal);
// randVal in [0,1] // randVal in [0,1]
double randVal = ((double)unscaledRandVal) / 0x7fffffff; double randVal = ((double)unscaledRandVal) / 0x7fffffff;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment