Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
MallocBench: Added recording for nimlang website, new recording detai…
…ls and added new options

https://bugs.webkit.org/show_bug.cgi?id=154485

Reviewed by Geoff Garen.

Added new capabilities to MallocBench.  These include:
    Added a recording of http://nim-lang.org/docs/lib.html.
    Added thread id to the recording and the ability to playback switching threads in MallocBench
    Added aligned allocations to recordings and the ability to playback
    Added --use-thread-id option to honor recorded thread ids
    Added --detailed-report to output remaining allocations by size after playback
    Added --no-warmup to not run the warm up iteration

Changed the way that options are passed down to the benchmarks.  Instead of passing individual
boolean or numeric option values, just pass a reference the CommandLine itself.  Each benchmark
can access the options that are appropriate.  The Benchmark class also uses the options for
is parallel, run counts and warm up.

Added thread id and aligned malloc to the Op by noticing that structure padding and Opcode allowed
for another 32 bits of data.  Breaking that unused 32 bits into a 16 bit thread id value and a
16 bit log base 2 of the alignment for aligned malloc allowed for existing recordings to playback
without any incompatibilities.

Threaded operation is simulated by creating threads as needed.  As long as the next Op's thread id
is the same as the last, operation continues as normal.  When the next Op has a different thread id,
we switch to that thread using the shared Op stream to continue playing back.  There is a mutex to
assure that only one thread is really running at a time and a condition variable used to wait
that the current thread id matches each block thread's thread id.  This doesn't simulate true
concurrent threading, but is instead plays back Ops recorded for multiple thread faithfully.

* MallocBench/MallocBench.xcodeproj/project.pbxproj:
* MallocBench/MallocBench/Benchmark.cpp:
(deallocateHeap):
(Benchmark::Benchmark):
(Benchmark::runOnce):
(Benchmark::run):
* MallocBench/MallocBench/Benchmark.h:
(Benchmark::isValid):
* MallocBench/MallocBench/CommandLine.cpp:
(CommandLine::printUsage):
* MallocBench/MallocBench/CommandLine.h:
(CommandLine::isValid):
(CommandLine::benchmarkName):
(CommandLine::isParallel):
(CommandLine::useThreadID):
(CommandLine::detailedReport):
(CommandLine::warmUp):
(CommandLine::heapSize):
(CommandLine::runs):
* MallocBench/MallocBench/Interpreter.cpp:
(Interpreter::Interpreter):
(Interpreter::run):
(Interpreter::readOps):
(Interpreter::doOnSameThread):
(Interpreter::switchToThread):
(Interpreter::detailedReport):
(compute2toPower):
(writeData):
(Interpreter::doMallocOp):
(Interpreter::Thread::Thread):
(Interpreter::Thread::stop):
(Interpreter::Thread::~Thread):
(Interpreter::Thread::runThread):
(Interpreter::Thread::waitToRun):
(Interpreter::Thread::switchTo):
* MallocBench/MallocBench/Interpreter.h:
(Interpreter::Thread::isMainThread):
* MallocBench/MallocBench/alloc_free.cpp: Added.
(benchmark_alloc_free):
* MallocBench/MallocBench/alloc_free.h: Added.
* MallocBench/MallocBench/balloon.cpp:
(benchmark_balloon):
* MallocBench/MallocBench/balloon.h:
* MallocBench/MallocBench/big.cpp:
(benchmark_big):
* MallocBench/MallocBench/big.h:
* MallocBench/MallocBench/churn.cpp:
(benchmark_churn):
* MallocBench/MallocBench/churn.h:
* MallocBench/MallocBench/facebook.cpp:
(benchmark_facebook):
* MallocBench/MallocBench/facebook.h:
* MallocBench/MallocBench/flickr.cpp:
(benchmark_flickr):
(benchmark_flickr_memory_warning):
* MallocBench/MallocBench/flickr.h:
* MallocBench/MallocBench/fragment.cpp:
(validate):
(benchmark_fragment):
(benchmark_fragment_iterate):
* MallocBench/MallocBench/fragment.h:
* MallocBench/MallocBench/list.cpp:
(benchmark_list_allocate):
(benchmark_list_traverse):
* MallocBench/MallocBench/list.h:
* MallocBench/MallocBench/main.cpp:
(main):
* MallocBench/MallocBench/medium.cpp:
(benchmark_medium):
* MallocBench/MallocBench/medium.h:
* MallocBench/MallocBench/memalign.cpp:
(test):
(benchmark_memalign):
* MallocBench/MallocBench/memalign.h:
* MallocBench/MallocBench/message.cpp:
(benchmark_message_one):
(benchmark_message_many):
* MallocBench/MallocBench/message.h:
* MallocBench/MallocBench/nimlang.cpp: Added.
(benchmark_nimlang):
* MallocBench/MallocBench/nimlang.h: Added.
* MallocBench/MallocBench/nimlang.ops: Added.
* MallocBench/MallocBench/realloc.cpp:
(benchmark_realloc):
* MallocBench/MallocBench/realloc.h:
* MallocBench/MallocBench/reddit.cpp:
(benchmark_reddit):
(benchmark_reddit_memory_warning):
* MallocBench/MallocBench/reddit.h:
* MallocBench/MallocBench/stress.cpp:
(deallocate):
(benchmark_stress):
* MallocBench/MallocBench/stress.h:
* MallocBench/MallocBench/stress_aligned.cpp:
(benchmark_stress_aligned):
* MallocBench/MallocBench/stress_aligned.h:
* MallocBench/MallocBench/theverge.cpp:
(benchmark_theverge):
(benchmark_theverge_memory_warning):
* MallocBench/MallocBench/theverge.h:
* MallocBench/MallocBench/tree.cpp:
(benchmark_tree_allocate):
(benchmark_tree_traverse):
(benchmark_tree_churn):
* MallocBench/MallocBench/tree.h:
* MallocBench/run-malloc-benchmarks:


