get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

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

{
    "id": 45128,
    "url": "http://patches.dpdk.org/api/patches/45128/?format=api",
    "web_url": "http://patches.dpdk.org/project/dpdk/patch/46f70047246d838756d3a51d99b7f89c68577995.1537546029.git.anatoly.burakov@intel.com/",
    "project": {
        "id": 1,
        "url": "http://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": "<46f70047246d838756d3a51d99b7f89c68577995.1537546029.git.anatoly.burakov@intel.com>",
    "list_archive_url": "https://inbox.dpdk.org/dev/46f70047246d838756d3a51d99b7f89c68577995.1537546029.git.anatoly.burakov@intel.com",
    "date": "2018-09-21T16:14:02",
    "name": "[v4,13/20] malloc: allow adding memory to named heaps",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": true,
    "hash": "644e350b9b5044437e1534932a8565f49e21f254",
    "submitter": {
        "id": 4,
        "url": "http://patches.dpdk.org/api/people/4/?format=api",
        "name": "Burakov, Anatoly",
        "email": "anatoly.burakov@intel.com"
    },
    "delegate": {
        "id": 1,
        "url": "http://patches.dpdk.org/api/users/1/?format=api",
        "username": "tmonjalo",
        "first_name": "Thomas",
        "last_name": "Monjalon",
        "email": "thomas@monjalon.net"
    },
    "mbox": "http://patches.dpdk.org/project/dpdk/patch/46f70047246d838756d3a51d99b7f89c68577995.1537546029.git.anatoly.burakov@intel.com/mbox/",
    "series": [
        {
            "id": 1446,
            "url": "http://patches.dpdk.org/api/series/1446/?format=api",
            "web_url": "http://patches.dpdk.org/project/dpdk/list/?series=1446",
            "date": "2018-09-21T16:13:49",
            "name": "Support externally allocated memory in DPDK",
            "version": 4,
            "mbox": "http://patches.dpdk.org/series/1446/mbox/"
        }
    ],
    "comments": "http://patches.dpdk.org/api/patches/45128/comments/",
    "check": "fail",
    "checks": "http://patches.dpdk.org/api/patches/45128/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 [127.0.0.1])\n\tby dpdk.org (Postfix) with ESMTP id 0B96B5F51;\n\tFri, 21 Sep 2018 18:14:33 +0200 (CEST)",
            "from mga09.intel.com (mga09.intel.com [134.134.136.24])\n\tby dpdk.org (Postfix) with ESMTP id E7674F04\n\tfor <dev@dpdk.org>; Fri, 21 Sep 2018 18:14:16 +0200 (CEST)",
            "from fmsmga001.fm.intel.com ([10.253.24.23])\n\tby orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384;\n\t21 Sep 2018 09:14:15 -0700",
            "from irvmail001.ir.intel.com ([163.33.26.43])\n\tby fmsmga001.fm.intel.com with ESMTP; 21 Sep 2018 09:14:12 -0700",
            "from sivswdev01.ir.intel.com (sivswdev01.ir.intel.com\n\t[10.237.217.45])\n\tby irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id\n\tw8LGECpu029219; Fri, 21 Sep 2018 17:14:12 +0100",
            "from sivswdev01.ir.intel.com (localhost [127.0.0.1])\n\tby sivswdev01.ir.intel.com with ESMTP id w8LGEC1p002890;\n\tFri, 21 Sep 2018 17:14:12 +0100",
            "(from aburakov@localhost)\n\tby sivswdev01.ir.intel.com with LOCAL id w8LGECZu002886;\n\tFri, 21 Sep 2018 17:14:12 +0100"
        ],
        "X-Amp-Result": "SKIPPED(no attachment in message)",
        "X-Amp-File-Uploaded": "False",
        "X-ExtLoop1": "1",
        "X-IronPort-AV": "E=Sophos;i=\"5.54,285,1534834800\"; d=\"scan'208\";a=\"92144609\"",
        "From": "Anatoly Burakov <anatoly.burakov@intel.com>",
        "To": "dev@dpdk.org",
        "Cc": "laszlo.madarassy@ericsson.com, laszlo.vadkerti@ericsson.com,\n\tandras.kovacs@ericsson.com, winnie.tian@ericsson.com,\n\tdaniel.andrasi@ericsson.com, janos.kobor@ericsson.com,\n\tgeza.koblo@ericsson.com, srinath.mannam@broadcom.com,\n\tscott.branden@broadcom.com, ajit.khaparde@broadcom.com,\n\tkeith.wiles@intel.com, bruce.richardson@intel.com, thomas@monjalon.net,\n\tshreyansh.jain@nxp.com, shahafs@mellanox.com, arybchenko@solarflare.com",
        "Date": "Fri, 21 Sep 2018 17:14:02 +0100",
        "Message-Id": "<46f70047246d838756d3a51d99b7f89c68577995.1537546029.git.anatoly.burakov@intel.com>",
        "X-Mailer": "git-send-email 1.7.0.7",
        "In-Reply-To": [
            "<cover.1537546029.git.anatoly.burakov@intel.com>",
            "<cover.1537546029.git.anatoly.burakov@intel.com>"
        ],
        "References": [
            "<cover.1537546029.git.anatoly.burakov@intel.com>",
            "<cover.1537443103.git.anatoly.burakov@intel.com>\n\t<cover.1537546029.git.anatoly.burakov@intel.com>"
        ],
        "Subject": "[dpdk-dev] [PATCH v4 13/20] malloc: allow adding memory to named\n\theaps",
        "X-BeenThere": "dev@dpdk.org",
        "X-Mailman-Version": "2.1.15",
        "Precedence": "list",
        "List-Id": "DPDK patches and discussions <dev.dpdk.org>",
        "List-Unsubscribe": "<https://mails.dpdk.org/options/dev>,\n\t<mailto:dev-request@dpdk.org?subject=unsubscribe>",
        "List-Archive": "<http://mails.dpdk.org/archives/dev/>",
        "List-Post": "<mailto:dev@dpdk.org>",
        "List-Help": "<mailto:dev-request@dpdk.org?subject=help>",
        "List-Subscribe": "<https://mails.dpdk.org/listinfo/dev>,\n\t<mailto:dev-request@dpdk.org?subject=subscribe>",
        "Errors-To": "dev-bounces@dpdk.org",
        "Sender": "\"dev\" <dev-bounces@dpdk.org>"
    },
    "content": "Add an API to add externally allocated memory to malloc heap. The\nmemory will be stored in memseg lists like regular DPDK memory.\nMultiple segments are allowed within a heap. If IOVA table is\nnot provided, IOVA addresses are filled in with RTE_BAD_IOVA.\n\nSigned-off-by: Anatoly Burakov <anatoly.burakov@intel.com>\n---\n lib/librte_eal/common/include/rte_malloc.h | 39 ++++++++++++\n lib/librte_eal/common/malloc_heap.c        | 74 ++++++++++++++++++++++\n lib/librte_eal/common/malloc_heap.h        |  4 ++\n lib/librte_eal/common/rte_malloc.c         | 51 +++++++++++++++\n lib/librte_eal/rte_eal_version.map         |  1 +\n 5 files changed, 169 insertions(+)",
    "diff": "diff --git a/lib/librte_eal/common/include/rte_malloc.h b/lib/librte_eal/common/include/rte_malloc.h\nindex 309bbbcc9..fb5b6e2f7 100644\n--- a/lib/librte_eal/common/include/rte_malloc.h\n+++ b/lib/librte_eal/common/include/rte_malloc.h\n@@ -263,6 +263,45 @@ int\n rte_malloc_get_socket_stats(int socket,\n \t\tstruct rte_malloc_socket_stats *socket_stats);\n \n+/**\n+ * Add memory chunk to a heap with specified name.\n+ *\n+ * @note Multiple memory chunks can be added to the same heap\n+ *\n+ * @note Memory must be previously allocated for DPDK to be able to use it as a\n+ *   malloc heap. Failing to do so will result in undefined behavior, up to and\n+ *   including segmentation faults.\n+ *\n+ * @note Calling this function will erase any contents already present at the\n+ *   supplied memory address.\n+ *\n+ * @param heap_name\n+ *   Name of the heap to add memory chunk to\n+ * @param va_addr\n+ *   Start of virtual area to add to the heap\n+ * @param len\n+ *   Length of virtual area to add to the heap\n+ * @param iova_addrs\n+ *   Array of page IOVA addresses corresponding to each page in this memory\n+ *   area. Can be NULL, in which case page IOVA addresses will be set to\n+ *   RTE_BAD_IOVA.\n+ * @param n_pages\n+ *   Number of elements in the iova_addrs array. Ignored if  ``iova_addrs``\n+ *   is NULL.\n+ * @param page_sz\n+ *   Page size of the underlying memory\n+ *\n+ * @return\n+ *   - 0 on success\n+ *   - -1 in case of error, with rte_errno set to one of the following:\n+ *     EINVAL - one of the parameters was invalid\n+ *     EPERM  - attempted to add memory to a reserved heap\n+ *     ENOSPC - no more space in internal config to store a new memory chunk\n+ */\n+int __rte_experimental\n+rte_malloc_heap_memory_add(const char *heap_name, void *va_addr, size_t len,\n+\t\trte_iova_t iova_addrs[], unsigned int n_pages, size_t page_sz);\n+\n /**\n  * Creates a new empty malloc heap with a specified name.\n  *\ndiff --git a/lib/librte_eal/common/malloc_heap.c b/lib/librte_eal/common/malloc_heap.c\nindex e98f720cb..2f6946f65 100644\n--- a/lib/librte_eal/common/malloc_heap.c\n+++ b/lib/librte_eal/common/malloc_heap.c\n@@ -1019,6 +1019,80 @@ malloc_heap_dump(struct malloc_heap *heap, FILE *f)\n \trte_spinlock_unlock(&heap->lock);\n }\n \n+int\n+malloc_heap_add_external_memory(struct malloc_heap *heap, void *va_addr,\n+\t\trte_iova_t iova_addrs[], unsigned int n_pages, size_t page_sz)\n+{\n+\tstruct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;\n+\tchar fbarray_name[RTE_FBARRAY_NAME_LEN];\n+\tstruct rte_memseg_list *msl = NULL;\n+\tstruct rte_fbarray *arr;\n+\tsize_t seg_len = n_pages * page_sz;\n+\tunsigned int i;\n+\n+\t/* first, find a free memseg list */\n+\tfor (i = 0; i < RTE_MAX_MEMSEG_LISTS; i++) {\n+\t\tstruct rte_memseg_list *tmp = &mcfg->memsegs[i];\n+\t\tif (tmp->base_va == NULL) {\n+\t\t\tmsl = tmp;\n+\t\t\tbreak;\n+\t\t}\n+\t}\n+\tif (msl == NULL) {\n+\t\tRTE_LOG(ERR, EAL, \"Couldn't find empty memseg list\\n\");\n+\t\trte_errno = ENOSPC;\n+\t\treturn -1;\n+\t}\n+\n+\tsnprintf(fbarray_name, sizeof(fbarray_name) - 1, \"%s_%p\",\n+\t\t\theap->name, va_addr);\n+\n+\t/* create the backing fbarray */\n+\tif (rte_fbarray_init(&msl->memseg_arr, fbarray_name, n_pages,\n+\t\t\tsizeof(struct rte_memseg)) < 0) {\n+\t\tRTE_LOG(ERR, EAL, \"Couldn't create fbarray backing the memseg list\\n\");\n+\t\treturn -1;\n+\t}\n+\tarr = &msl->memseg_arr;\n+\n+\t/* fbarray created, fill it up */\n+\tfor (i = 0; i < n_pages; i++) {\n+\t\tstruct rte_memseg *ms;\n+\n+\t\trte_fbarray_set_used(arr, i);\n+\t\tms = rte_fbarray_get(arr, i);\n+\t\tms->addr = RTE_PTR_ADD(va_addr, i * page_sz);\n+\t\tms->iova = iova_addrs == NULL ? RTE_BAD_IOVA : iova_addrs[i];\n+\t\tms->hugepage_sz = page_sz;\n+\t\tms->len = page_sz;\n+\t\tms->nchannel = rte_memory_get_nchannel();\n+\t\tms->nrank = rte_memory_get_nrank();\n+\t\tms->socket_id = heap->socket_id;\n+\t}\n+\n+\t/* set up the memseg list */\n+\tmsl->base_va = va_addr;\n+\tmsl->page_sz = page_sz;\n+\tmsl->socket_id = heap->socket_id;\n+\tmsl->len = seg_len;\n+\tmsl->version = 0;\n+\tmsl->external = 1;\n+\n+\t/* erase contents of new memory */\n+\tmemset(va_addr, 0, seg_len);\n+\n+\t/* now, add newly minted memory to the malloc heap */\n+\tmalloc_heap_add_memory(heap, msl, va_addr, seg_len);\n+\n+\theap->total_size += seg_len;\n+\n+\t/* all done! */\n+\tRTE_LOG(DEBUG, EAL, \"Added segment for heap %s starting at %p\\n\",\n+\t\t\theap->name, va_addr);\n+\n+\treturn 0;\n+}\n+\n int\n malloc_heap_create(struct malloc_heap *heap, const char *heap_name)\n {\ndiff --git a/lib/librte_eal/common/malloc_heap.h b/lib/librte_eal/common/malloc_heap.h\nindex 75278da3c..237ce9dc2 100644\n--- a/lib/librte_eal/common/malloc_heap.h\n+++ b/lib/librte_eal/common/malloc_heap.h\n@@ -39,6 +39,10 @@ malloc_heap_create(struct malloc_heap *heap, const char *heap_name);\n int\n malloc_heap_destroy(struct malloc_heap *heap);\n \n+int\n+malloc_heap_add_external_memory(struct malloc_heap *heap, void *va_addr,\n+\t\trte_iova_t iova_addrs[], unsigned int n_pages, size_t page_sz);\n+\n int\n malloc_heap_free(struct malloc_elem *elem);\n \ndiff --git a/lib/librte_eal/common/rte_malloc.c b/lib/librte_eal/common/rte_malloc.c\nindex 286e748ef..acdbd92a2 100644\n--- a/lib/librte_eal/common/rte_malloc.c\n+++ b/lib/librte_eal/common/rte_malloc.c\n@@ -328,6 +328,57 @@ find_named_heap(const char *name)\n \treturn NULL;\n }\n \n+int\n+rte_malloc_heap_memory_add(const char *heap_name, void *va_addr, size_t len,\n+\t\trte_iova_t iova_addrs[], unsigned int n_pages, size_t page_sz)\n+{\n+\tstruct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;\n+\tstruct malloc_heap *heap = NULL;\n+\tunsigned int n;\n+\tint ret;\n+\n+\tif (heap_name == NULL || va_addr == NULL ||\n+\t\t\tpage_sz == 0 || !rte_is_power_of_2(page_sz) ||\n+\t\t\tstrnlen(heap_name, RTE_HEAP_NAME_MAX_LEN) == 0 ||\n+\t\t\tstrnlen(heap_name, RTE_HEAP_NAME_MAX_LEN) ==\n+\t\t\t\tRTE_HEAP_NAME_MAX_LEN) {\n+\t\trte_errno = EINVAL;\n+\t\tret = -1;\n+\t\tgoto unlock;\n+\t}\n+\trte_rwlock_write_lock(&mcfg->memory_hotplug_lock);\n+\n+\t/* find our heap */\n+\theap = find_named_heap(heap_name);\n+\tif (heap == NULL) {\n+\t\trte_errno = ENOENT;\n+\t\tret = -1;\n+\t\tgoto unlock;\n+\t}\n+\tif (heap->socket_id < RTE_MAX_NUMA_NODES) {\n+\t\t/* cannot add memory to internal heaps */\n+\t\trte_errno = EPERM;\n+\t\tret = -1;\n+\t\tgoto unlock;\n+\t}\n+\tn = len / page_sz;\n+\tif (n != n_pages && iova_addrs != NULL) {\n+\t\trte_errno = EINVAL;\n+\t\tret = -1;\n+\t\tgoto unlock;\n+\t}\n+\n+\trte_spinlock_lock(&heap->lock);\n+\tret = malloc_heap_add_external_memory(heap, va_addr, iova_addrs, n,\n+\t\t\tpage_sz);\n+\trte_spinlock_unlock(&heap->lock);\n+\n+unlock:\n+\trte_rwlock_write_unlock(&mcfg->memory_hotplug_lock);\n+\n+\treturn ret;\n+}\n+\n int\n rte_malloc_heap_create(const char *heap_name)\n {\ndiff --git a/lib/librte_eal/rte_eal_version.map b/lib/librte_eal/rte_eal_version.map\nindex 27aac5bea..02254042c 100644\n--- a/lib/librte_eal/rte_eal_version.map\n+++ b/lib/librte_eal/rte_eal_version.map\n@@ -321,6 +321,7 @@ EXPERIMENTAL {\n \trte_malloc_heap_create;\n \trte_malloc_heap_destroy;\n \trte_malloc_heap_get_socket;\n+\trte_malloc_heap_memory_add;\n \trte_malloc_heap_socket_is_external;\n \trte_mem_alloc_validator_register;\n \trte_mem_alloc_validator_unregister;\n",
    "prefixes": [
        "v4",
        "13/20"
    ]
}