get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

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

{
    "id": 102607,
    "url": "https://patches.dpdk.org/api/patches/102607/?format=api",
    "web_url": "https://patches.dpdk.org/project/dpdk/patch/20211021213221.9239-1-honnappa.nagarahalli@arm.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": "<20211021213221.9239-1-honnappa.nagarahalli@arm.com>",
    "list_archive_url": "https://inbox.dpdk.org/dev/20211021213221.9239-1-honnappa.nagarahalli@arm.com",
    "date": "2021-10-21T21:32:20",
    "name": "[v5,1/2] eal: simplify the implementation of rte_ctrl_thread_create",
    "commit_ref": null,
    "pull_url": null,
    "state": "accepted",
    "archived": true,
    "hash": "4ad8a2fb9731e700b953237752228a9cf1c49f4b",
    "submitter": {
        "id": 1045,
        "url": "https://patches.dpdk.org/api/people/1045/?format=api",
        "name": "Honnappa Nagarahalli",
        "email": "honnappa.nagarahalli@arm.com"
    },
    "delegate": {
        "id": 24651,
        "url": "https://patches.dpdk.org/api/users/24651/?format=api",
        "username": "dmarchand",
        "first_name": "David",
        "last_name": "Marchand",
        "email": "david.marchand@redhat.com"
    },
    "mbox": "https://patches.dpdk.org/project/dpdk/patch/20211021213221.9239-1-honnappa.nagarahalli@arm.com/mbox/",
    "series": [
        {
            "id": 19887,
            "url": "https://patches.dpdk.org/api/series/19887/?format=api",
            "web_url": "https://patches.dpdk.org/project/dpdk/list/?series=19887",
            "date": "2021-10-21T21:32:20",
            "name": "[v5,1/2] eal: simplify the implementation of rte_ctrl_thread_create",
            "version": 5,
            "mbox": "https://patches.dpdk.org/series/19887/mbox/"
        }
    ],
    "comments": "https://patches.dpdk.org/api/patches/102607/comments/",
    "check": "success",
    "checks": "https://patches.dpdk.org/api/patches/102607/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 69D7BA0C43;\n\tThu, 21 Oct 2021 23:32:30 +0200 (CEST)",
            "from [217.70.189.124] (localhost [127.0.0.1])\n\tby mails.dpdk.org (Postfix) with ESMTP id 2264040040;\n\tThu, 21 Oct 2021 23:32:30 +0200 (CEST)",
            "from foss.arm.com (foss.arm.com [217.140.110.172])\n by mails.dpdk.org (Postfix) with ESMTP id BB36F4003F\n for <dev@dpdk.org>; Thu, 21 Oct 2021 23:32:28 +0200 (CEST)",
            "from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14])\n by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 388F0D6E;\n Thu, 21 Oct 2021 14:32:28 -0700 (PDT)",
            "from qc2400f-1.austin.arm.com (qc2400f-1.austin.arm.com\n [10.118.12.44])\n by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 2BB953F73D;\n Thu, 21 Oct 2021 14:32:28 -0700 (PDT)"
        ],
        "From": "Honnappa Nagarahalli <honnappa.nagarahalli@arm.com>",
        "To": "dev@dpdk.org, honnappa.nagarahalli@arm.com, olivier.matz@6wind.com,\n lucp.at.work@gmail.com, stephen@networkplumber.org,\n david.marchand@redhat.com, thomas@monjalon.net",
        "Cc": "ruifeng.wang@arm.com,\n\tnd@arm.com",
        "Date": "Thu, 21 Oct 2021 16:32:20 -0500",
        "Message-Id": "<20211021213221.9239-1-honnappa.nagarahalli@arm.com>",
        "X-Mailer": "git-send-email 2.17.1",
        "In-Reply-To": "<20210730213709.19400-1-honnappa.nagarahalli@arm.com>",
        "References": "<20210730213709.19400-1-honnappa.nagarahalli@arm.com>",
        "Subject": "[dpdk-dev] [PATCH v5 1/2] eal: simplify the implementation of\n rte_ctrl_thread_create",
        "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": "Remove the usage of pthread barrier and replace it with\nsynchronization using atomic variable. This also removes\nthe use of reference count required to synchronize freeing\nthe memory.\n\nSigned-off-by: Honnappa Nagarahalli <honnappa.nagarahalli@arm.com>\nReviewed-by: Olivier Matz <olivier.matz@6wind.com>\n---\n lib/eal/common/eal_common_thread.c | 87 +++++++++++++++---------------\n lib/eal/include/rte_lcore.h        |  9 ++--\n 2 files changed, 50 insertions(+), 46 deletions(-)",
    "diff": "diff --git a/lib/eal/common/eal_common_thread.c b/lib/eal/common/eal_common_thread.c\nindex 1a52f42a2b..c602bd2a0d 100644\n--- a/lib/eal/common/eal_common_thread.c\n+++ b/lib/eal/common/eal_common_thread.c\n@@ -166,38 +166,44 @@ __rte_thread_uninit(void)\n \tRTE_PER_LCORE(_lcore_id) = LCORE_ID_ANY;\n }\n \n+enum __rte_ctrl_thread_status {\n+\tCTRL_THREAD_LAUNCHING, /* Yet to call pthread_create function */\n+\tCTRL_THREAD_RUNNING, /* Control thread is running successfully */\n+\tCTRL_THREAD_ERROR /* Control thread encountered an error */\n+};\n+\n struct rte_thread_ctrl_params {\n \tvoid *(*start_routine)(void *);\n \tvoid *arg;\n-\tpthread_barrier_t configured;\n-\tunsigned int refcnt;\n+\tint ret;\n+\t/* Control thread status. If the status is CTRL_THREAD_ERROR\n+\t * 'ret' has the error code.\n+\t */\n+\tenum __rte_ctrl_thread_status ctrl_thread_status;\n };\n \n-static void ctrl_params_free(struct rte_thread_ctrl_params *params)\n-{\n-\tif (__atomic_sub_fetch(&params->refcnt, 1, __ATOMIC_ACQ_REL) == 0) {\n-\t\t(void)pthread_barrier_destroy(&params->configured);\n-\t\tfree(params);\n-\t}\n-}\n-\n static void *ctrl_thread_init(void *arg)\n {\n \tstruct internal_config *internal_conf =\n \t\teal_get_internal_configuration();\n \trte_cpuset_t *cpuset = &internal_conf->ctrl_cpuset;\n \tstruct rte_thread_ctrl_params *params = arg;\n-\tvoid *(*start_routine)(void *);\n+\tvoid *(*start_routine)(void *) = params->start_routine;\n \tvoid *routine_arg = params->arg;\n \n \t__rte_thread_init(rte_lcore_id(), cpuset);\n-\n-\tpthread_barrier_wait(&params->configured);\n-\tstart_routine = params->start_routine;\n-\tctrl_params_free(params);\n-\n-\tif (start_routine == NULL)\n+\tparams->ret = pthread_setaffinity_np(pthread_self(),\n+\t\t\t\tsizeof(*cpuset), cpuset);\n+\tif (params->ret != 0) {\n+\t\t__atomic_store_n(&params->ctrl_thread_status,\n+\t\t\t\t\tCTRL_THREAD_ERROR,\n+\t\t\t\t\t__ATOMIC_RELEASE);\n \t\treturn NULL;\n+\t}\n+\n+\t__atomic_store_n(&params->ctrl_thread_status,\n+\t\t\t\tCTRL_THREAD_RUNNING,\n+\t\t\t\t__ATOMIC_RELEASE);\n \n \treturn start_routine(routine_arg);\n }\n@@ -207,10 +213,8 @@ rte_ctrl_thread_create(pthread_t *thread, const char *name,\n \t\tconst pthread_attr_t *attr,\n \t\tvoid *(*start_routine)(void *), void *arg)\n {\n-\tstruct internal_config *internal_conf =\n-\t\teal_get_internal_configuration();\n-\trte_cpuset_t *cpuset = &internal_conf->ctrl_cpuset;\n \tstruct rte_thread_ctrl_params *params;\n+\tenum __rte_ctrl_thread_status ctrl_thread_status;\n \tint ret;\n \n \tparams = malloc(sizeof(*params));\n@@ -219,15 +223,14 @@ rte_ctrl_thread_create(pthread_t *thread, const char *name,\n \n \tparams->start_routine = start_routine;\n \tparams->arg = arg;\n-\tparams->refcnt = 2;\n-\n-\tret = pthread_barrier_init(&params->configured, NULL, 2);\n-\tif (ret != 0)\n-\t\tgoto fail_no_barrier;\n+\tparams->ret = 0;\n+\tparams->ctrl_thread_status = CTRL_THREAD_LAUNCHING;\n \n \tret = pthread_create(thread, attr, ctrl_thread_init, (void *)params);\n-\tif (ret != 0)\n-\t\tgoto fail_with_barrier;\n+\tif (ret != 0) {\n+\t\tfree(params);\n+\t\treturn -ret;\n+\t}\n \n \tif (name != NULL) {\n \t\tret = rte_thread_setname(*thread, name);\n@@ -236,24 +239,24 @@ rte_ctrl_thread_create(pthread_t *thread, const char *name,\n \t\t\t\t\"Cannot set name for ctrl thread\\n\");\n \t}\n \n-\tret = pthread_setaffinity_np(*thread, sizeof(*cpuset), cpuset);\n-\tif (ret != 0)\n-\t\tparams->start_routine = NULL;\n-\n-\tpthread_barrier_wait(&params->configured);\n-\tctrl_params_free(params);\n+\t/* Wait for the control thread to initialize successfully */\n+\twhile ((ctrl_thread_status =\n+\t\t__atomic_load_n(&params->ctrl_thread_status, __ATOMIC_ACQUIRE))\n+\t\t== CTRL_THREAD_LAUNCHING) {\n+\t\t/* Yield the CPU. Using sched_yield call requires maintaining\n+\t\t * another implementation for Windows as sched_yield is not\n+\t\t * supported on Windows.\n+\t\t */\n+\t\trte_delay_us_sleep(1);\n+\t}\n \n-\tif (ret != 0)\n-\t\t/* start_routine has been set to NULL above; */\n-\t\t/* ctrl thread will exit immediately */\n+\t/* Check if the control thread encountered an error */\n+\tif (ctrl_thread_status == CTRL_THREAD_ERROR) {\n+\t\t/* ctrl thread is exiting */\n \t\tpthread_join(*thread, NULL);\n+\t}\n \n-\treturn -ret;\n-\n-fail_with_barrier:\n-\t(void)pthread_barrier_destroy(&params->configured);\n-\n-fail_no_barrier:\n+\tret = params->ret;\n \tfree(params);\n \n \treturn -ret;\ndiff --git a/lib/eal/include/rte_lcore.h b/lib/eal/include/rte_lcore.h\nindex 1550b75da0..b81c8b2685 100644\n--- a/lib/eal/include/rte_lcore.h\n+++ b/lib/eal/include/rte_lcore.h\n@@ -420,10 +420,11 @@ rte_thread_unregister(void);\n /**\n  * Create a control thread.\n  *\n- * Wrapper to pthread_create(), pthread_setname_np() and\n- * pthread_setaffinity_np(). The affinity of the new thread is based\n- * on the CPU affinity retrieved at the time rte_eal_init() was called,\n- * the dataplane and service lcores are then excluded.\n+ * Creates a control thread with the given name and attributes. The\n+ * affinity of the new thread is based on the CPU affinity retrieved\n+ * at the time rte_eal_init() was called, the dataplane and service\n+ * lcores are then excluded. If setting the name of the thread fails,\n+ * the error is ignored and a debug message is logged.\n  *\n  * @param thread\n  *   Filled with the thread id of the new created thread.\n",
    "prefixes": [
        "v5",
        "1/2"
    ]
}