Canonical link: https://commits.webkit.org/172661@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@196955 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
msaboff committed Feb 22, 2016
1 parent d5dbfd0 commit a04166a
Show file tree
Hide file tree
Showing 47 changed files with 763 additions and 123 deletions.
139 changes: 139 additions & 0 deletions PerformanceTests/ChangeLog
@@ -1,3 +1,142 @@
2016-02-19 Michael Saboff <msaboff@apple.com>

MallocBench: Added recording for nimlang website, new recording details and added new options
https://bugs.webkit.org/show_bug.cgi?id=154485

Reviewed by Geoff Garen.

Added new capabilities to MallocBench. These include:
Added a recording of http://nim-lang.org/docs/lib.html.
Added thread id to the recording and the ability to playback switching threads in MallocBench
Added aligned allocations to recordings and the ability to playback
Added --use-thread-id option to honor recorded thread ids
Added --detailed-report to output remaining allocations by size after playback
Added --no-warmup to not run the warm up iteration

Changed the way that options are passed down to the benchmarks. Instead of passing individual
boolean or numeric option values, just pass a reference the CommandLine itself. Each benchmark
can access the options that are appropriate. The Benchmark class also uses the options for
is parallel, run counts and warm up.

Added thread id and aligned malloc to the Op by noticing that structure padding and Opcode allowed
for another 32 bits of data. Breaking that unused 32 bits into a 16 bit thread id value and a
16 bit log base 2 of the alignment for aligned malloc allowed for existing recordings to playback
without any incompatibilities.

Threaded operation is simulated by creating threads as needed. As long as the next Op's thread id
is the same as the last, operation continues as normal. When the next Op has a different thread id,
we switch to that thread using the shared Op stream to continue playing back. There is a mutex to
assure that only one thread is really running at a time and a condition variable used to wait
that the current thread id matches each block thread's thread id. This doesn't simulate true
concurrent threading, but is instead plays back Ops recorded for multiple thread faithfully.

