Skip to contentSkip to conversation

ccan: Add likely implementation

PATCH In review Leon Romanovsky 2 participants 3 messages Nov 16, 2016 – Nov 17, 2016 2 messages not in the archive InfiniBand

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ccan: Add likely implementation

Add likely/unlikely macros to ccan directory. This change includes adjustments to various providers, who defined it locally (nes, mlx4, mlx5 and hns).

The code of i40iw had such definitions too, but without actual usage and this patch removed this dead code.

---
 ccan/CMakeLists.txt           |   2 +
 ccan/likely.c                 | 136 ++++++++++++++++++++++++++++++++++++++++++
 ccan/likely.h                 | 111 ++++++++++++++++++++++++++++++++++
 providers/hns/hns_roce_u.h    |   5 +-
 providers/i40iw/i40iw_umain.h |   7 ---
 providers/mlx4/mlx4.h         |   8 ---
 providers/mlx4/qp.c           |   1 +
 providers/mlx5/mlx5.h         |   6 +-
 providers/nes/nes_umain.h     |   8 +--
 9 files changed, 253 insertions(+), 31 deletions(-)
 create mode 100644 ccan/likely.c
 create mode 100644 ccan/likely.h
ccan/CMakeLists.txt +2 -0
index b5de515..153426f 100644
@@ -6,11 +6,13 @@ publish_internal_headers(ccan
   minmax.h
   str.h
   str_debug.h
+  likely.h
   )
 
 set(C_FILES
   list.c
   str.c
+  likely.c
   )
 add_library(ccan STATIC ${C_FILES})
 add_library(ccan_pic STATIC ${C_FILES})
ccan/likely.c new file +136 -0

136 lines not on this page · raw message

ccan/likely.h new file +111 -0

111 lines not on this page · raw message

providers/hns/hns_roce_u.h +1 -4
index 4a6ed8e..1659958 100644
@@ -39,6 +39,7 @@
 #include <infiniband/arch.h>
 #include <infiniband/verbs.h>
 #include <ccan/container_of.h>
+#include <ccan/likely.h>
 
 #define HNS_ROCE_CQE_ENTRY_SIZE		0x20
 
@@ -51,10 +52,6 @@
 
 #define PFX				"hns: "
 
-#ifndef likely
-#define likely(x)     __builtin_expect(!!(x), 1)
-#endif
-
 #define roce_get_field(origin, mask, shift) \
 	(((origin) & (mask)) >> (shift))
 
providers/i40iw/i40iw_umain.h +0 -7
index 719aefc..6a23504 100644
@@ -47,13 +47,6 @@
 #include "i40iw_status.h"
 #include "i40iw_user.h"
 
-#ifndef likely
-#define likely(x)   __builtin_expect((x), 1)
-#endif
-#ifndef unlikely
-#define unlikely(x) __builtin_expect((x), 0)
-#endif
-
 #define PFX "libi40iw-"
 
 #define  I40IW_BASE_PUSH_PAGE	1
providers/mlx4/mlx4.h +0 -8
index b851e95..6467d5a 100644
@@ -51,14 +51,6 @@ enum {
 	MLX4_STAT_RATE_OFFSET		= 5
 };
 
