[dpdk-dev] [PATCH 2/3] librte_eal: Import FreeBSD sys/tree.h into librte_eal/common

2016-06-09 Thread Thomas Monjalon
2016-06-09 16:54, Nikita Kozlov:
> On 06/ 9/16 02:58 AM, Stephen Hemminger wrote:
> > Please don't copy a header file which is available already on both BSD and 
> > Linux.
> >
> I was quite hesitant on how to handle it. I had the feeling that dpdk
> wanted to avoid external dependency so I copied that file. If it's not
> the case I would be happy to resend the patches without that external
> import.

Yes please let's use external libraries where possible.
Being able to run in a bare metal environment has been a requirement
in the early days of DPDK. Now we got rid of this idea and run on
Linux and FreeBSD. An attempt to run on OSv has been done but without
more follow-up.


[dpdk-dev] [PATCH 2/3] librte_eal: Import FreeBSD sys/tree.h into librte_eal/common

2016-06-09 Thread Nikita Kozlov
On 06/ 9/16 02:58 AM, Stephen Hemminger wrote:
> On Thu,  9 Jun 2016 02:53:53 +0200
> Nikita Kozlov  wrote:
>
>> This structure is used inside the rte_lpm6 lib for storing added rules.
>> It's imported from FreeBSD-10.3 from /usr/include/sys/tree.h, another
>> solution could have been to use on Linux the version from libbsd but it
>> would create an external dependency.
>>
>> Signed-off-by: Nikita Kozlov 
> Using Red-black tree is a good idea, and we have been doing it for a while
> both on v4 and v6.
Yes, like I said in 1/3, the idea is taken from your patch.
I have tested it and it seemed to work pretty fine, maybe we could try
to split it a little bit and try to send it again ?
It's quite difficult to tell what was wrong with it since I cannot see
any public discussion about it.
>
> But this is not the way to handle it.
> Please don't copy a header file which is available already on both BSD and 
> Linux.
>
>
I was quite hesitant on how to handle it. I had the feeling that dpdk
wanted to avoid external dependency so I copied that file. If it's not
the case I would be happy to resend the patches without that external
import.


[dpdk-dev] [PATCH 2/3] librte_eal: Import FreeBSD sys/tree.h into librte_eal/common

2016-06-09 Thread Thomas Monjalon
2016-06-08 17:58, Stephen Hemminger:
> On Thu,  9 Jun 2016 02:53:53 +0200
> Nikita Kozlov  wrote:
> 
> > This structure is used inside the rte_lpm6 lib for storing added rules.
> > It's imported from FreeBSD-10.3 from /usr/include/sys/tree.h, another
> > solution could have been to use on Linux the version from libbsd but it
> > would create an external dependency.
> 
> Using Red-black tree is a good idea, and we have been doing it for a while
> both on v4 and v6.

When you say "we", you mean Vyatta? Brocade? in a commercial code?



[dpdk-dev] [PATCH 2/3] librte_eal: Import FreeBSD sys/tree.h into librte_eal/common

2016-06-09 Thread Nikita Kozlov
This structure is used inside the rte_lpm6 lib for storing added rules.
It's imported from FreeBSD-10.3 from /usr/include/sys/tree.h, another
solution could have been to use on Linux the version from libbsd but it
would create an external dependency.

Signed-off-by: Nikita Kozlov 
---
 lib/librte_eal/common/Makefile   |   2 +-
 lib/librte_eal/common/include/sys/tree.h | 801 +++
 2 files changed, 802 insertions(+), 1 deletion(-)
 create mode 100644 lib/librte_eal/common/include/sys/tree.h

diff --git a/lib/librte_eal/common/Makefile b/lib/librte_eal/common/Makefile
index f5ea0ee..57f58d6 100644
--- a/lib/librte_eal/common/Makefile
+++ b/lib/librte_eal/common/Makefile
@@ -40,7 +40,7 @@ INC += rte_string_fns.h rte_version.h
 INC += rte_eal_memconfig.h rte_malloc_heap.h
 INC += rte_hexdump.h rte_devargs.h rte_dev.h
 INC += rte_pci_dev_feature_defs.h rte_pci_dev_features.h
