get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

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

{
    "id": 5853,
    "url": "https://patches.dpdk.org/api/patches/5853/?format=api",
    "web_url": "https://patches.dpdk.org/project/dpdk/patch/1435332578-28415-7-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": "<1435332578-28415-7-git-send-email-sergio.gonzalez.monroy@intel.com>",
    "list_archive_url": "https://inbox.dpdk.org/dev/1435332578-28415-7-git-send-email-sergio.gonzalez.monroy@intel.com",
    "date": "2015-06-26T15:29:35",
    "name": "[dpdk-dev,v6,6/9] eal: new rte_memzone_free",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": true,
    "hash": "8d00eee5d28e8d2d336a3aef249cadc5b18640d4",
    "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/1435332578-28415-7-git-send-email-sergio.gonzalez.monroy@intel.com/mbox/",
    "series": [],
    "comments": "https://patches.dpdk.org/api/patches/5853/comments/",
    "check": "pending",
    "checks": "https://patches.dpdk.org/api/patches/5853/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 213B5C9BC;\n\tFri, 26 Jun 2015 17:29:51 +0200 (CEST)",
            "from mga03.intel.com (mga03.intel.com [134.134.136.65])\n\tby dpdk.org (Postfix) with ESMTP id E309CC966\n\tfor <dev@dpdk.org>; Fri, 26 Jun 2015 17:29:42 +0200 (CEST)",
            "from orsmga002.jf.intel.com ([10.7.209.21])\n\tby orsmga103.jf.intel.com with ESMTP; 26 Jun 2015 08:29:42 -0700",
            "from irvmail001.ir.intel.com ([163.33.26.43])\n\tby orsmga002.jf.intel.com with ESMTP; 26 Jun 2015 08:29:41 -0700",
            "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\tt5QFTdTg011012 for <dev@dpdk.org>; Fri, 26 Jun 2015 16:29:39 +0100",
            "from sivswdev02.ir.intel.com (localhost [127.0.0.1])\n\tby sivswdev02.ir.intel.com with ESMTP id t5QFTdVM028496\n\tfor <dev@dpdk.org>; Fri, 26 Jun 2015 16:29:39 +0100",
            "(from smonroy@localhost)\n\tby sivswdev02.ir.intel.com with  id t5QFTdXP028492\n\tfor dev@dpdk.org; Fri, 26 Jun 2015 16:29:39 +0100"
        ],
        "X-ExtLoop1": "1",
        "X-IronPort-AV": "E=Sophos;i=\"5.13,685,1427785200\"; d=\"scan'208\";a=\"753765245\"",
        "From": "Sergio Gonzalez Monroy <sergio.gonzalez.monroy@intel.com>",
        "To": "dev@dpdk.org",
        "Date": "Fri, 26 Jun 2015 16:29:35 +0100",
        "Message-Id": "<1435332578-28415-7-git-send-email-sergio.gonzalez.monroy@intel.com>",
        "X-Mailer": "git-send-email 1.8.5.4",
        "In-Reply-To": "<1435332578-28415-1-git-send-email-sergio.gonzalez.monroy@intel.com>",
        "References": "<1433586732-28217-1-git-send-email-sergio.gonzalez.monroy@intel.com>\n\t<1435332578-28415-1-git-send-email-sergio.gonzalez.monroy@intel.com>",
        "Subject": "[dpdk-dev] [PATCH v6 6/9] eal: new rte_memzone_free",
        "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": "Implement rte_memzone_free which, as its name implies, would free a\nmemzone.\n\nCurrently memzone are tracked in an array and cannot be free.\nTo be able to reuse the same array to track memzones, we have to\nchange how we keep track of reserved memzones.\n\nWith this patch, any memzone with addr NULL is not used, so we also need\nto change how we look for the next memzone entry free.\n\nSigned-off-by: Sergio Gonzalez Monroy <sergio.gonzalez.monroy@intel.com>\n---\n lib/librte_eal/bsdapp/eal/rte_eal_version.map     |  6 ++\n lib/librte_eal/common/eal_common_memzone.c        | 67 ++++++++++++++++++++++-\n lib/librte_eal/common/include/rte_eal_memconfig.h |  2 +-\n lib/librte_eal/common/include/rte_memzone.h       | 11 ++++\n lib/librte_eal/linuxapp/eal/eal_ivshmem.c         |  8 +--\n lib/librte_eal/linuxapp/eal/rte_eal_version.map   |  6 ++\n 6 files changed, 92 insertions(+), 8 deletions(-)",
    "diff": "diff --git a/lib/librte_eal/bsdapp/eal/rte_eal_version.map b/lib/librte_eal/bsdapp/eal/rte_eal_version.map\nindex 0401be2..7110816 100644\n--- a/lib/librte_eal/bsdapp/eal/rte_eal_version.map\n+++ b/lib/librte_eal/bsdapp/eal/rte_eal_version.map\n@@ -105,3 +105,9 @@ DPDK_2.0 {\n \n \tlocal: *;\n };\n+\n+DPDK_2.1 {\n+\tglobal:\n+\n+\trte_memzone_free;\n+} DPDK_2.0;\ndiff --git a/lib/librte_eal/common/eal_common_memzone.c b/lib/librte_eal/common/eal_common_memzone.c\nindex 943012b..5bc4ab4 100644\n--- a/lib/librte_eal/common/eal_common_memzone.c\n+++ b/lib/librte_eal/common/eal_common_memzone.c\n@@ -77,6 +77,23 @@ memzone_lookup_thread_unsafe(const char *name)\n \treturn NULL;\n }\n \n+static inline struct rte_memzone *\n+get_next_free_memzone(void)\n+{\n+\tstruct rte_mem_config *mcfg;\n+\tunsigned i = 0;\n+\n+\t/* get pointer to global configuration */\n+\tmcfg = rte_eal_get_configuration()->mem_config;\n+\n+\tfor (i = 0; i < RTE_MAX_MEMZONE; i++) {\n+\t\tif (mcfg->memzone[i].addr == NULL)\n+\t\t\treturn &mcfg->memzone[i];\n+\t}\n+\n+\treturn NULL;\n+}\n+\n /*\n  * Return a pointer to a correctly filled memzone descriptor. If the\n  * allocation cannot be done, return NULL.\n@@ -141,7 +158,7 @@ memzone_reserve_aligned_thread_unsafe(const char *name, size_t len,\n \tmcfg = rte_eal_get_configuration()->mem_config;\n \n \t/* no more room in config */\n-\tif (mcfg->memzone_idx >= RTE_MAX_MEMZONE) {\n+\tif (mcfg->memzone_cnt >= RTE_MAX_MEMZONE) {\n \t\tRTE_LOG(ERR, EAL, \"%s(): No more room in config\\n\", __func__);\n \t\trte_errno = ENOSPC;\n \t\treturn NULL;\n@@ -215,7 +232,16 @@ memzone_reserve_aligned_thread_unsafe(const char *name, size_t len,\n \tconst struct malloc_elem *elem = malloc_elem_from_data(mz_addr);\n \n \t/* fill the zone in config */\n-\tstruct rte_memzone *mz = &mcfg->memzone[mcfg->memzone_idx++];\n+\tstruct rte_memzone *mz = get_next_free_memzone();\n+\n+\tif (mz == NULL) {\n+\t\tRTE_LOG(ERR, EAL, \"%s(): Cannot find free memzone but there is room \"\n+\t\t\t\t\"in config!\\n\", __func__);\n+\t\trte_errno = ENOSPC;\n+\t\treturn NULL;\n+\t}\n+\n+\tmcfg->memzone_cnt++;\n \tsnprintf(mz->name, sizeof(mz->name), \"%s\", name);\n \tmz->phys_addr = rte_malloc_virt2phy(mz_addr);\n \tmz->addr = mz_addr;\n@@ -291,6 +317,41 @@ rte_memzone_reserve_bounded(const char *name, size_t len,\n \treturn mz;\n }\n \n+int\n+rte_memzone_free(const struct rte_memzone *mz)\n+{\n+\tstruct rte_mem_config *mcfg;\n+\tint ret = 0;\n+\tvoid *addr;\n+\tunsigned idx;\n+\n+\tif (mz == NULL)\n+\t\treturn -EINVAL;\n+\n+\tmcfg = rte_eal_get_configuration()->mem_config;\n+\n+\trte_rwlock_write_lock(&mcfg->mlock);\n+\n+\tidx = ((uintptr_t)mz - (uintptr_t)mcfg->memzone);\n+\tidx = idx / sizeof(struct rte_memzone);\n+\n+\taddr = mcfg->memzone[idx].addr;\n+\tif (addr == NULL)\n+\t\tret = -EINVAL;\n+\telse if (mcfg->memzone_cnt == 0) {\n+\t\trte_panic(\"%s(): memzone address not NULL but memzone_cnt is 0!\\n\",\n+\t\t\t\t__func__);\n+\t} else {\n+\t\tmemset(&mcfg->memzone[idx], 0, sizeof(mcfg->memzone[idx]));\n+\t\tmcfg->memzone_cnt--;\n+\t}\n+\n+\trte_rwlock_write_unlock(&mcfg->mlock);\n+\n+\trte_free(addr);\n+\n+\treturn ret;\n+}\n \n /*\n  * Lookup for the memzone identified by the given name\n@@ -364,7 +425,7 @@ rte_eal_memzone_init(void)\n \trte_rwlock_write_lock(&mcfg->mlock);\n \n \t/* delete all zones */\n-\tmcfg->memzone_idx = 0;\n+\tmcfg->memzone_cnt = 0;\n \tmemset(mcfg->memzone, 0, sizeof(mcfg->memzone));\n \n \trte_rwlock_write_unlock(&mcfg->mlock);\ndiff --git a/lib/librte_eal/common/include/rte_eal_memconfig.h b/lib/librte_eal/common/include/rte_eal_memconfig.h\nindex 7de906b..2b5e0b1 100644\n--- a/lib/librte_eal/common/include/rte_eal_memconfig.h\n+++ b/lib/librte_eal/common/include/rte_eal_memconfig.h\n@@ -67,7 +67,7 @@ struct rte_mem_config {\n \trte_rwlock_t qlock;   /**< used for tailq operation for thread safe. */\n \trte_rwlock_t mplock;  /**< only used by mempool LIB for thread-safe. */\n \n-\tuint32_t memzone_idx; /**< Index of memzone */\n+\tuint32_t memzone_cnt; /**< Number of allocated memzones */\n \n \t/* memory segments and zones */\n \tstruct rte_memseg memseg[RTE_MAX_MEMSEG];    /**< Physmem descriptors. */\ndiff --git a/lib/librte_eal/common/include/rte_memzone.h b/lib/librte_eal/common/include/rte_memzone.h\nindex ee62680..5223b1e 100644\n--- a/lib/librte_eal/common/include/rte_memzone.h\n+++ b/lib/librte_eal/common/include/rte_memzone.h\n@@ -240,6 +240,17 @@ const struct rte_memzone *rte_memzone_reserve_bounded(const char *name,\n \t\t\tunsigned flags, unsigned align, unsigned bound);\n \n /**\n+ * Free a memzone.\n+ *\n+ * @param mz\n+ *   A pointer to the memzone\n+ * @return\n+ *  -EINVAL - invalid parameter\n+ *  0 - success\n+ */\n+int rte_memzone_free(const struct rte_memzone *mz);\n+\n+/**\n  * Lookup for a memzone.\n  *\n  * Get a pointer to a descriptor of an already reserved memory\ndiff --git a/lib/librte_eal/linuxapp/eal/eal_ivshmem.c b/lib/librte_eal/linuxapp/eal/eal_ivshmem.c\nindex facfb80..589019b 100644\n--- a/lib/librte_eal/linuxapp/eal/eal_ivshmem.c\n+++ b/lib/librte_eal/linuxapp/eal/eal_ivshmem.c\n@@ -768,12 +768,12 @@ rte_eal_ivshmem_obj_init(void)\n \t\tseg = &ivshmem_config->segment[i];\n \n \t\t/* add memzone */\n-\t\tif (mcfg->memzone_idx == RTE_MAX_MEMZONE) {\n+\t\tif (mcfg->memzone_cnt == RTE_MAX_MEMZONE) {\n \t\t\tRTE_LOG(ERR, EAL, \"No more memory zones available!\\n\");\n \t\t\treturn -1;\n \t\t}\n \n-\t\tidx = mcfg->memzone_idx;\n+\t\tidx = mcfg->memzone_cnt;\n \n \t\tRTE_LOG(DEBUG, EAL, \"Found memzone: '%s' at %p (len 0x%\" PRIx64 \")\\n\",\n \t\t\t\tseg->entry.mz.name, seg->entry.mz.addr, seg->entry.mz.len);\n@@ -796,13 +796,13 @@ rte_eal_ivshmem_obj_init(void)\n \t\t\t}\n \t\t}\n \n-\t\tmcfg->memzone_idx++;\n+\t\tmcfg->memzone_cnt++;\n \t}\n \n \trte_rwlock_write_lock(RTE_EAL_TAILQ_RWLOCK);\n \n \t/* find rings */\n-\tfor (i = 0; i < mcfg->memzone_idx; i++) {\n+\tfor (i = 0; i < mcfg->memzone_cnt; i++) {\n \t\tmz = &mcfg->memzone[i];\n \n \t\t/* check if memzone has a ring prefix */\ndiff --git a/lib/librte_eal/linuxapp/eal/rte_eal_version.map b/lib/librte_eal/linuxapp/eal/rte_eal_version.map\nindex c107b05..e537b42 100644\n--- a/lib/librte_eal/linuxapp/eal/rte_eal_version.map\n+++ b/lib/librte_eal/linuxapp/eal/rte_eal_version.map\n@@ -111,3 +111,9 @@ DPDK_2.0 {\n \n \tlocal: *;\n };\n+\n+DPDK_2.1 {\n+\tglobal:\n+\n+\trte_memzone_free;\n+} DPDK_2.0;\n",
    "prefixes": [
        "dpdk-dev",
        "v6",
        "6/9"
    ]
}