Patch Detail
get:
Show a patch.
patch:
Update a patch.
put:
Update a patch.
GET /api/patches/3018/?format=api
https://patches.dpdk.org/api/patches/3018/?format=api", "web_url": "https://patches.dpdk.org/project/dpdk/patch/1423235164-3808-2-git-send-email-sergio.gonzalez.monroy@intel.com/", "project": { "id": 1, "url": "https://patches.dpdk.org/api/projects/1/?format=api", "name": "DPDK", "link_name": "dpdk", "list_id": "dev.dpdk.org", "list_email": "dev@dpdk.org", "web_url": "http://core.dpdk.org", "scm_url": "git://dpdk.org/dpdk", "webscm_url": "http://git.dpdk.org/dpdk", "list_archive_url": "https://inbox.dpdk.org/dev", "list_archive_url_format": "https://inbox.dpdk.org/dev/{}", "commit_url_format": "" }, "msgid": "<1423235164-3808-2-git-send-email-sergio.gonzalez.monroy@intel.com>", "list_archive_url": "https://inbox.dpdk.org/dev/1423235164-3808-2-git-send-email-sergio.gonzalez.monroy@intel.com", "date": "2015-02-06T15:06:00", "name": "[dpdk-dev,v3,1/5] reorder: new reorder library", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": true, "hash": "18b1b0f628170bc20279943b8daac6de05a58845", "submitter": { "id": 73, "url": "https://patches.dpdk.org/api/people/73/?format=api", "name": "Sergio Gonzalez Monroy", "email": "sergio.gonzalez.monroy@intel.com" }, "delegate": null, "mbox": "https://patches.dpdk.org/project/dpdk/patch/1423235164-3808-2-git-send-email-sergio.gonzalez.monroy@intel.com/mbox/", "series": [], "comments": "https://patches.dpdk.org/api/patches/3018/comments/", "check": "pending", "checks": "https://patches.dpdk.org/api/patches/3018/checks/", "tags": {}, "related": [], "headers": { "Return-Path": "<dev-bounces@dpdk.org>", "X-Original-To": "patchwork@dpdk.org", "Delivered-To": "patchwork@dpdk.org", "Received": [ "from [92.243.14.124] (localhost [IPv6:::1])\n\tby dpdk.org (Postfix) with ESMTP id C6FB0376E;\n\tFri, 6 Feb 2015 16:06:12 +0100 (CET)", "from mga01.intel.com (mga01.intel.com [192.55.52.88])\n\tby dpdk.org (Postfix) with ESMTP id 1CC39B55\n\tfor <dev@dpdk.org>; Fri, 6 Feb 2015 16:06:08 +0100 (CET)", "from fmsmga003.fm.intel.com ([10.253.24.29])\n\tby fmsmga101.fm.intel.com with ESMTP; 06 Feb 2015 07:06:06 -0800", "from irvmail001.ir.intel.com ([163.33.26.43])\n\tby FMSMGA003.fm.intel.com with ESMTP; 06 Feb 2015 06:51:46 -0800", "from sivswdev02.ir.intel.com (sivswdev02.ir.intel.com\n\t[10.237.217.46])\n\tby irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id\n\tt16F64Gj004384 for <dev@dpdk.org>; Fri, 6 Feb 2015 15:06:04 GMT", "from sivswdev02.ir.intel.com (localhost [127.0.0.1])\n\tby sivswdev02.ir.intel.com with ESMTP id t16F64Ro003853\n\tfor <dev@dpdk.org>; Fri, 6 Feb 2015 15:06:04 GMT", "(from smonroy@localhost)\n\tby sivswdev02.ir.intel.com with id t16F64PT003849\n\tfor dev@dpdk.org; Fri, 6 Feb 2015 15:06:04 GMT" ], "X-ExtLoop1": "1", "X-IronPort-AV": "E=Sophos;i=\"4.97,862,1389772800\"; d=\"scan'208\";a=\"450836128\"", "From": "Sergio Gonzalez Monroy <sergio.gonzalez.monroy@intel.com>", "To": "dev@dpdk.org", "Date": "Fri, 6 Feb 2015 15:06:00 +0000", "Message-Id": "<1423235164-3808-2-git-send-email-sergio.gonzalez.monroy@intel.com>", "X-Mailer": "git-send-email 1.8.5.4", "In-Reply-To": "<1423235164-3808-1-git-send-email-sergio.gonzalez.monroy@intel.com>", "References": "<1422623694-6430-1-git-send-email-sergio.gonzalez.monroy@intel.com>\n\t<1423235164-3808-1-git-send-email-sergio.gonzalez.monroy@intel.com>", "Subject": "[dpdk-dev] [PATCH v3 1/5] reorder: new reorder library", "X-BeenThere": "dev@dpdk.org", "X-Mailman-Version": "2.1.15", "Precedence": "list", "List-Id": "patches and discussions about DPDK <dev.dpdk.org>", "List-Unsubscribe": "<http://dpdk.org/ml/options/dev>,\n\t<mailto:dev-request@dpdk.org?subject=unsubscribe>", "List-Archive": "<http://dpdk.org/ml/archives/dev/>", "List-Post": "<mailto:dev@dpdk.org>", "List-Help": "<mailto:dev-request@dpdk.org?subject=help>", "List-Subscribe": "<http://dpdk.org/ml/listinfo/dev>,\n\t<mailto:dev-request@dpdk.org?subject=subscribe>", "Errors-To": "dev-bounces@dpdk.org", "Sender": "\"dev\" <dev-bounces@dpdk.org>" }, "content": "This library provides reordering capability for out of order mbufs based\non a sequence number in the mbuf structure.\n\nSigned-off-by: Reshma Pattan <reshma.pattan@intel.com>\nSigned-off-by: Richardson Bruce <bruce.richardson@intel.com>\nSigned-off-by: Sergio Gonzalez Monroy <sergio.gonzalez.monroy@intel.com>\n---\n config/common_bsdapp | 5 +\n config/common_linuxapp | 5 +\n lib/Makefile | 1 +\n lib/librte_eal/common/include/rte_tailq_elem.h | 2 +\n lib/librte_mbuf/rte_mbuf.h | 3 +\n lib/librte_reorder/Makefile | 50 +++\n lib/librte_reorder/rte_reorder.c | 416 +++++++++++++++++++++++++\n lib/librte_reorder/rte_reorder.h | 181 +++++++++++\n 8 files changed, 663 insertions(+)\n create mode 100644 lib/librte_reorder/Makefile\n create mode 100644 lib/librte_reorder/rte_reorder.c\n create mode 100644 lib/librte_reorder/rte_reorder.h", "diff": "diff --git a/config/common_bsdapp b/config/common_bsdapp\nindex 9177db1..e3e0e94 100644\n--- a/config/common_bsdapp\n+++ b/config/common_bsdapp\n@@ -334,6 +334,11 @@ CONFIG_RTE_SCHED_PORT_N_GRINDERS=8\n CONFIG_RTE_LIBRTE_DISTRIBUTOR=y\n \n #\n+# Compile the reorder library\n+#\n+CONFIG_RTE_LIBRTE_REORDER=y\n+\n+#\n # Compile librte_port\n #\n CONFIG_RTE_LIBRTE_PORT=y\ndiff --git a/config/common_linuxapp b/config/common_linuxapp\nindex 2f9643b..b5ec730 100644\n--- a/config/common_linuxapp\n+++ b/config/common_linuxapp\n@@ -342,6 +342,11 @@ CONFIG_RTE_SCHED_PORT_N_GRINDERS=8\n CONFIG_RTE_LIBRTE_DISTRIBUTOR=y\n \n #\n+# Compile the reorder library\n+#\n+CONFIG_RTE_LIBRTE_REORDER=y\n+\n+#\n # Compile librte_port\n #\n CONFIG_RTE_LIBRTE_PORT=y\ndiff --git a/lib/Makefile b/lib/Makefile\nindex 0ffc982..5919d32 100644\n--- a/lib/Makefile\n+++ b/lib/Makefile\n@@ -65,6 +65,7 @@ DIRS-$(CONFIG_RTE_LIBRTE_DISTRIBUTOR) += librte_distributor\n DIRS-$(CONFIG_RTE_LIBRTE_PORT) += librte_port\n DIRS-$(CONFIG_RTE_LIBRTE_TABLE) += librte_table\n DIRS-$(CONFIG_RTE_LIBRTE_PIPELINE) += librte_pipeline\n+DIRS-$(CONFIG_RTE_LIBRTE_REORDER) += librte_reorder\n \n ifeq ($(CONFIG_RTE_EXEC_ENV_LINUXAPP),y)\n DIRS-$(CONFIG_RTE_LIBRTE_KNI) += librte_kni\ndiff --git a/lib/librte_eal/common/include/rte_tailq_elem.h b/lib/librte_eal/common/include/rte_tailq_elem.h\nindex f74fc7c..3013869 100644\n--- a/lib/librte_eal/common/include/rte_tailq_elem.h\n+++ b/lib/librte_eal/common/include/rte_tailq_elem.h\n@@ -84,6 +84,8 @@ rte_tailq_elem(RTE_TAILQ_ACL, \"RTE_ACL\")\n \n rte_tailq_elem(RTE_TAILQ_DISTRIBUTOR, \"RTE_DISTRIBUTOR\")\n \n+rte_tailq_elem(RTE_TAILQ_REORDER, \"RTE_REORDER\")\n+\n rte_tailq_end(RTE_TAILQ_NUM)\n \n #undef rte_tailq_elem\ndiff --git a/lib/librte_mbuf/rte_mbuf.h b/lib/librte_mbuf/rte_mbuf.h\nindex 16059c6..ed27eb8 100644\n--- a/lib/librte_mbuf/rte_mbuf.h\n+++ b/lib/librte_mbuf/rte_mbuf.h\n@@ -262,6 +262,9 @@ struct rte_mbuf {\n \t\tuint32_t usr;\t /**< User defined tags. See @rte_distributor_process */\n \t} hash; /**< hash information */\n \n+\t/* sequence number - field used in distributor and reorder library */\n+\tuint32_t seqn;\n+\n \t/* second cache line - fields only used in slow path or on TX */\n \tMARKER cacheline1 __rte_cache_aligned;\n \ndiff --git a/lib/librte_reorder/Makefile b/lib/librte_reorder/Makefile\nnew file mode 100644\nindex 0000000..12b916f\n--- /dev/null\n+++ b/lib/librte_reorder/Makefile\n@@ -0,0 +1,50 @@\n+# BSD LICENSE\n+#\n+# Copyright(c) 2010-2014 Intel Corporation. All rights reserved.\n+# All rights reserved.\n+#\n+# Redistribution and use in source and binary forms, with or without\n+# modification, are permitted provided that the following conditions\n+# are met:\n+#\n+# * Redistributions of source code must retain the above copyright\n+# notice, this list of conditions and the following disclaimer.\n+# * Redistributions in binary form must reproduce the above copyright\n+# notice, this list of conditions and the following disclaimer in\n+# the documentation and/or other materials provided with the\n+# distribution.\n+# * Neither the name of Intel Corporation nor the names of its\n+# contributors may be used to endorse or promote products derived\n+# from this software without specific prior written permission.\n+#\n+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n+# \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\n+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\n+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n+\n+include $(RTE_SDK)/mk/rte.vars.mk\n+\n+# library name\n+LIB = librte_reorder.a\n+\n+CFLAGS += -O3\n+CFLAGS += $(WERROR_FLAGS) -I$(SRCDIR)\n+\n+# all source are stored in SRCS-y\n+SRCS-$(CONFIG_RTE_LIBRTE_REORDER) := rte_reorder.c\n+\n+# install this header file\n+SYMLINK-$(CONFIG_RTE_LIBRTE_REORDER)-include := rte_reorder.h\n+\n+# this lib depends upon:\n+DEPDIRS-$(CONFIG_RTE_LIBRTE_REORDER) += lib/librte_mbuf\n+DEPDIRS-$(CONFIG_RTE_LIBRTE_REORDER) += lib/librte_eal\n+\n+include $(RTE_SDK)/mk/rte.lib.mk\ndiff --git a/lib/librte_reorder/rte_reorder.c b/lib/librte_reorder/rte_reorder.c\nnew file mode 100644\nindex 0000000..42d2a47\n--- /dev/null\n+++ b/lib/librte_reorder/rte_reorder.c\n@@ -0,0 +1,416 @@\n+/*-\n+ * BSD LICENSE\n+ *\n+ * Copyright(c) 2010-2014 Intel Corporation. All rights reserved.\n+ * All rights reserved.\n+ *\n+ * Redistribution and use in source and binary forms, with or without\n+ * modification, are permitted provided that the following conditions\n+ * are met:\n+ *\n+ * * Redistributions of source code must retain the above copyright\n+ * notice, this list of conditions and the following disclaimer.\n+ * * Redistributions in binary form must reproduce the above copyright\n+ * notice, this list of conditions and the following disclaimer in\n+ * the documentation and/or other materials provided with the\n+ * distribution.\n+ * * Neither the name of Intel Corporation nor the names of its\n+ * contributors may be used to endorse or promote products derived\n+ * from this software without specific prior written permission.\n+ *\n+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n+ * \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\n+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\n+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n+ */\n+\n+#include <inttypes.h>\n+#include <string.h>\n+\n+#include <rte_log.h>\n+#include <rte_mbuf.h>\n+#include <rte_memzone.h>\n+#include <rte_eal_memconfig.h>\n+#include <rte_errno.h>\n+#include <rte_tailq.h>\n+#include <rte_malloc.h>\n+\n+#include \"rte_reorder.h\"\n+\n+TAILQ_HEAD(rte_reorder_list, rte_tailq_entry);\n+\n+#define NO_FLAGS 0\n+#define RTE_REORDER_PREFIX \"RO_\"\n+#define RTE_REORDER_NAMESIZE 32\n+\n+/* Macros for printing using RTE_LOG */\n+#define RTE_LOGTYPE_REORDER\tRTE_LOGTYPE_USER1\n+\n+/* A generic circular buffer */\n+struct cir_buffer {\n+\tunsigned int size; /**< Number of entries that can be stored */\n+\tunsigned int mask; /**< [buffer_size - 1]: used for wrap-around */\n+\tunsigned int head; /**< insertion point in buffer */\n+\tunsigned int tail; /**< extraction point in buffer */\n+\tstruct rte_mbuf **entries;\n+} __rte_cache_aligned;\n+\n+/* The reorder buffer data structure itself */\n+struct rte_reorder_buffer {\n+\tchar name[RTE_REORDER_NAMESIZE];\n+\tuint32_t min_seqn; /**< Lowest seq. number that can be in the buffer */\n+\tunsigned int memsize; /**< memory area size of reorder buffer */\n+\tstruct cir_buffer ready_buf; /**< temp buffer for dequeued entries */\n+\tstruct cir_buffer order_buf; /**< buffer used to reorder entries */\n+} __rte_cache_aligned;\n+\n+static void\n+rte_reorder_free_mbufs(struct rte_reorder_buffer *b);\n+\n+struct rte_reorder_buffer *\n+rte_reorder_init(struct rte_reorder_buffer *b, unsigned int bufsize,\n+\t\tconst char *name, unsigned int size)\n+{\n+\tconst unsigned int min_bufsize = sizeof(*b) +\n+\t\t\t\t\t(2 * size * sizeof(struct rte_mbuf *));\n+\n+\tif (b == NULL) {\n+\t\tRTE_LOG(ERR, REORDER, \"Invalid reorder buffer parameter:\"\n+\t\t\t\t\t\" NULL\\n\");\n+\t\trte_errno = EINVAL;\n+\t\treturn NULL;\n+\t}\n+\tif (!rte_is_power_of_2(size)) {\n+\t\tRTE_LOG(ERR, REORDER, \"Invalid reorder buffer size\"\n+\t\t\t\t\" - Not a power of 2\\n\");\n+\t\trte_errno = EINVAL;\n+\t\treturn NULL;\n+\t}\n+\tif (name == NULL) {\n+\t\tRTE_LOG(ERR, REORDER, \"Invalid reorder buffer name ptr:\"\n+\t\t\t\t\t\" NULL\\n\");\n+\t\trte_errno = EINVAL;\n+\t\treturn NULL;\n+\t}\n+\tif (bufsize < min_bufsize) {\n+\t\tRTE_LOG(ERR, REORDER, \"Invalid reorder buffer memory size: %u, \"\n+\t\t\t\"minimum required: %u\\n\", bufsize, min_bufsize);\n+\t\trte_errno = EINVAL;\n+\t\treturn NULL;\n+\t}\n+\n+\tmemset(b, 0, bufsize);\n+\tsnprintf(b->name, sizeof(b->name), \"%s\", name);\n+\tb->memsize = bufsize;\n+\tb->order_buf.size = b->ready_buf.size = size;\n+\tb->order_buf.mask = b->ready_buf.mask = size - 1;\n+\tb->ready_buf.entries = (void *)&b[1];\n+\tb->order_buf.entries = RTE_PTR_ADD(&b[1],\n+\t\t\tsize * sizeof(b->ready_buf.entries[0]));\n+\n+\treturn b;\n+}\n+\n+struct rte_reorder_buffer*\n+rte_reorder_create(const char *name, unsigned socket_id, unsigned int size)\n+{\n+\tstruct rte_reorder_buffer *b = NULL;\n+\tstruct rte_tailq_entry *te;\n+\tstruct rte_reorder_list *reorder_list;\n+\tconst unsigned int bufsize = sizeof(struct rte_reorder_buffer) +\n+\t\t\t\t\t(2 * size * sizeof(struct rte_mbuf *));\n+\n+\t/* check that we have an initialised tail queue */\n+\treorder_list = RTE_TAILQ_LOOKUP_BY_IDX(RTE_TAILQ_REORDER, rte_reorder_list);\n+\tif (!reorder_list) {\n+\t\trte_errno = E_RTE_NO_TAILQ;\n+\t\treturn NULL;\n+\t}\n+\n+\t/* Check user arguments. */\n+\tif (!rte_is_power_of_2(size)) {\n+\t\tRTE_LOG(ERR, REORDER, \"Invalid reorder buffer size\"\n+\t\t\t\t\" - Not a power of 2\\n\");\n+\t\trte_errno = EINVAL;\n+\t\treturn NULL;\n+\t}\n+\tif (name == NULL) {\n+\t\tRTE_LOG(ERR, REORDER, \"Invalid reorder buffer name ptr:\"\n+\t\t\t\t\t\" NULL\\n\");\n+\t\trte_errno = EINVAL;\n+\t\treturn NULL;\n+\t}\n+\n+\trte_rwlock_write_lock(RTE_EAL_TAILQ_RWLOCK);\n+\n+\t/* guarantee there's no existing */\n+\tTAILQ_FOREACH(te, reorder_list, next) {\n+\t\tb = (struct rte_reorder_buffer *) te->data;\n+\t\tif (strncmp(name, b->name, RTE_REORDER_NAMESIZE) == 0)\n+\t\t\tbreak;\n+\t}\n+\tif (te != NULL)\n+\t\tgoto exit;\n+\n+\t/* allocate tailq entry */\n+\tte = rte_zmalloc(\"REORDER_TAILQ_ENTRY\", sizeof(*te), 0);\n+\tif (te == NULL) {\n+\t\tRTE_LOG(ERR, REORDER, \"Failed to allocate tailq entry\\n\");\n+\t\trte_errno = ENOMEM;\n+\t\tb = NULL;\n+\t\tgoto exit;\n+\t}\n+\n+\t/* Allocate memory to store the reorder buffer structure. */\n+\tb = rte_zmalloc_socket(\"REORDER_BUFFER\", bufsize, 0, socket_id);\n+\tif (b == NULL) {\n+\t\tRTE_LOG(ERR, REORDER, \"Memzone allocation failed\\n\");\n+\t\trte_errno = ENOMEM;\n+\t\trte_free(te);\n+\t} else {\n+\t\trte_reorder_init(b, bufsize, name, size);\n+\t\tte->data = (void *)b;\n+\t\tTAILQ_INSERT_TAIL(reorder_list, te, next);\n+\t}\n+\n+exit:\n+\trte_rwlock_write_unlock(RTE_EAL_TAILQ_RWLOCK);\n+\treturn b;\n+}\n+\n+void\n+rte_reorder_reset(struct rte_reorder_buffer *b)\n+{\n+\tchar name[RTE_REORDER_NAMESIZE];\n+\n+\trte_reorder_free_mbufs(b);\n+\tsnprintf(name, sizeof(name), \"%s\", b->name);\n+\t/* No error checking as current values should be valid */\n+\trte_reorder_init(b, b->memsize, name, b->order_buf.size);\n+}\n+\n+static void\n+rte_reorder_free_mbufs(struct rte_reorder_buffer *b)\n+{\n+\tunsigned i;\n+\n+\t/* Free up the mbufs of order buffer & ready buffer */\n+\tfor (i = 0; i < b->order_buf.size; i++) {\n+\t\tif (b->order_buf.entries[i])\n+\t\t\trte_pktmbuf_free(b->order_buf.entries[i]);\n+\t\tif (b->ready_buf.entries[i])\n+\t\t\trte_pktmbuf_free(b->ready_buf.entries[i]);\n+\t}\n+}\n+\n+void\n+rte_reorder_free(struct rte_reorder_buffer *b)\n+{\n+\tstruct rte_reorder_list *reorder_list;\n+\tstruct rte_tailq_entry *te;\n+\n+\t/* Check user arguments. */\n+\tif (b == NULL)\n+\t\treturn;\n+\n+\t/* check that we have an initialised tail queue */\n+\treorder_list = RTE_TAILQ_LOOKUP_BY_IDX(RTE_TAILQ_REORDER, rte_reorder_list);\n+\tif (!reorder_list) {\n+\t\trte_errno = E_RTE_NO_TAILQ;\n+\t\treturn;\n+\t}\n+\n+\trte_rwlock_write_lock(RTE_EAL_TAILQ_RWLOCK);\n+\n+\t/* find our tailq entry */\n+\tTAILQ_FOREACH(te, reorder_list, next) {\n+\t\tif (te->data == (void *) b)\n+\t\t\tbreak;\n+\t}\n+\tif (te == NULL) {\n+\t\trte_rwlock_write_unlock(RTE_EAL_TAILQ_RWLOCK);\n+\t\treturn;\n+\t}\n+\n+\tTAILQ_REMOVE(reorder_list, te, next);\n+\n+\trte_rwlock_write_unlock(RTE_EAL_TAILQ_RWLOCK);\n+\n+\trte_reorder_free_mbufs(b);\n+\n+\trte_free(b);\n+\trte_free(te);\n+}\n+\n+struct rte_reorder_buffer *\n+rte_reorder_find_existing(const char *name)\n+{\n+\tstruct rte_reorder_buffer *b = NULL;\n+\tstruct rte_tailq_entry *te;\n+\tstruct rte_reorder_list *reorder_list;\n+\n+\t/* check that we have an initialised tail queue */\n+\treorder_list = RTE_TAILQ_LOOKUP_BY_IDX(RTE_TAILQ_REORDER, rte_reorder_list);\n+\tif (!reorder_list) {\n+\t\trte_errno = E_RTE_NO_TAILQ;\n+\t\treturn NULL;\n+\t}\n+\n+\trte_rwlock_read_lock(RTE_EAL_TAILQ_RWLOCK);\n+\tTAILQ_FOREACH(te, reorder_list, next) {\n+\t\tb = (struct rte_reorder_buffer *) te->data;\n+\t\tif (strncmp(name, b->name, RTE_REORDER_NAMESIZE) == 0)\n+\t\t\tbreak;\n+\t}\n+\trte_rwlock_read_unlock(RTE_EAL_TAILQ_RWLOCK);\n+\n+\tif (te == NULL) {\n+\t\trte_errno = ENOENT;\n+\t\treturn NULL;\n+\t}\n+\n+\treturn b;\n+}\n+\n+static unsigned\n+rte_reorder_fill_overflow(struct rte_reorder_buffer *b, unsigned n)\n+{\n+\t/*\n+\t * 1. Move all ready entries that fit to the ready_buf\n+\t * 2. check if we meet the minimum needed (n).\n+\t * 3. If not, then skip any gaps and keep moving.\n+\t * 4. If at any point the ready buffer is full, stop\n+\t * 5. Return the number of positions the order_buf head has moved\n+\t */\n+\n+\tstruct cir_buffer *order_buf = &b->order_buf,\n+\t\t\t*ready_buf = &b->ready_buf;\n+\n+\tunsigned int order_head_adv = 0;\n+\n+\t/*\n+\t * move at least n packets to ready buffer, assuming ready buffer\n+\t * has room for those packets.\n+\t */\n+\twhile (order_head_adv < n &&\n+\t\t\t((ready_buf->head + 1) & ready_buf->mask) != ready_buf->tail) {\n+\n+\t\t/* if we are blocked waiting on a packet, skip it */\n+\t\tif (order_buf->entries[order_buf->head] == NULL) {\n+\t\t\torder_buf->head = (order_buf->head + 1) & order_buf->mask;\n+\t\t\torder_head_adv++;\n+\t\t}\n+\n+\t\t/* Move all ready entries that fit to the ready_buf */\n+\t\twhile (order_buf->entries[order_buf->head] != NULL) {\n+\t\t\tready_buf->entries[ready_buf->head] =\n+\t\t\t\t\torder_buf->entries[order_buf->head];\n+\n+\t\t\torder_buf->entries[order_buf->head] = NULL;\n+\t\t\torder_head_adv++;\n+\n+\t\t\torder_buf->head = (order_buf->head + 1) & order_buf->mask;\n+\n+\t\t\tif (((ready_buf->head + 1) & ready_buf->mask) == ready_buf->tail)\n+\t\t\t\tbreak;\n+\n+\t\t\tready_buf->head = (ready_buf->head + 1) & ready_buf->mask;\n+\t\t}\n+\t}\n+\n+\tb->min_seqn += order_head_adv;\n+\t/* Return the number of positions the order_buf head has moved */\n+\treturn order_head_adv;\n+}\n+\n+int\n+rte_reorder_insert(struct rte_reorder_buffer *b, struct rte_mbuf *mbuf)\n+{\n+\tuint32_t offset, position;\n+\tstruct cir_buffer *order_buf = &b->order_buf;\n+\n+\t/*\n+\t * calculate the offset from the head pointer we need to go.\n+\t * The subtraction takes care of the sequence number wrapping.\n+\t * For example (using 16-bit for brevity):\n+\t *\tmin_seqn = 0xFFFD\n+\t *\tmbuf_seqn = 0x0010\n+\t *\toffset = 0x0010 - 0xFFFD = 0x13\n+\t */\n+\toffset = mbuf->seqn - b->min_seqn;\n+\n+\t/*\n+\t * action to take depends on offset.\n+\t * offset < buffer->size: the mbuf fits within the current window of\n+\t * sequence numbers we can reorder. EXPECTED CASE.\n+\t * offset > buffer->size: the mbuf is outside the current window. There\n+\t * are a number of cases to consider:\n+\t * 1. The packet sequence is just outside the window, then we need\n+\t * to see about shifting the head pointer and taking any ready\n+\t * to return packets out of the ring. If there was a delayed\n+\t * or dropped packet preventing drains from shifting the window\n+\t * this case will skip over the dropped packet instead, and any\n+\t * packets dequeued here will be returned on the next drain call.\n+\t * 2. The packet sequence number is vastly outside our window, taken\n+\t * here as having offset greater than twice the buffer size. In\n+\t * this case, the packet is probably an old or late packet that\n+\t * was previously skipped, so just enqueue the packet for\n+\t * immediate return on the next drain call, or else return error.\n+\t */\n+\tif (offset < b->order_buf.size) {\n+\t\tposition = (order_buf->head + offset) & order_buf->mask;\n+\t\torder_buf->entries[position] = mbuf;\n+\t} else if (offset < 2 * b->order_buf.size) {\n+\t\tif (rte_reorder_fill_overflow(b, offset + 1 - order_buf->size)\n+\t\t\t\t< (offset + 1 - order_buf->size)) {\n+\t\t\t/* Put in handling for enqueue straight to output */\n+\t\t\trte_errno = ENOSPC;\n+\t\t\treturn -1;\n+\t\t}\n+\t\toffset = mbuf->seqn - b->min_seqn;\n+\t\tposition = (order_buf->head + offset) & order_buf->mask;\n+\t\torder_buf->entries[position] = mbuf;\n+\t} else {\n+\t\t/* Put in handling for enqueue straight to output */\n+\t\trte_errno = ERANGE;\n+\t\treturn -1;\n+\t}\n+\treturn 0;\n+}\n+\n+unsigned int\n+rte_reorder_drain(struct rte_reorder_buffer *b, struct rte_mbuf **mbufs,\n+\t\tunsigned max_mbufs)\n+{\n+\tunsigned int drain_cnt = 0;\n+\n+\tstruct cir_buffer *order_buf = &b->order_buf,\n+\t\t\t*ready_buf = &b->ready_buf;\n+\n+\t/* Try to fetch requested number of mbufs from ready buffer */\n+\twhile ((drain_cnt < max_mbufs) && (ready_buf->tail != ready_buf->head)) {\n+\t\tmbufs[drain_cnt++] = ready_buf->entries[ready_buf->tail];\n+\t\tready_buf->tail = (ready_buf->tail + 1) & ready_buf->mask;\n+\t}\n+\n+\t/*\n+\t * If requested number of buffers not fetched from ready buffer, fetch\n+\t * remaining buffers from order buffer\n+\t */\n+\twhile ((drain_cnt < max_mbufs) &&\n+\t\t\t(order_buf->entries[order_buf->head] != NULL)) {\n+\t\tmbufs[drain_cnt++] = order_buf->entries[order_buf->head];\n+\t\torder_buf->entries[order_buf->head] = NULL;\n+\t\tb->min_seqn++;\n+\t\torder_buf->head = (order_buf->head + 1) & order_buf->mask;\n+\t}\n+\n+\treturn drain_cnt;\n+}\ndiff --git a/lib/librte_reorder/rte_reorder.h b/lib/librte_reorder/rte_reorder.h\nnew file mode 100644\nindex 0000000..8300bf0\n--- /dev/null\n+++ b/lib/librte_reorder/rte_reorder.h\n@@ -0,0 +1,181 @@\n+/*-\n+ * BSD LICENSE\n+ *\n+ * Copyright(c) 2010-2014 Intel Corporation. All rights reserved.\n+ * All rights reserved.\n+ *\n+ * Redistribution and use in source and binary forms, with or without\n+ * modification, are permitted provided that the following conditions\n+ * are met:\n+ *\n+ * * Redistributions of source code must retain the above copyright\n+ * notice, this list of conditions and the following disclaimer.\n+ * * Redistributions in binary form must reproduce the above copyright\n+ * notice, this list of conditions and the following disclaimer in\n+ * the documentation and/or other materials provided with the\n+ * distribution.\n+ * * Neither the name of Intel Corporation nor the names of its\n+ * contributors may be used to endorse or promote products derived\n+ * from this software without specific prior written permission.\n+ *\n+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n+ * \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\n+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\n+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n+ */\n+\n+#ifndef _RTE_REORDER_H_\n+#define _RTE_REORDER_H_\n+\n+/**\n+ * @file\n+ * RTE reorder\n+ *\n+ * Reorder library is a component which is designed to\n+ * provide ordering of out of ordered packets based on\n+ * sequence number present in mbuf.\n+ *\n+ */\n+\n+#ifdef __cplusplus\n+extern \"C\" {\n+#endif\n+\n+struct rte_reorder_buffer;\n+\n+/**\n+ * Create a new reorder buffer instance\n+ *\n+ * Allocate memory and initialize a new reorder buffer in that\n+ * memory, returning the reorder buffer pointer to the user\n+ *\n+ * @param name\n+ * The name to be given to the reorder buffer instance.\n+ * @param socket_id\n+ * The NUMA node on which the memory for the reorder buffer\n+ * instance is to be reserved.\n+ * @param size\n+ * Max number of elements that can be stored in the reorder buffer\n+ * @return\n+ * The initialized reorder buffer instance, or NULL on error\n+ * On error case, rte_errno will be set appropriately:\n+ * - ENOMEM - no appropriate memory area found in which to create memzone\n+ * - EINVAL - invalid parameters\n+ */\n+struct rte_reorder_buffer *\n+rte_reorder_create(const char *name, unsigned socket_id, unsigned int size);\n+\n+/**\n+ * Initializes given reorder buffer instance\n+ *\n+ * @param b\n+ * Reorder buffer instance to initialize\n+ * @param bufsize\n+ * Size of the reorder buffer\n+ * @param name\n+ * The name to be given to the reorder buffer\n+ * @param size\n+ * Number of elements that can be stored in reorder buffer\n+ * @return\n+ * The initialized reorder buffer instance, or NULL on error\n+ * On error case, rte_errno will be set appropriately:\n+ * - EINVAL - invalid parameters\n+ */\n+struct rte_reorder_buffer *\n+rte_reorder_init(struct rte_reorder_buffer *b, unsigned int bufsize,\n+\t\tconst char *name, unsigned int size);\n+\n+/**\n+ * Find an existing reorder buffer instance\n+ * and return a pointer to it.\n+ *\n+ * @param name\n+ * Name of the reorder buffer instacne as passed to rte_reorder_create()\n+ * @return\n+ * Pointer to reorder buffer instance or NULL if object not found with rte_errno\n+ * set appropriately. Possible rte_errno values include:\n+ * - ENOENT - required entry not available to return.\n+ * - E_RTE_NO_TAILQ - no tailq list could be got for the\n+ * reorder instance list\n+ */\n+struct rte_reorder_buffer *\n+rte_reorder_find_existing(const char *name);\n+\n+/**\n+ * Reset the given reorder buffer instance with initial values.\n+ *\n+ * @param b\n+ * Reorder buffer instance which has to be reset\n+ */\n+void\n+rte_reorder_reset(struct rte_reorder_buffer *b);\n+\n+/**\n+ * Free reorder buffer instance.\n+ *\n+ * @param b\n+ * reorder buffer instance\n+ * @return\n+ * None\n+ */\n+void\n+rte_reorder_free(struct rte_reorder_buffer *b);\n+\n+/**\n+ * Insert given mbuf in reorder buffer in its correct position\n+ *\n+ * The given mbuf is to be reordered relative to other mbufs in the system.\n+ * The mbuf must contain a sequence number which is then used to place\n+ * the buffer in the correct position in the reorder buffer. Reordered\n+ * packets can later be taken from the buffer using the rte_reorder_drain()\n+ * API.\n+ *\n+ * @param b\n+ * Reorder buffer where the mbuf has to be inserted.\n+ * @param mbuf\n+ * mbuf of packet that needs to be inserted in reorder buffer.\n+ * @return\n+ * 0 on success\n+ * -1 on error\n+ * On error case, rte_errno will be set appropriately:\n+ * - ENOSPC - Cannot move existing mbufs from reorder buffer to accommodate\n+ * ealry mbuf, but it can be accomodated by performing drain and then insert.\n+ * - ERANGE - Too early or late mbuf which is vastly out of range of expected\n+ * window should be ingnored without any handling.\n+ */\n+int\n+rte_reorder_insert(struct rte_reorder_buffer *b, struct rte_mbuf *mbuf);\n+\n+/**\n+ * Fetch reordered buffers\n+ *\n+ * Returns a set of in-order buffers from the reorder buffer structure. Gaps\n+ * may be present in the sequence numbers of the mbuf if packets have been\n+ * delayed too long before reaching the reorder window, or have been previously\n+ * dropped by the system.\n+ *\n+ * @param b\n+ * Reorder buffer instance from which packets are to be drained\n+ * @param mbufs\n+ * array of mbufs where reordered packets will be inserted from reorder buffer\n+ * @param max_mbufs\n+ * the number of elements in the mbufs array.\n+ * @return\n+ * number of mbuf pointers written to mbufs. 0 <= N < max_mbufs.\n+ */\n+unsigned int\n+rte_reorder_drain(struct rte_reorder_buffer *b, struct rte_mbuf **mbufs,\n+\t\tunsigned max_mbufs);\n+\n+#ifdef __cplusplus\n+}\n+#endif\n+\n+#endif /* _RTE_REORDER_H_ */\n", "prefixes": [ "dpdk-dev", "v3", "1/5" ] }{ "id": 3018, "url": "