-INC += rte_malloc.h rte_keepalive.h rte_time.h
+INC += rte_malloc.h rte_keepalive.h rte_time.h sys/tree.h

 ifeq ($(CONFIG_RTE_INSECURE_FUNCTION_WARNING),y)
 INC += rte_warnings.h
diff --git a/lib/librte_eal/common/include/sys/tree.h 
b/lib/librte_eal/common/include/sys/tree.h
new file mode 100644
index 000..1f5c628
--- /dev/null
+++ b/lib/librte_eal/common/include/sys/tree.h
@@ -0,0 +1,801 @@
+/* $NetBSD: tree.h,v 1.8 2004/03/28 19:38:30 provos Exp $  */
+/* $OpenBSD: tree.h,v 1.7 2002/10/17 21:51:54 art Exp $*/
+/* $FreeBSD: head/sys/sys/tree.h 277642 2015-01-24 12:43:36Z kib $ */
+
+/*-
+ * Copyright 2002 Niels Provos 
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. 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 AUTHOR ``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 AUTHOR 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_SYS_TREE_H_
+#define_SYS_TREE_H_
+
+#include 
+
+/*
+ * This file defines data structures for different types of trees:
+ * splay trees and red-black trees.
+ *
+ * A splay tree is a self-organizing data structure.  Every operation
+ * on the tree causes a splay to happen.  The splay moves the requested
+ * node to the root of the tree and partly rebalances it.
+ *
+ * This has the benefit that request locality causes faster lookups as
+ * the requested nodes move to the top of the tree.  On the other hand,
+ * every lookup causes memory writes.
+ *
+ * The Balance Theorem bounds the total access time for m operations
+ * and n inserts on an initially empty tree as O((m + n)lg n).  The
+ * amortized cost for a sequence of m accesses to a splay tree is O(lg n);
+ *
+ * A red-black tree is a binary search tree with the node color as an
+ * extra attribute.  It fulfills a set of conditions:
+ * - every search path from the root to a leaf consists of the
+ *   same number of black nodes,
+ * - each red node (except for the root) has a black parent,
+ * - each leaf node is black.
+ *
+ * Every operation on a red-black tree is bounded as O(lg n).
+ * The maximum height of a red-black tree is 2lg (n+1).
+ */
+
+#define SPLAY_HEAD(name, type) \
+struct name {  \
+   struct type *sph_root; /* root of the tree */   \
+}
+
+#define SPLAY_INITIALIZER(root)
\
+   { NULL }
+
+#define SPLAY_INIT(root) do {  \
+   (root)->sph_root = NULL;\
+} while (/*CONSTCOND*/ 0)
+
+#define SPLAY_ENTRY(type)  \
+struct {   \
+   struct type *spe_left; /* left element */   \
+   struct type *spe_right; /* right element */ \
+}
+
+#define SPLAY_LEFT(elm, field) (elm)->field.spe_left

[dpdk-dev] [PATCH 2/3] librte_eal: Import FreeBSD sys/tree.h into librte_eal/common

2016-06-08 Thread Stephen Hemminger
On Thu,  9 Jun 2016 02:53:53 +0200
Nikita Kozlov  wrote:

> This structure is used inside the rte_lpm6 lib for storing added rules.
> It's imported from FreeBSD-10.3 from /usr/include/sys/tree.h, another
> solution could have been to use on Linux the version from libbsd but it
> would create an external dependency.
> 
> Signed-off-by: Nikita Kozlov 

Using Red-black tree is a good idea, and we have been doing it for a while
both on v4 and v6.

But this is not the way to handle it.
Please don't copy a header file which is available already on both BSD and 
Linux.