All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH rdma-core 0/5] Add directory to place common code and move trivial functions into it
@ 2016-09-25  6:50 Leon Romanovsky
       [not found] ` <1474786207-2149-1-git-send-email-leon-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
  0 siblings, 1 reply; 21+ messages in thread
From: Leon Romanovsky @ 2016-09-25  6:50 UTC (permalink / raw)
  To: dledford-H+wXaHxf7aLQT0dZR+AlfA, linux-rdma-u79uwXL29TY76Z2rM5mHXA
  Cc: jgunthorpe-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/,
	yishaih-VPRAkNaXOzVWk0Htik3J/w

This is patch series which adds directory to place common code.

Highlights of this this series:
1. The min/max functions were moved into it.
2. OCRDMA list implementation was chosen as common code.
3. Libmlx5 was converted to use that list.h.
4. Remove container_of and offset local declarations.

View the commits on github:

https://github.com/linux-rdma/rdma-core/pull/4

Leon Romanovsky (5):
  cmake: Update build instructions in CmakeList
  utils: Create utils directory to put all common code and move min/max
    into it
  utils: Remove container_of and offset local declarations
  libocrdma: Move ocrdma's list implementation into common directory
  libmlx5: Convert libmlx5 to use common list implementation

 CMakeLists.txt                    |   7 +
 ibacm/linux/osd.h                 |   8 +-
 libibverbs/examples/rc_pingpong.c |   8 +-
 libmlx5/src/buf.c                 |  13 +-
 libmlx5/src/list.h                | 331 --------------------------------------
 libmlx5/src/mlx5.h                |  20 +--
 libocrdma/src/ocrdma_list.h       | 104 ------------
 libocrdma/src/ocrdma_main.c       |   8 +-
 libocrdma/src/ocrdma_main.h       |  12 +-
 libocrdma/src/ocrdma_verbs.c      |  16 +-
 librdmacm/src/cma.h               |  11 +-
 utils/list.h                      | 111 +++++++++++++
 utils/math.h                      |  44 +++++
 13 files changed, 196 insertions(+), 497 deletions(-)
 delete mode 100644 libmlx5/src/list.h
 delete mode 100644 libocrdma/src/ocrdma_list.h
 create mode 100644 utils/list.h
 create mode 100644 utils/math.h

--
2.7.4

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* [PATCH rdma-core 1/5] cmake: Update build instructions in CmakeList
       [not found] ` <1474786207-2149-1-git-send-email-leon-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
@ 2016-09-25  6:50   ` Leon Romanovsky
  2016-09-25  6:50   ` [PATCH rdma-core 2/5] utils: Create utils directory to put all common code and move min/max into it Leon Romanovsky
                     ` (3 subsequent siblings)
  4 siblings, 0 replies; 21+ messages in thread
From: Leon Romanovsky @ 2016-09-25  6:50 UTC (permalink / raw)
  To: dledford-H+wXaHxf7aLQT0dZR+AlfA, linux-rdma-u79uwXL29TY76Z2rM5mHXA
  Cc: jgunthorpe-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/,
	yishaih-VPRAkNaXOzVWk0Htik3J/w

Signed-off-by: Leon Romanovsky <leon-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
---
 CMakeLists.txt | 1 +
 1 file changed, 1 insertion(+)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index a829cd4..557d3a8 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,6 +1,7 @@
 # COPYRIGHT (c) 2016 Obsidian Research Corporation. See COPYING file
 # Run cmake as:
 #  mkdir build
+#  cd build
 #  cmake -GNinja ..
 #  ninja
 #
-- 
2.7.4

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* [PATCH rdma-core 2/5] utils: Create utils directory to put all common code and move min/max into it
       [not found] ` <1474786207-2149-1-git-send-email-leon-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
  2016-09-25  6:50   ` [PATCH rdma-core 1/5] cmake: Update build instructions in CmakeList Leon Romanovsky
@ 2016-09-25  6:50   ` Leon Romanovsky
       [not found]     ` <1474786207-2149-3-git-send-email-leon-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
  2016-09-25  6:50   ` [PATCH rdma-core 3/5] utils: Remove container_of and offset local declarations Leon Romanovsky
                     ` (2 subsequent siblings)
  4 siblings, 1 reply; 21+ messages in thread
From: Leon Romanovsky @ 2016-09-25  6:50 UTC (permalink / raw)
  To: dledford-H+wXaHxf7aLQT0dZR+AlfA, linux-rdma-u79uwXL29TY76Z2rM5mHXA
  Cc: jgunthorpe-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/,
	yishaih-VPRAkNaXOzVWk0Htik3J/w

Signed-off-by: Leon Romanovsky <leon-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.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

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 557d3a8..c997c6d 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -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)
diff --git a/ibacm/linux/osd.h b/ibacm/linux/osd.h
index 5ca4c6f..ec18f7b 100644
--- a/ibacm/linux/osd.h
+++ b/ibacm/linux/osd.h
@@ -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
diff --git a/libibverbs/examples/rc_pingpong.c b/libibverbs/examples/rc_pingpong.c
index 9676783..cc45741 100644
--- a/libibverbs/examples/rc_pingpong.c
+++ b/libibverbs/examples/rc_pingpong.c
@@ -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,
diff --git a/libmlx5/src/mlx5.h b/libmlx5/src/mlx5.h
index dc90892..453aeb8 100644
--- a/libmlx5/src/mlx5.h
+++ b/libmlx5/src/mlx5.h
@@ -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
diff --git a/librdmacm/src/cma.h b/librdmacm/src/cma.h
index 98eba8d..d640688 100644
--- a/librdmacm/src/cma.h
+++ b/librdmacm/src/cma.h
@@ -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)))
diff --git a/utils/math.h b/utils/math.h
new file mode 100644
index 0000000..ffef543
--- /dev/null
+++ b/utils/math.h
@@ -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_ */
-- 
2.7.4

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* [PATCH rdma-core 3/5] utils: Remove container_of and offset local declarations
       [not found] ` <1474786207-2149-1-git-send-email-leon-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
  2016-09-25  6:50   ` [PATCH rdma-core 1/5] cmake: Update build instructions in CmakeList Leon Romanovsky
  2016-09-25  6:50   ` [PATCH rdma-core 2/5] utils: Create utils directory to put all common code and move min/max into it Leon Romanovsky
@ 2016-09-25  6:50   ` Leon Romanovsky
       [not found]     ` <1474786207-2149-4-git-send-email-leon-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
  2016-09-25  6:50   ` [PATCH rdma-core 4/5] libocrdma: Move ocrdma's list implementation into common directory Leon Romanovsky
  2016-09-25  6:50   ` [PATCH rdma-core 5/5] libmlx5: Convert libmlx5 to use common list implementation Leon Romanovsky
  4 siblings, 1 reply; 21+ messages in thread
From: Leon Romanovsky @ 2016-09-25  6:50 UTC (permalink / raw)
  To: dledford-H+wXaHxf7aLQT0dZR+AlfA, linux-rdma-u79uwXL29TY76Z2rM5mHXA
  Cc: jgunthorpe-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/,
	yishaih-VPRAkNaXOzVWk0Htik3J/w

Signed-off-by: Leon Romanovsky <leon-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
---
 ibacm/linux/osd.h   |  3 ---
 libmlx5/src/list.h  | 19 -------------------
 librdmacm/src/cma.h |  6 ------
 3 files changed, 28 deletions(-)

diff --git a/ibacm/linux/osd.h b/ibacm/linux/osd.h
index ec18f7b..1a738e0 100644
--- a/ibacm/linux/osd.h
+++ b/ibacm/linux/osd.h
@@ -55,9 +55,6 @@
 #define LIB_DESTRUCTOR __attribute__((destructor))
 #define CDECL_FUNC
 
-#define container_of(ptr, type, field) \
-	((type *) ((void *) ptr - offsetof(type, field)))
-
 #if __BYTE_ORDER == __LITTLE_ENDIAN
 #define htonll(x) bswap_64(x)
 #else
diff --git a/libmlx5/src/list.h b/libmlx5/src/list.h
index cd7d25b..4f96482 100644
--- a/libmlx5/src/list.h
+++ b/libmlx5/src/list.h
@@ -201,25 +201,6 @@ static inline void list_splice_init(struct list_head *list,
 	}
 }
 
-#ifndef offsetof
-#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
-#endif
-
-/**
- * container_of - cast a member of a structure out to the containing structure
- *
- * @ptr:        the pointer to the member.
- * @type:       the type of the container struct this is embedded in.
- * @member:     the name of the member within the struct.
- *
- */
-#ifndef container_of
-#define container_of(ptr, type, member) ({			\
-	const typeof(((type *)0)->member)*__mptr = (ptr);	\
-	(type *)((char *)__mptr - offsetof(type, member)); })
-#endif	
-
-
 /**
  * list_entry - get the struct for this entry
  * @ptr:	the &struct list_head pointer.
diff --git a/librdmacm/src/cma.h b/librdmacm/src/cma.h
index d640688..83d98b0 100644
--- a/librdmacm/src/cma.h
+++ b/librdmacm/src/cma.h
@@ -70,12 +70,6 @@ static inline uint64_t htonll(uint64_t x) { return x; }
 static inline uint64_t ntohll(uint64_t x) { return x; }
 #endif
 
-#ifndef container_of
-#define container_of(ptr, type, field) \
-	((type *) ((void *)ptr - offsetof(type, field)))
-#endif
-
-
 /*
  * Fast synchronization for low contention locking.
  */
