get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

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

{
    "id": 5239,
    "url": "https://patches.dpdk.org/api/patches/5239/?format=api",
    "web_url": "https://patches.dpdk.org/project/dpdk/patch/1433586732-28217-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": "<1433586732-28217-7-git-send-email-sergio.gonzalez.monroy@intel.com>",
    "list_archive_url": "https://inbox.dpdk.org/dev/1433586732-28217-7-git-send-email-sergio.gonzalez.monroy@intel.com",
    "date": "2015-06-06T10:32:11",
    "name": "[dpdk-dev,v2,6/7] eal: new rte_memzone_free",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": true,
    "hash": "97ea8c75513b6c4367ed852dbe6517bc6d53587a",
    "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/1433586732-28217-7-git-send-email-sergio.gonzalez.monroy@intel.com/mbox/",
    "series": [],
    "comments": "https://patches.dpdk.org/api/patches/5239/comments/",
    "check": "pending",
    "checks": "https://patches.dpdk.org/api/patches/5239/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 A8516C3B4;\n\tSat,  6 Jun 2015 12:32:22 +0200 (CEST)",
            "from mga03.intel.com (mga03.intel.com [134.134.136.65])\n\tby dpdk.org (Postfix) with ESMTP id 24AF9C376\n\tfor <dev@dpdk.org>; Sat,  6 Jun 2015 12:32:16 +0200 (CEST)",
            "from fmsmga002.fm.intel.com ([10.253.24.26])\n\tby orsmga103.jf.intel.com with ESMTP; 06 Jun 2015 03:32:16 -0700",
            "from irvmail001.ir.intel.com ([163.33.26.43])\n\tby fmsmga002.fm.intel.com with ESMTP; 06 Jun 2015 03:32:14 -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\tt56AWDeC024227; Sat, 6 Jun 2015 11:32:13 +0100",
            "from sivswdev02.ir.intel.com (localhost [127.0.0.1])\n\tby sivswdev02.ir.intel.com with ESMTP id t56AWDmL028300;\n\tSat, 6 Jun 2015 11:32:13 +0100",
            "(from smonroy@localhost)\n\tby sivswdev02.ir.intel.com with  id t56AWDcY028296;\n\tSat, 6 Jun 2015 11:32:13 +0100"
        ],
        "X-ExtLoop1": "1",
        "X-IronPort-AV": "E=Sophos;i=\"5.13,563,1427785200\"; d=\"scan'208\";a=\"738233870\"",
        "From": "Sergio Gonzalez Monroy <sergio.gonzalez.monroy@intel.com>",
        "To": "dev@dpdk.org",
        "Date": "Sat,  6 Jun 2015 11:32:11 +0100",
        "Message-Id": "<1433586732-28217-7-git-send-email-sergio.gonzalez.monroy@intel.com>",
        "X-Mailer": "git-send-email 1.8.5.4",
        "In-Reply-To": "<1433586732-28217-1-git-send-email-sergio.gonzalez.monroy@intel.com>",
        "References": "<1431103079-18096-1-git-send-email-sergio.gonzalez.monroy@intel.com>\n\t<1433586732-28217-1-git-send-email-sergio.gonzalez.monroy@intel.com>",
        "Subject": "[dpdk-dev] [PATCH v2 6/7] 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        | 50 +++++++++++++++++++++--\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         | 28 +++++++++++--\n lib/librte_eal/linuxapp/eal/rte_eal_version.map   |  6 +++\n 6 files changed, 95 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 742f6c9..0b458ec 100644\n--- a/lib/librte_eal/common/eal_common_memzone.c\n+++ b/lib/librte_eal/common/eal_common_memzone.c\n@@ -76,6 +76,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 && mcfg->memzone[i].addr != NULL; i++);\n+\n+\tif (i < RTE_MAX_MEMZONE)\n+\t\treturn &mcfg->memzone[i];\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@@ -140,7 +157,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@@ -214,7 +231,8 @@ 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+\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@@ -290,6 +308,32 @@ 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_read_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+\tmcfg->memzone[idx].addr = NULL;\n+\trte_free(addr);\n+\n+\trte_rwlock_read_unlock(&mcfg->mlock);\n+\n+\treturn ret;\n+}\n \n /*\n  * Lookup for the memzone identified by the given name\n@@ -363,7 +407,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 055212a..2015074 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 81b6ad4..3f54bde 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 - sucess\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..db021c7 100644\n--- a/lib/librte_eal/linuxapp/eal/eal_ivshmem.c\n+++ b/lib/librte_eal/linuxapp/eal/eal_ivshmem.c\n@@ -735,6 +735,23 @@ map_all_segments(void)\n \treturn 0;\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 && mcfg->memzone[i].addr != NULL; i++);\n+\n+\tif (i < RTE_MAX_MEMZONE)\n+\t\treturn &mcfg->memzone[i];\n+\n+\treturn NULL;\n+}\n+\n /* this happens at a later stage, after general EAL memory initialization */\n int\n rte_eal_ivshmem_obj_init(void)\n@@ -768,12 +785,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 = get_next_free_memzone();\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,15 +813,18 @@ 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 < RTE_MAX_MEMZONE; i++) {\n \t\tmz = &mcfg->memzone[i];\n \n+\t\tif (mz->addr == NULL)\n+\t\t\tcontinue;\n+\n \t\t/* check if memzone has a ring prefix */\n \t\tif (strncmp(mz->name, RTE_RING_MZ_PREFIX,\n \t\t\t\tsizeof(RTE_RING_MZ_PREFIX) - 1) != 0)\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",
        "v2",
        "6/7"
    ]
}