get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

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

{
    "id": 51627,
    "url": "http://patchwork.dpdk.org/api/patches/51627/?format=api",
    "web_url": "http://patchwork.dpdk.org/project/dpdk/patch/1553512269-146074-4-git-send-email-joyce.kong@arm.com/",
    "project": {
        "id": 1,
        "url": "http://patchwork.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": "<1553512269-146074-4-git-send-email-joyce.kong@arm.com>",
    "list_archive_url": "https://inbox.dpdk.org/dev/1553512269-146074-4-git-send-email-joyce.kong@arm.com",
    "date": "2019-03-25T11:11:09",
    "name": "[v8,3/3] test/ticketlock: add ticket lock test case",
    "commit_ref": null,
    "pull_url": null,
    "state": "accepted",
    "archived": true,
    "hash": "88db91bfb7aa0a2dc10f5d77ad848a71063fe211",
    "submitter": {
        "id": 970,
        "url": "http://patchwork.dpdk.org/api/people/970/?format=api",
        "name": "Joyce Kong",
        "email": "joyce.kong@arm.com"
    },
    "delegate": {
        "id": 1,
        "url": "http://patchwork.dpdk.org/api/users/1/?format=api",
        "username": "tmonjalo",
        "first_name": "Thomas",
        "last_name": "Monjalon",
        "email": "thomas@monjalon.net"
    },
    "mbox": "http://patchwork.dpdk.org/project/dpdk/patch/1553512269-146074-4-git-send-email-joyce.kong@arm.com/mbox/",
    "series": [
        {
            "id": 3894,
            "url": "http://patchwork.dpdk.org/api/series/3894/?format=api",
            "web_url": "http://patchwork.dpdk.org/project/dpdk/list/?series=3894",
            "date": "2019-03-25T11:11:06",
            "name": "ticketlock: implement ticketlock and add test case",
            "version": 8,
            "mbox": "http://patchwork.dpdk.org/series/3894/mbox/"
        }
    ],
    "comments": "http://patchwork.dpdk.org/api/patches/51627/comments/",
    "check": "success",
    "checks": "http://patchwork.dpdk.org/api/patches/51627/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 416D93576;\n\tMon, 25 Mar 2019 12:11:34 +0100 (CET)",
            "from foss.arm.com (usa-sjc-mx-foss1.foss.arm.com [217.140.101.70])\n\tby dpdk.org (Postfix) with ESMTP id 59B4537B0\n\tfor <dev@dpdk.org>; Mon, 25 Mar 2019 12:11:32 +0100 (CET)",
            "from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249])\n\tby usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id B843815AB;\n\tMon, 25 Mar 2019 04:11:31 -0700 (PDT)",
            "from net-arm-thunderx2.shanghai.arm.com\n\t(net-arm-thunderx2.shanghai.arm.com [10.169.40.112])\n\tby usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id\n\t41C6C3F575; Mon, 25 Mar 2019 04:11:30 -0700 (PDT)"
        ],
        "From": "Joyce Kong <joyce.kong@arm.com>",
        "To": "dev@dpdk.org",
        "Cc": "nd@arm.com, stephen@networkplumber.org, jerin.jacob@caviumnetworks.com, \n\tkonstantin.ananyev@intel.com, thomas@monjalon.net,\n\thonnappa.nagarahalli@arm.com, gavin.hu@arm.com",
        "Date": "Mon, 25 Mar 2019 19:11:09 +0800",
        "Message-Id": "<1553512269-146074-4-git-send-email-joyce.kong@arm.com>",
        "X-Mailer": "git-send-email 2.7.4",
        "In-Reply-To": [
            "<1553512269-146074-1-git-send-email-joyce.kong@arm.com>",
            "<1547802943-18711-1-git-send-email-joyce.kong@arm.com>"
        ],
        "References": [
            "<1553512269-146074-1-git-send-email-joyce.kong@arm.com>",
            "<1547802943-18711-1-git-send-email-joyce.kong@arm.com>"
        ],
        "Subject": "[dpdk-dev] [PATCH v8 3/3] test/ticketlock: add ticket lock test case",
        "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 test cases for ticket lock, recursive ticket lock,\nand ticket lock performance.\n\nSigned-off-by: Joyce Kong <joyce.kong@arm.com>\nReviewed-by: Gavin Hu <gavin.hu@arm.com>\nReviewed-by: Phil Yang <phil.yang@arm.com>\n---\n MAINTAINERS                |   1 +\n app/test/Makefile          |   1 +\n app/test/autotest_data.py  |   6 +\n app/test/meson.build       |   1 +\n app/test/test_ticketlock.c | 319 +++++++++++++++++++++++++++++++++++++++++++++\n 5 files changed, 328 insertions(+)\n create mode 100644 app/test/test_ticketlock.c",
    "diff": "diff --git a/MAINTAINERS b/MAINTAINERS\nindex 3521271..b1ed4cc 100644\n--- a/MAINTAINERS\n+++ b/MAINTAINERS\n@@ -213,6 +213,7 @@ F: app/test/test_bitmap.c\n Ticketlock\n M: Joyce Kong <joyce.kong@arm.com>\n F: lib/librte_eal/common/include/generic/rte_ticketlock.h\n+F: app/test/test_ticketlock.c\n \n ARM v7\n M: Jan Viktorin <viktorin@rehivetech.com>\ndiff --git a/app/test/Makefile b/app/test/Makefile\nindex 89949c2..d6aa28b 100644\n--- a/app/test/Makefile\n+++ b/app/test/Makefile\n@@ -65,6 +65,7 @@ SRCS-y += test_barrier.c\n SRCS-y += test_malloc.c\n SRCS-y += test_cycles.c\n SRCS-y += test_spinlock.c\n+SRCS-y += test_ticketlock.c\n SRCS-y += test_memory.c\n SRCS-y += test_memzone.c\n SRCS-y += test_bitmap.c\ndiff --git a/app/test/autotest_data.py b/app/test/autotest_data.py\nindex 5f87bb9..db25274 100644\n--- a/app/test/autotest_data.py\n+++ b/app/test/autotest_data.py\n@@ -171,6 +171,12 @@\n         \"Report\":  None,\n     },\n     {\n+        \"Name\":    \"Ticketlock autotest\",\n+        \"Command\": \"ticketlock_autotest\",\n+        \"Func\":    ticketlock_autotest,\n+        \"Report\":  None,\n+    }\n+    {\n         \"Name\":    \"Byte order autotest\",\n         \"Command\": \"byteorder_autotest\",\n         \"Func\":    default_autotest,\ndiff --git a/app/test/meson.build b/app/test/meson.build\nindex 05e5dde..ddb4d09 100644\n--- a/app/test/meson.build\n+++ b/app/test/meson.build\n@@ -107,6 +107,7 @@ test_sources = files('commands.c',\n \t'test_timer.c',\n \t'test_timer_perf.c',\n \t'test_timer_racecond.c',\n+\t'test_ticketlock.c',\n \t'test_version.c',\n \t'virtual_pmd.c'\n )\ndiff --git a/app/test/test_ticketlock.c b/app/test/test_ticketlock.c\nnew file mode 100644\nindex 0000000..13bdadb\n--- /dev/null\n+++ b/app/test/test_ticketlock.c\n@@ -0,0 +1,319 @@\n+/* SPDX-License-Identifier: BSD-3-Clause\n+ * Copyright(c) 2018-2019 Arm Limited\n+ */\n+\n+#include <inttypes.h>\n+#include <stdint.h>\n+#include <stdio.h>\n+#include <string.h>\n+#include <sys/queue.h>\n+#include <unistd.h>\n+\n+#include <rte_atomic.h>\n+#include <rte_common.h>\n+#include <rte_cycles.h>\n+#include <rte_eal.h>\n+#include <rte_launch.h>\n+#include <rte_lcore.h>\n+#include <rte_memory.h>\n+#include <rte_per_lcore.h>\n+#include <rte_ticketlock.h>\n+\n+#include \"test.h\"\n+\n+/*\n+ * Ticketlock test\n+ * =============\n+ *\n+ * - There is a global ticketlock and a table of ticketlocks (one per lcore).\n+ *\n+ * - The test function takes all of these locks and launches the\n+ *   ``test_ticketlock_per_core()`` function on each core (except the master).\n+ *\n+ *   - The function takes the global lock, display something, then releases\n+ *     the global lock.\n+ *   - The function takes the per-lcore lock, display something, then releases\n+ *     the per-core lock.\n+ *\n+ * - The main function unlocks the per-lcore locks sequentially and\n+ *   waits between each lock. This triggers the display of a message\n+ *   for each core, in the correct order. The autotest script checks that\n+ *   this order is correct.\n+ *\n+ * - A load test is carried out, with all cores attempting to lock a single lock\n+ *   multiple times\n+ */\n+\n+static rte_ticketlock_t tl, tl_try;\n+static rte_ticketlock_t tl_tab[RTE_MAX_LCORE];\n+static rte_ticketlock_recursive_t tlr;\n+static unsigned int count;\n+\n+static rte_atomic32_t synchro;\n+\n+static int\n+test_ticketlock_per_core(__attribute__((unused)) void *arg)\n+{\n+\trte_ticketlock_lock(&tl);\n+\tprintf(\"Global lock taken on core %u\\n\", rte_lcore_id());\n+\trte_ticketlock_unlock(&tl);\n+\n+\trte_ticketlock_lock(&tl_tab[rte_lcore_id()]);\n+\tprintf(\"Hello from core %u !\\n\", rte_lcore_id());\n+\trte_ticketlock_unlock(&tl_tab[rte_lcore_id()]);\n+\n+\treturn 0;\n+}\n+\n+static int\n+test_ticketlock_recursive_per_core(__attribute__((unused)) void *arg)\n+{\n+\tunsigned int id = rte_lcore_id();\n+\n+\trte_ticketlock_recursive_lock(&tlr);\n+\tprintf(\"Global recursive lock taken on core %u - count = %d\\n\",\n+\t       id, tlr.count);\n+\trte_ticketlock_recursive_lock(&tlr);\n+\tprintf(\"Global recursive lock taken on core %u - count = %d\\n\",\n+\t       id, tlr.count);\n+\trte_ticketlock_recursive_lock(&tlr);\n+\tprintf(\"Global recursive lock taken on core %u - count = %d\\n\",\n+\t       id, tlr.count);\n+\n+\tprintf(\"Hello from within recursive locks from core %u !\\n\", id);\n+\n+\trte_ticketlock_recursive_unlock(&tlr);\n+\tprintf(\"Global recursive lock released on core %u - count = %d\\n\",\n+\t       id, tlr.count);\n+\trte_ticketlock_recursive_unlock(&tlr);\n+\tprintf(\"Global recursive lock released on core %u - count = %d\\n\",\n+\t       id, tlr.count);\n+\trte_ticketlock_recursive_unlock(&tlr);\n+\tprintf(\"Global recursive lock released on core %u - count = %d\\n\",\n+\t       id, tlr.count);\n+\n+\treturn 0;\n+}\n+\n+static rte_ticketlock_t lk = RTE_TICKETLOCK_INITIALIZER;\n+static uint64_t lcount __rte_cache_aligned;\n+static uint64_t lcore_count[RTE_MAX_LCORE] __rte_cache_aligned;\n+static uint64_t time_cost[RTE_MAX_LCORE];\n+\n+#define MAX_LOOP 10000\n+\n+static int\n+load_loop_fn(void *func_param)\n+{\n+\tuint64_t time_diff = 0, begin;\n+\tuint64_t hz = rte_get_timer_hz();\n+\tconst int use_lock = *(int *)func_param;\n+\tconst unsigned int lcore = rte_lcore_id();\n+\n+\t/* wait synchro for slaves */\n+\tif (lcore != rte_get_master_lcore())\n+\t\twhile (rte_atomic32_read(&synchro) == 0)\n+\t\t\t;\n+\n+\tbegin = rte_rdtsc_precise();\n+\twhile (lcore_count[lcore] < MAX_LOOP) {\n+\t\tif (use_lock)\n+\t\t\trte_ticketlock_lock(&lk);\n+\t\tlcore_count[lcore]++;\n+\t\tlcount++;\n+\t\tif (use_lock)\n+\t\t\trte_ticketlock_unlock(&lk);\n+\t}\n+\ttime_diff = rte_rdtsc_precise() - begin;\n+\ttime_cost[lcore] = time_diff * 1000000 / hz;\n+\treturn 0;\n+}\n+\n+static int\n+test_ticketlock_perf(void)\n+{\n+\tunsigned int i;\n+\tuint64_t tcount = 0;\n+\tuint64_t total_time = 0;\n+\tint lock = 0;\n+\tconst unsigned int lcore = rte_lcore_id();\n+\n+\tprintf(\"\\nTest with no lock on single core...\\n\");\n+\tload_loop_fn(&lock);\n+\tprintf(\"Core [%u] cost time = %\"PRIu64\" us\\n\", lcore, time_cost[lcore]);\n+\tmemset(lcore_count, 0, sizeof(lcore_count));\n+\tmemset(time_cost, 0, sizeof(time_cost));\n+\n+\tprintf(\"\\nTest with lock on single core...\\n\");\n+\tlock = 1;\n+\tload_loop_fn(&lock);\n+\tprintf(\"Core [%u] cost time = %\"PRIu64\" us\\n\", lcore, time_cost[lcore]);\n+\tmemset(lcore_count, 0, sizeof(lcore_count));\n+\tmemset(time_cost, 0, sizeof(time_cost));\n+\n+\tlcount = 0;\n+\tprintf(\"\\nTest with lock on %u cores...\\n\", rte_lcore_count());\n+\n+\t/* Clear synchro and start slaves */\n+\trte_atomic32_set(&synchro, 0);\n+\trte_eal_mp_remote_launch(load_loop_fn, &lock, SKIP_MASTER);\n+\n+\t/* start synchro and launch test on master */\n+\trte_atomic32_set(&synchro, 1);\n+\tload_loop_fn(&lock);\n+\n+\trte_eal_mp_wait_lcore();\n+\n+\tRTE_LCORE_FOREACH(i) {\n+\t\tprintf(\"Core [%u] cost time = %\"PRIu64\" us\\n\", i, time_cost[i]);\n+\t\ttcount += lcore_count[i];\n+\t\ttotal_time += time_cost[i];\n+\t}\n+\n+\tif (tcount != lcount)\n+\t\treturn -1;\n+\n+\tprintf(\"Total cost time = %\"PRIu64\" us\\n\", total_time);\n+\n+\treturn 0;\n+}\n+\n+/*\n+ * Use rte_ticketlock_trylock() to trylock a ticketlock object,\n+ * If it could not lock the object successfully, it would\n+ * return immediately and the variable of \"count\" would be\n+ * increased by one per times. the value of \"count\" could be\n+ * checked as the result later.\n+ */\n+static int\n+test_ticketlock_try(__attribute__((unused)) void *arg)\n+{\n+\tif (rte_ticketlock_trylock(&tl_try) == 0) {\n+\t\trte_ticketlock_lock(&tl);\n+\t\tcount++;\n+\t\trte_ticketlock_unlock(&tl);\n+\t}\n+\n+\treturn 0;\n+}\n+\n+\n+/*\n+ * Test rte_eal_get_lcore_state() in addition to ticketlocks\n+ * as we have \"waiting\" then \"running\" lcores.\n+ */\n+static int\n+test_ticketlock(void)\n+{\n+\tint ret = 0;\n+\tint i;\n+\n+\t/* slave cores should be waiting: print it */\n+\tRTE_LCORE_FOREACH_SLAVE(i) {\n+\t\tprintf(\"lcore %d state: %d\\n\", i,\n+\t\t       (int) rte_eal_get_lcore_state(i));\n+\t}\n+\n+\trte_ticketlock_init(&tl);\n+\trte_ticketlock_init(&tl_try);\n+\trte_ticketlock_recursive_init(&tlr);\n+\tRTE_LCORE_FOREACH_SLAVE(i) {\n+\t\trte_ticketlock_init(&tl_tab[i]);\n+\t}\n+\n+\trte_ticketlock_lock(&tl);\n+\n+\tRTE_LCORE_FOREACH_SLAVE(i) {\n+\t\trte_ticketlock_lock(&tl_tab[i]);\n+\t\trte_eal_remote_launch(test_ticketlock_per_core, NULL, i);\n+\t}\n+\n+\t/* slave cores should be busy: print it */\n+\tRTE_LCORE_FOREACH_SLAVE(i) {\n+\t\tprintf(\"lcore %d state: %d\\n\", i,\n+\t\t       (int) rte_eal_get_lcore_state(i));\n+\t}\n+\trte_ticketlock_unlock(&tl);\n+\n+\tRTE_LCORE_FOREACH_SLAVE(i) {\n+\t\trte_ticketlock_unlock(&tl_tab[i]);\n+\t\trte_delay_ms(10);\n+\t}\n+\n+\trte_eal_mp_wait_lcore();\n+\n+\trte_ticketlock_recursive_lock(&tlr);\n+\n+\t/*\n+\t * Try to acquire a lock that we already own\n+\t */\n+\tif (!rte_ticketlock_recursive_trylock(&tlr)) {\n+\t\tprintf(\"rte_ticketlock_recursive_trylock failed on a lock that \"\n+\t\t       \"we already own\\n\");\n+\t\tret = -1;\n+\t} else\n+\t\trte_ticketlock_recursive_unlock(&tlr);\n+\n+\tRTE_LCORE_FOREACH_SLAVE(i) {\n+\t\trte_eal_remote_launch(test_ticketlock_recursive_per_core,\n+\t\t\t\t\tNULL, i);\n+\t}\n+\trte_ticketlock_recursive_unlock(&tlr);\n+\trte_eal_mp_wait_lcore();\n+\n+\t/*\n+\t * Test if it could return immediately from try-locking a locked object.\n+\t * Here it will lock the ticketlock object first, then launch all the\n+\t * slave lcores to trylock the same ticketlock object.\n+\t * All the slave lcores should give up try-locking a locked object and\n+\t * return immediately, and then increase the \"count\" initialized with\n+\t * zero by one per times.\n+\t * We can check if the \"count\" is finally equal to the number of all\n+\t * slave lcores to see if the behavior of try-locking a locked\n+\t * ticketlock object is correct.\n+\t */\n+\tif (rte_ticketlock_trylock(&tl_try) == 0)\n+\t\treturn -1;\n+\n+\tcount = 0;\n+\tRTE_LCORE_FOREACH_SLAVE(i) {\n+\t\trte_eal_remote_launch(test_ticketlock_try, NULL, i);\n+\t}\n+\trte_eal_mp_wait_lcore();\n+\trte_ticketlock_unlock(&tl_try);\n+\tif (rte_ticketlock_is_locked(&tl)) {\n+\t\tprintf(\"ticketlock is locked but it should not be\\n\");\n+\t\treturn -1;\n+\t}\n+\trte_ticketlock_lock(&tl);\n+\tif (count != (rte_lcore_count() - 1))\n+\t\tret = -1;\n+\n+\trte_ticketlock_unlock(&tl);\n+\n+\t/*\n+\t * Test if it can trylock recursively.\n+\t * Use rte_ticketlock_recursive_trylock() to check if it can lock\n+\t * a ticketlock object recursively. Here it will try to lock a\n+\t * ticketlock object twice.\n+\t */\n+\tif (rte_ticketlock_recursive_trylock(&tlr) == 0) {\n+\t\tprintf(\"It failed to do the first ticketlock_recursive_trylock \"\n+\t\t\t   \"but it should able to do\\n\");\n+\t\treturn -1;\n+\t}\n+\tif (rte_ticketlock_recursive_trylock(&tlr) == 0) {\n+\t\tprintf(\"It failed to do the second ticketlock_recursive_trylock \"\n+\t\t\t   \"but it should able to do\\n\");\n+\t\treturn -1;\n+\t}\n+\trte_ticketlock_recursive_unlock(&tlr);\n+\trte_ticketlock_recursive_unlock(&tlr);\n+\n+\tif (test_ticketlock_perf() < 0)\n+\t\treturn -1;\n+\n+\treturn ret;\n+}\n+\n+REGISTER_TEST_COMMAND(ticketlock_autotest, test_ticketlock);\n",
    "prefixes": [
        "v8",
        "3/3"
    ]
}