get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

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

{
    "id": 96558,
    "url": "http://patchwork.dpdk.org/api/patches/96558/?format=api",
    "web_url": "http://patchwork.dpdk.org/project/dpdk/patch/1627925546-29982-7-git-send-email-navasile@linux.microsoft.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": "<1627925546-29982-7-git-send-email-navasile@linux.microsoft.com>",
    "list_archive_url": "https://inbox.dpdk.org/dev/1627925546-29982-7-git-send-email-navasile@linux.microsoft.com",
    "date": "2021-08-02T17:32:22",
    "name": "[v12,06/10] eal: add thread lifetime management",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": true,
    "hash": "d9641e5b6989e07fd74ab0c250d8bcc9582c3edb",
    "submitter": {
        "id": 1668,
        "url": "http://patchwork.dpdk.org/api/people/1668/?format=api",
        "name": "Narcisa Ana Maria Vasile",
        "email": "navasile@linux.microsoft.com"
    },
    "delegate": null,
    "mbox": "http://patchwork.dpdk.org/project/dpdk/patch/1627925546-29982-7-git-send-email-navasile@linux.microsoft.com/mbox/",
    "series": [
        {
            "id": 18146,
            "url": "http://patchwork.dpdk.org/api/series/18146/?format=api",
            "web_url": "http://patchwork.dpdk.org/project/dpdk/list/?series=18146",
            "date": "2021-08-02T17:32:16",
            "name": "eal: Add EAL API for threading",
            "version": 12,
            "mbox": "http://patchwork.dpdk.org/series/18146/mbox/"
        }
    ],
    "comments": "http://patchwork.dpdk.org/api/patches/96558/comments/",
    "check": "warning",
    "checks": "http://patchwork.dpdk.org/api/patches/96558/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 6DD83A0C41;\n\tMon,  2 Aug 2021 19:33:13 +0200 (CEST)",
            "from [217.70.189.124] (localhost [127.0.0.1])\n\tby mails.dpdk.org (Postfix) with ESMTP id C0AAE411A1;\n\tMon,  2 Aug 2021 19:32:40 +0200 (CEST)",
            "from linux.microsoft.com (linux.microsoft.com [13.77.154.182])\n by mails.dpdk.org (Postfix) with ESMTP id 8166441179\n for <dev@dpdk.org>; Mon,  2 Aug 2021 19:32:32 +0200 (CEST)",
            "by linux.microsoft.com (Postfix, from userid 1059)\n id 3A53920B36F3; Mon,  2 Aug 2021 10:32:31 -0700 (PDT)"
        ],
        "DKIM-Filter": "OpenDKIM Filter v2.11.0 linux.microsoft.com 3A53920B36F3",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com;\n s=default; t=1627925551;\n bh=7v0mT1XGJpsxfHldn7D8ZldGZ3HtVnyHPKXos0/UIw4=;\n h=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n b=Z/YdCqwwGpRyeB+EjtRl0rg6Hf0uEUy5vW1y6+nqNdrdeHnSVrGA52/zbTgeNukB8\n oOpe9NyI2Dn+Gjy3IbWxA/G9AouoGCpefmfLFk82yD9jjwRH7UMPuHFGPpAYcelaBQ\n +gWAfU9NJvgm5flPb7RbS3M9tnFbimWeI4lWaUIE=",
        "From": "Narcisa Ana Maria Vasile <navasile@linux.microsoft.com>",
        "To": "dev@dpdk.org, thomas@monjalon.net, dmitry.kozliuk@gmail.com,\n khot@microsoft.com, navasile@microsoft.com, dmitrym@microsoft.com,\n roretzla@microsoft.com, talshn@nvidia.com, ocardona@microsoft.com",
        "Cc": "bruce.richardson@intel.com, david.marchand@redhat.com,\n pallavi.kadam@intel.com",
        "Date": "Mon,  2 Aug 2021 10:32:22 -0700",
        "Message-Id": "<1627925546-29982-7-git-send-email-navasile@linux.microsoft.com>",
        "X-Mailer": "git-send-email 1.8.3.1",
        "In-Reply-To": "<1627925546-29982-1-git-send-email-navasile@linux.microsoft.com>",
        "References": "<1627684312-28630-1-git-send-email-navasile@linux.microsoft.com>\n <1627925546-29982-1-git-send-email-navasile@linux.microsoft.com>",
        "Subject": "[dpdk-dev] [PATCH v12 06/10] eal: add thread lifetime management",
        "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": "From: Narcisa Vasile <navasile@microsoft.com>\n\nAdd functions for thread creation, joining, detaching.\n\nThe *rte_thread_create()* function can optionally receive\nan rte_thread_attr_t object that will cause the thread to be\ncreated with the affinity and priority described by the\nattributes object. If no rte_thread_attr_t is passed (parameter is NULL),\nthe default affinity and priority are used.\n\nOn Windows, the function executed by a thread when the thread starts is\nrepreseneted by a function pointer of type DWORD (*func) (void*).\nOn other platforms, the function pointer is a void* (*func) (void*).\n\nPerforming a cast between these two types of function pointers to\nuniformize the API on all platforms may result in undefined behavior.\nTO fix this issue, a wrapper that respects the signature required by\nCreateThread() has been created on Windows.\n\nSigned-off-by: Narcisa Vasile <navasile@microsoft.com>\n---\n lib/eal/common/rte_thread.c     | 107 +++++++++++++++++++++++++\n lib/eal/include/rte_thread.h    |  55 +++++++++++++\n lib/eal/version.map             |   3 +\n lib/eal/windows/include/sched.h |   2 +-\n lib/eal/windows/rte_thread.c    | 138 ++++++++++++++++++++++++++++++++\n 5 files changed, 304 insertions(+), 1 deletion(-)",
    "diff": "diff --git a/lib/eal/common/rte_thread.c b/lib/eal/common/rte_thread.c\nindex fcebf7097c..a0a51bc190 100644\n--- a/lib/eal/common/rte_thread.c\n+++ b/lib/eal/common/rte_thread.c\n@@ -144,6 +144,113 @@ rte_thread_attr_set_priority(rte_thread_attr_t *thread_attr,\n \treturn 0;\n }\n \n+int\n+rte_thread_create(rte_thread_t *thread_id,\n+\t\tconst rte_thread_attr_t *thread_attr,\n+\t\trte_thread_func thread_func, void *args)\n+{\n+\tint ret = 0;\n+\tpthread_attr_t attr;\n+\tpthread_attr_t *attrp = NULL;\n+\tstruct sched_param param = {\n+\t\t.sched_priority = 0,\n+\t};\n+\tint policy = SCHED_OTHER;\n+\n+\tif (thread_attr != NULL) {\n+\t\tret = pthread_attr_init(&attr);\n+\t\tif (ret != 0) {\n+\t\t\tRTE_LOG(DEBUG, EAL, \"pthread_attr_init failed\\n\");\n+\t\t\tgoto cleanup;\n+\t\t}\n+\n+\t\tattrp = &attr;\n+\n+\t\tif (thread_attr->priority != RTE_THREAD_PRIORITY_UNDEFINED) {\n+\t\t\t/*\n+\t\t\t * Set the inherit scheduler parameter to explicit,\n+\t\t\t * otherwise the priority attribute is ignored.\n+\t\t\t */\n+\t\t\tret = pthread_attr_setinheritsched(attrp,\n+\t\t\t\t\tPTHREAD_EXPLICIT_SCHED);\n+\t\t\tif (ret != 0) {\n+\t\t\t\tRTE_LOG(DEBUG, EAL, \"pthread_attr_setinheritsched failed\\n\");\n+\t\t\t\tgoto cleanup;\n+\t\t\t}\n+\n+\t\t\tret = thread_map_priority_to_os_value(\n+\t\t\t\t\tthread_attr->priority,\n+\t\t\t\t\t&param.sched_priority, &policy\n+\t\t\t\t\t);\n+\t\t\tif (ret != 0)\n+\t\t\t\tgoto cleanup;\n+\n+\t\t\tret = pthread_attr_setschedpolicy(attrp, policy);\n+\t\t\tif (ret != 0) {\n+\t\t\t\tRTE_LOG(DEBUG, EAL, \"pthread_attr_setschedpolicy failed\\n\");\n+\t\t\t\tgoto cleanup;\n+\t\t\t}\n+\n+\t\t\tret = pthread_attr_setschedparam(attrp, &param);\n+\t\t\tif (ret != 0) {\n+\t\t\t\tRTE_LOG(DEBUG, EAL, \"pthread_attr_setschedparam failed\\n\");\n+\t\t\t\tgoto cleanup;\n+\t\t\t}\n+\t\t}\n+\n+\t\tif (CPU_COUNT(&thread_attr->cpuset) > 0) {\n+\t\t\tret = pthread_attr_setaffinity_np(attrp,\n+\t\t\t\t\tsizeof(thread_attr->cpuset),\n+\t\t\t\t\t&thread_attr->cpuset);\n+\t\t\tif (ret != 0) {\n+\t\t\t\tRTE_LOG(DEBUG, EAL, \"pthread_attr_setaffinity_np failed\\n\");\n+\t\t\t\tgoto cleanup;\n+\t\t\t}\n+\t\t}\n+\t}\n+\n+\tret = pthread_create((pthread_t *)&thread_id->opaque_id, attrp,\n+\t\tthread_func, args);\n+\tif (ret != 0) {\n+\t\tRTE_LOG(DEBUG, EAL, \"pthread_create failed\\n\");\n+\t\tgoto cleanup;\n+\t}\n+\n+cleanup:\n+\tif (attrp != NULL)\n+\t\tpthread_attr_destroy(&attr);\n+\n+\treturn ret;\n+}\n+\n+int\n+rte_thread_join(rte_thread_t thread_id, unsigned long *value_ptr)\n+{\n+\tint ret = 0;\n+\tvoid *res = NULL;\n+\tvoid **pres = NULL;\n+\n+\tif (value_ptr != NULL)\n+\t\tpres = &res;\n+\n+\tret = pthread_join((pthread_t)thread_id.opaque_id, pres);\n+\tif (ret != 0) {\n+\t\tRTE_LOG(DEBUG, EAL, \"pthread_join failed\\n\");\n+\t\treturn ret;\n+\t}\n+\n+\tif (pres != NULL)\n+\t\t*value_ptr = *(unsigned long *)(*pres);\n+\n+\treturn 0;\n+}\n+\n+int\n+rte_thread_detach(rte_thread_t thread_id)\n+{\n+\treturn pthread_detach((pthread_t)thread_id.opaque_id);\n+}\n+\n int\n rte_thread_key_create(rte_thread_key *key, void (*destructor)(void *))\n {\ndiff --git a/lib/eal/include/rte_thread.h b/lib/eal/include/rte_thread.h\nindex 5514b2f57f..098c3ba343 100644\n--- a/lib/eal/include/rte_thread.h\n+++ b/lib/eal/include/rte_thread.h\n@@ -31,6 +31,7 @@ typedef struct rte_thread_tag {\n \tuintptr_t opaque_id; /**< thread identifier */\n } rte_thread_t;\n \n+typedef void* (*rte_thread_func) (void *);\n /**\n  * Thread priority values.\n  */\n@@ -213,6 +214,60 @@ int rte_thread_set_affinity(rte_cpuset_t *cpusetp);\n  */\n void rte_thread_get_affinity(rte_cpuset_t *cpusetp);\n \n+/**\n+ * Create a new thread that will invoke the 'thread_func' routine.\n+ *\n+ * @param thread_id\n+ *    A pointer that will store the id of the newly created thread.\n+ *\n+ * @param thread_attr\n+ *    Attributes that are used at the creation of the new thread.\n+ *\n+ * @param thread_func\n+ *    The routine that the new thread will invoke when starting execution.\n+ *\n+ * @param args\n+ *    Arguments to be passed to the 'thread_func' routine.\n+ *\n+ * @return\n+ *   On success, return 0.\n+ *   On failure, return a positive errno-style error number.\n+ */\n+__rte_experimental\n+int rte_thread_create(rte_thread_t *thread_id,\n+\t\tconst rte_thread_attr_t *thread_attr,\n+\t\trte_thread_func thread_func, void *args);\n+\n+/**\n+ * Waits for the thread identified by 'thread_id' to terminate\n+ *\n+ * @param thread_id\n+ *    The identifier of the thread.\n+ *\n+ * @param value_ptr\n+ *    Stores the exit status of the thread.\n+ *\n+ * @return\n+ *   On success, return 0.\n+ *   On failure, return a positive errno-style error number.\n+ */\n+__rte_experimental\n+int rte_thread_join(rte_thread_t thread_id, unsigned long *value_ptr);\n+\n+/**\n+ * Indicate that the return value of the thread is not needed and\n+ * all thread resources should be release when the thread terminates.\n+ *\n+ * @param thread_id\n+ *    The id of the thread to be detached.\n+ *\n+ * @return\n+ *   On success, return 0.\n+ *   On failure, return a positive errno-style error number.\n+ */\n+__rte_experimental\n+int rte_thread_detach(rte_thread_t thread_id);\n+\n #endif /* RTE_HAS_CPUSET */\n \n /**\ndiff --git a/lib/eal/version.map b/lib/eal/version.map\nindex df01bbbbe4..02994dd3fb 100644\n--- a/lib/eal/version.map\n+++ b/lib/eal/version.map\n@@ -436,6 +436,9 @@ EXPERIMENTAL {\n \trte_thread_get_affinity_by_id;\n \trte_thread_set_affinity_by_id;\n \trte_thread_set_priority;\n+\trte_thread_create;\n+\trte_thread_join;\n+\trte_thread_detach;\n };\n \n INTERNAL {\ndiff --git a/lib/eal/windows/include/sched.h b/lib/eal/windows/include/sched.h\nindex ff572b5dcb..8f0b3cb71e 100644\n--- a/lib/eal/windows/include/sched.h\n+++ b/lib/eal/windows/include/sched.h\n@@ -44,7 +44,7 @@ typedef struct _rte_cpuset_s {\n \t(1LL << _WHICH_BIT(b))) != 0LL)\n \n static inline int\n-count_cpu(rte_cpuset_t *s)\n+count_cpu(const rte_cpuset_t *s)\n {\n \tunsigned int _i;\n \tint count = 0;\ndiff --git a/lib/eal/windows/rte_thread.c b/lib/eal/windows/rte_thread.c\nindex fb04718f58..e5e420fadd 100644\n--- a/lib/eal/windows/rte_thread.c\n+++ b/lib/eal/windows/rte_thread.c\n@@ -14,6 +14,11 @@ struct eal_tls_key {\n \tDWORD thread_index;\n };\n \n+struct thread_routine_ctx {\n+\trte_thread_func thread_func;\n+\tvoid *routine_args;\n+};\n+\n /* Translates the most common error codes related to threads */\n static int\n thread_translate_win32_error(DWORD error)\n@@ -309,6 +314,139 @@ rte_thread_attr_set_priority(rte_thread_attr_t *thread_attr,\n \treturn 0;\n }\n \n+static DWORD\n+thread_func_wrapper(void *args)\n+{\n+\tstruct thread_routine_ctx *pctx = args;\n+\tunsigned long *func_ret = NULL;\n+\tstruct thread_routine_ctx ctx;\n+\n+\tctx.thread_func = pctx->thread_func;\n+\tctx.routine_args = pctx->routine_args;\n+\n+\tfree(pctx);\n+\n+\tfunc_ret = (unsigned long *)ctx.thread_func(ctx.routine_args);\n+\treturn *func_ret;\n+}\n+\n+int\n+rte_thread_create(rte_thread_t *thread_id,\n+\t\t  const rte_thread_attr_t *thread_attr,\n+\t\t  rte_thread_func thread_func, void *args)\n+{\n+\tint ret = 0;\n+\tDWORD tid;\n+\tHANDLE thread_handle = NULL;\n+\tGROUP_AFFINITY thread_affinity;\n+\tstruct thread_routine_ctx *ctx = NULL;\n+\n+\tctx = calloc(1, sizeof(*ctx));\n+\tif (ctx == NULL) {\n+\t\tRTE_LOG(DEBUG, EAL, \"Insufficient memory for thread context allocations\\n\");\n+\t\tret = ENOMEM;\n+\t\tgoto cleanup;\n+\t}\n+\tctx->routine_args = args;\n+\tctx->thread_func = thread_func;\n+\n+\tthread_handle = CreateThread(NULL, 0, thread_func_wrapper, ctx,\n+\t\tCREATE_SUSPENDED, &tid);\n+\tif (thread_handle == NULL) {\n+\t\tret = thread_log_last_error(\"CreateThread()\");\n+\t\tfree(ctx);\n+\t\tgoto cleanup;\n+\t}\n+\tthread_id->opaque_id = tid;\n+\n+\tif (thread_attr != NULL) {\n+\t\tif (CPU_COUNT(&thread_attr->cpuset) > 0) {\n+\t\t\tret = rte_convert_cpuset_to_affinity(\n+\t\t\t\t\t\t\t&thread_attr->cpuset,\n+\t\t\t\t\t\t\t&thread_affinity\n+\t\t\t\t\t\t\t);\n+\t\t\tif (ret != 0) {\n+\t\t\t\tRTE_LOG(DEBUG, EAL, \"Unable to convert cpuset to thread affinity\\n\");\n+\t\t\t\tgoto cleanup;\n+\t\t\t}\n+\n+\t\t\tif (!SetThreadGroupAffinity(thread_handle,\n+\t\t\t\t\t\t    &thread_affinity, NULL)) {\n+\t\t\t\tret = thread_log_last_error(\"SetThreadGroupAffinity()\");\n+\t\t\t\tgoto cleanup;\n+\t\t\t}\n+\t\t}\n+\t\tif (thread_attr->priority != RTE_THREAD_PRIORITY_UNDEFINED) {\n+\t\t\tret = rte_thread_set_priority(*thread_id,\n+\t\t\t\t\t\t      thread_attr->priority);\n+\t\t\tif (ret != 0) {\n+\t\t\t\tRTE_LOG(DEBUG, EAL, \"Unable to set thread priority\\n\");\n+\t\t\t\tgoto cleanup;\n+\t\t\t}\n+\t\t}\n+\t}\n+\n+\tif (ResumeThread(thread_handle) == (DWORD)-1) {\n+\t\tret = thread_log_last_error(\"ResumeThread()\");\n+\t\tgoto cleanup;\n+\t}\n+\n+cleanup:\n+\tif (thread_handle != NULL) {\n+\t\tCloseHandle(thread_handle);\n+\t\tthread_handle = NULL;\n+\t}\n+\treturn ret;\n+}\n+\n+int\n+rte_thread_join(rte_thread_t thread_id, unsigned long *value_ptr)\n+{\n+\tHANDLE thread_handle;\n+\tDWORD result;\n+\tDWORD exit_code = 0;\n+\tBOOL err;\n+\tint ret = 0;\n+\n+\tthread_handle = OpenThread(SYNCHRONIZE | THREAD_QUERY_INFORMATION,\n+\t\t\t\t   FALSE, thread_id.opaque_id);\n+\tif (thread_handle == NULL) {\n+\t\tret = thread_log_last_error(\"OpenThread()\");\n+\t\tgoto cleanup;\n+\t}\n+\n+\tresult = WaitForSingleObject(thread_handle, INFINITE);\n+\tif (result != WAIT_OBJECT_0) {\n+\t\tret = thread_log_last_error(\"WaitForSingleObject()\");\n+\t\tgoto cleanup;\n+\t}\n+\n+\tif (value_ptr != NULL) {\n+\t\terr = GetExitCodeThread(thread_handle, &exit_code);\n+\t\tif (err == 0) {\n+\t\t\tret = thread_log_last_error(\"GetExitCodeThread()\");\n+\t\t\tgoto cleanup;\n+\t\t}\n+\t\t*value_ptr = exit_code;\n+\t}\n+\n+cleanup:\n+\tif (thread_handle != NULL) {\n+\t\tCloseHandle(thread_handle);\n+\t\tthread_handle = NULL;\n+\t}\n+\n+\treturn ret;\n+}\n+\n+int\n+rte_thread_detach(rte_thread_t thread_id)\n+{\n+\t/* No resources that need to be released. */\n+\tRTE_SET_USED(thread_id);\n+\treturn 0;\n+}\n+\n int\n rte_thread_key_create(rte_thread_key *key,\n \t\t__rte_unused void (*destructor)(void *))\n",
    "prefixes": [
        "v12",
        "06/10"
    ]
}