Show a patch.

GET /api/patches/74613/?format=api
Content-Type: application/json
Vary: Accept

    "id": 74613,
    "url": "",
    "web_url": "",
    "project": {
        "id": 1,
        "url": "",
        "name": "DPDK",
        "link_name": "dpdk",
        "list_id": "",
        "list_email": "",
        "web_url": "",
        "scm_url": "git://",
        "webscm_url": ""
    "msgid": "<>",
    "date": "2020-07-22T10:37:00",
    "name": "[v3,1/2] service: add API to retrieve service core active",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": true,
    "hash": "2bc4b80229e4db289b65f3472df353f65faeaf9f",
    "submitter": {
        "id": 317,
        "url": "",
        "name": "Van Haaren, Harry",
        "email": ""
    "delegate": {
        "id": 24651,
        "url": "",
        "username": "dmarchand",
        "first_name": "David",
        "last_name": "Marchand",
        "email": ""
    "mbox": "",
    "series": [
            "id": 11234,
            "url": "",
            "web_url": "",
            "date": "2020-07-22T10:37:00",
            "name": "[v3,1/2] service: add API to retrieve service core active",
            "version": 3,
            "mbox": ""
    "comments": "",
    "check": "fail",
    "checks": "",
    "tags": {},
    "headers": {
        "Return-Path": "<>",
        "References": "<>",
        "X-Mailman-Version": "2.1.15",
        "X-IronPort-AV": [
            "E=McAfee;i=\"6000,8403,9689\"; a=\"149470011\"",
            "E=Sophos;i=\"5.75,381,1589266800\"; d=\"scan'208\";a=\"149470011\"",
            "E=Sophos;i=\"5.75,381,1589266800\"; d=\"scan'208\";a=\"301910581\""
        "From": "Harry van Haaren <>",
        "IronPort-SDR": [
            "\n tQtv8wW6ryrFSDFdgZxU0ZmkghzgWhv4zbUwQjYyOGZmm+/PgN8L6u7N7DQ2Xtrk4cZwpAUv6Q\n ajmsS2MY593Q==",
            "\n X0xtXl4WMpJYpC+LeyuTm51psBVOoiZfBoqjEvPjTwLWzwG/irSFggW7E4ZjyT7bGGf6iLpf4Z\n Yi2UIjD7vLBg=="
        "List-Help": "<>",
        "X-ExtLoop1": "1",
        "X-BeenThere": "",
        "Message-Id": "<>",
        "X-Original-To": "",
        "Received": [
            "from ( [])\n\tby (Postfix) with ESMTP id BDB8EA0526;\n\tWed, 22 Jul 2020 12:36:13 +0200 (CEST)",
            "from [] (localhost [])\n\tby (Postfix) with ESMTP id 789461BFFF;\n\tWed, 22 Jul 2020 12:36:12 +0200 (CEST)",
            "from ( [])\n by (Postfix) with ESMTP id A54381BFFE\n for <>; Wed, 22 Jul 2020 12:36:10 +0200 (CEST)",
            "from ([])\n by with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384;\n 22 Jul 2020 03:36:09 -0700",
            "from (HELO\n ([])\n by with ESMTP; 22 Jul 2020 03:36:06 -0700"
        "X-Mailer": "git-send-email 2.17.1",
        "Sender": "\"dev\" <>",
        "Subject": "[dpdk-dev] [PATCH v3 1/2] service: add API to retrieve service core\n\tactive",
        "Precedence": "list",
        "Date": "Wed, 22 Jul 2020 11:37:00 +0100",
        "List-Archive": "<>",
        "X-Amp-File-Uploaded": "False",
        "List-Subscribe": "<>,\n <>",
        "Cc": ",,\n,,,\n,,,\n Harry van Haaren <>",
        "List-Id": "DPDK patches and discussions <>",
        "Delivered-To": "",
        "In-Reply-To": "<>",
        "List-Unsubscribe": "<>,\n <>",
        "List-Post": "<>",
        "To": "",
        "X-Amp-Result": "SKIPPED(no attachment in message)",
        "Errors-To": ""
    "content": "This commit adds a new experimental API which allows the user\nto retrieve the active state of an lcore. Knowing when the service\nlcore is completed its polling loop can be useful to applications\nto avoid race conditions when e.g. finalizing statistics.\n\nThe service thread itself now has a variable to indicate if its\nthread is active. When zero the service thread has completed its\nservice, and has returned from the service_runner_func() function.\n\nSuggested-by: Lukasz Wojciechowski <>\nSigned-off-by: Harry van Haaren <>\nReviewed-by: Phil Yang <>\n\n---\n\nv3:\n- Change service lcore stores to SEQ_CST (Honnappa, David)\n- Change control thread load to ACQ (Honnappa, David)\n- Comment reasons for SEQ_CST/ACQ (Honnappa, David)\n- Add comments to Doxygen for _stop() and _lcore_active() (Honnappa, David)\n- Add Phil's review tag from ML\n---\n lib/librte_eal/common/rte_service.c  | 23 ++++++++++++++++++++++-\n lib/librte_eal/include/rte_service.h | 20 +++++++++++++++++++-\n lib/librte_eal/   |  1 +\n 3 files changed, 42 insertions(+), 2 deletions(-)",
    "diff": "diff --git a/lib/librte_eal/common/rte_service.c b/lib/librte_eal/common/rte_service.c\nindex 6a0e0ff65..b0cf7c4ab 100644\n--- a/lib/librte_eal/common/rte_service.c\n+++ b/lib/librte_eal/common/rte_service.c\n@@ -65,6 +65,7 @@ struct core_state {\n \t/* map of services IDs are run on this core */\n \tuint64_t service_mask;\n \tuint8_t runstate; /* running or stopped */\n+\tuint8_t thread_active; /* indicates when thread is in service_run() */\n \tuint8_t is_service_core; /* set if core is currently a service core */\n \tuint8_t service_active_on_lcore[RTE_SERVICE_NUM_MAX];\n \tuint64_t loops;\n@@ -422,7 +423,7 @@ rte_service_may_be_active(uint32_t id)\n \t\treturn -EINVAL;\n \n \tfor (i = 0; i < lcore_count; i++) {\n-\t\tif (lcore_states[ids[i]].service_active_on_lcore[id])\n+\tif (lcore_states[ids[i]].service_active_on_lcore[id])\n \t\t\treturn 1;\n \t}\n \n@@ -457,6 +458,8 @@ service_runner_func(void *arg)\n \tconst int lcore = rte_lcore_id();\n \tstruct core_state *cs = &lcore_states[lcore];\n \n+\t__atomic_store_n(&cs->thread_active, 1, __ATOMIC_SEQ_CST);\n+\n \t/* runstate act as the guard variable. Use load-acquire\n \t * memory order here to synchronize with store-release\n \t * in runstate update functions.\n@@ -475,9 +478,27 @@ service_runner_func(void *arg)\n \t\tcs->loops++;\n \t}\n \n+\t/* Use SEQ CST memory ordering to avoid any re-ordering around\n+\t * this store, ensuring that once this store is visible, the service\n+\t * lcore thread really is done in service cores code.\n+\t */\n+\t__atomic_store_n(&cs->thread_active, 0, __ATOMIC_SEQ_CST);\n \treturn 0;\n }\n \n+int32_t\n+rte_service_lcore_active(uint32_t lcore)\n+{\n+\tif (lcore >= RTE_MAX_LCORE || !lcore_states[lcore].is_service_core)\n+\t\treturn -EINVAL;\n+\n+\t/* Load thread_active using ACQUIRE to avoid instructions dependent on\n+\t * the result being re-ordered before this load completes.\n+\t */\n+\treturn __atomic_load_n(&lcore_states[lcore].thread_active,\n+\t\t\t       __ATOMIC_ACQUIRE);\n+}\n+\n int32_t\n rte_service_lcore_count(void)\n {\ndiff --git a/lib/librte_eal/include/rte_service.h b/lib/librte_eal/include/rte_service.h\nindex e2d0a6dd3..84245020d 100644\n--- a/lib/librte_eal/include/rte_service.h\n+++ b/lib/librte_eal/include/rte_service.h\n@@ -249,7 +249,9 @@ int32_t rte_service_lcore_start(uint32_t lcore_id);\n  * Stop a service core.\n  *\n  * Stopping a core makes the core become idle, but remains  assigned as a\n- * service core.\n+ * service core. Note that the service lcore thread may not have returned from\n+ * the service it is running when this API returns. To check if the service\n+ * lcore is still active, the *rte_service_lcore_active* API is added.\n  *\n  * @retval 0 Success\n  * @retval -EINVAL Invalid *lcore_id* provided\n@@ -261,6 +263,22 @@ int32_t rte_service_lcore_start(uint32_t lcore_id);\n  */\n int32_t rte_service_lcore_stop(uint32_t lcore_id);\n \n+/**\n+ * Reports if a service lcore is currently running.\n+ *\n+ * This function returns if the core has finished service cores code, and has\n+ * returned to EAL control. If *rte_service_lcore_stop* has been called but\n+ * the lcore has not returned to EAL yet, it might be required to wait and call\n+ * this function again. The amount of time to wait before the core returns\n+ * depends on the duration of the services being run.\n+ *\n+ * @retval 0 Service thread is not active, and has been returned to EAL.\n+ * @retval 1 Service thread is in the service core polling loop.\n+ * @retval -EINVAL Invalid *lcore_id* provided.\n+ */\n+__rte_experimental\n+int32_t rte_service_lcore_active(uint32_t lcore_id);\n+\n /**\n  * Adds lcore to the list of service cores.\n  *\ndiff --git a/lib/librte_eal/ b/lib/librte_eal/\nindex bf0c17c23..d53d5d5b9 100644\n--- a/lib/librte_eal/\n+++ b/lib/librte_eal/\n@@ -401,6 +401,7 @@ EXPERIMENTAL {\n \trte_lcore_dump;\n \trte_lcore_iterate;\n \trte_mp_disable;\n+\trte_service_lcore_active;\n \trte_thread_register;\n \trte_thread_unregister;\n };\n",
    "prefixes": [