@@ -38,6 +38,8 @@ set(BUILD_INCLUDE ${CMAKE_BINARY_DIR}/include)
set(BUILD_BIN ${CMAKE_BINARY_DIR}/bin)
# Libraries
set(BUILD_LIB ${CMAKE_BINARY_DIR}/lib)
+# Common code
+set(COMMON_CODE utils)
# Location to place provider .driver files
set(CONFIG_DIR "${CMAKE_INSTALL_FULL_SYSCONFDIR}/libibverbs.d")
@@ -139,6 +141,10 @@ RDMA_AddOptCFlag(CMAKE_SHARED_LINKER_FLAGS SUPPORTS_NO_UNDEFINED "-Wl,--no-undef
find_package(LDSymVer REQUIRED)
#-------------------------
+# Common code
+include_directories(${COMMON_CODE})
+
+#-------------------------
# Find libraries
# pthread
FIND_PACKAGE (Threads REQUIRED)
@@ -46,6 +46,8 @@
#include <sys/time.h>
#include <netinet/in.h>
+#include "../../utils/math.h"
+
#define ACM_CONF_DIR IBACM_CONFIG_PATH
#define ACM_ADDR_FILE "ibacm_addr.cfg"
#define ACM_OPTS_FILE "ibacm_opts.cfg"
@@ -56,9 +58,6 @@
#define container_of(ptr, type, field) \
((type *) ((void *) ptr - offsetof(type, field)))
-#define min(a, b) (a < b ? a : b)
-#define max(a, b) (a > b ? a : b)
-
#if __BYTE_ORDER == __LITTLE_ENDIAN
#define htonll(x) bswap_64(x)
#else
@@ -49,13 +49,7 @@
#include "pingpong.h"
-#ifndef max
-#define max(x, y) (((x) > (y)) ? (x) : (y))
-#endif
-
-#ifndef min
-#define min(x, y) (((x) < (y)) ? (x) : (y))
-#endif
+#include "../../utils/math.h"
enum {
PINGPONG_RECV_WRID = 1,
@@ -42,6 +42,8 @@
#include "list.h"
#include "bitmap.h"
+#include "../../utils/math.h"
+
#ifdef __GNUC__
#define likely(x) __builtin_expect((x), 1)
#define unlikely(x) __builtin_expect((x), 0)
@@ -91,20 +93,6 @@
#endif
-#ifndef min
-#define min(a, b) \
- ({ typeof(a) _a = (a); \
- typeof(b) _b = (b); \
- _a < _b ? _a : _b; })
-#endif
-
-#ifndef max
-#define max(a, b) \
- ({ typeof(a) _a = (a); \
- typeof(b) _b = (b); \
- _a > _b ? _a : _b; })
-#endif
-
#define HIDDEN __attribute__((visibility("hidden")))
#ifdef HAVE_FUNC_ATTRIBUTE_ALWAYS_INLINE
@@ -47,6 +47,8 @@
#include <rdma/rdma_cma.h>
#include <infiniband/ib.h>
+#include "../../utils/math.h"
+
#ifdef INCLUDE_VALGRIND
# include <valgrind/memcheck.h>
# ifndef VALGRIND_MAKE_MEM_DEFINED
@@ -68,9 +70,6 @@ static inline uint64_t htonll(uint64_t x) { return x; }
static inline uint64_t ntohll(uint64_t x) { return x; }
#endif
-#define max(a, b) ((a) > (b) ? a : b)
-#define min(a, b) ((a) < (b) ? a : b)
-
#ifndef container_of
#define container_of(ptr, type, field) \
((type *) ((void *)ptr - offsetof(type, field)))
new file mode 100644
@@ -0,0 +1,44 @@
+/*
+ * This software is available to you under a choice of one of two
+ * licenses. You may choose to be licensed under the terms of the GNU
+ * General Public License (GPL) Version 2, available from the file
+ * COPYING in the main directory of this source tree, or the
+ * OpenIB.org BSD license below:
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * - Redistributions of source code must retain the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ */
+
+#ifndef _RDMA_MATH_H_
+#define _RDMA_MATH_H_
+/*
+ * This include contains all common mathematical functions
+ */
+#ifndef min
+#define min(a, b) (((a) < (b)) ? (a) : (b))
+#endif
+
+#ifndef max
+#define max(a, b) (((a) > (b)) ? (a) : (b))
+#endif
+#endif /* _RDMA_MATH_H_ */
Signed-off-by: Leon Romanovsky <leon@kernel.org> --- CMakeLists.txt | 6 ++++++ ibacm/linux/osd.h | 5 ++--- libibverbs/examples/rc_pingpong.c | 8 +------ libmlx5/src/mlx5.h | 16 ++------------ librdmacm/src/cma.h | 5 ++--- utils/math.h | 44 +++++++++++++++++++++++++++++++++++++++ 6 files changed, 57 insertions(+), 27 deletions(-) create mode 100644 utils/math.h