apps: remove threading benchmarks now in bench repo

This commit is contained in:
Amy Ousterhout 2019-02-22 17:11:17 -05:00 committed by Josh Fried
parent 9f7f74699d
commit 23d54f9f3b
5 changed files with 5 additions and 329 deletions

View File

@ -4,8 +4,6 @@ efficiency_linux
stress
stress_linux
tbench
tbench_arachne
tbench_linux
netbench
netbench2
netbench_udp

View File

@ -5,7 +5,6 @@ CXXPATH = ../../bindings/cc
INC = -I../../inc -I../../bindings/cc -I./
CXXFLAGS = -g -Wall -std=gnu++11 -D_GNU_SOURCE $(INC) -mssse3
LDFLAGS = -T../../base/base.ld -no-pie
ARACHNE ?= /home/friedj/memcached-arachne/arachne-all/Arachne
LD = g++
CC = g++
@ -27,9 +26,6 @@ fake_worker_obj = $(fake_worker_src:.cc=.o)
tbench_src = tbench.cc
tbench_obj = $(tbench_src:.cc=.o)
tbench_linux_src = tbench_linux.cc
tbench_linux_obj = $(tbench_linux_src:.cc=.o)
callibrate_src = callibrate.cc
callibrate_obj = $(callibrate_src:.cc=.o)
@ -65,25 +61,14 @@ linux_mech_bench_obj = $(linux_mech_bench_src:.cc=.o)
librt_libs = $(CXXPATH)/librt++.a $(BASEPATH)/libruntime.a $(BASEPATH)/libnet.a $(BASEPATH)/libbase.a
LIBS_ARACHNE=-I$(ARACHNE)/include -I$(ARACHNE)/../CoreArbiter/include -I$(ARACHNE)/../PerfUtils/include \
-L$(ARACHNE)/lib -lArachne -L$(ARACHNE)/../CoreArbiter/lib -lCoreArbiter \
$(ARACHNE)/../PerfUtils/lib/libPerfUtils.a -lpcrecpp -pthread
# must be first
all: tbench tbench_linux callibrate stress efficiency efficiency_linux \
all: tbench callibrate stress efficiency efficiency_linux \
netbench netbench2 netbench_udp netbench_linux netperf linux_mech_bench \
stress_linux tbench_arachne
stress_linux
tbench: $(tbench_obj) $(librt_libs)
$(LD) -o $@ $(LDFLAGS) $(tbench_obj) $(librt_libs) -lpthread
tbench_linux: $(tbench_linux_obj)
$(LD) -o $@ $(LDFLAGS) $(tbench_linux_obj) -lpthread
tbench_arachne: tbench_arachne.cc
$(LD) -o $@ $(LDFLAGS) tbench_arachne.cc $(LIBS_ARACHNE)
callibrate: $(fake_worker_obj) $(callibrate_obj)
$(LD) -o $@ $(LDFLAGS) $(fake_worker_obj) $(callibrate_obj) -lpthread
@ -120,7 +105,7 @@ linux_mech_bench: $(linux_mech_bench_obj) $(librt_libs)
$(LD) -o $@ $(LDFLAGS) $(linux_mech_bench_obj) $(librt_libs) -lpthread
# general build rules for all targets
src = $(fake_worker_src) $(tbench_src) $(tbench_linux_src) $(callibrate_src)
src = $(fake_worker_src) $(tbench_src) $(callibrate_src)
src += $(stress_src) $(efficiency_src) $(efficiency_linux_src) $(netbench_src)
src += $(netbench2_src) $(netbench_udp_src) $(netbench_linux_src) $(netperf_src)
src += $(linux_mech_bench_src)
@ -140,6 +125,6 @@ endif
.PHONY: clean
clean:
rm -f $(obj) $(dep) tbench tbench_linux callibrate stress efficiency \
rm -f $(obj) $(dep) tbench callibrate stress efficiency \
efficiency_linux netbench netbench2 netbench_udp netbench_linux \
netperf linux_mech_bench stress_linux tbench_arachne
netperf linux_mech_bench stress_linux

View File

@ -1,76 +0,0 @@
package main
import (
"testing"
"sync"
"runtime"
)
func BenchmarkSpawnJoin(b *testing.B) {
c := make(chan int, 1)
for i := 0; i < b.N; i++ {
go func() {
c <- 1
}()
<-c
}
}
func BenchmarkUncontendedMutex(b *testing.B) {
var m = &sync.Mutex{}
for i := 0; i < b.N; i++ {
m.Lock()
m.Unlock()
}
}
func BenchmarkYield(b *testing.B) {
c := make(chan int, 1)
go func() {
for i := 0; i < b.N / 2; i++ {
runtime.Gosched()
}
c <- 1
}()
for i := 0; i < b.N / 2; i++ {
runtime.Gosched()
}
<-c
}
func BenchmarkCondvarPingPong(b *testing.B) {
m := &sync.Mutex{}
cv := sync.NewCond(m)
c := make(chan int, 1)
dir := bool(false)
go func() {
m.Lock()
for i := 0; i < b.N / 2; i++ {
for dir {
cv.Wait()
}
dir = true
cv.Signal()
}
m.Unlock()
c <- 1
}()
m.Lock()
for i := 0; i < b.N / 2; i++ {
for !dir {
cv.Wait()
}
dir = false
cv.Signal()
}
m.Unlock()
<-c
}

View File