-- 
2.7.4

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* [PATCH rdma-core 4/5] libocrdma: Move ocrdma's list implementation into common directory
       [not found] ` <1474786207-2149-1-git-send-email-leon-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
                     ` (2 preceding siblings ...)
  2016-09-25  6:50   ` [PATCH rdma-core 3/5] utils: Remove container_of and offset local declarations Leon Romanovsky
@ 2016-09-25  6:50   ` Leon Romanovsky
       [not found]     ` <1474786207-2149-5-git-send-email-leon-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
  2016-09-25  6:50   ` [PATCH rdma-core 5/5] libmlx5: Convert libmlx5 to use common list implementation Leon Romanovsky
  4 siblings, 1 reply; 21+ messages in thread
From: Leon Romanovsky @ 2016-09-25  6:50 UTC (permalink / raw)
  To: dledford-H+wXaHxf7aLQT0dZR+AlfA, linux-rdma-u79uwXL29TY76Z2rM5mHXA
  Cc: jgunthorpe-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/,
	yishaih-VPRAkNaXOzVWk0Htik3J/w

Signed-off-by: Leon Romanovsky <leon-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
---
 libocrdma/src/ocrdma_list.h  | 104 -------------------------------------------
 libocrdma/src/ocrdma_main.c  |   8 ++--
 libocrdma/src/ocrdma_main.h  |  12 ++---
 libocrdma/src/ocrdma_verbs.c |  16 +++----
 utils/list.h                 | 104 +++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 122 insertions(+), 122 deletions(-)
 delete mode 100644 libocrdma/src/ocrdma_list.h
 create mode 100644 utils/list.h

diff --git a/libocrdma/src/ocrdma_list.h b/libocrdma/src/ocrdma_list.h
deleted file mode 100644
index 1e0f1ff..0000000
--- a/libocrdma/src/ocrdma_list.h
+++ /dev/null
@@ -1,104 +0,0 @@
-/*
- * Copyright (C) 2008-2013 Emulex.  All rights reserved.
- * 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
- * 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.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT  LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR  A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
- * THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef __OCRDMA_LIST_H__
-#define __OCRDMA_LIST_H__
-
-struct ocrdma_list_node {
-	struct ocrdma_list_node *next, *prev;
-};
-
-struct ocrdma_list_head {
-	struct ocrdma_list_node node;
-	pthread_mutex_t lock;
-};
-
-#define DBLY_LIST_HEAD_INIT(name) { { &(name.node), &(name.node) } , \
-                        PTHREAD_MUTEX_INITIALIZER }
-
-#define DBLY_LIST_HEAD(name) \
-	struct ocrdma_list_head name = DBLY_LIST_HEAD_INIT(name); \
-
-#define INIT_DBLY_LIST_NODE(ptr) do { \
-	(ptr)->next = (ptr); (ptr)->prev = (ptr); \
-} while (0)
-
-#define INIT_DBLY_LIST_HEAD(ptr) INIT_DBLY_LIST_NODE(ptr.node)
-
-static inline void __list_add_node(struct ocrdma_list_node *new,
-				       struct ocrdma_list_node *prev,
-				       struct ocrdma_list_node *next)
-{
-	next->prev = new;
-	new->next = next;
-	new->prev = prev;
-	prev->next = new;
-}
-
-static inline void list_add_node_tail(struct ocrdma_list_node *new,
-					  struct ocrdma_list_head *head)
-{
-	__list_add_node(new, head->node.prev, &head->node);
-}
-
-static inline void __list_del_node(struct ocrdma_list_node *prev,
-				       struct ocrdma_list_node *next)
-{
-	next->prev = prev;
-	prev->next = next;
-}
-
-static inline void list_del_node(struct ocrdma_list_node *entry)
-{
-	__list_del_node(entry->prev, entry->next);
-	entry->next = entry->prev = 0;
-}
-
-#define list_lock(head) pthread_mutex_lock(&((head)->lock))
-#define list_unlock(head) pthread_mutex_unlock(&((head)->lock))
-
-#define list_node(ptr, type, member) \
-    ((type *)((char *)(ptr)-(unsigned long)(&((type *)0)->member)))
-
-/**
- * list_for_each_node_safe	-	iterate over a list safe against removal of list entry
- * @pos:	the &struct ocrdma_list_head to use as a loop counter.
- * @n:		another &struct ocrdma_list_head to use as temporary storage
- * @head:	the head for your list.
- */
-#define list_for_each_node_safe(pos, n, head) \
-	for (pos = (head)->node.next, n = pos->next; pos != &((head)->node); \
-		pos = n, n = pos->next)
-
-#endif				/* __OCRDMA_LIST_H__ */
diff --git a/libocrdma/src/ocrdma_main.c b/libocrdma/src/ocrdma_main.c
index 5c494d8..6bd892c 100644
--- a/libocrdma/src/ocrdma_main.c
+++ b/libocrdma/src/ocrdma_main.c
@@ -46,7 +46,7 @@
 
 #include "ocrdma_main.h"
 #include "ocrdma_abi.h"
-#include "ocrdma_list.h"
+#include "../../utils/list.h"
 
 #include <sys/types.h>
 #include <sys/stat.h>
@@ -68,7 +68,7 @@ struct {
 	UCNA(EMULEX, GEN1), UCNA(EMULEX, GEN2), UCNA(EMULEX, GEN2_VF)
 };
 
-static DBLY_LIST_HEAD(ocrdma_dev_list);
+static LIST_HEAD(ocrdma_dev_list);
 
 static struct ibv_context *ocrdma_alloc_context(struct ibv_device *, int);
 static void ocrdma_free_context(struct ibv_context *);
@@ -222,7 +222,7 @@ found:
 	pthread_mutex_init(&dev->dev_lock, NULL);
 	pthread_spin_init(&dev->flush_q_lock, PTHREAD_PROCESS_PRIVATE);
 	dev->ibv_dev.ops = ocrdma_dev_ops;
-	INIT_DBLY_LIST_NODE(&dev->entry);
+	INIT_LIST_NODE(&dev->entry);
 	list_lock(&ocrdma_dev_list);
 	list_add_node_tail(&dev->entry, &ocrdma_dev_list);
 	list_unlock(&ocrdma_dev_list);
