forked from qemu/qemu
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2c60cb7
commit 957d0fe
Showing
2 changed files
with
78 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#include <cassert> | ||
#include <cstdint> | ||
#include <cstdlib> | ||
#include <atomic> | ||
#include <iostream> | ||
#include <thread> | ||
#include <vector> | ||
|
||
static std::atomic<uint64_t> count; | ||
static std::atomic<int> threads_launched; | ||
|
||
static void run(int num_threads, int num_iterations) | ||
{ | ||
threads_launched++; | ||
while (threads_launched != num_threads) { | ||
/* active wait */ | ||
} | ||
|
||
uint64_t res = 0; | ||
for (int i = 0; i < num_iterations; ++i) { | ||
res += 1; | ||
} | ||
count += res; | ||
} | ||
|
||
int main(int argc, char *argv[]) | ||
{ | ||
if (argc != 3) { | ||
std::cout << "usage: num_threads num_iterations\n"; | ||
exit(EXIT_FAILURE); | ||
} | ||
|
||
const int num_threads = std::stoi(argv[1]); | ||
const int num_iterations = std::stoi(argv[2]); | ||
std::vector<std::thread> threads; | ||
|
||
for (int i = 0; i < num_threads; ++i) { | ||
threads.push_back(std::thread(run, num_threads, num_iterations)); | ||
} | ||
for (auto & t : threads) { | ||
t.join(); | ||
} | ||
assert(count == num_iterations * num_threads); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -eu | ||
|
||
./build.sh | ||
|
||
ARCH=${ARCH:-amd64} | ||
qemu_system_args= | ||
if [ "$ARCH" == amd64 ]; then | ||
qemu_suffix=x86_64 | ||
elif [ "$ARCH" == i386 ]; then | ||
qemu_suffix=i386 | ||
elif [ "$ARCH" == arm64v8 ]; then | ||
qemu_suffix=aarch64 | ||
qemu_system_args="-M virt" | ||
fi | ||
|
||
gui_run=$(which xvfb-run || true) | ||
|
||
g++ mt.cpp -o build/mt | ||
|
||
qemu_user=./build/qemu-$qemu_suffix | ||
qemu_system="./build/qemu-system-$qemu_suffix $qemu_system_args" | ||
bin="build/mt 17 1000" # 17 threads, 1000 iterations | ||
$qemu_user -plugin build/tests/tcg/plugins/libinline.so -d plugin "$@" $bin | ||
#$qemu_user -plugin build/tests/tcg/plugins/libinline.so "$@" \ | ||
# -d op,op_opt,in_asm,out_asm $bin |& head -n 1000 > build/plugin.on | ||
#$qemu_user "$@" -d op,op_opt,in_asm,out_asm $bin |& | ||
# head -n 1000 > build/plugin.off | ||
echo ----------------------------------------- | ||
#$gui_run timeout --preserve-status 2 $qemu_system\ | ||
# -plugin build/tests/plugin/libinline.so -smp 8 | ||
#vim build/plugin_sys | ||
#vimdiff build/plugin.* |