<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[199761] trunk/Source/WTF</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/199761">199761</a></dd>
<dt>Author</dt> <dd>fpizlo@apple.com</dd>
<dt>Date</dt> <dd>2016-04-19 21:27:15 -0700 (Tue, 19 Apr 2016)</dd>
</dl>
<h3>Log Message</h3>
<pre>Add more locking algorithms to the LockSpeedTest.
Rubber stamped by Saam Barati.
* benchmarks/LockSpeedTest.cpp:
(main):</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWTFChangeLog">trunk/Source/WTF/ChangeLog</a></li>
<li><a href="#trunkSourceWTFbenchmarksLockSpeedTestcpp">trunk/Source/WTF/benchmarks/LockSpeedTest.cpp</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWTFChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WTF/ChangeLog (199760 => 199761)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WTF/ChangeLog        2016-04-20 04:25:02 UTC (rev 199760)
+++ trunk/Source/WTF/ChangeLog        2016-04-20 04:27:15 UTC (rev 199761)
</span><span class="lines">@@ -1,5 +1,14 @@
</span><span class="cx"> 2016-04-19 Filip Pizlo <fpizlo@apple.com>
</span><span class="cx">
</span><ins>+ Add more locking algorithms to the LockSpeedTest.
+
+ Rubber stamped by Saam Barati.
+
+ * benchmarks/LockSpeedTest.cpp:
+ (main):
+
+2016-04-19 Filip Pizlo <fpizlo@apple.com>
+
</ins><span class="cx"> Clean up the ParkingLot uparking API a bit
</span><span class="cx"> https://bugs.webkit.org/show_bug.cgi?id=156746
</span><span class="cx">
</span></span></pre></div>
<a id="trunkSourceWTFbenchmarksLockSpeedTestcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WTF/benchmarks/LockSpeedTest.cpp (199760 => 199761)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WTF/benchmarks/LockSpeedTest.cpp        2016-04-20 04:25:02 UTC (rev 199760)
+++ trunk/Source/WTF/benchmarks/LockSpeedTest.cpp        2016-04-20 04:27:15 UTC (rev 199761)
</span><span class="lines">@@ -1,5 +1,5 @@
</span><span class="cx"> /*
</span><del>- * Copyright (C) 2015 Apple Inc. All rights reserved.
</del><ins>+ * Copyright (C) 2015-2016 Apple Inc. All rights reserved.
</ins><span class="cx"> *
</span><span class="cx"> * Redistribution and use in source and binary forms, with or without
</span><span class="cx"> * modification, are permitted provided that the following conditions
</span><span class="lines">@@ -28,21 +28,34 @@
</span><span class="cx">
</span><span class="cx"> #include "config.h"
</span><span class="cx">
</span><ins>+#include <thread>
</ins><span class="cx"> #include <unistd.h>
</span><span class="cx"> #include <wtf/CurrentTime.h>
</span><ins>+#include <wtf/DataLog.h>
+#include <wtf/HashMap.h>
</ins><span class="cx"> #include <wtf/Lock.h>
</span><ins>+#include <wtf/ParkingLot.h>
</ins><span class="cx"> #include <wtf/StdLibExtras.h>
</span><span class="cx"> #include <wtf/Threading.h>
</span><span class="cx"> #include <wtf/ThreadingPrimitives.h>
</span><ins>+#include <wtf/Vector.h>
</ins><span class="cx"> #include <wtf/WordLock.h>
</span><ins>+#include <wtf/text/CString.h>
</ins><span class="cx">
</span><span class="cx"> namespace {
</span><span class="cx">
</span><ins>+unsigned numThreadGroups;
+unsigned numThreadsPerGroup;
+unsigned workPerCriticalSection;
+unsigned workBetweenCriticalSections;
+unsigned spinLimit;
+double secondsPerTest;
+
</ins><span class="cx"> // This is the old WTF::SpinLock class, included here so that we can still compare our new locks to a
</span><span class="cx"> // spinlock baseline.
</span><del>-class SpinLock {
</del><ins>+class YieldSpinLock {
</ins><span class="cx"> public:
</span><del>- SpinLock()
</del><ins>+ YieldSpinLock()
</ins><span class="cx"> {
</span><span class="cx"> m_lock.store(0, std::memory_order_relaxed);
</span><span class="cx"> }
</span><span class="lines">@@ -67,71 +80,463 @@
</span><span class="cx"> Atomic<unsigned> m_lock;
</span><span class="cx"> };
</span><span class="cx">
</span><del>-unsigned numThreadGroups;
-unsigned numThreadsPerGroup;
-unsigned workPerCriticalSection;
-unsigned numNoiseThreads;
-unsigned numIterations;
</del><ins>+class PauseSpinLock {
+public:
+ PauseSpinLock()
+ {
+ m_lock.store(0, std::memory_order_relaxed);
+ }
+
+ void lock()
+ {
+ while (!m_lock.compareExchangeWeak(0, 1, std::memory_order_acquire))
+ asm volatile ("pause");
+ }
+
+ void unlock()
+ {
+ m_lock.store(0, std::memory_order_release);
+ }
+
+ bool isLocked() const
+ {
+ return m_lock.load(std::memory_order_acquire);
+ }
+
+private:
+ Atomic<unsigned> m_lock;
+};
+
+template<typename StateType>
+class BargingLock {
+public:
+ BargingLock()
+ {
+ m_state.store(0);
+ }
</ins><span class="cx">
</span><ins>+ void lock()
+ {
+ if (LIKELY(m_state.compareExchangeWeak(0, isLockedBit, std::memory_order_acquire)))
+ return;
+
+ lockSlow();
+ }
+
+ void unlock()
+ {
+ if (LIKELY(m_state.compareExchangeWeak(isLockedBit, 0, std::memory_order_release)))
+ return;
+
+ unlockSlow();
+ }
+
+ bool isLocked() const
+ {
+ return m_state.load(std::memory_order_acquire) & isLockedBit;
+ }
+
+private:
+ NEVER_INLINE void lockSlow()
+ {
+ for (unsigned i = spinLimit; i--;) {
+ StateType currentState = m_state.load();
+
+ if (!(currentState & isLockedBit)
+ && m_state.compareExchangeWeak(currentState, currentState | isLockedBit))
+ return;
+
+ if (currentState & hasParkedBit)
+ break;
+
+ std::this_thread::yield();
+ }
+
+ for (;;) {
+ StateType currentState = m_state.load();
+
+ if (!(currentState & isLockedBit)
+ && m_state.compareExchangeWeak(currentState, currentState | isLockedBit))
+ return;
+
+ m_state.compareExchangeWeak(isLockedBit, isLockedBit | hasParkedBit);
+
+ ParkingLot::compareAndPark(&m_state, isLockedBit | hasParkedBit);
+ }
+ }
+
+ NEVER_INLINE void unlockSlow()
+ {
+ ParkingLot::unparkOne(
+ &m_state,
+ [this] (ParkingLot::UnparkResult result) {
+ if (result.mayHaveMoreThreads)
+ m_state.store(hasParkedBit);
+ else
+ m_state.store(0);
+ });
+ }
+
+ static const StateType isLockedBit = 1;
+ static const StateType hasParkedBit = 2;
+
+ Atomic<StateType> m_state;
+};
+
+template<typename StateType>
+class ThunderLock {
+public:
+ ThunderLock()
+ {
+ m_state.store(Unlocked);
+ }
+
+ void lock()
+ {
+ if (LIKELY(m_state.compareExchangeWeak(Unlocked, Locked, std::memory_order_acquire)))
+ return;
+
+ lockSlow();
+ }
+
+ void unlock()
+ {
+ if (LIKELY(m_state.compareExchangeWeak(Locked, Unlocked, std::memory_order_release)))
+ return;
+
+ unlockSlow();
+ }
+
+ bool isLocked() const
+ {
+ return m_state.load(std::memory_order_acquire) != Unlocked;
+ }
+
+private:
+ NEVER_INLINE void lockSlow()
+ {
+ for (unsigned i = spinLimit; i--;) {
+ State currentState = m_state.load();
+
+ if (currentState == Unlocked
+ && m_state.compareExchangeWeak(Unlocked, Locked))
+ return;
+
+ if (currentState == LockedAndParked)
+ break;
+
+ std::this_thread::yield();
+ }
+
+ for (;;) {
+ if (m_state.compareExchangeWeak(Unlocked, Locked))
+ return;
+
+ m_state.compareExchangeWeak(Locked, LockedAndParked);
+ ParkingLot::compareAndPark(&m_state, LockedAndParked);
+ }
+ }
+
+ NEVER_INLINE void unlockSlow()
+ {
+ if (m_state.exchange(Unlocked) == LockedAndParked)
+ ParkingLot::unparkAll(&m_state);
+ }
+
+ enum State : StateType {
+ Unlocked,
+ Locked,
+ LockedAndParked
+ };
+
+ Atomic<State> m_state;
+};
+
+template<typename StateType>
+class CascadeLock {
+public:
+ CascadeLock()
+ {
+ m_state.store(Unlocked);
+ }
+
+ void lock()
+ {
+ if (LIKELY(m_state.compareExchangeWeak(Unlocked, Locked, std::memory_order_acquire)))
+ return;
+
+ lockSlow();
+ }
+
+ void unlock()
+ {
+ if (LIKELY(m_state.compareExchangeWeak(Locked, Unlocked, std::memory_order_release)))
+ return;
+
+ unlockSlow();
+ }
+
+ bool isLocked() const
+ {
+ return m_state.load(std::memory_order_acquire) != Unlocked;
+ }
+
+private:
+ NEVER_INLINE void lockSlow()
+ {
+ for (unsigned i = spinLimit; i--;) {
+ State currentState = m_state.load();
+
+ if (currentState == Unlocked
+ && m_state.compareExchangeWeak(Unlocked, Locked))
+ return;
+
+ if (currentState == LockedAndParked)
+ break;
+
+ std::this_thread::yield();
+ }
+
+ State desiredState = Locked;
+ for (;;) {
+ if (m_state.compareExchangeWeak(Unlocked, desiredState))
+ return;
+
+ desiredState = LockedAndParked;
+ m_state.compareExchangeWeak(Locked, LockedAndParked);
+ ParkingLot::compareAndPark(&m_state, LockedAndParked);
+ }
+ }
+
+ NEVER_INLINE void unlockSlow()
+ {
+ if (m_state.exchange(Unlocked) == LockedAndParked)
+ ParkingLot::unparkOne(&m_state);
+ }
+
+ enum State : StateType {
+ Unlocked,
+ Locked,
+ LockedAndParked
+ };
+
+ Atomic<State> m_state;
+};
+
+class HandoffLock {
+public:
+ HandoffLock()
+ {
+ m_state.store(0);
+ }
+
+ void lock()
+ {
+ if (LIKELY(m_state.compareExchangeWeak(0, isLockedBit, std::memory_order_acquire)))
+ return;
+
+ lockSlow();
+ }
+
+ void unlock()
+ {
+ if (LIKELY(m_state.compareExchangeWeak(isLockedBit, 0, std::memory_order_release)))
+ return;
+
+ unlockSlow();
+ }
+
+ bool isLocked() const
+ {
+ return m_state.load(std::memory_order_acquire) & isLockedBit;
+ }
+
+private:
+ NEVER_INLINE void lockSlow()
+ {
+ for (;;) {
+ unsigned state = m_state.load();
+
+ if (!(state & isLockedBit)) {
+ if (m_state.compareExchangeWeak(state, state | isLockedBit))
+ return;
+ continue;
+ }
+
+ if (m_state.compareExchangeWeak(state, state + parkedCountUnit)) {
+ bool result = ParkingLot::compareAndPark(&m_state, state + parkedCountUnit);
+ m_state.exchangeAndAdd(-parkedCountUnit);
+ if (result)
+ return;
+ }
+ }
+ }
+
+ NEVER_INLINE void unlockSlow()
+ {
+ for (;;) {
+ unsigned state = m_state.load();
+
+ if (!(state >> parkedCountShift)) {
+ RELEASE_ASSERT(state == isLockedBit);
+ if (m_state.compareExchangeWeak(isLockedBit, 0))
+ return;
+ continue;
+ }
+
+ if (ParkingLot::unparkOne(&m_state).didUnparkThread) {
+ // We unparked someone. There are now running and they hold the lock.
+ return;
+ }
+
+ // Nobody unparked. Maybe there isn't anyone waiting. Just try again.
+ }
+ }
+
+ static const unsigned isLockedBit = 1;
+ static const unsigned parkedCountShift = 1;
+ static const unsigned parkedCountUnit = 1 << parkedCountShift;
+
+ Atomic<unsigned> m_state;
+};
+
</ins><span class="cx"> NO_RETURN void usage()
</span><span class="cx"> {
</span><del>- printf("Usage: LockSpeedTest spinlock|wordlock|lock|mutex|all <num thread groups> <num threads per group> <work per critical section> <num noise threads> <num iterations>\n");
</del><ins>+ printf("Usage: LockSpeedTest yieldspinlock|pausespinlock|wordlock|lock|barginglock|bargingwordlock|thunderlock|thunderwordlock|cascadelock|cascadewordlockhandofflock|mutex|all <num thread groups> <num threads per group> <work per critical section> <work between critical sections> <spin limit> <seconds per test>\n");
</ins><span class="cx"> exit(1);
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+template<typename Type>
+struct WithPadding {
+ Type value;
+ char buf[300]; // It's best if this isn't perfect to avoid false sharing.
+};
+
+HashMap<CString, Vector<double>> results;
+
+void reportResult(const char* name, double value)
+{
+ dataLogF("%s: %.3lf KHz\n", name, value);
+ results.add(name, Vector<double>()).iterator->value.append(value);
+}
+
+bool didRun;
+
</ins><span class="cx"> template<typename LockType>
</span><span class="cx"> void runBenchmark(const char* name)
</span><span class="cx"> {
</span><del>- std::unique_ptr<LockType[]> locks = std::make_unique<LockType[]>(numThreadGroups);
- std::unique_ptr<double[]> words = std::make_unique<double[]>(numThreadGroups);
</del><ins>+ std::unique_ptr<WithPadding<LockType>[]> locks = std::make_unique<WithPadding<LockType>[]>(numThreadGroups);
+ std::unique_ptr<WithPadding<double>[]> words = std::make_unique<WithPadding<double>[]>(numThreadGroups);
</ins><span class="cx"> std::unique_ptr<ThreadIdentifier[]> threads = std::make_unique<ThreadIdentifier[]>(numThreadGroups * numThreadsPerGroup);
</span><del>- std::unique_ptr<ThreadIdentifier[]> noiseThreads = std::make_unique<ThreadIdentifier[]>(numNoiseThreads);
- std::unique_ptr<double[]> noiseCounts = std::make_unique<double[]>(numNoiseThreads);
</del><span class="cx">
</span><del>- volatile bool shouldStop = false;
- for (unsigned threadIndex = numNoiseThreads; threadIndex--;) {
- noiseCounts[threadIndex] = 0;
- noiseThreads[threadIndex] = createThread(
- "Noise Thread",
- [&shouldStop, &noiseCounts, threadIndex] () {
- while (!shouldStop)
- noiseCounts[threadIndex]++;
- });
- }
</del><ins>+ volatile bool keepGoing = true;
</ins><span class="cx">
</span><del>- double before = monotonicallyIncreasingTimeMS();
</del><ins>+ double before = monotonicallyIncreasingTime();
</ins><span class="cx">
</span><ins>+ Lock numIterationsLock;
+ uint64_t numIterations = 0;
+
</ins><span class="cx"> for (unsigned threadGroupIndex = numThreadGroups; threadGroupIndex--;) {
</span><del>- words[threadGroupIndex] = 0;
</del><ins>+ words[threadGroupIndex].value = 0;
</ins><span class="cx">
</span><span class="cx"> for (unsigned threadIndex = numThreadsPerGroup; threadIndex--;) {
</span><span class="cx"> threads[threadGroupIndex * numThreadsPerGroup + threadIndex] = createThread(
</span><span class="cx"> "Benchmark thread",
</span><del>- [threadGroupIndex, &locks, &words] () {
- for (unsigned i = numIterations; i--;) {
- locks[threadGroupIndex].lock();
</del><ins>+ [threadGroupIndex, &locks, &words, &keepGoing, &numIterationsLock, &numIterations] () {
+ double localWord = 0;
+ double value = 1;
+ unsigned myNumIterations = 0;
+ while (keepGoing) {
+ locks[threadGroupIndex].value.lock();
</ins><span class="cx"> for (unsigned j = workPerCriticalSection; j--;) {
</span><del>- words[threadGroupIndex]++;
- words[threadGroupIndex] *= 1.01;
</del><ins>+ words[threadGroupIndex].value += value;
+ words[threadGroupIndex].value *= 1.01;
+ value = words[threadGroupIndex].value;
</ins><span class="cx"> }
</span><del>- locks[threadGroupIndex].unlock();
</del><ins>+ locks[threadGroupIndex].value.unlock();
+ for (unsigned j = workBetweenCriticalSections; j--;) {
+ localWord += value;
+ localWord *= 1.01;
+ value = localWord;
+ }
+ myNumIterations++;
</ins><span class="cx"> }
</span><ins>+ LockHolder locker(numIterationsLock);
+ numIterations += myNumIterations;
</ins><span class="cx"> });
</span><span class="cx"> }
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+ sleep(secondsPerTest);
+ keepGoing = false;
+
</ins><span class="cx"> for (unsigned threadIndex = numThreadGroups * numThreadsPerGroup; threadIndex--;)
</span><span class="cx"> waitForThreadCompletion(threads[threadIndex]);
</span><del>- shouldStop = true;
- double noiseCount = 0;
- for (unsigned threadIndex = numNoiseThreads; threadIndex--;) {
- waitForThreadCompletion(noiseThreads[threadIndex]);
- noiseCount += noiseCounts[threadIndex];
</del><ins>+
+ double after = monotonicallyIncreasingTime();
+
+ reportResult(name, numIterations / (after - before) / 1000);
+ didRun = true;
+}
+
+unsigned rangeMin;
+unsigned rangeMax;
+unsigned rangeStep;
+unsigned* rangeVariable;
+
+bool parseValue(const char* string, unsigned* variable)
+{
+ unsigned myRangeMin;
+ unsigned myRangeMax;
+ unsigned myRangeStep;
+ if (sscanf(string, "%u-%u:%u", &myRangeMin, &myRangeMax, &myRangeStep) == 3) {
+ if (rangeVariable) {
+ fprintf(stderr, "Can only have one variable with a range.\n");
+ return false;
+ }
+
+ rangeMin = myRangeMin;
+ rangeMax = myRangeMax;
+ rangeStep = myRangeStep;
+ rangeVariable = variable;
+ return true;
</ins><span class="cx"> }
</span><ins>+
+ if (sscanf(string, "%u", variable) == 1)
+ return true;
+
+ return false;
+}
</ins><span class="cx">
</span><del>- double after = monotonicallyIncreasingTimeMS();
</del><ins>+void runEverything(const char* what)
+{
+ if (!strcmp(what, "yieldspinlock") || !strcmp(what, "all"))
+ runBenchmark<YieldSpinLock>("YieldSpinLock");
+ if (!strcmp(what, "pausespinlock") || !strcmp(what, "all"))
+ runBenchmark<PauseSpinLock>("PauseSpinLock");
+ if (!strcmp(what, "wordlock") || !strcmp(what, "all"))
+ runBenchmark<WordLock>("WTFWordLock");
+ if (!strcmp(what, "lock") || !strcmp(what, "all"))
+ runBenchmark<Lock>("WTFLock");
+ if (!strcmp(what, "barginglock") || !strcmp(what, "all"))
+ runBenchmark<BargingLock<uint8_t>>("ByteBargingLock");
+ if (!strcmp(what, "bargingwordlock") || !strcmp(what, "all"))
+ runBenchmark<BargingLock<uint32_t>>("WordBargingLock");
+ if (!strcmp(what, "thunderlock") || !strcmp(what, "all"))
+ runBenchmark<ThunderLock<uint8_t>>("ByteThunderLock");
+ if (!strcmp(what, "thunderwordlock") || !strcmp(what, "all"))
+ runBenchmark<ThunderLock<uint32_t>>("WordThunderLock");
+ if (!strcmp(what, "cascadelock") || !strcmp(what, "all"))
+ runBenchmark<CascadeLock<uint8_t>>("ByteCascadeLock");
+ if (!strcmp(what, "cascadewordlock") || !strcmp(what, "all"))
+ runBenchmark<CascadeLock<uint32_t>>("WordCascadeLock");
+ if (!strcmp(what, "handofflock") || !strcmp(what, "all"))
+ runBenchmark<HandoffLock>("HandoffLock");
+ if (!strcmp(what, "mutex") || !strcmp(what, "all"))
+ runBenchmark<Mutex>("PlatformMutex");
</ins><span class="cx">
</span><del>- printf("%s: %.3lf ms, %.0lf noise.\n", name, after - before, noiseCount);
</del><ins>+ if (!didRun)
+ usage();
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> } // anonymous namespace
</span><span class="lines">@@ -140,34 +545,37 @@
</span><span class="cx"> {
</span><span class="cx"> WTF::initializeThreading();
</span><span class="cx">
</span><del>- if (argc != 7
- || sscanf(argv[2], "%u", &numThreadGroups) != 1
- || sscanf(argv[3], "%u", &numThreadsPerGroup) != 1
- || sscanf(argv[4], "%u", &workPerCriticalSection) != 1
- || sscanf(argv[5], "%u", &numNoiseThreads) != 1
- || sscanf(argv[6], "%u", &numIterations) != 1)
</del><ins>+ if (argc != 8
+ || !parseValue(argv[2], &numThreadGroups)
+ || !parseValue(argv[3], &numThreadsPerGroup)
+ || !parseValue(argv[4], &workPerCriticalSection)
+ || !parseValue(argv[5], &workBetweenCriticalSections)
+ || !parseValue(argv[6], &spinLimit)
+ || sscanf(argv[7], "%lf", &secondsPerTest) != 1)
</ins><span class="cx"> usage();
</span><del>-
- bool didRun = false;
- if (!strcmp(argv[1], "spinlock") || !strcmp(argv[1], "all")) {
- runBenchmark<SpinLock>("SpinLock");
- didRun = true;
</del><ins>+
+ if (rangeVariable) {
+ dataLog("Running with rangeMin = ", rangeMin, ", rangeMax = ", rangeMax, ", rangeStep = ", rangeStep, "\n");
+ for (unsigned value = rangeMin; value <= rangeMax; value += rangeStep) {
+ dataLog("Running with value = ", value, "\n");
+ *rangeVariable = value;
+ runEverything(argv[1]);
+ }
+ } else
+ runEverything(argv[1]);
+
+ for (auto& entry : results) {
+ printf("%s = {", entry.key.data());
+ bool first = true;
+ for (double value : entry.value) {
+ if (first)
+ first = false;
+ else
+ printf(", ");
+ printf("%.3lf", value);
+ }
+ printf("};\n");
</ins><span class="cx"> }
</span><del>- if (!strcmp(argv[1], "wordlock") || !strcmp(argv[1], "all")) {
- runBenchmark<WordLock>("WTF WordLock");
- didRun = true;
- }
- if (!strcmp(argv[1], "lock") || !strcmp(argv[1], "all")) {
- runBenchmark<Lock>("WTF Lock");
- didRun = true;
- }
- if (!strcmp(argv[1], "mutex") || !strcmp(argv[1], "all")) {
- runBenchmark<Mutex>("Platform Mutex");
- didRun = true;
- }
</del><span class="cx">
</span><del>- if (!didRun)
- usage();
-
</del><span class="cx"> return 0;
</span><span class="cx"> }
</span></span></pre>
</div>
</div>
</body>
</html>