File tree Expand file tree Collapse file tree 2 files changed +78
-0
lines changed Expand file tree Collapse file tree 2 files changed +78
-0
lines changed Original file line number Diff line number Diff line change
1
+ #include < cassert>
2
+ #include < cstdint>
3
+ #include < cstdlib>
4
+ #include < atomic>
5
+ #include < iostream>
6
+ #include < thread>
7
+ #include < vector>
8
+
9
+ static std::atomic<uint64_t > count;
10
+ static std::atomic<int > threads_launched;
11
+
12
+ static void run (int num_threads, int num_iterations)
13
+ {
14
+ threads_launched++;
15
+ while (threads_launched != num_threads) {
16
+ /* active wait */
17
+ }
18
+
19
+ uint64_t res = 0 ;
20
+ for (int i = 0 ; i < num_iterations; ++i) {
21
+ res += 1 ;
22
+ }
23
+ count += res;
24
+ }
25
+
26
+ int main (int argc, char *argv[])
27
+ {
28
+ if (argc != 3 ) {
29
+ std::cout << " usage: num_threads num_iterations\n " ;
30
+ exit (EXIT_FAILURE);
31
+ }
32
+
33
+ const int num_threads = std::stoi (argv[1 ]);
34
+ const int num_iterations = std::stoi (argv[2 ]);
35
+ std::vector<std::thread> threads;
36
+
37
+ for (int i = 0 ; i < num_threads; ++i) {
38
+ threads.push_back (std::thread (run, num_threads, num_iterations));
39
+ }
40
+ for (auto & t : threads) {
41
+ t.join ();
42
+ }
43
+ assert (count == num_iterations * num_threads);
44
+ }
Original file line number Diff line number Diff line change
1
+ #! /usr/bin/env bash
2
+
3
+ set -eu
4
+
5
+ ./build.sh
6
+
7
+ ARCH=${ARCH:- amd64}
8
+ qemu_system_args=
9
+ if [ " $ARCH " == amd64 ]; then
10
+ qemu_suffix=x86_64
11
+ elif [ " $ARCH " == i386 ]; then
12
+ qemu_suffix=i386
13
+ elif [ " $ARCH " == arm64v8 ]; then
14
+ qemu_suffix=aarch64
15
+ qemu_system_args=" -M virt"
16
+ fi
17
+
18
+ gui_run=$( which xvfb-run || true)
19
+
20
+ g++ mt.cpp -o build/mt
21
+
22
+ qemu_user=./build/qemu-$qemu_suffix
23
+ qemu_system=" ./build/qemu-system-$qemu_suffix $qemu_system_args "
24
+ bin=" build/mt 17 1000" # 17 threads, 1000 iterations
25
+ $qemu_user -plugin build/tests/tcg/plugins/libinline.so -d plugin " $@ " $bin
26
+ # $qemu_user -plugin build/tests/tcg/plugins/libinline.so "$@" \
27
+ # -d op,op_opt,in_asm,out_asm $bin |& head -n 1000 > build/plugin.on
28
+ # $qemu_user "$@" -d op,op_opt,in_asm,out_asm $bin |&
29
+ # head -n 1000 > build/plugin.off
30
+ echo -----------------------------------------
31
+ # $gui_run timeout --preserve-status 2 $qemu_system\
32
+ # -plugin build/tests/plugin/libinline.so -smp 8
33
+ # vim build/plugin_sys
34
+ # vimdiff build/plugin.*
You can’t perform that action at this time.
0 commit comments