@@ -244,7 +244,7 @@ void ocrdma_register_driver(void)
 static __attribute__ ((destructor))
 void ocrdma_unregister_driver(void)
 {
-	struct ocrdma_list_node *cur, *tmp;
+	struct list_node *cur, *tmp;
 	struct ocrdma_device *dev;
 	list_lock(&ocrdma_dev_list);
 	list_for_each_node_safe(cur, tmp, &ocrdma_dev_list) {
diff --git a/libocrdma/src/ocrdma_main.h b/libocrdma/src/ocrdma_main.h
index c81188b..c7359c8 100644
--- a/libocrdma/src/ocrdma_main.h
+++ b/libocrdma/src/ocrdma_main.h
@@ -42,7 +42,7 @@
 #include <infiniband/driver.h>
 #include <infiniband/arch.h>
 
-#include "ocrdma_list.h"
+#include "../../utils/list.h"
 
 #define ocrdma_err(format, arg...) printf(format, ##arg)
 
@@ -58,7 +58,7 @@ struct ocrdma_device {
 	struct ocrdma_qp **qp_tbl;
 	pthread_mutex_t dev_lock;
 	pthread_spinlock_t flush_q_lock;
-	struct ocrdma_list_node entry;
+	struct list_node entry;
 	int id;
 	int gen;
 	uint32_t wqe_size;
@@ -106,8 +106,8 @@ struct ocrdma_cq {
 	uint8_t deferred_arm;
 	uint8_t deferred_sol;
 	uint8_t first_arm;
-	struct ocrdma_list_head sq_head;
-	struct ocrdma_list_head rq_head;
+	struct list_head sq_head;
+	struct list_head rq_head;
 };
 
 enum {
@@ -203,8 +203,8 @@ struct ocrdma_qp {
 
 	enum ibv_qp_type qp_type;
 	enum ocrdma_qp_state state;
-	struct ocrdma_list_node sq_entry;
-	struct ocrdma_list_node rq_entry;
+	struct list_node sq_entry;
+	struct list_node rq_entry;
 	uint16_t id;
 	uint16_t rsvd;
 	uint32_t db_shift;
diff --git a/libocrdma/src/ocrdma_verbs.c b/libocrdma/src/ocrdma_verbs.c
index 6062626..3efc8bb 100644
--- a/libocrdma/src/ocrdma_verbs.c
+++ b/libocrdma/src/ocrdma_verbs.c
@@ -51,7 +51,7 @@
 
 #include "ocrdma_main.h"
 #include "ocrdma_abi.h"
-#include "ocrdma_list.h"
+#include "../../utils/list.h"
 
 static void ocrdma_ring_cq_db(struct ocrdma_cq *cq, uint32_t armed,
 			      int solicited, uint32_t num_cqe);
@@ -307,8 +307,8 @@ static struct ibv_cq *ocrdma_create_cq_common(struct ibv_context *context,
 		ocrdma_ring_cq_db(cq, 0, 0, 0);
 	}
 	cq->ibv_cq.cqe = cqe;
-	INIT_DBLY_LIST_HEAD(&cq->sq_head);
-	INIT_DBLY_LIST_HEAD(&cq->rq_head);
+	INIT_LIST_HEAD(&cq->sq_head);
+	INIT_LIST_HEAD(&cq->rq_head);
 	return &cq->ibv_cq;
 cq_err2:
 	(void)ibv_cmd_destroy_cq(&cq->ibv_cq);
@@ -621,8 +621,8 @@ struct ibv_qp *ocrdma_create_qp(struct ibv_pd *pd,
 		}
 	}
 	qp->state = OCRDMA_QPS_RST;
-	INIT_DBLY_LIST_NODE(&qp->sq_entry);
-	INIT_DBLY_LIST_NODE(&qp->rq_entry);
+	INIT_LIST_NODE(&qp->sq_entry);
+	INIT_LIST_NODE(&qp->rq_entry);
 	return &qp->ibv_qp;
 
 map_err:
@@ -663,7 +663,7 @@ static int ocrdma_is_qp_in_sq_flushlist(struct ocrdma_cq *cq,
 					struct ocrdma_qp *qp)
 {
 	struct ocrdma_qp *list_qp;
-	struct ocrdma_list_node *cur, *tmp;
+	struct list_node *cur, *tmp;
 	int found = 0;
 	list_for_each_node_safe(cur, tmp, &cq->sq_head) {
 		list_qp = list_node(cur, struct ocrdma_qp, sq_entry);
@@ -679,7 +679,7 @@ static int ocrdma_is_qp_in_rq_flushlist(struct ocrdma_cq *cq,
 					struct ocrdma_qp *qp)
 {
 	struct ocrdma_qp *list_qp;
-	struct ocrdma_list_node *cur, *tmp;
+	struct list_node *cur, *tmp;
 	int found = 0;
 	list_for_each_node_safe(cur, tmp, &cq->rq_head) {
 		list_qp = list_node(cur, struct ocrdma_qp, rq_entry);
@@ -2034,7 +2034,7 @@ int ocrdma_poll_cq(struct ibv_cq *ibcq, int num_entries, struct ibv_wc *wc)
 	int cqes_to_poll = num_entries;
 	int num_os_cqe = 0, err_cqes = 0;
 	struct ocrdma_qp *qp;
-	struct ocrdma_list_node *cur, *tmp;
+	struct list_node *cur, *tmp;
 
 	cq = get_ocrdma_cq(ibcq);
 	pthread_spin_lock(&cq->cq_lock);
diff --git a/utils/list.h b/utils/list.h
new file mode 100644
index 0000000..e229348
--- /dev/null
+++ b/utils/list.h
@@ -0,0 +1,104 @@
+/*
+ * Copyright (C) 2008-2013 Emulex.  All rights reserved.
+ * 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
+ * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT  LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR  A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _RDMA_LIST_H__
+#define _RDMA_LIST_H__
+
+struct list_node {
+	struct list_node *next, *prev;
+};
+
+struct list_head {
+	struct list_node node;
+	pthread_mutex_t lock;
+};
+
+#define LIST_HEAD_INIT(name) { { &(name.node), &(name.node) } , \
+                        PTHREAD_MUTEX_INITIALIZER }
+
+#define LIST_HEAD(name) \
+	struct list_head name = LIST_HEAD_INIT(name); \
+
+#define INIT_LIST_NODE(ptr) do { \
+	(ptr)->next = (ptr); (ptr)->prev = (ptr); \
+} while (0)
+
+#define INIT_LIST_HEAD(ptr) INIT_LIST_NODE(ptr.node)
+
+static inline void __list_add_node(struct list_node *new,
+				   struct list_node *prev,
+				   struct list_node *next)
+{
+	next->prev = new;
+	new->next = next;
+	new->prev = prev;
+	prev->next = new;
+}
+
+static inline void list_add_node_tail(struct list_node *new,
+				      struct list_head *head)
+{
+	__list_add_node(new, head->node.prev, &head->node);
+}
+
+static inline void __list_del_node(struct list_node *prev,
+				   struct list_node *next)
+{
+	next->prev = prev;
+	prev->next = next;
+}
+
+static inline void list_del_node(struct list_node *entry)
+{
+	__list_del_node(entry->prev, entry->next);
+	entry->next = entry->prev = 0;
+}
+
+#define list_lock(head) pthread_mutex_lock(&((head)->lock))
+#define list_unlock(head) pthread_mutex_unlock(&((head)->lock))
+
+#define list_node(ptr, type, member) \
+    ((type *)((char *)(ptr)-(unsigned long)(&((type *)0)->member)))
+
+/**
+ * list_for_each_node_safe	-	iterate over a list safe against removal of list entry
+ * @pos:	the &struct list_head to use as a loop counter.
+ * @n:		another &struct list_head to use as temporary storage
+ * @head:	the head for your list.
+ */
+#define list_for_each_node_safe(pos, n, head) \
+	for (pos = (head)->node.next, n = pos->next; pos != &((head)->node); \
+		pos = n, n = pos->next)
+
+#endif /* _RDMA_LIST_H_ */
-- 
2.7.4

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* [PATCH rdma-core 5/5] libmlx5: Convert libmlx5 to use common list implementation
       [not found] ` <1474786207-2149-1-git-send-email-leon-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
                     ` (3 preceding siblings ...)
  2016-09-25  6:50   ` [PATCH rdma-core 4/5] libocrdma: Move ocrdma's list implementation into common directory Leon Romanovsky
@ 2016-09-25  6:50   ` Leon Romanovsky
  4 siblings, 0 replies; 21+ messages in thread
From: Leon Romanovsky @ 2016-09-25  6:50 UTC (permalink / raw)
  To: dledford-H+wXaHxf7aLQT0dZR+AlfA, linux-rdma-u79uwXL29TY76Z2rM5mHXA
  Cc: jgunthorpe-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/,
	yishaih-VPRAkNaXOzVWk0Htik3J/w

Signed-off-by: Leon Romanovsky <leon-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
---
 libmlx5/src/buf.c  |  13 +--
 libmlx5/src/list.h | 312 -----------------------------------------------------
 libmlx5/src/mlx5.h |   4 +-
 utils/list.h       |   9 +-
 4 files changed, 17 insertions(+), 321 deletions(-)
 delete mode 100644 libmlx5/src/list.h

diff --git a/libmlx5/src/buf.c b/libmlx5/src/buf.c
index c827930..ec8611e 100644
--- a/libmlx5/src/buf.c
+++ b/libmlx5/src/buf.c
@@ -259,16 +259,17 @@ static int alloc_huge_buf(struct mlx5_context *mctx, struct mlx5_buf *buf,
 			  size_t size, int page_size)
 {
 	int found = 0;
-	LIST_HEAD(slist);
 	int nchunk;
 	struct mlx5_hugetlb_mem *hmem;
+	struct list_node *tmp, *cur;
 	int ret;
 
 	buf->length = align(size, MLX5_Q_CHUNK_SIZE);
 	nchunk = buf->length / MLX5_Q_CHUNK_SIZE;
 
 	mlx5_spin_lock(&mctx->hugetlb_lock);
-	list_for_each_entry(hmem, &mctx->hugetlb_list, list) {
+	list_for_each_node_safe(cur, tmp, &mctx->hugetlb_list) {
+		hmem = list_node(cur, struct mlx5_hugetlb_mem, entry);
 		if (bitmap_avail(&hmem->bitmap)) {
 			buf->base = bitmap_alloc_range(&hmem->bitmap, nchunk, 1);
 			if (buf->base != -1) {
@@ -297,9 +298,9 @@ static int alloc_huge_buf(struct mlx5_context *mctx, struct mlx5_buf *buf,
 
 		mlx5_spin_lock(&mctx->hugetlb_lock);
 		if (bitmap_avail(&hmem->bitmap))
-			list_add(&hmem->list, &mctx->hugetlb_list);
+			list_add_node(&hmem->entry, &mctx->hugetlb_list);
 		else
-			list_add_tail(&hmem->list, &mctx->hugetlb_list);
+			list_add_node_tail(&hmem->entry, &mctx->hugetlb_list);
 		mlx5_spin_unlock(&mctx->hugetlb_lock);
 	}
 
@@ -318,7 +319,7 @@ out_fork:
 	mlx5_spin_lock(&mctx->hugetlb_lock);
 	bitmap_free_range(&hmem->bitmap, buf->base, nchunk);
 	if (bitmap_empty(&hmem->bitmap)) {
-		list_del(&hmem->list);
+		list_del_node(&hmem->entry);
 		mlx5_spin_unlock(&mctx->hugetlb_lock);
 		free_huge_mem(hmem);
 	} else
@@ -335,7 +336,7 @@ static void free_huge_buf(struct mlx5_context *ctx, struct mlx5_buf *buf)
 	mlx5_spin_lock(&ctx->hugetlb_lock);
 	bitmap_free_range(&buf->hmem->bitmap, buf->base, nchunk);
 	if (bitmap_empty(&buf->hmem->bitmap)) {
-		list_del(&buf->hmem->list);
+		list_del_node(&buf->hmem->entry);
 		mlx5_spin_unlock(&ctx->hugetlb_lock);
 		free_huge_mem(buf->hmem);
 	} else
diff --git a/libmlx5/src/list.h b/libmlx5/src/list.h
deleted file mode 100644
index 4f96482..0000000
--- a/libmlx5/src/list.h
+++ /dev/null
@@ -1,312 +0,0 @@
-#ifndef _LINUX_LIST_H
-#define _LINUX_LIST_H
-
-/*
- * These are non-NULL pointers that will result in page faults
- * under normal circumstances, used to verify that nobody uses
- * non-initialized list entries.
- */
-#define LIST_POISON1  ((void *) 0x00100100)
-#define LIST_POISON2  ((void *) 0x00200200)
-
-/*
- * Simple doubly linked list implementation.
- *
- * Some of the internal functions ("__xxx") are useful when
- * manipulating whole lists rather than single entries, as
- * sometimes we already know the next/prev entries and we can
- * generate better code by using them directly rather than
- * using the generic single-entry routines.
- */
-
-struct list_head {
-	struct list_head *next, *prev;
-};
-
-#define LIST_HEAD_INIT(name) { &(name), &(name) }
-
-#define LIST_HEAD(name) \
-	struct list_head name = LIST_HEAD_INIT(name)
-
-#define INIT_LIST_HEAD(ptr) do { \
-	(ptr)->next = (ptr); (ptr)->prev = (ptr); \
-} while (0)
-
-/*
- * Insert a new entry between two known consecutive entries.
- *
- * This is only for internal list manipulation where we know
- * the prev/next entries already!
- */
-static inline void __list_add(struct list_head *new,
-			      struct list_head *prev,
-			      struct list_head *next)
-{
-	next->prev = new;
-	new->next = next;
-	new->prev = prev;
-	prev->next = new;
-}
-
-/**
- * list_add - add a new entry
- * @new: new entry to be added
- * @head: list head to add it after
- *
- * Insert a new entry after the specified head.
- * This is good for implementing stacks.
- */
-static inline void list_add(struct list_head *new, struct list_head *head)
-{
-	__list_add(new, head, head->next);
-}
-
-/**
- * list_add_tail - add a new entry
- * @new: new entry to be added
- * @head: list head to add it before
- *
- * Insert a new entry before the specified head.
- * This is useful for implementing queues.
- */
-static inline void list_add_tail(struct list_head *new, struct list_head *head)
-{
-	__list_add(new, head->prev, head);
-}
-
-/*
- * Delete a list entry by making the prev/next entries
- * point to each other.
- *
- * This is only for internal list manipulation where we know
- * the prev/next entries already!
- */
-static inline void __list_del(struct list_head *prev, struct list_head *next)
-{
-	next->prev = prev;
-	prev->next = next;
-}
-
-/**
- * list_del - deletes entry from list.
- * @entry: the element to delete from the list.
- * Note: list_empty on entry does not return true after this, the entry is
- * in an undefined state.
- */
-static inline void list_del(struct list_head *entry)
-{
-	__list_del(entry->prev, entry->next);
-	entry->next = LIST_POISON1;
-	entry->prev = LIST_POISON2;
-}
-
-/**
- * list_del_init - deletes entry from list and reinitialize it.
- * @entry: the element to delete from the list.
- */
-static inline void list_del_init(struct list_head *entry)
-{
-	__list_del(entry->prev, entry->next);
-	INIT_LIST_HEAD(entry);
-}
-
-/**
- * list_move - delete from one list and add as another's head
- * @list: the entry to move
- * @head: the head that will precede our entry
- */
-static inline void list_move(struct list_head *list, struct list_head *head)
-{
-	__list_del(list->prev, list->next);
-	list_add(list, head);
-}
-
-/**
- * list_move_tail - delete from one list and add as another's tail
- * @list: the entry to move
- * @head: the head that will follow our entry
- */
-static inline void list_move_tail(struct list_head *list,
-				  struct list_head *head)
-{
-	__list_del(list->prev, list->next);
-	list_add_tail(list, head);
-}
-
-/**
- * list_empty - tests whether a list is empty
- * @head: the list to test.
- */
-static inline int list_empty(const struct list_head *head)
-{
-	return head->next == head;
-}
-
-/**
- * list_empty_careful - tests whether a list is
- * empty _and_ checks that no other CPU might be
- * in the process of still modifying either member
- *
- * NOTE: using list_empty_careful() without synchronization
- * can only be safe if the only activity that can happen
- * to the list entry is list_del_init(). Eg. it cannot be used
- * if another CPU could re-list_add() it.
- *
- * @head: the list to test.
- */
-static inline int list_empty_careful(const struct list_head *head)
-{
-	struct list_head *next = head->next;
-	return (next == head) && (next == head->prev);
-}
-
-static inline void __list_splice(struct list_head *list,
-				 struct list_head *head)
-{
-	struct list_head *first = list->next;
-	struct list_head *last = list->prev;
-	struct list_head *at = head->next;
-
-	first->prev = head;
-	head->next = first;
-
-	last->next = at;
-	at->prev = last;
-}
-
-/**
- * list_splice - join two lists
- * @list: the new list to add.
- * @head: the place to add it in the first list.
- */
-static inline void list_splice(struct list_head *list, struct list_head *head)
-{
-	if (!list_empty(list))
-		__list_splice(list, head);
-}
-
-/**
- * list_splice_init - join two lists and reinitialise the emptied list.
- * @list: the new list to add.
- * @head: the place to add it in the first list.
- *
- * The list at @list is reinitialised
- */
-static inline void list_splice_init(struct list_head *list,
-				    struct list_head *head)
-{
-	if (!list_empty(list)) {
-		__list_splice(list, head);
-		INIT_LIST_HEAD(list);
-	}
-}
-
-/**
- * list_entry - get the struct for this entry
- * @ptr:	the &struct list_head pointer.
- * @type:	the type of the struct this is embedded in.
- * @member:	the name of the list_struct within the struct.
- */
-#define list_entry(ptr, type, member) \
-	container_of(ptr, type, member)
-
-/**
- * list_for_each	-	iterate over a list
- * @pos:	the &struct list_head to use as a loop counter.
- * @head:	the head for your list.
- */
-#define list_for_each(pos, head) \
-	for (pos = (head)->next; prefetch(pos->next), pos != (head); \
-		pos->next)
-
-/**
- * __list_for_each	-	iterate over a list
- * @pos:	the &struct list_head to use as a loop counter.
- * @head:	the head for your list.
- *
- * This variant differs from list_for_each() in that it's the
- * simplest possible list iteration code, no prefetching is done.
- * Use this for code that knows the list to be very short (empty
- * or 1 entry) most of the time.
- */
-#define __list_for_each(pos, head) \
-	for (pos = (head)->next; pos != (head); pos = pos->next)
-
-/**
- * list_for_each_prev	-	iterate over a list backwards
- * @pos:	the &struct list_head to use as a loop counter.
- * @head:	the head for your list.
- */
-#define list_for_each_prev(pos, head) \
-	for (pos = (head)->prev; prefetch(pos->prev), pos != (head); \
-		pos = pos->prev)
-
-/**
- * list_for_each_safe	-	iterate over a list safe against removal of list entry
- * @pos:	the &struct list_head to use as a loop counter.
- * @n:		another &struct list_head to use as temporary storage
- * @head:	the head for your list.
- */
-#define list_for_each_safe(pos, n, head) \
-	for (pos = (head)->next, n = pos->next; pos != (head); \
-		pos = n, n = pos->next)
-
-/**
- * list_for_each_entry	-	iterate over list of given type
- * @pos:	the type * to use as a loop counter.
- * @head:	the head for your list.
- * @member:	the name of the list_struct within the struct.
- */
-#define list_for_each_entry(pos, head, member)				\
-	for (pos = list_entry((head)->next, typeof(*pos), member);	\
-		&pos->member != (head);					\
-		pos = list_entry(pos->member.next, typeof(*pos), member))
-
-/**
- * list_for_each_entry_reverse - iterate backwards over list of given type.
- * @pos:	the type * to use as a loop counter.
- * @head:	the head for your list.
- * @member:	the name of the list_struct within the struct.
- */
-#define list_for_each_entry_reverse(pos, head, member)			\
-	for (pos = list_entry((head)->prev, typeof(*pos), member);	\
-		prefetch(pos->member.prev), &pos->member != (head);	\
-		pos = list_entry(pos->member.prev, typeof(*pos), member))
-
-/**
- * list_prepare_entry - prepare a pos entry for use as a start point in
- *			list_for_each_entry_continue
- * @pos:	the type * to use as a start point
- * @head:	the head of the list
- * @member:	the name of the list_struct within the struct.
- */
-#define list_prepare_entry(pos, head, member) \
-	((pos) ? : list_entry(head, typeof(*pos), member))
-
-/**
- * list_for_each_entry_continue -	iterate over list of given type
- *			continuing after existing point
- * @pos:	the type * to use as a loop counter.
- * @head:	the head for your list.
- * @member:	the name of the list_struct within the struct.
- */
-#define list_for_each_entry_continue(pos, head, member)		\
-	for (pos = list_entry(pos->member.next, typeof(*pos), member);	\
-		prefetch(pos->member.next), &pos->member != (head);	\
-		pos = list_entry(pos->member.next, typeof(*pos), member))
-
-/**
- * list_for_each_entry_safe - iterate over list of given type safe against removal of list entry
- * @pos:	the type * to use as a loop counter.
- * @n:		another type * to use as temporary storage
- * @head:	the head for your list.
- * @member:	the name of the list_struct within the struct.
- */
-#define list_for_each_entry_safe(pos, n, head, member)			\
-	for (pos = list_entry((head)->next, typeof(*pos), member),	\
-		n = list_entry(pos->member.next, typeof(*pos), member);	\
-	     &pos->member != (head);					\
-	     pos = n, n = list_entry(n->member.next, typeof(*n), member))
-
-#endif
-
diff --git a/libmlx5/src/mlx5.h b/libmlx5/src/mlx5.h
index 453aeb8..7392499 100644
--- a/libmlx5/src/mlx5.h
+++ b/libmlx5/src/mlx5.h
@@ -39,10 +39,10 @@
 #include <infiniband/driver.h>
 #include <infiniband/arch.h>
 #include "mlx5-abi.h"
-#include "list.h"
 #include "bitmap.h"
 
 #include "../../utils/math.h"
+#include "../../utils/list.h"
 
 #ifdef __GNUC__
 #define likely(x)	__builtin_expect((x), 1)
@@ -355,7 +355,7 @@ struct mlx5_hugetlb_mem {
 	int			shmid;
 	void		       *shmaddr;
 	struct mlx5_bitmap	bitmap;
-	struct list_head	list;
+	struct list_node	entry;
 };
 
 struct mlx5_buf {
diff --git a/utils/list.h b/utils/list.h
index e229348..bc03e2b 100644
--- a/utils/list.h
+++ b/utils/list.h
@@ -48,7 +48,7 @@ struct list_head {
                         PTHREAD_MUTEX_INITIALIZER }
 
 #define LIST_HEAD(name) \
-	struct list_head name = LIST_HEAD_INIT(name); \
+	struct list_head name = LIST_HEAD_INIT(name);
 
 #define INIT_LIST_NODE(ptr) do { \
 	(ptr)->next = (ptr); (ptr)->prev = (ptr); \
@@ -72,6 +72,13 @@ static inline void list_add_node_tail(struct list_node *new,
 	__list_add_node(new, head->node.prev, &head->node);
 }
 
+static inline void list_add_node(struct list_node *new,
+				 struct list_head *head)
+{
+	__list_add_node(new, &head->node, head->node.next);
+}
+
+
 static inline void __list_del_node(struct list_node *prev,
 				   struct list_node *next)
 {
-- 
2.7.4

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: [PATCH rdma-core 4/5] libocrdma: Move ocrdma's list implementation into common directory
       [not found]     ` <1474786207-2149-5-git-send-email-leon-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
@ 2016-09-25 14:41       ` Christoph Hellwig
       [not found]         ` <20160925144121.GA12246-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org>
  0 siblings, 1 reply; 21+ messages in thread
From: Christoph Hellwig @ 2016-09-25 14:41 UTC (permalink / raw)
  To: Leon Romanovsky
  Cc: dledford-H+wXaHxf7aLQT0dZR+AlfA,
	linux-rdma-u79uwXL29TY76Z2rM5mHXA,
	jgunthorpe-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/,
	yishaih-VPRAkNaXOzVWk0Htik3J/w

This implementation was also copy and pasted from the Linux kernel
one, including the kernel document comments, and an incorrect license
was added to it.  It should be removed just like the Mellanox copy.
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: [PATCH rdma-core 4/5] libocrdma: Move ocrdma's list implementation into common directory
       [not found]         ` <20160925144121.GA12246-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org>
@ 2016-09-25 16:13           ` Leon Romanovsky
       [not found]             ` <20160925161315.GD4088-2ukJVAZIZ/Y@public.gmane.org>
  0 siblings, 1 reply; 21+ messages in thread
From: Leon Romanovsky @ 2016-09-25 16:13 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: dledford-H+wXaHxf7aLQT0dZR+AlfA,
	linux-rdma-u79uwXL29TY76Z2rM5mHXA,
	jgunthorpe-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/,
	yishaih-VPRAkNaXOzVWk0Htik3J/w

[-- Attachment #1: Type: text/plain, Size: 458 bytes --]

On Sun, Sep 25, 2016 at 07:41:21AM -0700, Christoph Hellwig wrote:
> This implementation was also copy and pasted from the Linux kernel
> one, including the kernel document comments, and an incorrect license
> was added to it.  It should be removed just like the Mellanox copy.

Awesome,
Any suggestion where can we get list.h compliant with BSD license?
Is this enough [1] ?

[1]
https://github.com/lattera/freebsd/blob/master/sys/ofed/include/linux/list.h

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

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

* Re: [PATCH rdma-core 4/5] libocrdma: Move ocrdma's list implementation into common directory
       [not found]             ` <20160925161315.GD4088-2ukJVAZIZ/Y@public.gmane.org>
@ 2016-09-25 16:22               ` Christoph Hellwig
       [not found]                 ` <20160925162203.GA32434-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org>
  2016-09-25 22:05               ` Jason Gunthorpe
  1 sibling, 1 reply; 21+ messages in thread
From: Christoph Hellwig @ 2016-09-25 16:22 UTC (permalink / raw)
  To: Leon Romanovsky
  Cc: Christoph Hellwig, dledford-H+wXaHxf7aLQT0dZR+AlfA,
	linux-rdma-u79uwXL29TY76Z2rM5mHXA,
	jgunthorpe-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/,
	yishaih-VPRAkNaXOzVWk0Htik3J/w

On Sun, Sep 25, 2016 at 07:13:15PM +0300, Leon Romanovsky wrote:
> Any suggestion where can we get list.h compliant with BSD license?
> Is this enough [1] ?

That one looks like someone who knew the Linux one very well spend
a lot of effort obsfucating it after starting with the Linux version :)

If I were the copyright holder of the file I'd be okay with that given
that the list implementation is pretty much trivial anyway.

But given that I don't know who owns every little bit of the Linux
lists.h I'd simply avoid anything looking like it and use something
like the BSD queue.h instead (which glibc also provides, but in a
horribly outdated version).
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: [PATCH rdma-core 4/5] libocrdma: Move ocrdma's list implementation into common directory
       [not found]                 ` <20160925162203.GA32434-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org>
@ 2016-09-25 17:50                   ` Bart Van Assche
  2016-09-26 17:40                   ` Jason Gunthorpe
  1 sibling, 0 replies; 21+ messages in thread
From: Bart Van Assche @ 2016-09-25 17:50 UTC (permalink / raw)
  To: Christoph Hellwig, Leon Romanovsky
  Cc: dledford-H+wXaHxf7aLQT0dZR+AlfA,
	linux-rdma-u79uwXL29TY76Z2rM5mHXA,
	jgunthorpe-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/,
	yishaih-VPRAkNaXOzVWk0Htik3J/w

On 09/25/16 09:22, Christoph Hellwig wrote:
> On Sun, Sep 25, 2016 at 07:13:15PM +0300, Leon Romanovsky wrote:
>> Any suggestion where can we get list.h compliant with BSD license?
>> Is this enough [1] ?
>
> That one looks like someone who knew the Linux one very well spend
> a lot of effort obsfucating it after starting with the Linux version :)
>
> If I were the copyright holder of the file I'd be okay with that given
> that the list implementation is pretty much trivial anyway.
>
> But given that I don't know who owns every little bit of the Linux
> lists.h I'd simply avoid anything looking like it and use something
> like the BSD queue.h instead (which glibc also provides, but in a
> horribly outdated version).

How about using <list> from libstdc++? It is allowed to use libstdc++ 
headers to build non-GPL software. See also 
https://gcc.gnu.org/onlinedocs/libstdc++/manual/license.html for 
libstdc++ license information.

Bart.

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: [PATCH rdma-core 4/5] libocrdma: Move ocrdma's list implementation into common directory
       [not found]             ` <20160925161315.GD4088-2ukJVAZIZ/Y@public.gmane.org>
  2016-09-25 16:22               ` Christoph Hellwig
@ 2016-09-25 22:05               ` Jason Gunthorpe
  1 sibling, 0 replies; 21+ messages in thread
From: Jason Gunthorpe @ 2016-09-25 22:05 UTC (permalink / raw)
  To: Leon Romanovsky
  Cc: Christoph Hellwig, dledford-H+wXaHxf7aLQT0dZR+AlfA,
	linux-rdma-u79uwXL29TY76Z2rM5mHXA,
	yishaih-VPRAkNaXOzVWk0Htik3J/w

On Sun, Sep 25, 2016 at 07:13:15PM +0300, Leon Romanovsky wrote:
> On Sun, Sep 25, 2016 at 07:41:21AM -0700, Christoph Hellwig wrote:
> > This implementation was also copy and pasted from the Linux kernel
> > one, including the kernel document comments, and an incorrect license
> > was added to it.  It should be removed just like the Mellanox copy.
> 
> Awesome,
> Any suggestion where can we get list.h compliant with BSD license?
> Is this enough [1] ?
> 
> [1]
> https://github.com/lattera/freebsd/blob/master/sys/ofed/include/linux/list.h

I recommend CCAN's version, it looks like it would be trivial to
convert to.

https://github.com/rustyrussell/ccan/blob/master/ccan/list/list.h

We should also try and use their macros for the other stuff your
migrated, eg their container_of has more static checking, as does the
min/max, and they have a min/max_t implementation.

Jason
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: [PATCH rdma-core 2/5] utils: Create utils directory to put all common code and move min/max into it
       [not found]     ` <1474786207-2149-3-git-send-email-leon-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
@ 2016-09-26  7:05       ` Leon Romanovsky
       [not found]         ` <20160926070520.GJ4088-2ukJVAZIZ/Y@public.gmane.org>
  2016-09-26 17:20       ` Jason Gunthorpe
  1 sibling, 1 reply; 21+ messages in thread
From: Leon Romanovsky @ 2016-09-26  7:05 UTC (permalink / raw)
  To: dledford-H+wXaHxf7aLQT0dZR+AlfA, linux-rdma-u79uwXL29TY76Z2rM5mHXA
  Cc: jgunthorpe-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/,
	yishaih-VPRAkNaXOzVWk0Htik3J/w

[-- Attachment #1: Type: text/plain, Size: 758 bytes --]

On Sun, Sep 25, 2016 at 09:50:04AM +0300, Leon Romanovsky wrote:
> Signed-off-by: Leon Romanovsky <leon-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.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
>
>
> +#include "../../utils/math.h"

Jason,
Can you give me a suggestion where and how should I use include_directories
command to be able to write "#include <utils/math.h>"?

Thanks

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

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

* RE: [PATCH rdma-core 3/5] utils: Remove container_of and offset local declarations
       [not found]     ` <1474786207-2149-4-git-send-email-leon-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
@ 2016-09-26 15:32       ` Hefty, Sean
  2016-09-26 17:27       ` Jason Gunthorpe
  1 sibling, 0 replies; 21+ messages in thread
From: Hefty, Sean @ 2016-09-26 15:32 UTC (permalink / raw)
  To: Leon Romanovsky, dledford-H+wXaHxf7aLQT0dZR+AlfA,
	linux-rdma-u79uwXL29TY76Z2rM5mHXA
  Cc: jgunthorpe-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/,
	yishaih-VPRAkNaXOzVWk0Htik3J/w

> Signed-off-by: Leon Romanovsky <leon-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>

For ibacm/librdmacm:

Acked-by: Sean Hefty <sean.hefty-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: [PATCH rdma-core 2/5] utils: Create utils directory to put all common code and move min/max into it
       [not found]         ` <20160926070520.GJ4088-2ukJVAZIZ/Y@public.gmane.org>
@ 2016-09-26 17:17           ` Jason Gunthorpe
  0 siblings, 0 replies; 21+ messages in thread
From: Jason Gunthorpe @ 2016-09-26 17:17 UTC (permalink / raw)
  To: Leon Romanovsky
  Cc: dledford-H+wXaHxf7aLQT0dZR+AlfA,
	linux-rdma-u79uwXL29TY76Z2rM5mHXA,
	yishaih-VPRAkNaXOzVWk0Htik3J/w

On Mon, Sep 26, 2016 at 10:05:20AM +0300, Leon Romanovsky wrote:

> Can you give me a suggestion where and how should I use include_directories
> command to be able to write "#include <utils/math.h>"?

You were close, you did 'include_directories(util/)' which causes
something like 'gcc -I../util' - but that already stripped the util/
prefix, you'd need something like 'include_directories(.)'

However, let us continue to use the publish_headers scheme, so I
recommend you squish this into your series:

>From 406b60c89bd928d54b98e097e914f2131794ea62 Mon Sep 17 00:00:00 2001
From: Jason Gunthorpe <jgunthorpe-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
Date: Mon, 26 Sep 2016 11:15:09 -0600
Subject: [PATCH] Use the publish_headers scheme for internal utils headers too

Signed-off-by: Jason Gunthorpe <jgunthorpe-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
---
 CMakeLists.txt                    |  7 +------
 buildlib/publish_headers.cmake    | 18 ++++++++++++++----
 ibacm/linux/osd.h                 |  2 +-
 libibverbs/examples/rc_pingpong.c |  2 +-
 libmlx5/src/mlx5.h                |  4 ++--
 libocrdma/src/ocrdma_main.c       |  2 +-
 libocrdma/src/ocrdma_main.h       |  2 +-
 libocrdma/src/ocrdma_verbs.c      |  2 +-
 librdmacm/src/cma.h               |  2 +-
 utils/CMakeLists.txt              |  4 ++++
 10 files changed, 27 insertions(+), 18 deletions(-)
 create mode 100644 utils/CMakeLists.txt

diff --git a/CMakeLists.txt b/CMakeLists.txt
index c997c6d90f3c..b28977550c39 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -38,8 +38,6 @@ 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")
@@ -141,10 +139,6 @@ 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)
@@ -228,6 +222,7 @@ configure_file("${BUILDLIB}/config.h.in" "${BUILD_INCLUDE}/config.h" ESCAPE_QUOT
 
 #-------------------------
 # Sub-directories
+add_subdirectory(utils)
 # Libraries
 add_subdirectory(libibumad/src)
 add_subdirectory(libibumad/man)
diff --git a/buildlib/publish_headers.cmake b/buildlib/publish_headers.cmake
index ccd22960c141..c1909d677586 100644
--- a/buildlib/publish_headers.cmake
+++ b/buildlib/publish_headers.cmake
@@ -1,10 +1,9 @@
 # COPYRIGHT (c) 2016 Obsidian Research Corporation. See COPYING file
 
-# Copy headers from the source directory to the proper place in the
-# build/include directory
-function(PUBLISH_HEADERS DEST)
+# Same as publish_headers but does not install them during the install phase
+function(publish_internal_headers DEST)
   if(NOT ARGN)
-    message(SEND_ERROR "Error: PUBLISH_HEADERS called without any files")
+    message(SEND_ERROR "Error: publish_internal_headers called without any files")
     return()
   endif()
 
@@ -15,6 +14,17 @@ function(PUBLISH_HEADERS DEST)
     get_filename_component(FIL ${SFIL} NAME)
     execute_process(COMMAND "ln" "-Tsf"
       "${CMAKE_CURRENT_SOURCE_DIR}/${SFIL}" "${DDIR}/${FIL}")
+  endforeach()
+endfunction()
+
+# Copy headers from the source directory to the proper place in the
+# build/include directory. This also installs them into /usr/include/xx during
+# the install phase
+function(publish_headers DEST)
+  publish_internal_headers("${DEST}" ${ARGN})
+
+  foreach(SFIL ${ARGN})
+    get_filename_component(FIL ${SFIL} NAME)
     install(FILES "${SFIL}" DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/${DEST}/" RENAME "${FIL}")
   endforeach()
 endfunction()
diff --git a/ibacm/linux/osd.h b/ibacm/linux/osd.h
index 1a738e0bfc6b..2094e859e7eb 100644
--- a/ibacm/linux/osd.h
+++ b/ibacm/linux/osd.h
@@ -46,7 +46,7 @@
 #include <sys/time.h>
 #include <netinet/in.h>
 
-#include "../../utils/math.h"
+#include <utils/math.h>
 
 #define ACM_CONF_DIR  IBACM_CONFIG_PATH
 #define ACM_ADDR_FILE "ibacm_addr.cfg"
diff --git a/libibverbs/examples/rc_pingpong.c b/libibverbs/examples/rc_pingpong.c
index cc45741be152..59f369c2e1fc 100644
--- a/libibverbs/examples/rc_pingpong.c
+++ b/libibverbs/examples/rc_pingpong.c
@@ -49,7 +49,7 @@
 
 #include "pingpong.h"
 
-#include "../../utils/math.h"
+#include <utils/math.h>
 
 enum {
 	PINGPONG_RECV_WRID = 1,
diff --git a/libmlx5/src/mlx5.h b/libmlx5/src/mlx5.h
index 739249941650..aa270288e840 100644
--- a/libmlx5/src/mlx5.h
+++ b/libmlx5/src/mlx5.h
@@ -41,8 +41,8 @@
 #include "mlx5-abi.h"
 #include "bitmap.h"
 
-#include "../../utils/math.h"
-#include "../../utils/list.h"
+#include <utils/math.h>
+#include <utils/list.h>
 
 #ifdef __GNUC__
 #define likely(x)	__builtin_expect((x), 1)
diff --git a/libocrdma/src/ocrdma_main.c b/libocrdma/src/ocrdma_main.c
index 6bd892c1f799..d86b2d779dc1 100644
--- a/libocrdma/src/ocrdma_main.c
+++ b/libocrdma/src/ocrdma_main.c
@@ -46,7 +46,7 @@
 
 #include "ocrdma_main.h"
 #include "ocrdma_abi.h"
-#include "../../utils/list.h"
+#include <utils/list.h>
 
 #include <sys/types.h>
 #include <sys/stat.h>
diff --git a/libocrdma/src/ocrdma_main.h b/libocrdma/src/ocrdma_main.h
index c7359c8ffaef..dc96cd214aff 100644
--- a/libocrdma/src/ocrdma_main.h
+++ b/libocrdma/src/ocrdma_main.h
@@ -42,7 +42,7 @@
 #include <infiniband/driver.h>
 #include <infiniband/arch.h>
 
-#include "../../utils/list.h"
+#include <utils/list.h>
 
 #define ocrdma_err(format, arg...) printf(format, ##arg)
 
diff --git a/libocrdma/src/ocrdma_verbs.c b/libocrdma/src/ocrdma_verbs.c
index 3efc8bbdb623..0507e7c8252a 100644
--- a/libocrdma/src/ocrdma_verbs.c
+++ b/libocrdma/src/ocrdma_verbs.c
@@ -51,7 +51,7 @@
 
 #include "ocrdma_main.h"
 #include "ocrdma_abi.h"
-#include "../../utils/list.h"
+#include <utils/list.h>
 
 static void ocrdma_ring_cq_db(struct ocrdma_cq *cq, uint32_t armed,
 			      int solicited, uint32_t num_cqe);
diff --git a/librdmacm/src/cma.h b/librdmacm/src/cma.h
index 83d98b0d0a84..c01c3c0cc35c 100644
--- a/librdmacm/src/cma.h
+++ b/librdmacm/src/cma.h
@@ -47,7 +47,7 @@
 #include <rdma/rdma_cma.h>
 #include <infiniband/ib.h>
 
-#include "../../utils/math.h"
+#include <utils/math.h>
 
 #ifdef INCLUDE_VALGRIND
 #   include <valgrind/memcheck.h>
diff --git a/utils/CMakeLists.txt b/utils/CMakeLists.txt
new file mode 100644
index 000000000000..2ad8d90d5a75
--- /dev/null
+++ b/utils/CMakeLists.txt
@@ -0,0 +1,4 @@
+publish_internal_headers(utils
+  list.h
+  math.h
+  )
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: [PATCH rdma-core 2/5] utils: Create utils directory to put all common code and move min/max into it
       [not found]     ` <1474786207-2149-3-git-send-email-leon-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
  2016-09-26  7:05       ` Leon Romanovsky
@ 2016-09-26 17:20       ` Jason Gunthorpe
  1 sibling, 0 replies; 21+ messages in thread
From: Jason Gunthorpe @ 2016-09-26 17:20 UTC (permalink / raw)
  To: Leon Romanovsky
  Cc: dledford-H+wXaHxf7aLQT0dZR+AlfA,
	linux-rdma-u79uwXL29TY76Z2rM5mHXA,
	yishaih-VPRAkNaXOzVWk0Htik3J/w

On Sun, Sep 25, 2016 at 09:50:04AM +0300, Leon Romanovsky wrote:

> -#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

I'm not excited to replace the safer min above with the less safe min
below, that could actually break something.

> +/*
> + * 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_ */

Jason
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: [PATCH rdma-core 3/5] utils: Remove container_of and offset local declarations
       [not found]     ` <1474786207-2149-4-git-send-email-leon-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
  2016-09-26 15:32       ` Hefty, Sean
@ 2016-09-26 17:27       ` Jason Gunthorpe
  1 sibling, 0 replies; 21+ messages in thread
From: Jason Gunthorpe @ 2016-09-26 17:27 UTC (permalink / raw)
  To: Leon Romanovsky
  Cc: dledford-H+wXaHxf7aLQT0dZR+AlfA,
	linux-rdma-u79uwXL29TY76Z2rM5mHXA,
	yishaih-VPRAkNaXOzVWk0Htik3J/w

missed one in libibcm/src/cm.c..

Elaborate the description a bit:

Remove container_of and offsetof local declarations

This tree uses the version of container_of in infinband/verbs.h,
and requries stddef.h to declare offsetof

Jason
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: [PATCH rdma-core 4/5] libocrdma: Move ocrdma's list implementation into common directory
       [not found]                 ` <20160925162203.GA32434-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org>
  2016-09-25 17:50                   ` Bart Van Assche
@ 2016-09-26 17:40                   ` Jason Gunthorpe
       [not found]                     ` <20160926174057.GD22965-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
  1 sibling, 1 reply; 21+ messages in thread
From: Jason Gunthorpe @ 2016-09-26 17:40 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: Leon Romanovsky, dledford-H+wXaHxf7aLQT0dZR+AlfA,
	linux-rdma-u79uwXL29TY76Z2rM5mHXA,
	yishaih-VPRAkNaXOzVWk0Htik3J/w

On Sun, Sep 25, 2016 at 09:22:03AM -0700, Christoph Hellwig wrote:

> But given that I don't know who owns every little bit of the Linux
> lists.h I'd simply avoid anything looking like it and use something
> like the BSD queue.h instead (which glibc also provides, but in a
> horribly outdated version).

Copyright isn't a patent, assuming freebsd didn't copy any code and
just implemented the same API independently (eg it is an Independent
Creation) they should be OK from a copyright perspective. As should be
Rusty's version in CCAN.

Jason
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: [PATCH rdma-core 4/5] libocrdma: Move ocrdma's list implementation into common directory
       [not found]                     ` <20160926174057.GD22965-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
@ 2016-09-26 22:14                       ` Christoph Hellwig
       [not found]                         ` <20160926221440.GA5878-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org>
  0 siblings, 1 reply; 21+ messages in thread
From: Christoph Hellwig @ 2016-09-26 22:14 UTC (permalink / raw)
  To: Jason Gunthorpe
  Cc: Christoph Hellwig, Leon Romanovsky,
	dledford-H+wXaHxf7aLQT0dZR+AlfA,
	linux-rdma-u79uwXL29TY76Z2rM5mHXA,
	yishaih-VPRAkNaXOzVWk0Htik3J/w

On Mon, Sep 26, 2016 at 11:40:57AM -0600, Jason Gunthorpe wrote:
> Copyright isn't a patent,

I know very well, thanks..

> assuming freebsd didn't copy any code and
> just implemented the same API independently (eg it is an Independent
> Creation) they should be OK from a copyright perspective.

That's a big IF, as I'm honestly not sure it is.  I don't want to blame
anywone because I really don't know but if I had to decided to use it
or not I would error on the safe side.

> As should be
> Rusty's version in CCAN.

That's a much safer choice.  It's a lightly different API, though.
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: [PATCH rdma-core 4/5] libocrdma: Move ocrdma's list implementation into common directory
       [not found]                         ` <20160926221440.GA5878-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org>
@ 2016-09-26 22:23                           ` Jason Gunthorpe
       [not found]                             ` <20160926222319.GA2358-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
  0 siblings, 1 reply; 21+ messages in thread
From: Jason Gunthorpe @ 2016-09-26 22:23 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: Leon Romanovsky, dledford-H+wXaHxf7aLQT0dZR+AlfA,
	linux-rdma-u79uwXL29TY76Z2rM5mHXA,
	yishaih-VPRAkNaXOzVWk0Htik3J/w

On Mon, Sep 26, 2016 at 03:14:40PM -0700, Christoph Hellwig wrote:
> On Mon, Sep 26, 2016 at 11:40:57AM -0600, Jason Gunthorpe wrote:
> > Copyright isn't a patent,
> 
> I know very well, thanks..

Right, mainly for others..

> > assuming freebsd didn't copy any code and
> > just implemented the same API independently (eg it is an Independent
> > Creation) they should be OK from a copyright perspective.
> 
> That's a big IF, as I'm honestly not sure it is.  I don't want to blame
> anywone because I really don't know but if I had to decided to use it
> or not I would error on the safe side.

Sounds reasonable.

> > As should be
> > Rusty's version in CCAN.
> 
> That's a much safer choice.  It's a lightly different API, though.

Leon? Does this seem doable to you?

Jason
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: [PATCH rdma-core 4/5] libocrdma: Move ocrdma's list implementation into common directory
       [not found]                             ` <20160926222319.GA2358-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
@ 2016-09-27 16:14                               ` Yishai Hadas
       [not found]                                 ` <ff764b75-19af-340b-7228-328462c524ae-LDSdmyG8hGV8YrgS2mwiifqBs+8SCbDb@public.gmane.org>
  0 siblings, 1 reply; 21+ messages in thread
From: Yishai Hadas @ 2016-09-27 16:14 UTC (permalink / raw)
  To: Jason Gunthorpe
  Cc: Christoph Hellwig, Leon Romanovsky,
	dledford-H+wXaHxf7aLQT0dZR+AlfA,
	linux-rdma-u79uwXL29TY76Z2rM5mHXA,
	yishaih-VPRAkNaXOzVWk0Htik3J/w

On 9/27/2016 1:23 AM, Jason Gunthorpe wrote:
> On Mon, Sep 26, 2016 at 03:14:40PM -0700, Christoph Hellwig wrote:
>> On Mon, Sep 26, 2016 at 11:40:57AM -0600, Jason Gunthorpe wrote:
>>> Copyright isn't a patent,
>>
>> I know very well, thanks..
>
> Right, mainly for others..
>
>>> assuming freebsd didn't copy any code and
>>> just implemented the same API independently (eg it is an Independent
>>> Creation) they should be OK from a copyright perspective.
>>
>> That's a big IF, as I'm honestly not sure it is.  I don't want to blame
>> anywone because I really don't know but if I had to decided to use it
>> or not I would error on the safe side.
>
> Sounds reasonable.
>
>>> As should be
>>> Rusty's version in CCAN.
>>
>> That's a much safer choice.  It's a lightly different API, though.
>
> Leon? Does this seem doable to you?

Hi Jason,

Leon is out of office for a week, I can take it from here and come to 
the list in coming days with a new candidate series based on previous notes.

Few notes to sync on:
1) Looking at ocrdma_list.h it extends the list default functionality to 
use an internal mutex, see list_lock & list_unlock calls. This is not a 
standard usage of a list. It may require some logic outside list.h to 
replace the usage without introducing the mutex in the shared new H file.

2) Taking list.h from the 'CCAN' URL requires taking as well few other H 
files that it uses internally (e.g. build_assert.h). In few cases I 
don't see any reason to take the full file into rdma-core (e.g. 
ccan/str/str.h for stringify) will take only the needed functionality 
into list.h.

3) Need to clean up the 'CCAN' files from its include to "config.h",  in 
addition, need to consider the functionality that need to be taken when 
there are some #if HAVE_XXX internally. (see #if HAVE_TYPEOF in list.h).

4) Re the licensing disclaimer in each H file, what do you suggest to 
put ? for example minmax.h uses licenses/CC0 see 
https://github.com/rustyrussell/ccan/blob/master/ccan/minmax/LICENSE 
which is different comparing list.h which is ../../licenses/BSD-MIT.

Yishai














--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: [PATCH rdma-core 4/5] libocrdma: Move ocrdma's list implementation into common directory
       [not found]                                 ` <ff764b75-19af-340b-7228-328462c524ae-LDSdmyG8hGV8YrgS2mwiifqBs+8SCbDb@public.gmane.org>
@ 2016-09-27 18:03                                   ` Jason Gunthorpe
  0 siblings, 0 replies; 21+ messages in thread
From: Jason Gunthorpe @ 2016-09-27 18:03 UTC (permalink / raw)
  To: Yishai Hadas
  Cc: Christoph Hellwig, Leon Romanovsky,
	dledford-H+wXaHxf7aLQT0dZR+AlfA,
	linux-rdma-u79uwXL29TY76Z2rM5mHXA,
	yishaih-VPRAkNaXOzVWk0Htik3J/w

On Tue, Sep 27, 2016 at 07:14:09PM +0300, Yishai Hadas wrote:
> Leon is out of office for a week, I can take it from here and come to the
> list in coming days with a new candidate series based on previous notes.

Right, I forgot..

> Few notes to sync on:
> 1) Looking at ocrdma_list.h it extends the list default functionality to use
> an internal mutex, see list_lock & list_unlock calls. This is not a standard
> usage of a list. It may require some logic outside list.h to replace the
> usage without introducing the mutex in the shared new H file.

I noticed that. It doesn't look too bad, there are only two call sites
to list_lock, so I'd just move the mutex from the list head to the
ocrdma_dev_list.

> 2) Taking list.h from the 'CCAN' URL requires taking as well few other H
> files that it uses internally (e.g. build_assert.h). In few cases I don't
> see any reason to take the full file into rdma-core (e.g. ccan/str/str.h for
> stringify) will take only the needed functionality into list.h.

Hum. We have various other places using stringify and other
macros. Nothing in str.h looks bad at my first glance, so I'd just
take the whole thing.

It will be easier to work with ccan going forward if you minimize the
changes made to their stuff.

I suggest putting into a top level ccan/ (or util/ccan?) directory,
flatten the directory structure and we will compile the C component of
it into libccan.a and libccan_pic.a and link everything to it.

> 3) Need to clean up the 'CCAN' files from its include to "config.h",  in
> addition, need to consider the functionality that need to be taken when
> there are some #if HAVE_XXX internally. (see #if HAVE_TYPEOF in list.h).

If you can get the code ported with a hardwired config.h (just add
stuff to buildlib/config.h.in) and whatever else, send it to me and
I'll get everything sorted out for cmake.

Generally speaking though, as code that targets only Linux, and only
Linux distros of a certain age, we can safely make a lot of
assumptions.

> 4) Re the licensing disclaimer in each H file, what do you suggest to put ?
> for example minmax.h uses licenses/CC0 see
> https://github.com/rustyrussell/ccan/blob/master/ccan/minmax/LICENSE which
> is different comparing list.h which is ../../licenses/BSD-MIT.

If we go with the ccan/ top level then add the the files as
ccan/COPYING.CCO and ccan/COPYING.MIT, etc and update the comments
accordingly.

So far all the options we've found require accepting single-licened
code. I view this as OK since those two licenses are widely regarded
to be GPLv2 compatible, and specifically OK'd by the FSF. I'd prefer
this situation to the current situation of having potentially
GPLv2-only code...

Jason
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

end of thread, other threads:[~2016-09-27 18:03 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-09-25  6:50 [PATCH rdma-core 0/5] Add directory to place common code and move trivial functions into it Leon Romanovsky
     [not found] ` <1474786207-2149-1-git-send-email-leon-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2016-09-25  6:50   ` [PATCH rdma-core 1/5] cmake: Update build instructions in CmakeList Leon Romanovsky
2016-09-25  6:50   ` [PATCH rdma-core 2/5] utils: Create utils directory to put all common code and move min/max into it Leon Romanovsky
     [not found]     ` <1474786207-2149-3-git-send-email-leon-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2016-09-26  7:05       ` Leon Romanovsky
     [not found]         ` <20160926070520.GJ4088-2ukJVAZIZ/Y@public.gmane.org>
2016-09-26 17:17           ` Jason Gunthorpe
2016-09-26 17:20       ` Jason Gunthorpe
2016-09-25  6:50   ` [PATCH rdma-core 3/5] utils: Remove container_of and offset local declarations Leon Romanovsky
     [not found]     ` <1474786207-2149-4-git-send-email-leon-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2016-09-26 15:32       ` Hefty, Sean
2016-09-26 17:27       ` Jason Gunthorpe
2016-09-25  6:50   ` [PATCH rdma-core 4/5] libocrdma: Move ocrdma's list implementation into common directory Leon Romanovsky
     [not found]     ` <1474786207-2149-5-git-send-email-leon-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2016-09-25 14:41       ` Christoph Hellwig
     [not found]         ` <20160925144121.GA12246-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org>
2016-09-25 16:13           ` Leon Romanovsky
     [not found]             ` <20160925161315.GD4088-2ukJVAZIZ/Y@public.gmane.org>
2016-09-25 16:22               ` Christoph Hellwig
     [not found]                 ` <20160925162203.GA32434-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org>
2016-09-25 17:50                   ` Bart Van Assche
2016-09-26 17:40                   ` Jason Gunthorpe
     [not found]                     ` <20160926174057.GD22965-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2016-09-26 22:14                       ` Christoph Hellwig
     [not found]                         ` <20160926221440.GA5878-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org>
2016-09-26 22:23                           ` Jason Gunthorpe
     [not found]                             ` <20160926222319.GA2358-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2016-09-27 16:14                               ` Yishai Hadas
     [not found]                                 ` <ff764b75-19af-340b-7228-328462c524ae-LDSdmyG8hGV8YrgS2mwiifqBs+8SCbDb@public.gmane.org>
2016-09-27 18:03                                   ` Jason Gunthorpe
2016-09-25 22:05               ` Jason Gunthorpe
2016-09-25  6:50   ` [PATCH rdma-core 5/5] libmlx5: Convert libmlx5 to use common list implementation Leon Romanovsky

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.