C++ and Travis patches
cover C++ and Travis patches
Hi Jens,
This patch series includes patches that restore C++ compatibility, that restore clang compatibility and also that improve the Travis build. Please consider these patches for inclusion in the official liburing repository.
Thanks,
Bart.
Bart Van Assche (7):
src/Makefile: Only specify -shared at link time src/include/liburing/barrier.h: Restore clang compatibility Make the liburing header files again compatible with C++ Add a C++ unit test
configure: Use $CC and $CXX as default compilers if set .travis.yml: Change the language from C to C++ .travis.yml: Run tests as root and ignore test results
.travis.yml | 4 +-- configure | 6 ++-- src/Makefile | 4 +-- src/include/liburing.h | 8 +++--- src/include/liburing/barrier.h | 49 +++++++++++++++++++++++++++++---- src/include/liburing/io_uring.h | 8 ++++++ test/Makefile | 12 ++++++++ test/sq-full-cpp.cc | 45 ++++++++++++++++++++++++++++++ 8 files changed, 120 insertions(+), 16 deletions(-) create mode 100644 test/sq-full-cpp.cc
PATCH 1/7 src/Makefile: Only specify -shared at link time
Since -shared only takes effect when linking, only specify it when linking. This patch fixes the following clang warning:
clang-10.0: warning: argument unused during compilation: '-shared' [-Wunused-command-line-argument]
--- src/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
src/Makefile +2 -2
@@ -6,7 +6,7 @@ libdevdir ?= $(prefix)/lib CFLAGS ?= -g -fomit-frame-pointer -O2 override CFLAGS += -Wall -Wextra -Wno-unused-parameter -Wno-sign-compare\ -Iinclude/ -include ../config-host.h -SO_CFLAGS=-shared -fPIC $(CFLAGS) +SO_CFLAGS=-fPIC $(CFLAGS) L_CFLAGS=$(CFLAGS) LINK_FLAGS= LINK_FLAGS+=$(LDFLAGS)
@@ -51,7 +51,7 @@ liburing.a: $(liburing_objs) $(QUIET_RANLIB)$(RANLIB) liburing.a $(libname): $(liburing_sobjs) liburing.map - $(QUIET_CC)$(CC) $(SO_CFLAGS) -Wl,--version-script=liburing.map -Wl,-soname=$(soname) -o $@ $(liburing_sobjs) $(LINK_FLAGS) + $(QUIET_CC)$(CC) $(SO_CFLAGS) -shared -Wl,--version-script=liburing.map -Wl,-soname=$(soname) -o $@ $(liburing_sobjs) $(LINK_FLAGS) install: $(all_targets) install -D -m 644 include/liburing/io_uring.h $(includedir)/liburing/io_uring.h
PATCH 2/7 src/include/liburing/barrier.h: Restore clang compatibility
In reply to Bart Van AsscheThis patch fixes the following class of clang compiler errors:
include/liburing.h:150:3: error: address argument to atomic operation must be a
pointer to _Atomic type ('unsigned int *' invalid)
io_uring_smp_store_release(cq->khead, *cq->khead + nr);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~--- src/include/liburing/barrier.h | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)
src/include/liburing/barrier.h +8 -4
@@ -24,13 +24,17 @@ after the acquire operation executes. This is implemented using*/ #define IO_URING_WRITE_ONCE (var, val) \ - atomic_store_explicit(&(var), (val), memory_order_relaxed) + atomic_store_explicit((_Atomic typeof(var) *)&(var), \ + (val), memory_order_relaxed)#define IO_URING_READ_ONCE (var) \ - atomic_load_explicit(&(var), memory_order_relaxed) + atomic_load_explicit((_Atomic typeof(var) *)&(var), \ + memory_order_relaxed)#define io_uring_smp_store_release (p, v) \ - atomic_store_explicit((p), (v), memory_order_release) + atomic_store_explicit((_Atomic typeof(*(p)) *)(p), (v), \ + memory_order_release)#define io_uring_smp_load_acquire (p) \ - atomic_load_explicit((p), memory_order_acquire) + atomic_load_explicit((_Atomic typeof(*(p)) *)(p), \ + memory_order_acquire)#endif /* defined(LIBURING_BARRIER_H) */
PATCH 3/7 Make the liburing header files again compatible with C++
In reply to Bart Van AsscheInclude <atomic> instead of <stdatomic.h> if built with a C++ compiler.
--- src/include/liburing.h | 8 +++---- src/include/liburing/barrier.h | 37 +++++++++++++++++++++++++++++++-- src/include/liburing/io_uring.h | 8 +++++++ 3 files changed, 47 insertions(+), 6 deletions(-)
src/include/liburing.h +4 -4
@@ -2,10 +2,6 @@#ifndef LIB_URING_H #define LIB_URING_H -#ifdef __cplusplus -extern "C" { -#endif -#include <sys/socket.h> #include <sys/uio.h> #include <sys/stat.h>
@@ -19,6 +15,10 @@ extern "C" {#include "liburing/io_uring.h" #include "liburing/barrier.h" +#ifdef __cplusplus +extern "C" { +#endif +/* * Library interface to io_uring */
src/include/liburing/barrier.h +35 -2
@@ -2,8 +2,6 @@#ifndef LIBURING_BARRIER_H #define LIBURING_BARRIER_H -#include <stdatomic.h> -/* From the kernel documentation file refcount-vs-atomic.rst:
@@ -23,6 +21,40 @@ after the acquire operation executes. This is implemented using:c:func:`smp_acquire__after_ctrl_dep`. */ +#ifdef __cplusplus +#include <atomic> + +template <typename T> +static inline void IO_URING_WRITE_ONCE(T &var, T val) +{ + std::atomic_store_explicit(reinterpret_cast<std::atomic<T> *>(&var), + val, std::memory_order_relaxed); +} +template <typename T> +static inline T IO_URING_READ_ONCE(const T &var) +{ + return std::atomic_load_explicit( + reinterpret_cast<const std::atomic<T> *>(&var), + std::memory_order_relaxed); +} + +template <typename T> +static inline void io_uring_smp_store_release(T *p, T v) +{ + std::atomic_store_explicit(reinterpret_cast<std::atomic<T> *>(p), v, + std::memory_order_release); +} + +template <typename T> +static inline T io_uring_smp_load_acquire(const T *p) +{ + return std::atomic_load_explicit( + reinterpret_cast<const std::atomic<T> *>(p), + std::memory_order_acquire); +} +#else +#include <stdatomic.h> +#define IO_URING_WRITE_ONCE (var, val) \ atomic_store_explicit((_Atomic typeof(var) *)&(var), \ (val), memory_order_relaxed)
@@ -36,5 +68,6 @@ after the acquire operation executes. This is implemented using#define io_uring_smp_load_acquire (p) \ atomic_load_explicit((_Atomic typeof(*(p)) *)(p), \ memory_order_acquire) +#endif #endif /* defined(LIBURING_BARRIER_H) */
src/include/liburing/io_uring.h +8 -0
@@ -11,6 +11,10 @@#include <linux/fs.h> #include <linux/types.h> +#ifdef __cplusplus +extern "C" { +#endif +/* * IO submission data structure (Submission Queue Entry) */
@@ -289,4 +293,8 @@ struct io_uring_probe {struct io_uring_probe_op ops[0 ]; }; +#ifdef __cplusplus +} +#endif +#endif
PATCH 4/7 Add a C++ unit test
In reply to Bart Van AsscheSince the liburing header files support C++ compilers, add a C++ unit test. This helps to verify C++ compatibility of the liburing header files.
--- test/Makefile | 12 ++++++++++++ test/sq-full-cpp.cc | 45 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 test/sq-full-cpp.cc
test/Makefile +12 -0
@@ -8,6 +8,7 @@ XCFLAGS = override CFLAGS += -Wall -Wextra -Wno-unused-parameter -Wno-sign-compare\ -D_GNU_SOURCE -D__SANE_USERSPACE_TYPES__ -L../src/ \ -I../src/include/ -include ../config-host.h +CXXFLAGS += $(CFLAGS) -std=c++11 all_targets += poll poll-cancel ring-leak fsync io_uring_setup io_uring_register \ io_uring_enter nop sq-full cq-full 35fa71a030ca-test \
@@ -36,11 +37,18 @@ ifdef CONFIG_HAVE_STATX all_targets += statx endif +ifdef CONFIG_HAVE_CXX +all_targets += sq-full-cpp +endif + all: $(all_targets) %: %.c $(QUIET_CC)$(CC) $(CFLAGS) -o $@ $< -luring $(XCFLAGS) +%: %.cc + $(QUIET_CC)$(CXX) $(CXXFLAGS) -o $@ $< -luring $(XCFLAGS) + test_srcs := poll.c poll-cancel.c ring-leak.c fsync.c io_uring_setup.c \ io_uring_register.c io_uring_enter.c nop.c sq-full.c cq-full.c \ 35fa71a030ca-test.c 917257daa0fe-test.c b19062a56726-test.c \
@@ -63,6 +71,10 @@ ifdef CONFIG_HAVE_STATX test_srcs += statx.c endif +ifdef CONFIG_HAVE_CXX +test_srcs += sq-full-cpp +endif + test_objs := $(patsubst %.c,%.ol,$(test_srcs)) 35fa71a030ca-test: XCFLAGS = -lpthread
test/sq-full-cpp.cc new file +45 -0
45 lines not on this page · raw message
PATCH 5/7 configure: Use $CC and $CXX as default compilers if set
In reply to Bart Van AsscheThis change causes .travis.yml to use the compilers configured in the $CC and $CXX variables. Additionally, make the configure script show the compiler names.
--- configure | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
configure +4 -2
@@ -9,8 +9,8 @@ else TMPDIR1="/tmp" fi -cc=gcc -cxx=g++ +cc=${CC:-gcc} +cxx=${CXX:-g++} for opt do optarg=$(expr "x$opt" : 'x[^=]*=\(.*\)')
@@ -315,7 +315,9 @@ if test "$has_cxx" = "yes"; then fi echo "CC=$cc" >> $config_host_mak +print_config "CC" "$cc" echo "CXX=$cxx" >> $config_host_mak +print_config "CXX" "$cxx" # generate compat.h compat_h="src/include/liburing/compat.h"
PATCH 6/7 .travis.yml: Change the language from C to C++
In reply to Bart Van AsscheThis causes Travis to set both the CC and CXX environment variables instead of only CC.
--- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
.travis.yml +1 -1
@@ -1,4 +1,4 @@ -language: c +language: cpp os: - linux compiler:
PATCH 7/7 .travis.yml: Run tests as root and ignore test results
In reply to Bart Van AsscheSince many tests require root privileges, run the tests with root privileges. Ignore the test results because the kernel of Travis VMs is too old for all tests to pass.
--- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
.travis.yml +1 -1
@@ -19,4 +19,4 @@ before_install: - EXTRA_CFLAGS="-Werror" script: - ./configure && make - - make runtests + - sudo make runtests || true
Jens Axboe
maintainerQuoted 5 lines · Bart Van Assche
Hi Jens,
This patch series includes patches that restore C++ compatibility, that restore clang compatibility and also that improve the Travis build. Please consider these patches for inclusion in the official liburing repository.
Looks good to me, thanks Bart.
Signature · 1 line
Jens Axboe