get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

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

{
    "id": 94350,
    "url": "https://patches.dpdk.org/api/patches/94350/?format=api",
    "web_url": "https://patches.dpdk.org/project/dpdk/patch/20210617105845.125472-6-maxime.coquelin@redhat.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": "<20210617105845.125472-6-maxime.coquelin@redhat.com>",
    "list_archive_url": "https://inbox.dpdk.org/dev/20210617105845.125472-6-maxime.coquelin@redhat.com",
    "date": "2021-06-17T10:58:43",
    "name": "[5/7] vhost: improve NUMA reallocation",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": true,
    "hash": "9a715e5458f2cf614ad02466c2a92d97ee972775",
    "submitter": {
        "id": 512,
        "url": "https://patches.dpdk.org/api/people/512/?format=api",
        "name": "Maxime Coquelin",
        "email": "maxime.coquelin@redhat.com"
    },
    "delegate": {
        "id": 2642,
        "url": "https://patches.dpdk.org/api/users/2642/?format=api",
        "username": "mcoquelin",
        "first_name": "Maxime",
        "last_name": "Coquelin",
        "email": "maxime.coquelin@redhat.com"
    },
    "mbox": "https://patches.dpdk.org/project/dpdk/patch/20210617105845.125472-6-maxime.coquelin@redhat.com/mbox/",
    "series": [
        {
            "id": 17373,
            "url": "https://patches.dpdk.org/api/series/17373/?format=api",
            "web_url": "https://patches.dpdk.org/project/dpdk/list/?series=17373",
            "date": "2021-06-17T10:58:38",
            "name": "vhost: Fix and improve NUMA reallocation",
            "version": 1,
            "mbox": "https://patches.dpdk.org/series/17373/mbox/"
        }
    ],
    "comments": "https://patches.dpdk.org/api/patches/94350/comments/",
    "check": "success",
    "checks": "https://patches.dpdk.org/api/patches/94350/checks/",
    "tags": {},
    "related": [],
    "headers": {
        "Return-Path": "<dev-bounces@dpdk.org>",
        "X-Original-To": "patchwork@inbox.dpdk.org",
        "Delivered-To": "patchwork@inbox.dpdk.org",
        "Received": [
            "from mails.dpdk.org (mails.dpdk.org [217.70.189.124])\n\tby inbox.dpdk.org (Postfix) with ESMTP id 9FAB7A0C4D;\n\tThu, 17 Jun 2021 13:01:05 +0200 (CEST)",
            "from [217.70.189.124] (localhost [127.0.0.1])\n\tby mails.dpdk.org (Postfix) with ESMTP id DF5D741199;\n\tThu, 17 Jun 2021 12:59:06 +0200 (CEST)",
            "from us-smtp-delivery-124.mimecast.com\n (us-smtp-delivery-124.mimecast.com [170.10.133.124])\n by mails.dpdk.org (Postfix) with ESMTP id 2320241187\n for <dev@dpdk.org>; Thu, 17 Jun 2021 12:59:05 +0200 (CEST)",
            "from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com\n [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id\n us-mta-558-7Dt5qGEeN8ymvTQwArFlQg-1; Thu, 17 Jun 2021 06:59:01 -0400",
            "from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com\n [10.5.11.12])\n (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits))\n (No client certificate requested)\n by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B5B0380EDB1;\n Thu, 17 Jun 2021 10:58:58 +0000 (UTC)",
            "from max-t490s.redhat.com (unknown [10.36.110.45])\n by smtp.corp.redhat.com (Postfix) with ESMTP id 9AD5D60E3A;\n Thu, 17 Jun 2021 10:58:57 +0000 (UTC)"
        ],
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n s=mimecast20190719; t=1623927544;\n h=from:from:reply-to:subject:subject:date:date:message-id:message-id:\n to:to:cc:cc:mime-version:mime-version:content-type:content-type:\n content-transfer-encoding:content-transfer-encoding:\n in-reply-to:in-reply-to:references:references;\n bh=E0+sO/kOVMFWMqSyGAIC6ojuPpfGQFUZYlxpy+BWn+I=;\n b=dAh8/PgXNlOU4rGZuR7e/LQO/IhSwntS0i7N7/dtuQKwmuFzjgkjjJ0TXuc4JEtMuo/Ahr\n rc+FwgnKPKFp3Hby8VxEd7w0V5Jah9bnpxMtbKg8IMcln1WJ7emGwrRjQ7a4J55Wn189fx\n x1zYCrIShtYz1KquZ1ldyrc5+R++9D0=",
        "X-MC-Unique": "7Dt5qGEeN8ymvTQwArFlQg-1",
        "From": "Maxime Coquelin <maxime.coquelin@redhat.com>",
        "To": "dev@dpdk.org,\n\tdavid.marchand@redhat.com,\n\tchenbo.xia@intel.com",
        "Cc": "Maxime Coquelin <maxime.coquelin@redhat.com>",
        "Date": "Thu, 17 Jun 2021 12:58:43 +0200",
        "Message-Id": "<20210617105845.125472-6-maxime.coquelin@redhat.com>",
        "In-Reply-To": "<20210617105845.125472-1-maxime.coquelin@redhat.com>",
        "References": "<20210617105845.125472-1-maxime.coquelin@redhat.com>",
        "MIME-Version": "1.0",
        "X-Scanned-By": "MIMEDefang 2.79 on 10.5.11.12",
        "Authentication-Results": "relay.mimecast.com;\n auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=maxime.coquelin@redhat.com",
        "X-Mimecast-Spam-Score": "0",
        "X-Mimecast-Originator": "redhat.com",
        "Content-Transfer-Encoding": "8bit",
        "Content-Type": "text/plain; charset=\"US-ASCII\"",
        "Subject": "[dpdk-dev] [PATCH 5/7] vhost: improve NUMA reallocation",
        "X-BeenThere": "dev@dpdk.org",
        "X-Mailman-Version": "2.1.29",
        "Precedence": "list",
        "List-Id": "DPDK patches and discussions <dev.dpdk.org>",
        "List-Unsubscribe": "<https://mails.dpdk.org/options/dev>,\n <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 <mailto:dev-request@dpdk.org?subject=subscribe>",
        "Errors-To": "dev-bounces@dpdk.org",
        "Sender": "\"dev\" <dev-bounces@dpdk.org>"
    },
    "content": "This patch improves the numa_realloc() function by making use\nof rte_realloc_socket(), which takes care of the memory copy\nand freeing of the old data.\n\nSuggested-by: David Marchand <david.marchand@redhat.com>\nSigned-off-by: Maxime Coquelin <maxime.coquelin@redhat.com>\n---\n lib/vhost/vhost_user.c | 190 +++++++++++++++++------------------------\n 1 file changed, 80 insertions(+), 110 deletions(-)",
    "diff": "diff --git a/lib/vhost/vhost_user.c b/lib/vhost/vhost_user.c\nindex 6e7b327ef8..50830f0870 100644\n--- a/lib/vhost/vhost_user.c\n+++ b/lib/vhost/vhost_user.c\n@@ -480,144 +480,114 @@ vhost_user_set_vring_num(struct virtio_net **pdev,\n static struct virtio_net*\n numa_realloc(struct virtio_net *dev, int index)\n {\n-\tint oldnode, newnode;\n+\tint node;\n \tstruct virtio_net *old_dev;\n-\tstruct vhost_virtqueue *old_vq, *vq;\n-\tstruct vring_used_elem *new_shadow_used_split;\n-\tstruct vring_used_elem_packed *new_shadow_used_packed;\n-\tstruct batch_copy_elem *new_batch_copy_elems;\n+\tstruct vhost_virtqueue *vq;\n+\tstruct batch_copy_elem *bce;\n+\tstruct guest_page *gp;\n+\tstruct rte_vhost_memory *mem;\n+\tsize_t mem_size;\n \tint ret;\n \n \told_dev = dev;\n-\tvq = old_vq = dev->virtqueue[index];\n-\n-\tret = get_mempolicy(&newnode, NULL, 0, old_vq->desc,\n-\t\t\t    MPOL_F_NODE | MPOL_F_ADDR);\n+\tvq = dev->virtqueue[index];\n \n-\t/* check if we need to reallocate vq */\n-\tret |= get_mempolicy(&oldnode, NULL, 0, old_vq,\n-\t\t\t     MPOL_F_NODE | MPOL_F_ADDR);\n+\tret = get_mempolicy(&node, NULL, 0, vq->desc, MPOL_F_NODE | MPOL_F_ADDR);\n \tif (ret) {\n-\t\tVHOST_LOG_CONFIG(ERR,\n-\t\t\t\"Unable to get vq numa information.\\n\");\n+\t\tVHOST_LOG_CONFIG(ERR, \"Unable to get virtqueue %d numa information.\\n\", index);\n \t\treturn dev;\n \t}\n-\tif (oldnode != newnode) {\n-\t\tif (vq->ready) {\n-\t\t\tvq->ready = false;\n-\t\t\tvhost_user_notify_queue_state(dev, index, 0);\n-\t\t}\n \n-\t\tVHOST_LOG_CONFIG(INFO,\n-\t\t\t\"reallocate vq from %d to %d node\\n\", oldnode, newnode);\n-\t\tvq = rte_malloc_socket(NULL, sizeof(*vq), 0, newnode);\n-\t\tif (!vq)\n-\t\t\treturn dev;\n+\tif (vq->ready) {\n+\t\tvq->ready = false;\n+\t\tvhost_user_notify_queue_state(dev, index, 0);\n+\t}\n+\n+\tvq = rte_realloc_socket(vq, sizeof(*vq), 0, node);\n+\tif (!vq) {\n+\t\tVHOST_LOG_CONFIG(ERR, \"Failed to realloc virtqueue %d on node %d\\n\",\n+\t\t\t\tindex, node);\n+\t\treturn dev;\n+\t}\n \n-\t\tmemcpy(vq, old_vq, sizeof(*vq));\n+\tif (vq != dev->virtqueue[index]) {\n+\t\tVHOST_LOG_CONFIG(INFO, \"reallocated virtqueue on node %d\\n\", node);\n+\t\tdev->virtqueue[index] = vq;\n+\t\tvhost_user_iotlb_init(dev, index);\n+\t}\n \n-\t\tif (vq_is_packed(dev)) {\n-\t\t\tnew_shadow_used_packed = rte_malloc_socket(NULL,\n-\t\t\t\t\tvq->size *\n-\t\t\t\t\tsizeof(struct vring_used_elem_packed),\n-\t\t\t\t\tRTE_CACHE_LINE_SIZE,\n-\t\t\t\t\tnewnode);\n-\t\t\tif (new_shadow_used_packed) {\n-\t\t\t\trte_free(vq->shadow_used_packed);\n-\t\t\t\tvq->shadow_used_packed = new_shadow_used_packed;\n-\t\t\t}\n-\t\t} else {\n-\t\t\tnew_shadow_used_split = rte_malloc_socket(NULL,\n-\t\t\t\t\tvq->size *\n-\t\t\t\t\tsizeof(struct vring_used_elem),\n-\t\t\t\t\tRTE_CACHE_LINE_SIZE,\n-\t\t\t\t\tnewnode);\n-\t\t\tif (new_shadow_used_split) {\n-\t\t\t\trte_free(vq->shadow_used_split);\n-\t\t\t\tvq->shadow_used_split = new_shadow_used_split;\n-\t\t\t}\n-\t\t}\n+\tif (vq_is_packed(dev)) {\n+\t\tstruct vring_used_elem_packed *sup;\n \n-\t\tnew_batch_copy_elems = rte_malloc_socket(NULL,\n-\t\t\tvq->size * sizeof(struct batch_copy_elem),\n-\t\t\tRTE_CACHE_LINE_SIZE,\n-\t\t\tnewnode);\n-\t\tif (new_batch_copy_elems) {\n-\t\t\trte_free(vq->batch_copy_elems);\n-\t\t\tvq->batch_copy_elems = new_batch_copy_elems;\n+\t\tsup = rte_realloc_socket(vq->shadow_used_packed, vq->size * sizeof(*sup),\n+\t\t\t\tRTE_CACHE_LINE_SIZE, node);\n+\t\tif (!sup) {\n+\t\t\tVHOST_LOG_CONFIG(ERR, \"Failed to realloc shadow packed on node %d\\n\", node);\n+\t\t\treturn dev;\n \t\t}\n+\t\tvq->shadow_used_packed = sup;\n \n-\t\tif (vq->log_cache) {\n-\t\t\tstruct log_cache_entry *log_cache;\n+\t} else {\n+\t\tstruct vring_used_elem *sus;\n \n-\t\t\tlog_cache = rte_realloc_socket(vq->log_cache,\n-\t\t\t\t\tsizeof(struct log_cache_entry) * VHOST_LOG_CACHE_NR,\n-\t\t\t\t\t0, newnode);\n-\t\t\tif (log_cache)\n-\t\t\t\tvq->log_cache = log_cache;\n+\t\tsus = rte_realloc_socket(vq->shadow_used_split, vq->size * sizeof(*sus),\n+\t\t\t\tRTE_CACHE_LINE_SIZE, node);\n+\t\tif (!sus) {\n+\t\t\tVHOST_LOG_CONFIG(ERR, \"Failed to realloc shadow split on node %d\\n\", node);\n+\t\t\treturn dev;\n \t\t}\n-\n-\t\trte_free(old_vq);\n+\t\tvq->shadow_used_split = sus;\n \t}\n \n-\tif (dev->flags & VIRTIO_DEV_RUNNING)\n-\t\tgoto out;\n-\n-\t/* check if we need to reallocate dev */\n-\tret = get_mempolicy(&oldnode, NULL, 0, old_dev,\n-\t\t\t    MPOL_F_NODE | MPOL_F_ADDR);\n-\tif (ret) {\n-\t\tVHOST_LOG_CONFIG(ERR,\n-\t\t\t\"Unable to get dev numa information.\\n\");\n-\t\tgoto out;\n+\tbce = rte_realloc_socket(vq->batch_copy_elems, vq->size * sizeof(*bce),\n+\t\t\tRTE_CACHE_LINE_SIZE, node);\n+\tif (!bce) {\n+\t\tVHOST_LOG_CONFIG(ERR, \"Failed to realloc batch copy elem on node %d\\n\", node);\n+\t\treturn dev;\n \t}\n-\tif (oldnode != newnode) {\n-\t\tstruct rte_vhost_memory *old_mem;\n-\t\tstruct guest_page *old_gp;\n-\t\tssize_t mem_size, gp_size;\n-\n-\t\tVHOST_LOG_CONFIG(INFO,\n-\t\t\t\"reallocate dev from %d to %d node\\n\",\n-\t\t\toldnode, newnode);\n-\t\tdev = rte_malloc_socket(NULL, sizeof(*dev), 0, newnode);\n-\t\tif (!dev) {\n-\t\t\tdev = old_dev;\n-\t\t\tgoto out;\n-\t\t}\n+\tvq->batch_copy_elems = bce;\n \n-\t\tmemcpy(dev, old_dev, sizeof(*dev));\n-\t\trte_free(old_dev);\n+\tif (vq->log_cache) {\n+\t\tstruct log_cache_entry *lc;\n \n-\t\tmem_size = sizeof(struct rte_vhost_memory) +\n-\t\t\tsizeof(struct rte_vhost_mem_region) * dev->mem->nregions;\n-\t\told_mem = dev->mem;\n-\t\tdev->mem = rte_malloc_socket(NULL, mem_size, 0, newnode);\n-\t\tif (!dev->mem) {\n-\t\t\tdev->mem = old_mem;\n-\t\t\tgoto out;\n+\t\tlc = rte_realloc_socket(vq->log_cache, sizeof(*lc) * VHOST_LOG_CACHE_NR, 0, node);\n+\t\tif (!lc) {\n+\t\t\tVHOST_LOG_CONFIG(ERR, \"Failed to realloc log cache on node %d\\n\", node);\n+\t\t\treturn dev;\n \t\t}\n+\t\tvq->log_cache = lc;\n+\t}\n \n-\t\tmemcpy(dev->mem, old_mem, mem_size);\n-\t\trte_free(old_mem);\n+\tif (dev->flags & VIRTIO_DEV_RUNNING)\n+\t\treturn dev;\n \n-\t\tgp_size = dev->max_guest_pages * sizeof(*dev->guest_pages);\n-\t\told_gp = dev->guest_pages;\n-\t\tdev->guest_pages = rte_malloc_socket(NULL, gp_size, RTE_CACHE_LINE_SIZE, newnode);\n-\t\tif (!dev->guest_pages) {\n-\t\t\tdev->guest_pages = old_gp;\n-\t\t\tgoto out;\n-\t\t}\n+\tdev = rte_realloc_socket(old_dev, sizeof(*dev), 0, node);\n+\tif (!dev) {\n+\t\tVHOST_LOG_CONFIG(ERR, \"Failed to realloc dev on node %d\\n\", node);\n+\t\treturn old_dev;\n+\t}\n \n-\t\tmemcpy(dev->guest_pages, old_gp, gp_size);\n-\t\trte_free(old_gp);\n+\tif (dev != old_dev) {\n+\t\tVHOST_LOG_CONFIG(INFO, \"reallocated device on node %d\\n\", node);\n+\t\tvhost_devices[dev->vid] = dev;\n \t}\n \n-out:\n-\tdev->virtqueue[index] = vq;\n-\tvhost_devices[dev->vid] = dev;\n+\tmem_size = sizeof(struct rte_vhost_memory) +\n+\t\tsizeof(struct rte_vhost_mem_region) * dev->mem->nregions;\n+\tmem = rte_realloc_socket(dev->mem, mem_size, 0, node);\n+\tif (!mem) {\n+\t\tVHOST_LOG_CONFIG(ERR, \"Failed to realloc mem table on node %d\\n\", node);\n+\t\treturn dev;\n+\t}\n+\tdev->mem = mem;\n \n-\tif (old_vq != vq)\n-\t\tvhost_user_iotlb_init(dev, index);\n+\tgp = rte_realloc_socket(dev->guest_pages, dev->max_guest_pages * sizeof(*gp),\n+\t\t\tRTE_CACHE_LINE_SIZE, node);\n+\tif (!gp) {\n+\t\tVHOST_LOG_CONFIG(ERR, \"Failed to realloc guest pages on node %d\\n\", node);\n+\t\treturn dev;\n+\t}\n+\tdev->guest_pages = gp;\n \n \treturn dev;\n }\n",
    "prefixes": [
        "5/7"
    ]
}