* MallocBench/MallocBench.xcodeproj/project.pbxproj:
* MallocBench/MallocBench/Benchmark.cpp:
(deallocateHeap):
(Benchmark::Benchmark):
(Benchmark::runOnce):
(Benchmark::run):
* MallocBench/MallocBench/Benchmark.h:
(Benchmark::isValid):
* MallocBench/MallocBench/CommandLine.cpp:
(CommandLine::printUsage):
* MallocBench/MallocBench/CommandLine.h:
(CommandLine::isValid):
(CommandLine::benchmarkName):
(CommandLine::isParallel):
(CommandLine::useThreadID):
(CommandLine::detailedReport):
(CommandLine::warmUp):
(CommandLine::heapSize):
(CommandLine::runs):
* MallocBench/MallocBench/Interpreter.cpp:
(Interpreter::Interpreter):
(Interpreter::run):
(Interpreter::readOps):
(Interpreter::doOnSameThread):
(Interpreter::switchToThread):
(Interpreter::detailedReport):
(compute2toPower):
(writeData):
(Interpreter::doMallocOp):
(Interpreter::Thread::Thread):
(Interpreter::Thread::stop):
(Interpreter::Thread::~Thread):
(Interpreter::Thread::runThread):
(Interpreter::Thread::waitToRun):
(Interpreter::Thread::switchTo):
* MallocBench/MallocBench/Interpreter.h:
(Interpreter::Thread::isMainThread):
* MallocBench/MallocBench/alloc_free.cpp: Added.
(benchmark_alloc_free):
* MallocBench/MallocBench/alloc_free.h: Added.
* MallocBench/MallocBench/balloon.cpp:
(benchmark_balloon):
* MallocBench/MallocBench/balloon.h:
* MallocBench/MallocBench/big.cpp:
(benchmark_big):
* MallocBench/MallocBench/big.h:
* MallocBench/MallocBench/churn.cpp:
(benchmark_churn):
* MallocBench/MallocBench/churn.h:
* MallocBench/MallocBench/facebook.cpp:
(benchmark_facebook):
* MallocBench/MallocBench/facebook.h:
* MallocBench/MallocBench/flickr.cpp:
(benchmark_flickr):
(benchmark_flickr_memory_warning):
* MallocBench/MallocBench/flickr.h:
* MallocBench/MallocBench/fragment.cpp:
(validate):
(benchmark_fragment):
(benchmark_fragment_iterate):
* MallocBench/MallocBench/fragment.h:
* MallocBench/MallocBench/list.cpp:
(benchmark_list_allocate):
(benchmark_list_traverse):
* MallocBench/MallocBench/list.h:
* MallocBench/MallocBench/main.cpp:
(main):
* MallocBench/MallocBench/medium.cpp:
(benchmark_medium):
* MallocBench/MallocBench/medium.h:
* MallocBench/MallocBench/memalign.cpp:
(test):
(benchmark_memalign):
* MallocBench/MallocBench/memalign.h:
* MallocBench/MallocBench/message.cpp:
(benchmark_message_one):
(benchmark_message_many):
* MallocBench/MallocBench/message.h:
* MallocBench/MallocBench/nimlang.cpp: Added.
(benchmark_nimlang):
* MallocBench/MallocBench/nimlang.h: Added.
* MallocBench/MallocBench/nimlang.ops: Added.
* MallocBench/MallocBench/realloc.cpp:
(benchmark_realloc):
* MallocBench/MallocBench/realloc.h:
* MallocBench/MallocBench/reddit.cpp:
(benchmark_reddit):
(benchmark_reddit_memory_warning):
* MallocBench/MallocBench/reddit.h:
* MallocBench/MallocBench/stress.cpp:
(deallocate):
(benchmark_stress):
* MallocBench/MallocBench/stress.h:
* MallocBench/MallocBench/stress_aligned.cpp:
(benchmark_stress_aligned):
* MallocBench/MallocBench/stress_aligned.h:
* MallocBench/MallocBench/theverge.cpp:
(benchmark_theverge):
(benchmark_theverge_memory_warning):
* MallocBench/MallocBench/theverge.h:
* MallocBench/MallocBench/tree.cpp:
(benchmark_tree_allocate):
(benchmark_tree_traverse):
(benchmark_tree_churn):
* MallocBench/MallocBench/tree.h:
* MallocBench/run-malloc-benchmarks:

2016-02-11 Jon Lee <jonlee@apple.com>

Fix a missing refactoring.
Expand Down
14 changes: 14 additions & 0 deletions PerformanceTests/MallocBench/MallocBench.xcodeproj/project.pbxproj
Expand Up @@ -38,6 +38,8 @@
14D6322E1A69BE0B00A8F84F /* memalign.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 14D6322C1A69BE0B00A8F84F /* memalign.cpp */; };
14E11932177ECC8B003A8D15 /* CPUCount.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 14E11930177ECC8B003A8D15 /* CPUCount.cpp */; };
14FCA36119A7C917001CFDA9 /* stress.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 14FCA35F19A7C917001CFDA9 /* stress.cpp */; };
65E401A61C657A87003C6E9C /* nimlang.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 65E401A41C657A87003C6E9C /* nimlang.cpp */; };
65E401AC1C73B068003C6E9C /* alloc_free.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 65E401AA1C73B068003C6E9C /* alloc_free.cpp */; };
/* End PBXBuildFile section */

