diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000000000000000000000000000000000000..5f8df3c8c9e8490845248e33e3a7cdf1e20c89a7 --- /dev/null +++ b/.clang-format @@ -0,0 +1,5 @@ +--- +BasedOnStyle: Google +ColumnLimit: 100 +TabWidth: 2 +UseTab: Always diff --git a/.clang-tidy b/.clang-tidy new file mode 100644 index 0000000000000000000000000000000000000000..b914e66b2dbd60a60b3c86493b0f09439fe15064 --- /dev/null +++ b/.clang-tidy @@ -0,0 +1,24 @@ +Checks: > + bugprone-*, + cert-*, + linuxkernel-*, + modernize-*, + performance-*, + portability-*, + readability-*, + -cert-err58-cpp, + -clang-diagnostic-empty-translation-unit, + -readability-braces-around-statements, + -readability-function-cognitive-complexity, + -readability-implicit-bool-conversion, + -readability-isolate-declaration, + -readability-magic-numbers, + +WarningsAsErrors: > + bugprone-*, + modernize-*, + clang-*, + readability-*, + performance-*, + +HeaderFilterRegex: .* diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 550e2f028887b50da3420a13f510a83ab8e77eef..ccdc51fa7973be5d916e8f65d867a3610a2f3ad7 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -14,3 +14,11 @@ before_script: test-eval: script: - make + +tidy: + script: + - make tidy + +check-format: + script: + - make check-format diff --git a/Makefile b/Makefile index 139ebf00e484c843e211e95e898ee29cffc8b82b..addbf9445e244ca1deb5c54b75b009f50c620f94 100644 --- a/Makefile +++ b/Makefile @@ -27,3 +27,12 @@ $(foreach syscall,$(SYSCALLS),$(eval $(call generateTargets,$(syscall)))) clean: rm -f $(OBJ) + +tidy: + clang-tidy *.c + +check-format: + tools/check-format + +format: + clang-format -i *.c *.h diff --git a/compile_commands.json b/compile_commands.json new file mode 100644 index 0000000000000000000000000000000000000000..ca4b9445b8031c904cc4f7e8919d89ce602696d2 --- /dev/null +++ b/compile_commands.json @@ -0,0 +1,359 @@ +[ + { + "arguments": [ + "/sbin/cc", + "-c", + "-Werror", + "-Wall", + "-g", + "-O0", + "-pthread", + "-o", + "bench-blocking", + "blocking.c" + ], + "directory": "/home/muhq/code/fgbs-syscall-eval", + "file": "/home/muhq/code/fgbs-syscall-eval/blocking.c", + "output": "/home/muhq/code/fgbs-syscall-eval/bench-blocking" + }, + { + "arguments": [ + "/sbin/cc", + "-c", + "-Werror", + "-Wall", + "-g", + "-O0", + "-pthread", + "-o", + "bench-blocking", + "bench.c" + ], + "directory": "/home/muhq/code/fgbs-syscall-eval", + "file": "/home/muhq/code/fgbs-syscall-eval/bench.c", + "output": "/home/muhq/code/fgbs-syscall-eval/bench-blocking" + }, + { + "arguments": [ + "/sbin/cc", + "-c", + "-Werror", + "-Wall", + "-g", + "-O0", + "-pthread", + "-o", + "bench-blocking", + "stopwatch.c" + ], + "directory": "/home/muhq/code/fgbs-syscall-eval", + "file": "/home/muhq/code/fgbs-syscall-eval/stopwatch.c", + "output": "/home/muhq/code/fgbs-syscall-eval/bench-blocking" + }, + { + "arguments": [ + "/sbin/cc", + "-c", + "-Werror", + "-Wall", + "-g", + "-O0", + "-pthread", + "-o", + "bench-io-uring", + "io-uring.c" + ], + "directory": "/home/muhq/code/fgbs-syscall-eval", + "file": "/home/muhq/code/fgbs-syscall-eval/io-uring.c", + "output": "/home/muhq/code/fgbs-syscall-eval/bench-io-uring" + }, + { + "arguments": [ + "/sbin/cc", + "-c", + "-Werror", + "-Wall", + "-g", + "-O0", + "-pthread", + "-o", + "bench-io-uring", + "bench.c" + ], + "directory": "/home/muhq/code/fgbs-syscall-eval", + "file": "/home/muhq/code/fgbs-syscall-eval/bench.c", + "output": "/home/muhq/code/fgbs-syscall-eval/bench-io-uring" + }, + { + "arguments": [ + "/sbin/cc", + "-c", + "-Werror", + "-Wall", + "-g", + "-O0", + "-pthread", + "-o", + "bench-io-uring", + "stopwatch.c" + ], + "directory": "/home/muhq/code/fgbs-syscall-eval", + "file": "/home/muhq/code/fgbs-syscall-eval/stopwatch.c", + "output": "/home/muhq/code/fgbs-syscall-eval/bench-io-uring" + }, + { + "arguments": [ + "/sbin/cc", + "-c", + "-Werror", + "-Wall", + "-g", + "-O0", + "-pthread", + "-o", + "bench-io-uring-sqpoll", + "io-uring-sqpoll.c" + ], + "directory": "/home/muhq/code/fgbs-syscall-eval", + "file": "/home/muhq/code/fgbs-syscall-eval/io-uring-sqpoll.c", + "output": "/home/muhq/code/fgbs-syscall-eval/bench-io-uring-sqpoll" + }, + { + "arguments": [ + "/sbin/cc", + "-c", + "-Werror", + "-Wall", + "-g", + "-O0", + "-pthread", + "-o", + "bench-io-uring-sqpoll", + "bench.c" + ], + "directory": "/home/muhq/code/fgbs-syscall-eval", + "file": "/home/muhq/code/fgbs-syscall-eval/bench.c", + "output": "/home/muhq/code/fgbs-syscall-eval/bench-io-uring-sqpoll" + }, + { + "arguments": [ + "/sbin/cc", + "-c", + "-Werror", + "-Wall", + "-g", + "-O0", + "-pthread", + "-o", + "bench-io-uring-sqpoll", + "stopwatch.c" + ], + "directory": "/home/muhq/code/fgbs-syscall-eval", + "file": "/home/muhq/code/fgbs-syscall-eval/stopwatch.c", + "output": "/home/muhq/code/fgbs-syscall-eval/bench-io-uring-sqpoll" + }, + { + "arguments": [ + "/sbin/cc", + "-c", + "-Werror", + "-Wall", + "-g", + "-O0", + "-pthread", + "-o", + "bench-io-uring-no-syscall", + "io-uring-no-syscall.c" + ], + "directory": "/home/muhq/code/fgbs-syscall-eval", + "file": "/home/muhq/code/fgbs-syscall-eval/io-uring-no-syscall.c", + "output": "/home/muhq/code/fgbs-syscall-eval/bench-io-uring-no-syscall" + }, + { + "arguments": [ + "/sbin/cc", + "-c", + "-Werror", + "-Wall", + "-g", + "-O0", + "-pthread", + "-o", + "bench-io-uring-no-syscall", + "bench.c" + ], + "directory": "/home/muhq/code/fgbs-syscall-eval", + "file": "/home/muhq/code/fgbs-syscall-eval/bench.c", + "output": "/home/muhq/code/fgbs-syscall-eval/bench-io-uring-no-syscall" + }, + { + "arguments": [ + "/sbin/cc", + "-c", + "-Werror", + "-Wall", + "-g", + "-O0", + "-pthread", + "-o", + "bench-io-uring-no-syscall", + "stopwatch.c" + ], + "directory": "/home/muhq/code/fgbs-syscall-eval", + "file": "/home/muhq/code/fgbs-syscall-eval/stopwatch.c", + "output": "/home/muhq/code/fgbs-syscall-eval/bench-io-uring-no-syscall" + }, + { + "arguments": [ + "/sbin/cc", + "-c", + "-Werror", + "-Wall", + "-g", + "-O0", + "-pthread", + "-o", + "bench-epoll", + "epoll.c" + ], + "directory": "/home/muhq/code/fgbs-syscall-eval", + "file": "/home/muhq/code/fgbs-syscall-eval/epoll.c", + "output": "/home/muhq/code/fgbs-syscall-eval/bench-epoll" + }, + { + "arguments": [ + "/sbin/cc", + "-c", + "-Werror", + "-Wall", + "-g", + "-O0", + "-pthread", + "-o", + "bench-epoll", + "bench.c" + ], + "directory": "/home/muhq/code/fgbs-syscall-eval", + "file": "/home/muhq/code/fgbs-syscall-eval/bench.c", + "output": "/home/muhq/code/fgbs-syscall-eval/bench-epoll" + }, + { + "arguments": [ + "/sbin/cc", + "-c", + "-Werror", + "-Wall", + "-g", + "-O0", + "-pthread", + "-o", + "bench-epoll", + "stopwatch.c" + ], + "directory": "/home/muhq/code/fgbs-syscall-eval", + "file": "/home/muhq/code/fgbs-syscall-eval/stopwatch.c", + "output": "/home/muhq/code/fgbs-syscall-eval/bench-epoll" + }, + { + "arguments": [ + "/sbin/cc", + "-c", + "-Werror", + "-Wall", + "-g", + "-O0", + "-pthread", + "-o", + "bench-aio-sig", + "aio-sig.c" + ], + "directory": "/home/muhq/code/fgbs-syscall-eval", + "file": "/home/muhq/code/fgbs-syscall-eval/aio-sig.c", + "output": "/home/muhq/code/fgbs-syscall-eval/bench-aio-sig" + }, + { + "arguments": [ + "/sbin/cc", + "-c", + "-Werror", + "-Wall", + "-g", + "-O0", + "-pthread", + "-o", + "bench-aio-sig", + "bench.c" + ], + "directory": "/home/muhq/code/fgbs-syscall-eval", + "file": "/home/muhq/code/fgbs-syscall-eval/bench.c", + "output": "/home/muhq/code/fgbs-syscall-eval/bench-aio-sig" + }, + { + "arguments": [ + "/sbin/cc", + "-c", + "-Werror", + "-Wall", + "-g", + "-O0", + "-pthread", + "-o", + "bench-aio-sig", + "stopwatch.c" + ], + "directory": "/home/muhq/code/fgbs-syscall-eval", + "file": "/home/muhq/code/fgbs-syscall-eval/stopwatch.c", + "output": "/home/muhq/code/fgbs-syscall-eval/bench-aio-sig" + }, + { + "arguments": [ + "/sbin/cc", + "-c", + "-Werror", + "-Wall", + "-g", + "-O0", + "-pthread", + "-o", + "bench-aio-thrd", + "aio-thrd.c" + ], + "directory": "/home/muhq/code/fgbs-syscall-eval", + "file": "/home/muhq/code/fgbs-syscall-eval/aio-thrd.c", + "output": "/home/muhq/code/fgbs-syscall-eval/bench-aio-thrd" + }, + { + "arguments": [ + "/sbin/cc", + "-c", + "-Werror", + "-Wall", + "-g", + "-O0", + "-pthread", + "-o", + "bench-aio-thrd", + "bench.c" + ], + "directory": "/home/muhq/code/fgbs-syscall-eval", + "file": "/home/muhq/code/fgbs-syscall-eval/bench.c", + "output": "/home/muhq/code/fgbs-syscall-eval/bench-aio-thrd" + }, + { + "arguments": [ + "/sbin/cc", + "-c", + "-Werror", + "-Wall", + "-g", + "-O0", + "-pthread", + "-o", + "bench-aio-thrd", + "stopwatch.c" + ], + "directory": "/home/muhq/code/fgbs-syscall-eval", + "file": "/home/muhq/code/fgbs-syscall-eval/stopwatch.c", + "output": "/home/muhq/code/fgbs-syscall-eval/bench-aio-thrd" + } +] diff --git a/tools/check-format b/tools/check-format new file mode 100755 index 0000000000000000000000000000000000000000..005c77c1ecfef05fc891dbb6ffc2d3c90a2a6912 --- /dev/null +++ b/tools/check-format @@ -0,0 +1,51 @@ +#!/usr/bin/env bash +set -euo pipefail + +# Pretty fancy method to get reliable the absolute path of a shell +# script, *even if it is sourced*. Credits go to GreenFox on +# stackoverflow: http://stackoverflow.com/a/12197518/194894 +pushd . > /dev/null +SCRIPTDIR="${BASH_SOURCE[0]}"; +while([ -h "${SCRIPTDIR}" ]); do + cd "`dirname "${SCRIPTDIR}"`" + SCRIPTDIR="$(readlink "`basename "${SCRIPTDIR}"`")"; +done +cd "`dirname "${SCRIPTDIR}"`" > /dev/null +SCRIPTDIR="`pwd`"; +popd > /dev/null + +DEBUG=false +while getopts d OPT; do + case $OPT in + d) + set -x + DEBUG=true + ;; + *) + echo "usage: ${0##*/} [-dq} [--] ARGS..." + exit 2 + esac +done +shift $(( OPTIND - 1 )) +OPTIND=1 + +ROOTDIR=$(readlink -f "${SCRIPTDIR}/..") + +MAX_PROCS=$(nproc) + +CHECKED_FILES_FILE=$(mktemp) +if ! $DEBUG; then + trap 'rm "${CHECKED_FILES_FILE}"' EXIT +fi + +cd "${ROOTDIR}" +# Note that the --dry-run and --Werror clang-format arguments require +# clang-format 10 or higher. See https://reviews.llvm.org/D68554 +find . \( -path '*/\.*' -o -path "./subprojects*" -o -path "./build*" \) -prune -o \ + -type f -regextype posix-extended -regex '.*\.(c|h|cpp|hpp)' -print0 |\ + tee "${CHECKED_FILES_FILE}" |\ + xargs --null --max-args=3 --max-procs="${MAX_PROCS}" \ + clang-format --style=file --dry-run -Werror + +FILE_COUNT=$(<"${CHECKED_FILES_FILE}" tr -cd '\0' | wc -c) +echo "Checked ${FILE_COUNT} files for format violations"