get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

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

{
    "id": 806352,
    "url": "http://patchwork.ozlabs.org/api/patches/806352/?format=api",
    "web_url": "http://patchwork.ozlabs.org/project/qemu-devel/patch/20170828035327.17146-2-bobby.prani@gmail.com/",
    "project": {
        "id": 14,
        "url": "http://patchwork.ozlabs.org/api/projects/14/?format=api",
        "name": "QEMU Development",
        "link_name": "qemu-devel",
        "list_id": "qemu-devel.nongnu.org",
        "list_email": "qemu-devel@nongnu.org",
        "web_url": "",
        "scm_url": "",
        "webscm_url": "",
        "list_archive_url": "",
        "list_archive_url_format": "",
        "commit_url_format": ""
    },
    "msgid": "<20170828035327.17146-2-bobby.prani@gmail.com>",
    "list_archive_url": null,
    "date": "2017-08-28T03:53:25",
    "name": "[RFC,2/3] cpus-common: Cache allocated work items",
    "commit_ref": null,
    "pull_url": null,
    "state": "new",
    "archived": false,
    "hash": "6b3bce992300a9df49b2a7d9db20779e427f730a",
    "submitter": {
        "id": 64653,
        "url": "http://patchwork.ozlabs.org/api/people/64653/?format=api",
        "name": "Pranith Kumar",
        "email": "bobby.prani@gmail.com"
    },
    "delegate": null,
    "mbox": "http://patchwork.ozlabs.org/project/qemu-devel/patch/20170828035327.17146-2-bobby.prani@gmail.com/mbox/",
    "series": [
        {
            "id": 62,
            "url": "http://patchwork.ozlabs.org/api/series/62/?format=api",
            "web_url": "http://patchwork.ozlabs.org/project/qemu-devel/list/?series=62",
            "date": "2017-08-28T03:53:25",
            "name": null,
            "version": 1,
            "mbox": "http://patchwork.ozlabs.org/series/62/mbox/"
        }
    ],
    "comments": "http://patchwork.ozlabs.org/api/patches/806352/comments/",
    "check": "pending",
    "checks": "http://patchwork.ozlabs.org/api/patches/806352/checks/",
    "tags": {},
    "related": [],
    "headers": {
        "Return-Path": "<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>",
        "X-Original-To": "incoming@patchwork.ozlabs.org",
        "Delivered-To": "patchwork-incoming@bilbo.ozlabs.org",
        "Authentication-Results": [
            "ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=nongnu.org\n\t(client-ip=2001:4830:134:3::11; helo=lists.gnu.org;\n\tenvelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org;\n\treceiver=<UNKNOWN>)",
            "ozlabs.org;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n\tunprotected) header.d=gmail.com header.i=@gmail.com\n\theader.b=\"uPepT6cN\"; dkim-atps=neutral"
        ],
        "Received": [
            "from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11])\n\t(using TLSv1 with cipher AES256-SHA (256/256 bits))\n\t(No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3xgdDk0NwLz9s81\n\tfor <incoming@patchwork.ozlabs.org>;\n\tMon, 28 Aug 2017 13:54:13 +1000 (AEST)",
            "from localhost ([::1]:36794 helo=lists.gnu.org)\n\tby lists.gnu.org with esmtp (Exim 4.71) (envelope-from\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>)\n\tid 1dmB7r-0003oV-SA\n\tfor incoming@patchwork.ozlabs.org; Sun, 27 Aug 2017 23:54:11 -0400",
            "from eggs.gnu.org ([2001:4830:134:3::10]:55710)\n\tby lists.gnu.org with esmtp (Exim 4.71)\n\t(envelope-from <bobby.prani@gmail.com>) id 1dmB7E-0003hZ-DE\n\tfor qemu-devel@nongnu.org; Sun, 27 Aug 2017 23:53:33 -0400",
            "from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)\n\t(envelope-from <bobby.prani@gmail.com>) id 1dmB7C-0003wK-Gp\n\tfor qemu-devel@nongnu.org; Sun, 27 Aug 2017 23:53:32 -0400",
            "from mail-yw0-x241.google.com ([2607:f8b0:4002:c05::241]:34176)\n\tby eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16)\n\t(Exim 4.71) (envelope-from <bobby.prani@gmail.com>)\n\tid 1dmB7C-0003vz-Av\n\tfor qemu-devel@nongnu.org; Sun, 27 Aug 2017 23:53:30 -0400",
            "by mail-yw0-x241.google.com with SMTP id h127so2734778ywf.1\n\tfor <qemu-devel@nongnu.org>; Sun, 27 Aug 2017 20:53:30 -0700 (PDT)",
            "from localhost.localdomain ([98.192.46.210])\n\tby smtp.gmail.com with ESMTPSA id\n\ti64sm4820865ywi.64.2017.08.27.20.53.28\n\t(version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);\n\tSun, 27 Aug 2017 20:53:29 -0700 (PDT)"
        ],
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025;\n\th=from:to:cc:subject:date:message-id:in-reply-to:references;\n\tbh=dRw9oTjsSlN4Y4flZNeZWXuYy0aQltMSKQSBYL5ypk4=;\n\tb=uPepT6cNmOYXBZ4n8VNo9HAHcfwMAffHapEXA3L7VIKucecQ2NzFXn0ZFDONjGczgJ\n\t0epzUy/+ESE61emWv7h53xBYOvMkBhl7wq0d++N78VPKOEERfUaNpvcJ+ISReblXewIc\n\tAKMWwPMjXNtB32+JeYLwTINb4nan60sf9zZCyqwx0eonxMooH5/u3FS8cQV27MzGlk+B\n\tNWvQXwc1RkmVa8K5aFiIYTcsL0nZ7dsr47ef7gYIgTGMP7WdHbjXx/eL9KrElJzGmxRN\n\tkzc8TdMGIoimgFhK8phzSnuH44oCrB585BL54ZeVDFyIO4pg3eTXGs/t937Ck70jjnyc\n\tREkw==",
        "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to\n\t:references;\n\tbh=dRw9oTjsSlN4Y4flZNeZWXuYy0aQltMSKQSBYL5ypk4=;\n\tb=RtKlfLcOubaoCo3AFA5R2U5DuaIdlhrbL1YVlNeUuoYs0YqI+CKa12xXzgVD+IwwR1\n\tar+3eY890XsHJJSd/VMYRN4zk/+HPOaFRg2vTzEUwfvv5FF8ckDEgkz7ySUh4N+A42t8\n\tAs9i9ng/gKaaASs7M47S7dArb1NRHpyFBRA3rnJjMKWHQ3EamXeeWYDNZCwXU7b1SSVQ\n\tnD5ZrblUAlAiLccOb51pBclMcEs4b4M+ZEUFwNqB5w9WGLWl2Lh3RutB2S5iFW0jtmLb\n\tt1O9FTZxnY9P4T+cMh8HPv10ZYb+51uv8EbfXD1U+/ffpwLgQAWEJyYbwv6ZOvysfJiw\n\t/DqA==",
        "X-Gm-Message-State": "AHYfb5iG5l/sxMB1lSUbTyt5k+66If5YlzWW4Mao9gZ76w5qGLlfp5QV\n\tFgNQGwMMqeCsXQ==",
        "X-Received": "by 10.37.160.141 with SMTP id y13mr2187377ybh.353.1503892409640; \n\tSun, 27 Aug 2017 20:53:29 -0700 (PDT)",
        "From": "Pranith Kumar <bobby.prani@gmail.com>",
        "To": "alex.bennee@linaro.org, Paolo Bonzini <pbonzini@redhat.com>,\n\tRichard Henderson <rth@twiddle.net>,\n\tSergey Fedorov <serge.fdrv@gmail.com>, \n\tqemu-devel@nongnu.org (open list:All patches CC here)",
        "Date": "Sun, 27 Aug 2017 23:53:25 -0400",
        "Message-Id": "<20170828035327.17146-2-bobby.prani@gmail.com>",
        "X-Mailer": "git-send-email 2.13.0",
        "In-Reply-To": "<20170828035327.17146-1-bobby.prani@gmail.com>",
        "References": "<20170828035327.17146-1-bobby.prani@gmail.com>",
        "X-detected-operating-system": "by eggs.gnu.org: Genre and OS details not\n\trecognized.",
        "X-Received-From": "2607:f8b0:4002:c05::241",
        "Subject": "[Qemu-devel] [RFC PATCH 2/3] cpus-common: Cache allocated work items",
        "X-BeenThere": "qemu-devel@nongnu.org",
        "X-Mailman-Version": "2.1.21",
        "Precedence": "list",
        "List-Id": "<qemu-devel.nongnu.org>",
        "List-Unsubscribe": "<https://lists.nongnu.org/mailman/options/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>",
        "List-Archive": "<http://lists.nongnu.org/archive/html/qemu-devel/>",
        "List-Post": "<mailto:qemu-devel@nongnu.org>",
        "List-Help": "<mailto:qemu-devel-request@nongnu.org?subject=help>",
        "List-Subscribe": "<https://lists.nongnu.org/mailman/listinfo/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=subscribe>",
        "Cc": "qemu-devel@nongnu.org",
        "Errors-To": "qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org",
        "Sender": "\"Qemu-devel\"\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>"
    },
    "content": "Using heaptrack, I found that quite a few of our temporary allocations\nare coming from allocating work items. Instead of doing this\ncontinously, we can cache the allocated items and reuse them instead\nof freeing them.\n\nThis reduces the number of allocations by 25% (200000 -> 150000 for\nARM64 boot+shutdown test).\n\nSigned-off-by: Pranith Kumar <bobby.prani@gmail.com>\n---\n cpus-common.c | 85 ++++++++++++++++++++++++++++++++++++++++++++++++-----------\n 1 file changed, 70 insertions(+), 15 deletions(-)",
    "diff": "diff --git a/cpus-common.c b/cpus-common.c\nindex 59f751ecf9..a1c4c7d1a3 100644\n--- a/cpus-common.c\n+++ b/cpus-common.c\n@@ -24,6 +24,7 @@\n #include \"sysemu/cpus.h\"\n \n static QemuMutex qemu_cpu_list_lock;\n+static QemuMutex qemu_wi_pool_lock;\n static QemuCond exclusive_cond;\n static QemuCond exclusive_resume;\n static QemuCond qemu_work_cond;\n@@ -33,6 +34,58 @@ static QemuCond qemu_work_cond;\n  */\n static int pending_cpus;\n \n+typedef struct qemu_work_item {\n+    struct qemu_work_item *next;\n+    run_on_cpu_func func;\n+    run_on_cpu_data data;\n+    bool free, exclusive, done;\n+} qemu_work_item;\n+\n+typedef struct qemu_wi_pool {\n+    qemu_work_item *first, *last;\n+} qemu_wi_pool;\n+\n+qemu_wi_pool *wi_free_pool;\n+\n+static void qemu_init_workitem_pool(void)\n+{\n+    wi_free_pool = g_malloc0(sizeof(qemu_wi_pool));\n+    wi_free_pool->first = NULL;\n+    wi_free_pool->last  = NULL;\n+}\n+\n+static void qemu_wi_pool_insert(qemu_work_item *item)\n+{\n+    qemu_mutex_lock(&qemu_wi_pool_lock);\n+    if (wi_free_pool->last == NULL) {\n+        wi_free_pool->first = item;\n+        wi_free_pool->last = item;\n+    } else {\n+        wi_free_pool->last->next = item;\n+        wi_free_pool->last = item;\n+    }\n+    qemu_mutex_unlock(&qemu_wi_pool_lock);\n+}\n+\n+static qemu_work_item* qemu_wi_pool_remove(void)\n+{\n+    qemu_mutex_lock(&qemu_wi_pool_lock);\n+    qemu_work_item *ret = wi_free_pool->first;\n+\n+    if (ret == NULL)\n+        goto out;\n+\n+    wi_free_pool->first = ret->next;\n+    if (wi_free_pool->last == ret) {\n+        wi_free_pool->last = NULL;\n+    }\n+    ret->next = NULL;\n+\n+ out:\n+    qemu_mutex_unlock(&qemu_wi_pool_lock);\n+    return ret;\n+}\n+\n void qemu_init_cpu_list(void)\n {\n     /* This is needed because qemu_init_cpu_list is also called by the\n@@ -43,6 +96,9 @@ void qemu_init_cpu_list(void)\n     qemu_cond_init(&exclusive_cond);\n     qemu_cond_init(&exclusive_resume);\n     qemu_cond_init(&qemu_work_cond);\n+\n+    qemu_init_workitem_pool();\n+    qemu_mutex_init(&qemu_wi_pool_lock);\n }\n \n void cpu_list_lock(void)\n@@ -106,14 +162,7 @@ void cpu_list_remove(CPUState *cpu)\n     qemu_mutex_unlock(&qemu_cpu_list_lock);\n }\n \n-struct qemu_work_item {\n-    struct qemu_work_item *next;\n-    run_on_cpu_func func;\n-    run_on_cpu_data data;\n-    bool free, exclusive, done;\n-};\n-\n-static void queue_work_on_cpu(CPUState *cpu, struct qemu_work_item *wi)\n+static void queue_work_on_cpu(CPUState *cpu, qemu_work_item *wi)\n {\n     qemu_mutex_lock(&cpu->work_mutex);\n     if (cpu->queued_work_first == NULL) {\n@@ -132,7 +181,7 @@ static void queue_work_on_cpu(CPUState *cpu, struct qemu_work_item *wi)\n void do_run_on_cpu(CPUState *cpu, run_on_cpu_func func, run_on_cpu_data data,\n                    QemuMutex *mutex)\n {\n-    struct qemu_work_item wi;\n+    qemu_work_item wi;\n \n     if (qemu_cpu_is_self(cpu)) {\n         func(cpu, data);\n@@ -145,6 +194,7 @@ void do_run_on_cpu(CPUState *cpu, run_on_cpu_func func, run_on_cpu_data data,\n     wi.free = false;\n     wi.exclusive = false;\n \n+\n     queue_work_on_cpu(cpu, &wi);\n     while (!atomic_mb_read(&wi.done)) {\n         CPUState *self_cpu = current_cpu;\n@@ -156,9 +206,11 @@ void do_run_on_cpu(CPUState *cpu, run_on_cpu_func func, run_on_cpu_data data,\n \n void async_run_on_cpu(CPUState *cpu, run_on_cpu_func func, run_on_cpu_data data)\n {\n-    struct qemu_work_item *wi;\n+    qemu_work_item *wi = qemu_wi_pool_remove();\n \n-    wi = g_malloc0(sizeof(struct qemu_work_item));\n+    if (!wi) {\n+        wi = g_malloc0(sizeof(qemu_work_item));\n+    }\n     wi->func = func;\n     wi->data = data;\n     wi->free = true;\n@@ -299,9 +351,11 @@ void cpu_exec_end(CPUState *cpu)\n void async_safe_run_on_cpu(CPUState *cpu, run_on_cpu_func func,\n                            run_on_cpu_data data)\n {\n-    struct qemu_work_item *wi;\n+    qemu_work_item *wi = qemu_wi_pool_remove();\n \n-    wi = g_malloc0(sizeof(struct qemu_work_item));\n+    if (!wi) {\n+        wi = g_malloc0(sizeof(qemu_work_item));\n+    }\n     wi->func = func;\n     wi->data = data;\n     wi->free = true;\n@@ -312,7 +366,7 @@ void async_safe_run_on_cpu(CPUState *cpu, run_on_cpu_func func,\n \n void process_queued_cpu_work(CPUState *cpu)\n {\n-    struct qemu_work_item *wi;\n+    qemu_work_item *wi;\n \n     if (cpu->queued_work_first == NULL) {\n         return;\n@@ -343,7 +397,8 @@ void process_queued_cpu_work(CPUState *cpu)\n         }\n         qemu_mutex_lock(&cpu->work_mutex);\n         if (wi->free) {\n-            g_free(wi);\n+            memset(wi, 0, sizeof(qemu_work_item));\n+            qemu_wi_pool_insert(wi);\n         } else {\n             atomic_mb_set(&wi->done, true);\n         }\n",
    "prefixes": [
        "RFC",
        "2/3"
    ]
}