From 13f59428d9038e265d3088a440959f19622047d5 Mon Sep 17 00:00:00 2001 From: TheTechsTech Date: Tue, 9 May 2023 12:19:08 -0400 Subject: [PATCH 1/8] add GHA CI, and performance timing test --- .github/workflows/ci.yml | 87 ++++++++++++++++++++++++++++++++++++++++ tests/Makefile | 10 +++-- tests/coro_timing.c | 65 ++++++++++++++++++++++++++++++ 3 files changed, 159 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/ci.yml create mode 100644 tests/coro_timing.c diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..2e78270 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,87 @@ +name: CI + +on: [push, pull_request] + +jobs: + build: + name: ${{ matrix.target }} + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + include: + - target: amd64 + flags: -O3 -fomit-frame-pointer + - target: x86 + flags: -m32 -O3 -fomit-frame-pointer + steps: + - uses: actions/checkout@v3 + - name: Prepare + run: | + sudo dpkg --add-architecture i386 + sudo apt-get update -q -y + sudo apt-get install -y gcc-multilib g++-multilib valgrind libc6-dbg libc6-dbg:i386 + - name: Build + working-directory: tests + run: make + - name: Test + working-directory: tests + run: make test-all + + build-qemu: + name: ${{ matrix.target }} + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + include: + - target: arm + arch: armv7 + - target: aarch64 + arch: aarch64 + - target: ppc64v2 + arch: ppc64le + steps: + - uses: actions/checkout@v3 + - uses: uraimo/run-on-arch-action@v2 + with: + arch: ${{ matrix.arch }} + distro: ubuntu_latest + install: | + apt-get update -q -y + apt-get install -q -y --no-install-recommends build-essential valgrind + env: | + target: ${{ matrix.target }} + run: | + cd tests + make + make test-all + + build-windows: + name: Windows (${{ matrix.arch }}) + runs-on: windows-latest + strategy: + fail-fast: false + matrix: + arch: [amd64, x86] + steps: + - uses: ilammy/msvc-dev-cmd@v1 + with: + arch: ${{ matrix.arch }} + - uses: actions/checkout@v3 + - name: Build + working-directory: tests + run: | + cl /I .. coro_timing.c + cl /I .. testsuite.c + cl /I .. example.c + cl /I .. mt-example.c + cl /I .. simple.c + - name: Test + working-directory: tests + run: | + .\testsuite.exe + .\example.exe + .\mt-example.exe + .\simple.exe + .\coro_timing.exe diff --git a/tests/Makefile b/tests/Makefile index 2aad113..1167905 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -26,7 +26,7 @@ WASMTIME=wasmtime # OUTEXT=.exe # RUNNER= -all: testsuite example mt-example simple benchmark +all: testsuite example mt-example simple benchmark coro_timing test: testsuite $(RUNNER) ./testsuite$(OUTEXT) @@ -34,11 +34,12 @@ test: testsuite test-example: example $(RUNNER) ./example$(OUTEXT) -test-all: testsuite example mt-example simple +test-all: testsuite example mt-example simple coro_timing $(RUNNER) ./testsuite$(OUTEXT) $(RUNNER) ./example$(OUTEXT) $(RUNNER) ./mt-example$(OUTEXT) $(RUNNER) ./simple$(OUTEXT) + $(RUNNER) ./coro_timing$(OUTEXT) bench: benchmark ./benchmark$(OUTEXT) @@ -46,6 +47,9 @@ bench: benchmark testsuite: testsuite.c ../minicoro.h Makefile $(CC) testsuite.c -o testsuite $(EXTRA_CFLAGS) $(CFLAGS) +coro_timing: coro_timing.c ../minicoro.h Makefile + $(CC) coro_timing.c -o coro_timing $(EXTRA_CFLAGS) $(CFLAGS) + example: example.c ../minicoro.h Makefile $(CC) example.c -o example $(EXTRA_CFLAGS) $(CFLAGS) @@ -59,7 +63,7 @@ benchmark: benchmark.c ../minicoro.h Makefile $(CC) benchmark.c -o benchmark $(EXTRA_CFLAGS) $(CFLAGS) $(RELEASE_CFLAGS) -std=c99 clean: - rm -f testsuite$(OUTEXT) example$(OUTEXT) mt-example$(OUTEXT) simple$(OUTEXT) benchmark$(OUTEXT) + rm -f testsuite$(OUTEXT) example$(OUTEXT) mt-example$(OUTEXT) simple$(OUTEXT) benchmark$(OUTEXT) coro_timing$(OUTEXT) test-riscv64: $(MAKE) --no-print-directory CC=riscv64-elf-gcc CFLAGS="-march=rv64gc -mabi=lp64d" RUNNER=qemu-riscv64 clean test test-example diff --git a/tests/coro_timing.c b/tests/coro_timing.c new file mode 100644 index 0000000..f6b7f1e --- /dev/null +++ b/tests/coro_timing.c @@ -0,0 +1,65 @@ +#define MINICORO_IMPL +#define MCO_NO_DEBUG 1 +#include "minicoro.h" +#include +#include +#include +#include + +enum +{ + Iterations = 500000000 +}; + +static int counter; + +void co_timingtest(mco_coro *co) +{ + for (;;) + { + counter++; + mco_yield(co); + } +} + +void sub_timingtest() +{ + counter++; +} + +int main() +{ + printf("context-switching timing test\n\n"); + time_t start, end; + mco_coro *thread_y; + int i, t1, t2; + + start = clock(); + for (counter = 0, i = 0; i < Iterations; i++) + { + sub_timingtest(); + } + end = clock(); + + t1 = (int)difftime(end, start); + printf("%2.3f seconds per 50 million subroutine calls (%d iterations)\n", (float)t1 / CLOCKS_PER_SEC, counter); + + mco_desc desc = mco_desc_init(co_timingtest, 0); + desc.user_data = NULL; + mco_create(&thread_y, &desc); + mco_resume(thread_y); + start = clock(); + for (counter = 0, i = 0; i < Iterations; i++) + { + mco_resume(thread_y); + } + end = clock(); + + mco_destroy(thread_y); + + t2 = (int)difftime(end, start); + printf("%2.3f seconds per 100 million mco_resume calls (%d iterations)\n", (float)t2 / CLOCKS_PER_SEC, counter); + + printf("mco_resume skew = %fx\n\n", (double)t2 / (double)t1); + return 0; +} From e23d92b6fed29548453fbc4acea0184e933b3d8e Mon Sep 17 00:00:00 2001 From: TheTechsTech Date: Tue, 9 May 2023 12:31:31 -0400 Subject: [PATCH 2/8] ci: update ci.yml - remove ppc64le, add benchmark --- .github/workflows/ci.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2e78270..6d81848 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -39,8 +39,6 @@ jobs: arch: armv7 - target: aarch64 arch: aarch64 - - target: ppc64v2 - arch: ppc64le steps: - uses: actions/checkout@v3 - uses: uraimo/run-on-arch-action@v2 @@ -72,11 +70,12 @@ jobs: - name: Build working-directory: tests run: | - cl /I .. coro_timing.c cl /I .. testsuite.c cl /I .. example.c cl /I .. mt-example.c cl /I .. simple.c + cl /I .. coro_timing.c + cl /I .. benchmark.c - name: Test working-directory: tests run: | @@ -85,3 +84,4 @@ jobs: .\mt-example.exe .\simple.exe .\coro_timing.exe + .\benchmark.exe From 8e12f0ea20376012b1265261a6b4ed1289cae85f Mon Sep 17 00:00:00 2001 From: Lawrence Stubbs Date: Tue, 9 May 2023 18:55:43 -0400 Subject: [PATCH 3/8] update ci.yml, remove Windows benchmark build --- .github/workflows/ci.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6d81848..843bf7e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -75,7 +75,6 @@ jobs: cl /I .. mt-example.c cl /I .. simple.c cl /I .. coro_timing.c - cl /I .. benchmark.c - name: Test working-directory: tests run: | @@ -84,4 +83,3 @@ jobs: .\mt-example.exe .\simple.exe .\coro_timing.exe - .\benchmark.exe From 8e42829bffba4ecc1e722f25ad3ddc4abfd25ec1 Mon Sep 17 00:00:00 2001 From: Lawrence Stubbs Date: Tue, 9 May 2023 20:57:20 -0400 Subject: [PATCH 4/8] ci: update ci.yml - run sanitizers from Makefile --- .github/workflows/ci.yml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 843bf7e..c611b72 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -83,3 +83,14 @@ jobs: .\mt-example.exe .\simple.exe .\coro_timing.exe + + sanitizers: + name: Linux full - thread, undefined, leak, address + runs-on: ubuntu-latest + strategy: + fail-fast: false + steps: + - uses: actions/checkout@v3 + - name: Build and run sanitizer tests + working-directory: tests + run: make test-linux-full From 259e8dc39588089984370abbbe383a04e4268c41 Mon Sep 17 00:00:00 2001 From: Lawrence Stubbs Date: Fri, 9 Jun 2023 21:22:38 -0400 Subject: [PATCH 5/8] update ci.yml --- .github/workflows/ci.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c611b72..e0b614c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -91,6 +91,10 @@ jobs: fail-fast: false steps: - uses: actions/checkout@v3 + - name: Prepare + run: | + sudo apt-get update -q -y + sudo apt-get install -y gcc-multilib g++-multilib valgrind libc6-dbg - name: Build and run sanitizer tests working-directory: tests run: make test-linux-full From 099ed154249fac7f8b924f7e987ed6fa93881d3e Mon Sep 17 00:00:00 2001 From: Lawrence Stubbs Date: Sat, 10 Jun 2023 03:58:43 -0400 Subject: [PATCH 6/8] ci: update ci.yml --- .github/workflows/ci.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e0b614c..a494222 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -93,8 +93,9 @@ jobs: - uses: actions/checkout@v3 - name: Prepare run: | + sudo dpkg --add-architecture i386 sudo apt-get update -q -y - sudo apt-get install -y gcc-multilib g++-multilib valgrind libc6-dbg + sudo apt-get install -y gcc-multilib g++-multilib valgrind libc6-dbg libc6-dbg:i386 - name: Build and run sanitizer tests working-directory: tests run: make test-linux-full From 2e5722347db5738a82aa8b14bff55a515aa86f45 Mon Sep 17 00:00:00 2001 From: Lawrence Stubbs Date: Sat, 10 Jun 2023 04:14:06 -0400 Subject: [PATCH 7/8] ci: update ci.yml --- .github/workflows/ci.yml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a494222..903939f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,9 +18,8 @@ jobs: - uses: actions/checkout@v3 - name: Prepare run: | - sudo dpkg --add-architecture i386 sudo apt-get update -q -y - sudo apt-get install -y gcc-multilib g++-multilib valgrind libc6-dbg libc6-dbg:i386 + sudo apt-get install -y gcc-multilib g++-multilib valgrind - name: Build working-directory: tests run: make @@ -93,9 +92,8 @@ jobs: - uses: actions/checkout@v3 - name: Prepare run: | - sudo dpkg --add-architecture i386 sudo apt-get update -q -y - sudo apt-get install -y gcc-multilib g++-multilib valgrind libc6-dbg libc6-dbg:i386 + sudo apt-get install -y gcc-multilib g++-multilib valgrind - name: Build and run sanitizer tests working-directory: tests run: make test-linux-full From 75023747200f6f628d337cf691fbe7c7315e83aa Mon Sep 17 00:00:00 2001 From: Lawrence Stubbs Date: Sat, 10 Jun 2023 06:15:49 -0400 Subject: [PATCH 8/8] ci: update ci.yml - remove arm build --- .github/workflows/ci.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 903939f..431400a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -34,8 +34,6 @@ jobs: fail-fast: false matrix: include: - - target: arm - arch: armv7 - target: aarch64 arch: aarch64 steps: