Skip to contentSkip to conversation

tools/io_uring: Use <asm/barrier.h> instead of tools/io_uring/barrier.h

PATCH In review Bart Van Assche 2 participants 2 messages Jul 1, 2019 Block layer

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tools/io_uring: Use <asm/barrier.h> instead of tools/io_uring/barrier.h

This patch avoids that multiple definitions of barrier primitives occur in the tools directory. This patch does not change the behavior of the code on x86 since on x86 smp_rmb() and smp_wmb() are defined as follows in tools/arch/x86/include/asm/barrier.h:

#define barrier() __asm__ __volatile__("": : :"memory") #define smp_rmb() barrier()
#define smp_wmb() barrier()

---
 tools/io_uring/barrier.h        | 16 ----------------
 tools/io_uring/io_uring-bench.c | 12 ++++++------
 tools/io_uring/liburing.h       |  4 ++--
 tools/io_uring/queue.c          | 14 +++++++-------
 4 files changed, 15 insertions(+), 31 deletions(-)
 delete mode 100644 tools/io_uring/barrier.h
tools/io_uring/barrier.h deleted +0 -16
deleted file mode 100644
index ef00f6722ba9..000000000000
@@ -1,16 +0,0 @@
-#ifndef LIBURING_BARRIER_H
-#define LIBURING_BARRIER_H
-
-#if defined(__x86_64) || defined(__i386__)
-#define read_barrier()	__asm__ __volatile__("":::"memory")
-#define write_barrier()	__asm__ __volatile__("":::"memory")
-#else
-/*
- * Add arch appropriate definitions. Be safe and use full barriers for
- * archs we don't have support for.
- */
-#define read_barrier()	__sync_synchronize()
-#define write_barrier()	__sync_synchronize()
-#endif
-
-#endif
tools/io_uring/io_uring-bench.c +6 -6
index 0f257139b003..3ce715247c5e 100644
@@ -28,9 +28,9 @@
 #include <string.h>
 #include <pthread.h>
 #include <sched.h>
+#include <asm/barrier.h>
 
 #include "liburing.h"
-#include "barrier.h"
 
 #define min(a, b)		((a < b) ? (a) : (b))
 
@@ -199,7 +199,7 @@ static int prep_more_ios(struct submitter *s, unsigned max_ios)
 	next_tail = tail = *ring->tail;
 	do {
 		next_tail++;
-		read_barrier();
+		smp_rmb();
 		if (next_tail == *ring->head)
 			break;
 
@@ -212,9 +212,9 @@ static int prep_more_ios(struct submitter *s, unsigned max_ios)
 
 	if (*ring->tail != tail) {
 		/* order tail store with writes to sqes above */
-		write_barrier();
+		smp_wmb();
 		*ring->tail = tail;
-		write_barrier();
+		smp_wmb();
 	}
 	return prepped;
 }
@@ -251,7 +251,7 @@ static int reap_events(struct submitter *s)
 	do {
 		struct file *f;
 
-		read_barrier();
+		smp_rmb();
 		if (head == *ring->tail)
 			break;
 		cqe = &ring->cqes[head & cq_ring_mask];
@@ -271,7 +271,7 @@ static int reap_events(struct submitter *s)
 
 	s->inflight -= reaped;
 	*ring->head = head;
-	write_barrier();
+	smp_wmb();
 	return reaped;
 }
 
tools/io_uring/liburing.h +2 -2
index 5f305c86b892..3670a08101c7 100644
@@ -10,7 +10,7 @@ extern "C" {
 #include <string.h>
 #include "../../include/uapi/linux/io_uring.h"
 #include <inttypes.h>
-#include "barrier.h"
+#include <asm/barrier.h>
 
 /*
  * Library interface to io_uring
@@ -87,7 +87,7 @@ static inline void io_uring_cqe_seen(struct io_uring *ring,
 		 * Ensure that the kernel sees our new head, the kernel has
 		 * the matching read barrier.
 		 */
-		write_barrier();
+		smp_wmb();
 	}
 }
 
tools/io_uring/queue.c +7 -7
index 321819c132c7..aadf4d926c8e 100644
@@ -4,9 +4,9 @@
 #include <unistd.h>
 #include <errno.h>
 #include <string.h>
+#include <asm/barrier.h>
 
 #include "liburing.h"
-#include "barrier.h"
 
 static int __io_uring_get_cqe(struct io_uring *ring,
 			      struct io_uring_cqe **cqe_ptr, int wait)
@@ -20,13 +20,13 @@ static int __io_uring_get_cqe(struct io_uring *ring,
 	head = *cq->khead;
 	do {
 		/*
-		 * It's necessary to use a read_barrier() before reading
+		 * It's necessary to use a smp_rmb() before reading
 		 * the CQ tail, since the kernel updates it locklessly. The
 		 * kernel has the matching store barrier for the update. The
 		 * kernel also ensures that previous stores to CQEs are ordered
 		 * with the tail update.
 		 */
-		read_barrier();
+		smp_rmb();
 		if (head != *cq->ktail) {
 			*cqe_ptr = &cq->cqes[head & mask];
 			break;
@@ -77,7 +77,7 @@ int io_uring_submit(struct io_uring *ring)
 	 * read barrier here to match the kernels store barrier when updating
 	 * the SQ head.
 	 */
-	read_barrier();
+	smp_rmb();
 	if (*sq->khead != *sq->ktail) {
 		submitted = *sq->kring_entries;
 		goto submit;
@@ -94,7 +94,7 @@ int io_uring_submit(struct io_uring *ring)
 	to_submit = sq->sqe_tail - sq->sqe_head;
 	while (to_submit--) {
 		ktail_next++;
-		read_barrier();
+		smp_rmb();
 
 		sq->array[ktail & mask] = sq->sqe_head & mask;
 		ktail = ktail_next;
@@ -113,13 +113,13 @@ int io_uring_submit(struct io_uring *ring)
 		 * will never see a tail update without the preceeding sQE
 		 * stores being done.
 		 */
-		write_barrier();
+		smp_wmb();
 		*sq->ktail = ktail;
 		/*
 		 * The kernel has the matching read barrier for reading the
 		 * SQ tail.
 		 */
-		write_barrier();
+		smp_wmb();
 	}
 
 submit:
Signature · 1 line
2.22.0.410.gd8fdbe21b5-goog
maintainer
#1 lore raw
Quoted 8 lines · Bart Van Assche

This patch avoids that multiple definitions of barrier primitives occur in the tools directory. This patch does not change the behavior of the code on x86 since on x86 smp_rmb() and smp_wmb() are defined as follows in tools/arch/x86/include/asm/barrier.h:

  #define barrier() __asm__ __volatile__("": : :"memory")
  #define smp_rmb() barrier()
  #define smp_wmb() barrier()

The kernel bits are just synced from liburing, essentially. So I don't think it makes a lot of sense to add this change on the kernel side, though cleaning up the liburing side would be great (and could then bubble to the kernel as well).

Signature · 1 line
Jens Axboe