-#ifndef likely
-#ifdef __GNUC__
-#define likely(x)       __builtin_expect(!!(x),1)
-#else
-#define likely(x)      (x)
-#endif
-#endif
-
 enum {
 	MLX4_QP_TABLE_BITS		= 8,
 	MLX4_QP_TABLE_SIZE		= 1 << MLX4_QP_TABLE_BITS,
providers/mlx4/qp.c +1 -0
index 268fb7d..af08874 100644
@@ -40,6 +40,7 @@
 #include <string.h>
 #include <errno.h>
 #include <util/compiler.h>
+#include <ccan/likely.h>
 
 #include "mlx4.h"
 #include "doorbell.h"
providers/mlx5/mlx5.h +1 -5
index cb65429..d5704d4 100644
@@ -42,11 +42,7 @@
 #include <ccan/list.h>
 #include "bitmap.h"
 #include <ccan/minmax.h>
-
-#ifdef __GNUC__
-#define likely(x)	__builtin_expect((x), 1)
-#define unlikely(x)	__builtin_expect((x), 0)
-#endif
+#include <ccan/likely.h>
 
 #include <valgrind/memcheck.h>
 
providers/nes/nes_umain.h +1 -7
index 093956a..5f357a2 100644
@@ -40,13 +40,7 @@
 
 #include <infiniband/driver.h>
 #include <infiniband/arch.h>
-
-#ifndef likely
-#define likely(x)   __builtin_expect((x),1)
-#endif
-#ifndef unlikely
-#define unlikely(x) __builtin_expect((x),0)
-#endif
+#include <ccan/likely.h>
 
 #define PFX	"libnes: "
 
Signature · 6 lines
2.7.4

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#2 lore raw
In reply to a message not in the archive
Quoted 4 lines · Leon Romanovsky

index b5de515..153426f 100644
+++ b/ccan/CMakeLists.txt

ccan/CMakeLists.txt +0 -0
@@ -6,11 +6,13 @@ publish_internal_headers(ccan
   minmax.h

ccan/CMakeLists.txt publish_internal_headers(ccan · line 16

Quoted 10 lines
ccan/CMakeLists.txt +2 -0
   str.h
   str_debug.h
+  likely.h
   )
 
 set(C_FILES
   list.c
   str.c
+  likely.c
   )

Keep these lists sorted please

ccan/likely.c line 5

Quoted 7 lines
ccan/likely.c new file +6 -0
+++ b/ccan/likely.c
@@ -0,0 +1,136 @@
+/* CC0 (Public domain) - see LICENSE file for details. */
+#ifdef CCAN_LIKELY_DEBUG
+#include <ccan/likely/likely.h>
+#include <ccan/hash/hash.h>
+#include <ccan/htable/htable_type.h>

Hmm, this isn't going to compile if the debug is set, maybe drop the .c - but this seems really interesting to see if likely is being used sensibly....

ccan/likely.h line 8

Quoted 2 lines
ccan/likely.h new file +2 -0
+#ifndef CCAN_LIKELY_DEBUG
+#if HAVE_BUILTIN_EXPECT

You need to add '#define HAVE_BUILTIN_EXPECT 1' to buildlib/config.h.in - or this doesn't work at all.

Jason
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#4 lore raw
In reply to a message not in the archive
Quoted 11 lines · Jason Gunthorpe
Quoted 9 lines · Leon Romanovsky

index b5de515..153426f 100644
+++ b/ccan/CMakeLists.txt

ccan/CMakeLists.txt +1 -0
@@ -6,11 +6,13 @@ publish_internal_headers(ccan
   minmax.h
   str.h
   str_debug.h
+  likely.h
   )
 
Quoted 7 lines

ccan/CMakeLists.txt publish_internal_headers(ccan · line 16

Quoted 5 lines
ccan/CMakeLists.txt +1 -0
 set(C_FILES
   list.c
   str.c
+  likely.c
   )

Keep these lists sorted please

Sure

Quoted 13 lines

ccan/likely.c line 5

Quoted 8 lines
ccan/likely.c new file +6 -0
+++ b/ccan/likely.c
@@ -0,0 +1,136 @@
+/* CC0 (Public domain) - see LICENSE file for details. */
+#ifdef CCAN_LIKELY_DEBUG
+#include <ccan/likely/likely.h>
+#include <ccan/hash/hash.h>
+#include <ccan/htable/htable_type.h>

Hmm, this isn't going to compile if the debug is set, maybe drop the .c - but this seems really interesting to see if likely is being used sensibly....

Quoted 5 lines

ccan/likely.h line 8

Quoted 2 lines
ccan/likely.h new file +2 -0
+#ifndef CCAN_LIKELY_DEBUG
+#if HAVE_BUILTIN_EXPECT

You need to add '#define HAVE_BUILTIN_EXPECT 1' to buildlib/config.h.in - or this doesn't work at all.

This is exactly what I wanted to discuss over ML.

From one side, I wanted to ensure that ccan files are similar to official ones, so upgrade to new versions will be seamless.

From another side, I don't see the real usage of likely/unlikely debug facilities.

So my approach was to add these files as is, but don't connect debug functionality.

Quoted 2 lines

Jason