io-uring.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH liburing 0/7] C++ and Travis patches
@ 2020-06-28 19:58 Bart Van Assche
  2020-06-28 19:58 ` [PATCH liburing 1/7] src/Makefile: Only specify -shared at link time Bart Van Assche
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: Bart Van Assche @ 2020-06-28 19:58 UTC (permalink / raw)
  To: Jens Axboe; +Cc: io-uring, 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.

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


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH liburing 1/7] src/Makefile: Only specify -shared at link time
  2020-06-28 19:58 [PATCH liburing 0/7] C++ and Travis patches Bart Van Assche
@ 2020-06-28 19:58 ` Bart Van Assche
  2020-06-28 19:58 ` [PATCH liburing 2/7] src/include/liburing/barrier.h: Restore clang compatibility Bart Van Assche
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Bart Van Assche @ 2020-06-28 19:58 UTC (permalink / raw)
  To: Jens Axboe; +Cc: io-uring, Bart Van Assche

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]

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
 src/Makefile | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/Makefile b/src/Makefile
index 3099f7cd51ec..44a95ad78afa 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -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

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH liburing 2/7] src/include/liburing/barrier.h: Restore clang compatibility
  2020-06-28 19:58 [PATCH liburing 0/7] C++ and Travis patches Bart Van Assche
  2020-06-28 19:58 ` [PATCH liburing 1/7] src/Makefile: Only specify -shared at link time Bart Van Assche
@ 2020-06-28 19:58 ` Bart Van Assche
  2020-06-28 19:58 ` [PATCH liburing 3/7] Make the liburing header files again compatible with C++ Bart Van Assche
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Bart Van Assche @ 2020-06-28 19:58 UTC (permalink / raw)
  To: Jens Axboe; +Cc: io-uring, Bart Van Assche

This 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);
                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Fixes: b9c0bf79aa87 ("src/include/liburing/barrier.h: Use C11 atomics")
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
 src/include/liburing/barrier.h | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/src/include/liburing/barrier.h b/src/include/liburing/barrier.h
index c8aa4210371c..57324348466b 100644
--- a/src/include/liburing/barrier.h
+++ b/src/include/liburing/barrier.h
@@ -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) */

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH liburing 3/7] Make the liburing header files again compatible with C++
  2020-06-28 19:58 [PATCH liburing 0/7] C++ and Travis patches Bart Van Assche
  2020-06-28 19:58 ` [PATCH liburing 1/7] src/Makefile: Only specify -shared at link time Bart Van Assche
  2020-06-28 19:58 ` [PATCH liburing 2/7] src/include/liburing/barrier.h: Restore clang compatibility Bart Van Assche
@ 2020-06-28 19:58 ` Bart Van Assche
  2020-06-28 19:58 ` [PATCH liburing 4/7] Add a C++ unit test Bart Van Assche
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Bart Van Assche @ 2020-06-28 19:58 UTC (permalink / raw)
  To: Jens Axboe; +Cc: io-uring, Bart Van Assche

Include <atomic> instead of <stdatomic.h> if built with a C++ compiler.

Fixes: b9c0bf79aa87 ("src/include/liburing/barrier.h: Use C11 atomics")
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
 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(-)

diff --git a/src/include/liburing.h b/src/include/liburing.h
index c9034fc0df1b..76e2b854f957 100644
--- a/src/include/liburing.h
+++ b/src/include/liburing.h
@@ -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
  */
diff --git a/src/include/liburing/barrier.h b/src/include/liburing/barrier.h
index 57324348466b..a4a59fb499d6 100644
--- a/src/include/liburing/barrier.h
+++ b/src/include/liburing/barrier.h
@@ -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) */
diff --git a/src/include/liburing/io_uring.h b/src/include/liburing/io_uring.h
index 785a6a4f2233..6a73522de0cb 100644
--- a/src/include/liburing/io_uring.h
+++ b/src/include/liburing/io_uring.h
@@ -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

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH liburing 4/7] Add a C++ unit test
  2020-06-28 19:58 [PATCH liburing 0/7] C++ and Travis patches Bart Van Assche
                   ` (2 preceding siblings ...)
  2020-06-28 19:58 ` [PATCH liburing 3/7] Make the liburing header files again compatible with C++ Bart Van Assche
@ 2020-06-28 19:58 ` Bart Van Assche
  2020-06-28 19:58 ` [PATCH liburing 5/7] configure: Use $CC and $CXX as default compilers if set Bart Van Assche
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Bart Van Assche @ 2020-06-28 19:58 UTC (permalink / raw)
  To: Jens Axboe; +Cc: io-uring, Bart Van Assche

Since the liburing header files support C++ compilers, add a C++ unit test.
This helps to verify C++ compatibility of the liburing header files.

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
 test/Makefile       | 12 ++++++++++++
 test/sq-full-cpp.cc | 45 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 57 insertions(+)
 create mode 100644 test/sq-full-cpp.cc

diff --git a/test/Makefile b/test/Makefile
index e103296fabdd..c80ad421a938 100644
--- a/test/Makefile
+++ b/test/Makefile
@@ -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
diff --git a/test/sq-full-cpp.cc b/test/sq-full-cpp.cc
new file mode 100644
index 000000000000..ba400996e615
--- /dev/null
+++ b/test/sq-full-cpp.cc
@@ -0,0 +1,45 @@
+/* SPDX-License-Identifier: MIT */
+/*
+ * Description: test SQ queue full condition
+ *
+ */
+#include <errno.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <string.h>
+#include <fcntl.h>
+
+#include "liburing.h"
+
+int main(int argc, char *argv[])
+{
+	struct io_uring_sqe *sqe;
+	struct io_uring ring;
+	int ret, i;
+
+	if (argc > 1)
+		return 0;
+
+	ret = io_uring_queue_init(8, &ring, 0);
+	if (ret) {
+		fprintf(stderr, "ring setup failed: %d\n", ret);
+		return 1;
+
+	}
+
+	i = 0;
+	while ((sqe = io_uring_get_sqe(&ring)) != NULL)
+		i++;
+
+	if (i != 8) {
+		fprintf(stderr, "Got %d SQEs, wanted 8\n", i);
+		goto err;
+	}
+
+	io_uring_queue_exit(&ring);
+	return 0;
+err:
+	io_uring_queue_exit(&ring);
+	return 1;
+}

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH liburing 5/7] configure: Use $CC and $CXX as default compilers if set
  2020-06-28 19:58 [PATCH liburing 0/7] C++ and Travis patches Bart Van Assche
                   ` (3 preceding siblings ...)
  2020-06-28 19:58 ` [PATCH liburing 4/7] Add a C++ unit test Bart Van Assche
@ 2020-06-28 19:58 ` Bart Van Assche
  2020-06-28 19:58 ` [PATCH liburing 6/7] .travis.yml: Change the language from C to C++ Bart Van Assche
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Bart Van Assche @ 2020-06-28 19:58 UTC (permalink / raw)
  To: Jens Axboe; +Cc: io-uring, Bart Van Assche

This change causes .travis.yml to use the compilers configured in the $CC
and $CXX variables. Additionally, make the configure script show the
compiler names.

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
 configure | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/configure b/configure
index c02a97875862..223192b8a5f9 100755
--- a/configure
+++ b/configure
@@ -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"

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH liburing 6/7] .travis.yml: Change the language from C to C++
  2020-06-28 19:58 [PATCH liburing 0/7] C++ and Travis patches Bart Van Assche
                   ` (4 preceding siblings ...)
  2020-06-28 19:58 ` [PATCH liburing 5/7] configure: Use $CC and $CXX as default compilers if set Bart Van Assche
@ 2020-06-28 19:58 ` Bart Van Assche
  2020-06-28 19:58 ` [PATCH liburing 7/7] .travis.yml: Run tests as root and ignore test results Bart Van Assche
  2020-06-28 20:04 ` [PATCH liburing 0/7] C++ and Travis patches Jens Axboe
  7 siblings, 0 replies; 9+ messages in thread
From: Bart Van Assche @ 2020-06-28 19:58 UTC (permalink / raw)
  To: Jens Axboe; +Cc: io-uring, Bart Van Assche

This causes Travis to set both the CC and CXX environment variables instead
of only CC.

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
 .travis.yml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/.travis.yml b/.travis.yml
index 7ed15c7ab142..69da3c07df7d 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,4 +1,4 @@
-language: c
+language: cpp
 os:
   - linux
 compiler:

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH liburing 7/7] .travis.yml: Run tests as root and ignore test results
  2020-06-28 19:58 [PATCH liburing 0/7] C++ and Travis patches Bart Van Assche
                   ` (5 preceding siblings ...)
  2020-06-28 19:58 ` [PATCH liburing 6/7] .travis.yml: Change the language from C to C++ Bart Van Assche
@ 2020-06-28 19:58 ` Bart Van Assche
  2020-06-28 20:04 ` [PATCH liburing 0/7] C++ and Travis patches Jens Axboe
  7 siblings, 0 replies; 9+ messages in thread
From: Bart Van Assche @ 2020-06-28 19:58 UTC (permalink / raw)
  To: Jens Axboe; +Cc: io-uring, Bart Van Assche

Since 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.

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
 .travis.yml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/.travis.yml b/.travis.yml
index 69da3c07df7d..e02fdd03392f 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -19,4 +19,4 @@ before_install:
   - EXTRA_CFLAGS="-Werror"
 script:
   - ./configure && make
-  - make runtests
+  - sudo make runtests || true

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH liburing 0/7] C++ and Travis patches
  2020-06-28 19:58 [PATCH liburing 0/7] C++ and Travis patches Bart Van Assche
                   ` (6 preceding siblings ...)
  2020-06-28 19:58 ` [PATCH liburing 7/7] .travis.yml: Run tests as root and ignore test results Bart Van Assche
@ 2020-06-28 20:04 ` Jens Axboe
  7 siblings, 0 replies; 9+ messages in thread
From: Jens Axboe @ 2020-06-28 20:04 UTC (permalink / raw)
  To: Bart Van Assche; +Cc: io-uring

On 6/28/20 1:58 PM, Bart Van Assche wrote:
> 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.

-- 
Jens Axboe


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2020-06-28 20:04 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-28 19:58 [PATCH liburing 0/7] C++ and Travis patches Bart Van Assche
2020-06-28 19:58 ` [PATCH liburing 1/7] src/Makefile: Only specify -shared at link time Bart Van Assche
2020-06-28 19:58 ` [PATCH liburing 2/7] src/include/liburing/barrier.h: Restore clang compatibility Bart Van Assche
2020-06-28 19:58 ` [PATCH liburing 3/7] Make the liburing header files again compatible with C++ Bart Van Assche
2020-06-28 19:58 ` [PATCH liburing 4/7] Add a C++ unit test Bart Van Assche
2020-06-28 19:58 ` [PATCH liburing 5/7] configure: Use $CC and $CXX as default compilers if set Bart Van Assche
2020-06-28 19:58 ` [PATCH liburing 6/7] .travis.yml: Change the language from C to C++ Bart Van Assche
2020-06-28 19:58 ` [PATCH liburing 7/7] .travis.yml: Run tests as root and ignore test results Bart Van Assche
2020-06-28 20:04 ` [PATCH liburing 0/7] C++ and Travis patches Jens Axboe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).