get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

GET /api/patches/639/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 639,
    "url": "http://patchwork.dpdk.org/api/patches/639/?format=api",
    "web_url": "http://patchwork.dpdk.org/project/dpdk/patch/1411985756-2744-1-git-send-email-marc.sune@bisdn.de/",
    "project": {
        "id": 1,
        "url": "http://patchwork.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": "<1411985756-2744-1-git-send-email-marc.sune@bisdn.de>",
    "list_archive_url": "https://inbox.dpdk.org/dev/1411985756-2744-1-git-send-email-marc.sune@bisdn.de",
    "date": "2014-09-29T10:15:56",
    "name": "[dpdk-dev] KNI: use a memzone pool for KNI alloc/release",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": true,
    "hash": "f43bac282fa0db9da324e9731017161a8a00e348",
    "submitter": {
        "id": 83,
        "url": "http://patchwork.dpdk.org/api/people/83/?format=api",
        "name": "Marc Sune",
        "email": "marc.sune@bisdn.de"
    },
    "delegate": null,
    "mbox": "http://patchwork.dpdk.org/project/dpdk/patch/1411985756-2744-1-git-send-email-marc.sune@bisdn.de/mbox/",
    "series": [],
    "comments": "http://patchwork.dpdk.org/api/patches/639/comments/",
    "check": "pending",
    "checks": "http://patchwork.dpdk.org/api/patches/639/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 E76085902;\n\tMon, 29 Sep 2014 12:09:35 +0200 (CEST)",
            "from mx.bisdn.de (mx.bisdn.de [185.27.182.31])\n\tby dpdk.org (Postfix) with ESMTP id 7581A1F7\n\tfor <dev@dpdk.org>; Mon, 29 Sep 2014 12:09:34 +0200 (CEST)",
            "from localhost.localdomain (unknown [172.16.250.161])\n\tby mx.bisdn.de (Postfix) with ESMTP id CB036A2D2E;\n\tMon, 29 Sep 2014 12:16:09 +0200 (CEST)"
        ],
        "From": "Marc Sune <marc.sune@bisdn.de>",
        "To": "dev@dpdk.org",
        "Date": "Mon, 29 Sep 2014 12:15:56 +0200",
        "Message-Id": "<1411985756-2744-1-git-send-email-marc.sune@bisdn.de>",
        "X-Mailer": "git-send-email 1.7.10.4",
        "Subject": "[dpdk-dev] [PATCH] KNI: use a memzone pool for KNI alloc/release",
        "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 patch implements the KNI memzone pool in order to:\n\n* prevent memzone exhaustion when allocating/deallocating KNI\n  interfaces.\n* be able to allocate KNI interfaces with the same name as\n  previously deallocated ones.\n\nIt adds a new API call, rte_kni_init(max_kni_ifaces) that shall\nbe called before any call to rte_kni_alloc() if KNI is used.\n\nSigned-off-by: Marc Sune <marc.sune@bisdn.de>\n---\n lib/librte_kni/rte_kni.c |  302 ++++++++++++++++++++++++++++++++++++++--------\n lib/librte_kni/rte_kni.h |   18 +++\n 2 files changed, 269 insertions(+), 51 deletions(-)",
    "diff": "diff --git a/lib/librte_kni/rte_kni.c b/lib/librte_kni/rte_kni.c\nindex 76feef4..df55789 100644\n--- a/lib/librte_kni/rte_kni.c\n+++ b/lib/librte_kni/rte_kni.c\n@@ -40,6 +40,7 @@\n #include <unistd.h>\n #include <sys/ioctl.h>\n \n+#include <rte_spinlock.h>\n #include <rte_string_fns.h>\n #include <rte_ethdev.h>\n #include <rte_malloc.h>\n@@ -58,7 +59,7 @@\n \n #define KNI_REQUEST_MBUF_NUM_MAX      32\n \n-#define KNI_MZ_CHECK(mz) do { if (mz) goto fail; } while (0)\n+#define KNI_MEM_CHECK(cond) do { if (cond) goto kni_fail; } while (0)\n \n /**\n  * KNI context\n@@ -66,6 +67,7 @@\n struct rte_kni {\n \tchar name[RTE_KNI_NAMESIZE];        /**< KNI interface name */\n \tuint16_t group_id;                  /**< Group ID of KNI devices */\n+\tunsigned slot_id;                   /**< KNI pool slot ID */\n \tstruct rte_mempool *pktmbuf_pool;   /**< pkt mbuf mempool */\n \tunsigned mbuf_size;                 /**< mbuf size */\n \n@@ -88,10 +90,48 @@ enum kni_ops_status {\n \tKNI_REQ_REGISTERED,\n };\n \n+/**\n+* KNI memzone pool slot\n+*/\n+struct rte_kni_memzone_slot{\n+\tunsigned id;\n+\tuint8_t in_use : 1;                    /**< slot in use */\n+\n+\t//Memzones\n+\tconst struct rte_memzone *m_ctx;       /**< KNI ctx */\n+\tconst struct rte_memzone *m_tx_q;      /**< TX queue */\n+\tconst struct rte_memzone *m_rx_q;      /**< RX queue */\n+\tconst struct rte_memzone *m_alloc_q;   /**< Allocated mbufs queue */\n+\tconst struct rte_memzone *m_free_q;    /**< To be freed mbufs queue */\n+\tconst struct rte_memzone *m_req_q;     /**< Request queue */\n+\tconst struct rte_memzone *m_resp_q;    /**< Response queue */\n+\tconst struct rte_memzone *m_sync_addr;         \n+\t\n+\t/* Free linked list */\n+\tstruct rte_kni_memzone_slot *next;     /**< Next slot link.list */\n+};\n+\n+/**\n+* KNI memzone pool\n+*/\n+struct rte_kni_memzone_pool{\n+\tuint8_t initialized : 1;            /**< Global KNI pool init flag */\n+ \n+\tunsigned max_ifaces;                /**< Max. num of KNI ifaces */\n+\tstruct rte_kni_memzone_slot *slots;        /**< Pool slots */\n+\trte_spinlock_t mutex;               /**< alloc/relase mutex */\n+\n+\t//Free memzone slots linked-list\n+\tstruct rte_kni_memzone_slot *free;         /**< First empty slot */\n+\tstruct rte_kni_memzone_slot *free_tail;    /**< Last empty slot */\n+};\n+\n+\n static void kni_free_mbufs(struct rte_kni *kni);\n static void kni_allocate_mbufs(struct rte_kni *kni);\n \n static volatile int kni_fd = -1;\n+static struct rte_kni_memzone_pool kni_memzone_pool = {0};\n \n static const struct rte_memzone *\n kni_memzone_reserve(const char *name, size_t len, int socket_id,\n@@ -105,6 +145,154 @@ kni_memzone_reserve(const char *name, size_t len, int socket_id,\n \treturn mz;\n }\n \n+/* Pool mgmt */\n+static struct rte_kni_memzone_slot*\n+kni_memzone_pool_alloc(void)\n+{\n+\tstruct rte_kni_memzone_slot* slot;\n+\t\n+\trte_spinlock_lock(&kni_memzone_pool.mutex);\t\n+\n+\tif(!kni_memzone_pool.free) {\n+\t\trte_spinlock_unlock(&kni_memzone_pool.mutex);\t\n+\t\treturn NULL;\n+\t}\n+\n+\tslot = kni_memzone_pool.free;\n+\tkni_memzone_pool.free = slot->next;\n+\n+\tif(!kni_memzone_pool.free)\n+\t\tkni_memzone_pool.free_tail = NULL;\n+\n+\trte_spinlock_unlock(&kni_memzone_pool.mutex);\n+\n+\treturn slot;\n+}\n+\n+static void \n+kni_memzone_pool_dealloc(struct rte_kni_memzone_slot* slot)\n+{\n+\trte_spinlock_lock(&kni_memzone_pool.mutex);\t\n+\n+\tif(kni_memzone_pool.free)\n+\t\tkni_memzone_pool.free_tail->next = slot;\n+\telse\n+\t\tkni_memzone_pool.free = slot;\n+\n+\tkni_memzone_pool.free_tail = slot;\n+\tslot->next = NULL;\n+\n+\trte_spinlock_unlock(&kni_memzone_pool.mutex);\n+}\n+\n+\n+/* Shall be called before any allocation happens */\n+void\n+rte_kni_init(unsigned int max_kni_ifaces)\n+{\n+\tunsigned i;\n+\tstruct rte_kni_memzone_slot* it;\n+\tconst struct rte_memzone *mz;\n+#define OBJNAMSIZ 32\n+\tchar obj_name[OBJNAMSIZ];\n+\tchar mz_name[RTE_MEMZONE_NAMESIZE];\n+\n+\tif(max_kni_ifaces == 0) {\n+\t\t//Panic\n+\t\tRTE_LOG(ERR, KNI, \"Invalid number of max_kni_ifaces %d\\n\",\n+\t\t\t\t\t\t\tmax_kni_ifaces);\n+\t\trte_panic(\"Unable to initialize KNI\\n\");\n+\t}\n+\n+\t//Allocate slot objects\n+\tkni_memzone_pool.slots = (struct rte_kni_memzone_slot*)rte_malloc(NULL,\n+\t\t\t\t\tsizeof(struct rte_kni_memzone_slot) *\n+\t\t\t\t\tmax_kni_ifaces,\n+\t\t\t\t\t0);\n+\tKNI_MEM_CHECK(kni_memzone_pool.slots == NULL);\n+\n+\t//Initialize general stuff \n+\tkni_memzone_pool.initialized = 1;\n+\tkni_memzone_pool.max_ifaces = max_kni_ifaces;\n+\tkni_memzone_pool.free = &kni_memzone_pool.slots[0];\n+\n+\t//Pre-allocate all memzones of the slots; panic on error\n+\tfor(i=0; i<max_kni_ifaces; i++) {\n+\n+\t\t//Recover current slot\n+\t\tit = &kni_memzone_pool.slots[i];\n+\t\tit->id = i;\n+\t\n+\t\t//Allocate KNI context\n+\t\tsnprintf(mz_name, RTE_MEMZONE_NAMESIZE, \"KNI_INFO_%d\", i);\n+\t\tmz = kni_memzone_reserve(mz_name, sizeof(struct rte_kni),\n+\t\t\t\t\tSOCKET_ID_ANY, 0);\n+\t\tKNI_MEM_CHECK(mz == NULL);\n+\t\tit->m_ctx = mz;\n+\t\t\t\n+\t\t/* TX RING */\n+\t\tsnprintf(obj_name, OBJNAMSIZ, \"kni_tx_%d\", i);\n+\t\tmz = kni_memzone_reserve(obj_name, KNI_FIFO_SIZE, \n+\t\t\t\t\t\t\tSOCKET_ID_ANY, 0);\n+\t\tKNI_MEM_CHECK(mz == NULL);\n+\t\tit->m_tx_q = mz;\n+\n+\t\t/* RX RING */\n+\t\tsnprintf(obj_name, OBJNAMSIZ, \"kni_rx_%d\", i);\n+\t\tmz = kni_memzone_reserve(obj_name, KNI_FIFO_SIZE, \n+\t\t\t\t\t\t\tSOCKET_ID_ANY, 0);\n+\t\tKNI_MEM_CHECK(mz == NULL);\n+\t\tit->m_rx_q = mz;\n+\n+\t\t/* ALLOC RING */\n+\t\tsnprintf(obj_name, OBJNAMSIZ, \"kni_alloc_%d\", i);\n+\t\tmz = kni_memzone_reserve(obj_name, KNI_FIFO_SIZE,\n+\t\t\t\t\t\t\tSOCKET_ID_ANY, 0);\n+\t\tKNI_MEM_CHECK(mz == NULL);\n+\t\tit->m_alloc_q = mz;\n+\n+\t\t/* FREE RING */\n+\t\tsnprintf(obj_name, OBJNAMSIZ, \"kni_free_%d\", i);\n+\t\tmz = kni_memzone_reserve(obj_name, KNI_FIFO_SIZE, \n+\t\t\t\t\t\t\tSOCKET_ID_ANY, 0);\n+\t\tKNI_MEM_CHECK(mz == NULL);\n+\t\tit->m_free_q = mz;\n+\n+\t\t/* Request RING */\n+\t\tsnprintf(obj_name, OBJNAMSIZ, \"kni_req_%d\", i);\n+\t\tmz = kni_memzone_reserve(obj_name, KNI_FIFO_SIZE, \n+\t\t\t\t\t\t\tSOCKET_ID_ANY, 0);\n+\t\tKNI_MEM_CHECK(mz == NULL);\n+\t\tit->m_req_q = mz;\n+\n+\t\t/* Response RING */\n+\t\tsnprintf(obj_name, OBJNAMSIZ, \"kni_resp_%d\", i);\n+\t\tmz = kni_memzone_reserve(obj_name, KNI_FIFO_SIZE, \n+\t\t\t\t\t\t\tSOCKET_ID_ANY, 0);\n+\t\tKNI_MEM_CHECK(mz == NULL);\n+\t\tit->m_resp_q = mz;\n+\n+\t\t/* Req/Resp sync mem area */\n+\t\tsnprintf(obj_name, OBJNAMSIZ, \"kni_sync_%d\", i);\n+\t\tmz = kni_memzone_reserve(obj_name, KNI_FIFO_SIZE, \n+\t\t\t\t\t\t\tSOCKET_ID_ANY, 0);\n+\t\tKNI_MEM_CHECK(mz == NULL);\n+\t\tit->m_sync_addr = mz;\n+\n+\t\tif(i+1 == max_kni_ifaces) {\n+\t\t\tit->next = NULL;\n+\t\t\tkni_memzone_pool.free_tail = it;\n+\t\t}else\n+\t\t\tit->next = &kni_memzone_pool.slots[i+1];\n+\t}\n+\t\n+\treturn;\n+\n+kni_fail:\n+\trte_panic(\"Unable to allocate memory for max_kni_ifaces:%d.\"\n+\t\t\"increase the amount of hugepages memory\\n\", max_kni_ifaces);\n+}\n+\n /* It is deprecated and just for backward compatibility */\n struct rte_kni *\n rte_kni_create(uint8_t port_id,\n@@ -140,14 +328,20 @@ rte_kni_alloc(struct rte_mempool *pktmbuf_pool,\n \tstruct rte_kni_device_info dev_info;\n \tstruct rte_kni *ctx;\n \tchar intf_name[RTE_KNI_NAMESIZE];\n-#define OBJNAMSIZ 32\n-\tchar obj_name[OBJNAMSIZ];\n \tchar mz_name[RTE_MEMZONE_NAMESIZE];\n \tconst struct rte_memzone *mz;\n+\tstruct rte_kni_memzone_slot* slot=NULL;\n \n \tif (!pktmbuf_pool || !conf || !conf->name[0])\n \t\treturn NULL;\n \n+\t/* Check inited */\n+\tif (kni_memzone_pool.initialized != 1) {\n+\t\tRTE_LOG(ERR, KNI, \"KNI subsystem has not been initialized. \"\n+\t\t\t\t\"Invoke rte_kni_init() first\\n\");\n+\t\treturn NULL;\n+\t}\n+\n \t/* Check FD and open once */\n \tif (kni_fd < 0) {\n \t\tkni_fd = open(\"/dev/\" KNI_DEVICE, O_RDWR);\n@@ -158,16 +352,23 @@ rte_kni_alloc(struct rte_mempool *pktmbuf_pool,\n \t\t}\n \t}\n \n+\t/* Get an available slot from the pool */\n+\tslot = kni_memzone_pool_alloc();\n+\tif(!slot) {\n+\t\tRTE_LOG(ERR, KNI, \"Cannot allocate more KNI interfaces; \"\n+\t\t\t\"increase the number of max_kni_ifaces(current %d) or \"\n+\t\t\t\"deallocate unusued ones.\\n\", \n+\t\t\tkni_memzone_pool.max_ifaces);\n+\t\treturn NULL;\n+\t}\n+\t\n+\t//Recover ctx\n+\tctx = slot->m_ctx->addr;\n \tsnprintf(intf_name, RTE_KNI_NAMESIZE, \"%s\", conf->name);\n-\tsnprintf(mz_name, RTE_MEMZONE_NAMESIZE, \"KNI_INFO_%s\", intf_name);\n-\tmz = kni_memzone_reserve(mz_name, sizeof(struct rte_kni),\n-\t\t\t\tSOCKET_ID_ANY, 0);\n-\tKNI_MZ_CHECK(mz == NULL);\n-\tctx = mz->addr;\n \n \tif (ctx->in_use) {\n \t\tRTE_LOG(ERR, KNI, \"KNI %s is in use\\n\", ctx->name);\n-\t\tgoto fail;\n+\t\treturn NULL;\n \t}\n \tmemset(ctx, 0, sizeof(struct rte_kni));\n \tif (ops)\n@@ -190,83 +391,72 @@ rte_kni_alloc(struct rte_mempool *pktmbuf_pool,\n \tRTE_LOG(INFO, KNI, \"pci: %02x:%02x:%02x \\t %02x:%02x\\n\",\n \t\tdev_info.bus, dev_info.devid, dev_info.function,\n \t\t\tdev_info.vendor_id, dev_info.device_id);\n-\n \t/* TX RING */\n-\tsnprintf(obj_name, OBJNAMSIZ, \"kni_tx_%s\", intf_name);\n-\tmz = kni_memzone_reserve(obj_name, KNI_FIFO_SIZE, SOCKET_ID_ANY, 0);\n-\tKNI_MZ_CHECK(mz == NULL);\n+\tmz = slot->m_tx_q;\n \tctx->tx_q = mz->addr;\n \tkni_fifo_init(ctx->tx_q, KNI_FIFO_COUNT_MAX);\n \tdev_info.tx_phys = mz->phys_addr;\n \n \t/* RX RING */\n-\tsnprintf(obj_name, OBJNAMSIZ, \"kni_rx_%s\", intf_name);\n-\tmz = kni_memzone_reserve(obj_name, KNI_FIFO_SIZE, SOCKET_ID_ANY, 0);\n-\tKNI_MZ_CHECK(mz == NULL);\n+\tmz = slot->m_rx_q;\n \tctx->rx_q = mz->addr;\n \tkni_fifo_init(ctx->rx_q, KNI_FIFO_COUNT_MAX);\n \tdev_info.rx_phys = mz->phys_addr;\n \n \t/* ALLOC RING */\n-\tsnprintf(obj_name, OBJNAMSIZ, \"kni_alloc_%s\", intf_name);\n-\tmz = kni_memzone_reserve(obj_name, KNI_FIFO_SIZE, SOCKET_ID_ANY, 0);\n-\tKNI_MZ_CHECK(mz == NULL);\n+\tmz = slot->m_alloc_q;\n \tctx->alloc_q = mz->addr;\n \tkni_fifo_init(ctx->alloc_q, KNI_FIFO_COUNT_MAX);\n \tdev_info.alloc_phys = mz->phys_addr;\n \n \t/* FREE RING */\n-\tsnprintf(obj_name, OBJNAMSIZ, \"kni_free_%s\", intf_name);\n-\tmz = kni_memzone_reserve(obj_name, KNI_FIFO_SIZE, SOCKET_ID_ANY, 0);\n-\tKNI_MZ_CHECK(mz == NULL);\n+\tmz = slot->m_free_q;\n \tctx->free_q = mz->addr;\n \tkni_fifo_init(ctx->free_q, KNI_FIFO_COUNT_MAX);\n \tdev_info.free_phys = mz->phys_addr;\n \n \t/* Request RING */\n-\tsnprintf(obj_name, OBJNAMSIZ, \"kni_req_%s\", intf_name);\n-\tmz = kni_memzone_reserve(obj_name, KNI_FIFO_SIZE, SOCKET_ID_ANY, 0);\n-\tKNI_MZ_CHECK(mz == NULL);\n+\tmz = slot->m_req_q;\n \tctx->req_q = mz->addr;\n \tkni_fifo_init(ctx->req_q, KNI_FIFO_COUNT_MAX);\n \tdev_info.req_phys = mz->phys_addr;\n \n \t/* Response RING */\n-\tsnprintf(obj_name, OBJNAMSIZ, \"kni_resp_%s\", intf_name);\n-\tmz = kni_memzone_reserve(obj_name, KNI_FIFO_SIZE, SOCKET_ID_ANY, 0);\n-\tKNI_MZ_CHECK(mz == NULL);\n+\tmz = slot->m_resp_q;\n \tctx->resp_q = mz->addr;\n \tkni_fifo_init(ctx->resp_q, KNI_FIFO_COUNT_MAX);\n \tdev_info.resp_phys = mz->phys_addr;\n \n \t/* Req/Resp sync mem area */\n-\tsnprintf(obj_name, OBJNAMSIZ, \"kni_sync_%s\", intf_name);\n-\tmz = kni_memzone_reserve(obj_name, KNI_FIFO_SIZE, SOCKET_ID_ANY, 0);\n-\tKNI_MZ_CHECK(mz == NULL);\n+\tmz = slot->m_sync_addr; \n \tctx->sync_addr = mz->addr;\n \tdev_info.sync_va = mz->addr;\n \tdev_info.sync_phys = mz->phys_addr;\n \n+\n \t/* MBUF mempool */\n \tsnprintf(mz_name, sizeof(mz_name), RTE_MEMPOOL_OBJ_NAME,\n \t\tpktmbuf_pool->name);\n \tmz = rte_memzone_lookup(mz_name);\n-\tKNI_MZ_CHECK(mz == NULL);\n+\tKNI_MEM_CHECK(mz == NULL);\n \tdev_info.mbuf_va = mz->addr;\n \tdev_info.mbuf_phys = mz->phys_addr;\n \tctx->pktmbuf_pool = pktmbuf_pool;\n \tctx->group_id = conf->group_id;\n+\tctx->slot_id = slot->id;\n \tctx->mbuf_size = conf->mbuf_size;\n \n \tret = ioctl(kni_fd, RTE_KNI_IOCTL_CREATE, &dev_info);\n-\tKNI_MZ_CHECK(ret < 0);\n+\tKNI_MEM_CHECK(ret < 0);\n \n \tctx->in_use = 1;\n \n \treturn ctx;\n \n-fail:\n-\n+kni_fail:\n+\tif(slot)\n+\t\tkni_memzone_pool_dealloc(&kni_memzone_pool.slots[slot->id]);\n+\t\t\t\n \treturn NULL;\n }\n \n@@ -287,6 +477,7 @@ int\n rte_kni_release(struct rte_kni *kni)\n {\n \tstruct rte_kni_device_info dev_info;\n+\tunsigned slot_id;\n \n \tif (!kni || !kni->in_use)\n \t\treturn -1;\n@@ -302,8 +493,19 @@ rte_kni_release(struct rte_kni *kni)\n \tkni_free_fifo(kni->rx_q);\n \tkni_free_fifo(kni->alloc_q);\n \tkni_free_fifo(kni->free_q);\n+\n+\tslot_id = kni->slot_id;\t\t\n+\n+\t//Memset\n \tmemset(kni, 0, sizeof(struct rte_kni));\n \n+\t//Release memzone\n+\tif(slot_id > kni_memzone_pool.max_ifaces) {\n+\t\trte_panic(\"KNI pool: corrupted slot ID: %d, max: %d\\n\", \n+\t\t\tslot_id, kni_memzone_pool.max_ifaces);\n+\t}\n+\tkni_memzone_pool_dealloc(&kni_memzone_pool.slots[slot_id]);\n+\n \treturn 0;\n }\n \n@@ -437,23 +639,21 @@ rte_kni_get_port_id(struct rte_kni *kni)\n struct rte_kni *\n rte_kni_get(const char *name)\n {\n-\tstruct rte_kni *kni;\n-\tconst struct rte_memzone *mz;\n-\tchar mz_name[RTE_MEMZONE_NAMESIZE];\n-\n-\tif (!name || !name[0])\n-\t\treturn NULL;\n-\n-\tsnprintf(mz_name, RTE_MEMZONE_NAMESIZE, \"KNI_INFO_%s\", name);\n-\tmz = rte_memzone_lookup(mz_name);\n-\tif (!mz)\n-\t\treturn NULL;\n-\n-\tkni = mz->addr;\n-\tif (!kni->in_use)\n-\t\treturn NULL;\n+\tunsigned i;\n+\tstruct rte_kni_memzone_slot* it;\n+\tstruct rte_kni* kni;\n+\n+\t//Could be improved perf-wise if necessary\n+\tfor(i=0; i<kni_memzone_pool.max_ifaces; i++) {\n+\t\tit = &kni_memzone_pool.slots[i];\n+\t\tif(it->in_use == 0)\n+\t\t\tcontinue;\n+\t\tkni = it->m_ctx->addr;\n+\t\tif(strncmp(kni->name, name, RTE_KNI_NAMESIZE) == 0)\n+\t\t\treturn kni;\n+\t}\n \n-\treturn kni;\n+\treturn NULL;\n }\n \n /*\ndiff --git a/lib/librte_kni/rte_kni.h b/lib/librte_kni/rte_kni.h\nindex 1a0b004..0159a1d 100644\n--- a/lib/librte_kni/rte_kni.h\n+++ b/lib/librte_kni/rte_kni.h\n@@ -90,11 +90,27 @@ struct rte_kni_conf {\n };\n \n /**\n+ * Initialize and preallocate KNI subsystem\n+ *\n+ * This function is to be executed on the MASTER lcore only, after EAL \n+ * initialization and before any KNI interface is attempted to be\n+ * allocated\n+ * \n+ * @param max_kni_ifaces \n+ *  The maximum number of KNI interfaces that can coexist concurrently\n+ */\n+extern void rte_kni_init(unsigned int max_kni_ifaces);\n+\n+\n+/**\n  * Allocate KNI interface according to the port id, mbuf size, mbuf pool,\n  * configurations and callbacks for kernel requests.The KNI interface created\n  * in the kernel space is the net interface the traditional Linux application\n  * talking to.\n  *\n+ * The rte_kni_alloc shall not be called before rte_kni_init() has been\n+ * called. rte_kni_alloc is thread safe. \n+ *\n  * @param pktmbuf_pool\n  *  The mempool for allocting mbufs for packets.\n  * @param conf\n@@ -138,6 +154,8 @@ extern struct rte_kni *rte_kni_create(uint8_t port_id,\n  * Release KNI interface according to the context. It will also release the\n  * paired KNI interface in kernel space. All processing on the specific KNI\n  * context need to be stopped before calling this interface.\n+ * \n+ * rte_kni_release is thread safe.\n  *\n  * @param kni\n  *  The pointer to the context of an existent KNI interface.\n",
    "prefixes": [
        "dpdk-dev"
    ]
}