@ -1,127 +0,0 @@
#include <chrono>
#include <iostream>
#include "Arachne/Arachne.h"
namespace {
using us = std::chrono::duration<double, std::micro>;
constexpr int kMeasureRounds = 1000000;
void empty_thread() {;}
void BenchSpawnJoin() {
for (int i = 0; i < kMeasureRounds; ++i) {
auto th = Arachne::createThread(empty_thread);
Arachne::join(th);
}
}
void BenchUncontendedMutex() {
Arachne::SpinLock mutex;
volatile unsigned long foo = 0;
for (int i = 0; i < kMeasureRounds; ++i) {
mutex.lock();
foo++;
mutex.unlock();
}
}
void yielder() {
for (int i = 0; i < kMeasureRounds / 2; ++i)
Arachne::yield();
}
void BenchYield() {
auto th = Arachne::createThread(yielder);
yielder();
Arachne::join(th);
}
struct pong {
Arachne::SpinLock mutex;
Arachne::ConditionVariable cv;
bool dir = false;
};
void ping_pong_1(struct pong *p)
{
p->mutex.lock();
for (int i = 0; i < kMeasureRounds / 2; ++i) {
while (p->dir)
p->cv.wait(p->mutex);
p->dir = true;
p->cv.notifyOne();
}
p->mutex.unlock();
}
void BenchCondvarPingPong() {
struct pong p;
auto th = Arachne::createThread(ping_pong_1, &p);
p.mutex.lock();
for (int i = 0; i < kMeasureRounds / 2; ++i) {
while (!p.dir)
p.cv.wait(p.mutex);
p.dir = false;
p.cv.notifyOne();
}
Arachne::join(th);
}
void PrintResult(std::string name, us time) {
time /= kMeasureRounds;
std::cout << "test '" << name << "' took "<< time.count() << " us."
<< std::endl;
}
int MainHandler() {
auto start = std::chrono::steady_clock::now();
BenchSpawnJoin();
auto finish = std::chrono::steady_clock::now();
PrintResult("SpawnJoin",
std::chrono::duration_cast<us>(finish - start));
start = std::chrono::steady_clock::now();
BenchUncontendedMutex();
finish = std::chrono::steady_clock::now();
PrintResult("UncontendedMutex",
std::chrono::duration_cast<us>(finish - start));
start = std::chrono::steady_clock::now();
BenchYield();
finish = std::chrono::steady_clock::now();
PrintResult("Yield",
std::chrono::duration_cast<us>(finish - start));
start = std::chrono::steady_clock::now();
BenchCondvarPingPong();
finish = std::chrono::steady_clock::now();
PrintResult("CondvarPingPong",
std::chrono::duration_cast<us>(finish - start));
Arachne::shutDown();
return 0;
}
} // anonymous namespace
// Requires coreArbiter: ./coreArbiterServer
int
main(int argc, const char** argv) {
// Initialize the library
Arachne::minNumCores = 1;
Arachne::maxNumCores = 1;
Arachne::disableLoadEstimation = true;
Arachne::init(&argc, argv);
Arachne::createThreadOnCore(2, MainHandler);
Arachne::waitForTermination();
return 0;
}

View File

@ -1,104 +0,0 @@
#include <chrono>
#include <iostream>
#include <thread>
#include <mutex>
#include <condition_variable>
namespace {
using us = std::chrono::duration<double, std::micro>;
constexpr int kMeasureRounds = 1000000;
void BenchSpawnJoin() {
for (int i = 0; i < kMeasureRounds; ++i) {
auto th = std::thread([](){;});
th.join();
}
}
void BenchUncontendedMutex() {
std::mutex m;
volatile unsigned long foo = 0;
for (int i = 0; i < kMeasureRounds; ++i) {
std::unique_lock<std::mutex> l(m);
foo++;
}
}
void BenchYield() {
auto th = std::thread([](){
for (int i = 0; i < kMeasureRounds / 2; ++i)
std::this_thread::yield();
});
for (int i = 0; i < kMeasureRounds / 2; ++i)
std::this_thread::yield();
th.join();
}
void BenchCondvarPingPong() {
std::mutex m;
std::condition_variable cv;
bool dir = false; // shared and protected by @m.
auto th = std::thread([&](){
std::unique_lock<std::mutex> l(m);
for (int i = 0; i < kMeasureRounds / 2; ++i) {
while (dir)
cv.wait(l);
dir = true;
cv.notify_one();
}
});
std::unique_lock<std::mutex> l(m);
for (int i = 0; i < kMeasureRounds / 2; ++i) {
while (!dir)
cv.wait(l);
dir = false;
cv.notify_one();
}
th.join();
}
void PrintResult(std::string name, us time) {
time /= kMeasureRounds;
std::cout << "test '" << name << "' took "<< time.count() << " us."
<< std::endl;
}
void MainHandler(void *arg) {
auto start = std::chrono::steady_clock::now();
BenchSpawnJoin();
auto finish = std::chrono::steady_clock::now();
PrintResult("SpawnJoin",
std::chrono::duration_cast<us>(finish - start));
start = std::chrono::steady_clock::now();
BenchUncontendedMutex();
finish = std::chrono::steady_clock::now();
PrintResult("UncontendedMutex",
std::chrono::duration_cast<us>(finish - start));
start = std::chrono::steady_clock::now();
BenchYield();
finish = std::chrono::steady_clock::now();
PrintResult("Yield",
std::chrono::duration_cast<us>(finish - start));
start = std::chrono::steady_clock::now();
BenchCondvarPingPong();
finish = std::chrono::steady_clock::now();
PrintResult("CondvarPingPong",
std::chrono::duration_cast<us>(finish - start));
}
} // anonymous namespace
int main(int argc, char *argv[]) {
MainHandler(NULL);
return 0;
}