/* Begin PBXCopyFilesBuildPhase section */
Expand Down Expand Up @@ -114,6 +116,11 @@
14E11934177F5219003A8D15 /* mbmalloc.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = mbmalloc.h; path = MallocBench/mbmalloc.h; sourceTree = "<group>"; };
14FCA35F19A7C917001CFDA9 /* stress.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = stress.cpp; path = MallocBench/stress.cpp; sourceTree = "<group>"; };
14FCA36019A7C917001CFDA9 /* stress.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = stress.h; path = MallocBench/stress.h; sourceTree = "<group>"; };
65E401A41C657A87003C6E9C /* nimlang.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = nimlang.cpp; path = MallocBench/nimlang.cpp; sourceTree = "<group>"; };
65E401A51C657A87003C6E9C /* nimlang.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = nimlang.h; path = MallocBench/nimlang.h; sourceTree = "<group>"; };
65E401AA1C73B068003C6E9C /* alloc_free.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = alloc_free.cpp; path = MallocBench/alloc_free.cpp; sourceTree = "<group>"; };
65E401AB1C73B068003C6E9C /* alloc_free.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = alloc_free.h; path = MallocBench/alloc_free.h; sourceTree = "<group>"; };
65E401AD1C77E7C8003C6E9C /* nimlang.ops */ = {isa = PBXFileReference; lastKnownFileType = file; name = nimlang.ops; path = MallocBench/nimlang.ops; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -192,6 +199,8 @@
14E11933177F51AC003A8D15 /* Benchmarks */ = {
isa = PBXGroup;
children = (
65E401AA1C73B068003C6E9C /* alloc_free.cpp */,
65E401AB1C73B068003C6E9C /* alloc_free.h */,
14105E7D18DF7D73003A106E /* balloon.cpp */,
14105E7E18DF7D73003A106E /* balloon.h */,
14CE4A5E17BD355800288DAA /* big.cpp */,
Expand All @@ -216,6 +225,9 @@
1444AE94177E8DF200F8030A /* message.cpp */,
1444AE95177E8DF200F8030A /* message.h */,
14105E8018E13EEC003A106E /* realloc.cpp */,
65E401A41C657A87003C6E9C /* nimlang.cpp */,
65E401AD1C77E7C8003C6E9C /* nimlang.ops */,
65E401A51C657A87003C6E9C /* nimlang.h */,
14105E8118E13EEC003A106E /* realloc.h */,
1447AE9718FB59D900B3D7FF /* reddit_memory_warning.ops */,
1447AE8A18FB584200B3D7FF /* reddit.cpp */,
Expand Down Expand Up @@ -317,13 +329,15 @@
14CE4A6017BD355800288DAA /* big.cpp in Sources */,
14976ED1177E4AF7006B819A /* tree.cpp in Sources */,
1444AE96177E8DF200F8030A /* message.cpp in Sources */,
65E401AC1C73B068003C6E9C /* alloc_free.cpp in Sources */,
14452CEF177D47110097E057 /* churn.cpp in Sources */,
14452CB0177D24460097E057 /* main.cpp in Sources */,
14FCA36119A7C917001CFDA9 /* stress.cpp in Sources */,
14C5008D184016CF007A531D /* facebook.cpp in Sources */,
1447AE9018FB584200B3D7FF /* flickr.cpp in Sources */,
14976EC8177E3649006B819A /* list.cpp in Sources */,
14976ECC177E3C87006B819A /* CommandLine.cpp in Sources */,
65E401A61C657A87003C6E9C /* nimlang.cpp in Sources */,
1447AE9218FB584200B3D7FF /* theverge.cpp in Sources */,
14D0BFF31A6F4D3B00109F31 /* stress_aligned.cpp in Sources */,
1451FAED18B14B7100DB6D47 /* medium.cpp in Sources */,
Expand Down
32 changes: 19 additions & 13 deletions PerformanceTests/MallocBench/MallocBench/Benchmark.cpp
Expand Up @@ -25,6 +25,7 @@

#include "Benchmark.h"
#include "CPUCount.h"
#include "alloc_free.h"
#include "balloon.h"
#include "big.h"
#include "churn.h"
Expand All @@ -35,8 +36,10 @@
#include "medium.h"
#include "memalign.h"
#include "message.h"
#include "nimlang.h"
#include "reddit.h"
#include "realloc.h"
#include "simple.h"
#include "stress.h"
#include "stress_aligned.h"
#include "theverge.h"
Expand All @@ -61,6 +64,7 @@ struct BenchmarkPair {
};

static const BenchmarkPair benchmarkPairs[] = {
{ "alloc_free", benchmark_alloc_free },
{ "balloon", benchmark_balloon },
{ "big", benchmark_big },
{ "churn", benchmark_churn },
Expand All @@ -75,6 +79,7 @@ static const BenchmarkPair benchmarkPairs[] = {
{ "memalign", benchmark_memalign },
{ "message_many", benchmark_message_many },
{ "message_one", benchmark_message_one },
{ "nimlang", benchmark_nimlang },
{ "realloc", benchmark_realloc },
{ "reddit", benchmark_reddit },
{ "reddit_memory_warning", benchmark_reddit_memory_warning },
Expand Down Expand Up @@ -127,15 +132,13 @@ static void deallocateHeap(void*** chunks, size_t heapSize, size_t chunkSize, si
mbfree(chunks, chunkCount * sizeof(void**));
}

Benchmark::Benchmark(const string& benchmarkName, bool isParallel, size_t runs, size_t heapSize)
Benchmark::Benchmark(CommandLine& commandLine)
: m_benchmarkPair()
, m_elapsedTime()
, m_isParallel(isParallel)
, m_heapSize(heapSize)
, m_runs(runs)
, m_commandLine(commandLine)
{
const BenchmarkPair* benchmarkPair = std::find(
benchmarkPairs, benchmarkPairs + benchmarksPairsCount, benchmarkName);
benchmarkPairs, benchmarkPairs + benchmarksPairsCount, m_commandLine.benchmarkName());
if (benchmarkPair == benchmarkPairs + benchmarksPairsCount)
return;

Expand All @@ -151,16 +154,16 @@ void Benchmark::printBenchmarks()

void Benchmark::runOnce()
{
if (!m_isParallel) {
m_benchmarkPair->function(m_isParallel);
if (!m_commandLine.isParallel()) {
m_benchmarkPair->function(m_commandLine);
return;
}

dispatch_group_t group = dispatch_group_create();

for (size_t i = 0; i < cpuCount(); ++i) {
dispatch_group_async(group, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
m_benchmarkPair->function(m_isParallel);
m_benchmarkPair->function(m_commandLine);
});
}

Expand All @@ -174,20 +177,23 @@ void Benchmark::run()
static const size_t objectSize = 32;
static const size_t chunkSize = 1024 * 1024;

void*** heap = allocateHeap(m_heapSize, chunkSize, objectSize);
void*** heap = allocateHeap(m_commandLine.heapSize(), chunkSize, objectSize);

runOnce(); // Warmup run.
if (m_commandLine.warmUp())
runOnce(); // Warmup run.

for (size_t i = 0; i < m_runs; ++i) {
size_t runs = m_commandLine.runs();

for (size_t i = 0; i < runs; ++i) {
double start = currentTimeMS();
runOnce();
double end = currentTimeMS();
double elapsed = end - start;
m_elapsedTime += elapsed;
}
m_elapsedTime /= m_runs;
m_elapsedTime /= runs;

deallocateHeap(heap, m_heapSize, chunkSize, objectSize);
deallocateHeap(heap, m_commandLine.heapSize(), chunkSize, objectSize);

mbscavenge();
m_memory = currentMemoryBytes();
Expand Down
10 changes: 5 additions & 5 deletions PerformanceTests/MallocBench/MallocBench/Benchmark.h
Expand Up @@ -26,10 +26,11 @@
#ifndef Benchmark_h
#define Benchmark_h

#include "CommandLine.h"
#include <map>
#include <string>

typedef void (*BenchmarkFunction)(bool isParallel);
typedef void (*BenchmarkFunction)(CommandLine& commandLine);
struct BenchmarkPair;

class Benchmark {
Expand Down Expand Up @@ -59,7 +60,7 @@ class Benchmark {
static double currentTimeMS();
static Memory currentMemoryBytes();

Benchmark(const std::string&, bool isParallel, size_t runs, size_t heapSize);
Benchmark(CommandLine&);

bool isValid() { return m_benchmarkPair; }

Expand All @@ -75,9 +76,8 @@ class Benchmark {
MapType m_map;

const BenchmarkPair* m_benchmarkPair;
bool m_isParallel;
size_t m_runs;
size_t m_heapSize;

CommandLine& m_commandLine;

Memory m_memory;
double m_elapsedTime;
Expand Down

0 comments on commit a04166a

Please sign in to comment.