get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

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

{
    "id": 72267,
    "url": "http://patches.dpdk.org/api/patches/72267/?format=api",
    "web_url": "http://patches.dpdk.org/project/dpdk/patch/20200626144736.11011-7-david.marchand@redhat.com/",
    "project": {
        "id": 1,
        "url": "http://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": "<20200626144736.11011-7-david.marchand@redhat.com>",
    "list_archive_url": "https://inbox.dpdk.org/dev/20200626144736.11011-7-david.marchand@redhat.com",
    "date": "2020-06-26T14:47:33",
    "name": "[v4,6/9] eal: register non-EAL threads as lcores",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": true,
    "hash": "75644eaa7ed31ea1d34c19327a7bb5172b44d9c4",
    "submitter": {
        "id": 1173,
        "url": "http://patches.dpdk.org/api/people/1173/?format=api",
        "name": "David Marchand",
        "email": "david.marchand@redhat.com"
    },
    "delegate": {
        "id": 1,
        "url": "http://patches.dpdk.org/api/users/1/?format=api",
        "username": "tmonjalo",
        "first_name": "Thomas",
        "last_name": "Monjalon",
        "email": "thomas@monjalon.net"
    },
    "mbox": "http://patches.dpdk.org/project/dpdk/patch/20200626144736.11011-7-david.marchand@redhat.com/mbox/",
    "series": [
        {
            "id": 10635,
            "url": "http://patches.dpdk.org/api/series/10635/?format=api",
            "web_url": "http://patches.dpdk.org/project/dpdk/list/?series=10635",
            "date": "2020-06-26T14:47:27",
            "name": "Register non-EAL threads as lcore",
            "version": 4,
            "mbox": "http://patches.dpdk.org/series/10635/mbox/"
        }
    ],
    "comments": "http://patches.dpdk.org/api/patches/72267/comments/",
    "check": "success",
    "checks": "http://patches.dpdk.org/api/patches/72267/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 dpdk.org (dpdk.org [92.243.14.124])\n\tby inbox.dpdk.org (Postfix) with ESMTP id 6BB34A051C;\n\tFri, 26 Jun 2020 16:49:36 +0200 (CEST)",
            "from [92.243.14.124] (localhost [127.0.0.1])\n\tby dpdk.org (Postfix) with ESMTP id 544DE1C0BF;\n\tFri, 26 Jun 2020 16:49:36 +0200 (CEST)",
            "from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com\n [205.139.110.120]) by dpdk.org (Postfix) with ESMTP id 8A2271C0B8\n for <dev@dpdk.org>; Fri, 26 Jun 2020 16:49:34 +0200 (CEST)",
            "from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com\n [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id\n us-mta-294-njwkrWSJPpquoJTVQ-EHhA-1; Fri, 26 Jun 2020 10:49:30 -0400",
            "from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com\n [10.5.11.15])\n (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits))\n (No client certificate requested)\n by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9E18C190C822;\n Fri, 26 Jun 2020 14:49:00 +0000 (UTC)",
            "from dmarchan.remote.csb (unknown [10.40.193.229])\n by smtp.corp.redhat.com (Postfix) with ESMTP id 265419CFCA;\n Fri, 26 Jun 2020 14:48:56 +0000 (UTC)"
        ],
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n s=mimecast20190719; t=1593182974;\n h=from:from:reply-to:subject:subject:date:date:message-id:message-id:\n to:to:cc:cc:mime-version:mime-version:content-type:content-type:\n content-transfer-encoding:content-transfer-encoding:\n in-reply-to:in-reply-to:references:references;\n bh=HoVXtARxAtcU4NkgxK5yosEbQS+bOBUdjKPZu1r0XIU=;\n b=ElOro01I7EtR7dchcwGhVs7ilVElzUUvSQaKXh2uK2zc+C7ASEdegXQM1UZkTjYTJel+x2\n Gx0w8UNBU0QTOsgif/jKxQTfEVDhirKyowd0YDxK5BTCbOKk7zyOYYpRGceXXrSmDZd8zz\n ZVWYd9hOLTyCnZZUDJBWjyI/ps+s+So=",
        "X-MC-Unique": "njwkrWSJPpquoJTVQ-EHhA-1",
        "From": "David Marchand <david.marchand@redhat.com>",
        "To": "dev@dpdk.org",
        "Cc": "jerinjacobk@gmail.com, bruce.richardson@intel.com, mdr@ashroe.eu,\n thomas@monjalon.net, arybchenko@solarflare.com, ktraynor@redhat.com,\n ian.stokes@intel.com, i.maximets@ovn.org,\n John McNamara <john.mcnamara@intel.com>,\n Marko Kovacevic <marko.kovacevic@intel.com>,\n Anatoly Burakov <anatoly.burakov@intel.com>,\n Olivier Matz <olivier.matz@6wind.com>, Neil Horman <nhorman@tuxdriver.com>",
        "Date": "Fri, 26 Jun 2020 16:47:33 +0200",
        "Message-Id": "<20200626144736.11011-7-david.marchand@redhat.com>",
        "In-Reply-To": "<20200626144736.11011-1-david.marchand@redhat.com>",
        "References": "<20200610144506.30505-1-david.marchand@redhat.com>\n <20200626144736.11011-1-david.marchand@redhat.com>",
        "MIME-Version": "1.0",
        "X-Scanned-By": "MIMEDefang 2.79 on 10.5.11.15",
        "X-Mimecast-Spam-Score": "0",
        "X-Mimecast-Originator": "redhat.com",
        "Content-Type": "text/plain; charset=US-ASCII",
        "Content-Transfer-Encoding": "8bit",
        "Subject": "[dpdk-dev] [PATCH v4 6/9] eal: register non-EAL threads as lcores",
        "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 <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": "DPDK allows calling some part of its API from a non-EAL thread but this\nhas some limitations.\nOVS (and other applications) has its own thread management but still\nwant to avoid such limitations by hacking RTE_PER_LCORE(_lcore_id) and\nfaking EAL threads potentially unknown of some DPDK component.\n\nIntroduce a new API to register non-EAL thread and associate them to a\nfree lcore with a new NON_EAL role.\nThis role denotes lcores that do not run DPDK mainloop and as such\nprevents use of rte_eal_wait_lcore() and consorts.\n\nMultiprocess is not supported as the need for cohabitation with this new\nfeature is unclear at the moment.\n\nSigned-off-by: David Marchand <david.marchand@redhat.com>\nAcked-by: Andrew Rybchenko <arybchenko@solarflare.com>\n---\nChanges since v2:\n- refused multiprocess init once rte_thread_register got called, and\n  vice versa,\n- added warning on multiprocess in rte_thread_register doxygen,\n\nChanges since v1:\n- moved cleanup on lcore role code in patch 5,\n- added unit test,\n- updated documentation,\n- changed naming from \"external thread\" to \"registered non-EAL thread\"\n\n---\n MAINTAINERS                                   |   1 +\n app/test/Makefile                             |   1 +\n app/test/autotest_data.py                     |   6 +\n app/test/meson.build                          |   2 +\n app/test/test_lcores.c                        | 139 ++++++++++++++++++\n doc/guides/howto/debug_troubleshoot.rst       |   5 +-\n .../prog_guide/env_abstraction_layer.rst      |  22 +--\n doc/guides/prog_guide/mempool_lib.rst         |   2 +-\n lib/librte_eal/common/eal_common_lcore.c      |  50 ++++++-\n lib/librte_eal/common/eal_common_mcfg.c       |  36 +++++\n lib/librte_eal/common/eal_common_thread.c     |  33 +++++\n lib/librte_eal/common/eal_memcfg.h            |  10 ++\n lib/librte_eal/common/eal_private.h           |  18 +++\n lib/librte_eal/freebsd/eal.c                  |   4 +\n lib/librte_eal/include/rte_lcore.h            |  25 +++-\n lib/librte_eal/linux/eal.c                    |   4 +\n lib/librte_eal/rte_eal_version.map            |   2 +\n lib/librte_mempool/rte_mempool.h              |  11 +-\n 18 files changed, 349 insertions(+), 22 deletions(-)\n create mode 100644 app/test/test_lcores.c",
    "diff": "diff --git a/MAINTAINERS b/MAINTAINERS\nindex 45b6c3a990..88c6d85e07 100644\n--- a/MAINTAINERS\n+++ b/MAINTAINERS\n@@ -182,6 +182,7 @@ F: app/test/test_cycles.c\n F: app/test/test_debug.c\n F: app/test/test_eal*\n F: app/test/test_errno.c\n+F: app/test/test_lcores.c\n F: app/test/test_logs.c\n F: app/test/test_memcpy*\n F: app/test/test_per_lcore.c\ndiff --git a/app/test/Makefile b/app/test/Makefile\nindex 7b96a03a64..4a8dea2425 100644\n--- a/app/test/Makefile\n+++ b/app/test/Makefile\n@@ -97,6 +97,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_FLOW_CLASSIFY) += test_flow_classify.c\n endif\n \n SRCS-y += test_rwlock.c\n+SRCS-y += test_lcores.c\n \n SRCS-$(CONFIG_RTE_LIBRTE_STACK) += test_stack.c\n SRCS-$(CONFIG_RTE_LIBRTE_STACK) += test_stack_perf.c\ndiff --git a/app/test/autotest_data.py b/app/test/autotest_data.py\nindex 238ab631b4..4b7da45e09 100644\n--- a/app/test/autotest_data.py\n+++ b/app/test/autotest_data.py\n@@ -62,6 +62,12 @@\n         \"Func\":    rwlock_autotest,\n         \"Report\":  None,\n     },\n+    {\n+        \"Name\":    \"Lcores autotest\",\n+        \"Command\": \"lcores_autotest\",\n+        \"Func\":    default_autotest,\n+        \"Report\":  None,\n+    },\n     {\n         \"Name\":    \"Logs autotest\",\n         \"Command\": \"logs_autotest\",\ndiff --git a/app/test/meson.build b/app/test/meson.build\nindex 5233ead46e..a57477b7cc 100644\n--- a/app/test/meson.build\n+++ b/app/test/meson.build\n@@ -67,6 +67,7 @@ test_sources = files('commands.c',\n \t'test_ipsec_perf.c',\n \t'test_kni.c',\n \t'test_kvargs.c',\n+\t'test_lcores.c',\n \t'test_logs.c',\n \t'test_lpm.c',\n \t'test_lpm6.c',\n@@ -206,6 +207,7 @@ fast_tests = [\n         ['hash_autotest', true],\n         ['interrupt_autotest', true],\n         ['ipfrag_autotest', false],\n+        ['lcores_autotest', true],\n         ['logs_autotest', true],\n         ['lpm_autotest', true],\n         ['lpm6_autotest', true],\ndiff --git a/app/test/test_lcores.c b/app/test/test_lcores.c\nnew file mode 100644\nindex 0000000000..864bcbade7\n--- /dev/null\n+++ b/app/test/test_lcores.c\n@@ -0,0 +1,139 @@\n+/* SPDX-License-Identifier: BSD-3-Clause\n+ * Copyright (c) 2020 Red Hat, Inc.\n+ */\n+\n+#include <pthread.h>\n+#include <string.h>\n+\n+#include <rte_lcore.h>\n+\n+#include \"test.h\"\n+\n+struct thread_context {\n+\tenum { INIT, ERROR, DONE } state;\n+\tbool lcore_id_any;\n+\tpthread_t id;\n+\tunsigned int *registered_count;\n+};\n+static void *thread_loop(void *arg)\n+{\n+\tstruct thread_context *t = arg;\n+\tunsigned int lcore_id;\n+\n+\tlcore_id = rte_lcore_id();\n+\tif (lcore_id != LCORE_ID_ANY) {\n+\t\tprintf(\"Incorrect lcore id for new thread %u\\n\", lcore_id);\n+\t\tt->state = ERROR;\n+\t}\n+\trte_thread_register();\n+\tlcore_id = rte_lcore_id();\n+\tif ((t->lcore_id_any && lcore_id != LCORE_ID_ANY) ||\n+\t\t\t(!t->lcore_id_any && lcore_id == LCORE_ID_ANY)) {\n+\t\tprintf(\"Could not register new thread, got %u while %sexpecting %u\\n\",\n+\t\t\tlcore_id, t->lcore_id_any ? \"\" : \"not \", LCORE_ID_ANY);\n+\t\tt->state = ERROR;\n+\t}\n+\t/* Report register happened to the control thread. */\n+\t__atomic_add_fetch(t->registered_count, 1, __ATOMIC_RELEASE);\n+\n+\t/* Wait for release from the control thread. */\n+\twhile (__atomic_load_n(t->registered_count, __ATOMIC_ACQUIRE) != 0)\n+\t\t;\n+\trte_thread_unregister();\n+\tlcore_id = rte_lcore_id();\n+\tif (lcore_id != LCORE_ID_ANY) {\n+\t\tprintf(\"Could not unregister new thread, %u still assigned\\n\",\n+\t\t\tlcore_id);\n+\t\tt->state = ERROR;\n+\t}\n+\n+\tif (t->state != ERROR)\n+\t\tt->state = DONE;\n+\n+\treturn NULL;\n+}\n+\n+static int\n+test_non_eal_lcores(unsigned int eal_threads_count)\n+{\n+\tstruct thread_context thread_contexts[RTE_MAX_LCORE];\n+\tunsigned int non_eal_threads_count;\n+\tunsigned int registered_count;\n+\tstruct thread_context *t;\n+\tunsigned int i;\n+\tint ret;\n+\n+\tnon_eal_threads_count = 0;\n+\tregistered_count = 0;\n+\n+\t/* Try to create as many threads as possible. */\n+\tfor (i = 0; i < RTE_MAX_LCORE - eal_threads_count; i++) {\n+\t\tt = &thread_contexts[i];\n+\t\tt->state = INIT;\n+\t\tt->registered_count = &registered_count;\n+\t\tt->lcore_id_any = false;\n+\t\tif (pthread_create(&t->id, NULL, thread_loop, t) != 0)\n+\t\t\tbreak;\n+\t\tnon_eal_threads_count++;\n+\t}\n+\tprintf(\"non-EAL threads count: %u\\n\", non_eal_threads_count);\n+\t/* Wait all non-EAL threads to register. */\n+\twhile (__atomic_load_n(&registered_count, __ATOMIC_ACQUIRE) !=\n+\t\t\tnon_eal_threads_count)\n+\t\t;\n+\n+\t/* We managed to create the max number of threads, let's try to create\n+\t * one more. This will allow one more check.\n+\t */\n+\tif (eal_threads_count + non_eal_threads_count < RTE_MAX_LCORE)\n+\t\tgoto skip_lcore_any;\n+\tt = &thread_contexts[non_eal_threads_count];\n+\tt->state = INIT;\n+\tt->registered_count = &registered_count;\n+\tt->lcore_id_any = true;\n+\tif (pthread_create(&t->id, NULL, thread_loop, t) == 0) {\n+\t\tnon_eal_threads_count++;\n+\t\tprintf(\"non-EAL threads count: %u\\n\", non_eal_threads_count);\n+\t\twhile (__atomic_load_n(&registered_count, __ATOMIC_ACQUIRE) !=\n+\t\t\t\tnon_eal_threads_count)\n+\t\t\t;\n+\t}\n+\n+skip_lcore_any:\n+\t/* Release all threads, and check their states. */\n+\t__atomic_store_n(&registered_count, 0, __ATOMIC_RELEASE);\n+\tret = 0;\n+\tfor (i = 0; i < non_eal_threads_count; i++) {\n+\t\tt = &thread_contexts[i];\n+\t\tpthread_join(t->id, NULL);\n+\t\tif (t->state != DONE)\n+\t\t\tret = -1;\n+\t}\n+\n+\treturn ret;\n+}\n+\n+static int\n+test_lcores(void)\n+{\n+\tunsigned int eal_threads_count = 0;\n+\tunsigned int i;\n+\n+\tfor (i = 0; i < RTE_MAX_LCORE; i++) {\n+\t\tif (!rte_lcore_has_role(i, ROLE_OFF))\n+\t\t\teal_threads_count++;\n+\t}\n+\tif (eal_threads_count == 0) {\n+\t\tprintf(\"Something is broken, no EAL thread detected.\\n\");\n+\t\treturn TEST_FAILED;\n+\t}\n+\tprintf(\"EAL threads count: %u, RTE_MAX_LCORE=%u\\n\", eal_threads_count,\n+\t\tRTE_MAX_LCORE);\n+\n+\tif (test_non_eal_lcores(eal_threads_count) < 0)\n+\t\treturn TEST_FAILED;\n+\n+\treturn TEST_SUCCESS;\n+}\n+\n+REGISTER_TEST_COMMAND(lcores_autotest, test_lcores);\ndiff --git a/doc/guides/howto/debug_troubleshoot.rst b/doc/guides/howto/debug_troubleshoot.rst\nindex cef016b2fe..5a46f5fba3 100644\n--- a/doc/guides/howto/debug_troubleshoot.rst\n+++ b/doc/guides/howto/debug_troubleshoot.rst\n@@ -307,8 +307,9 @@ Custom worker function :numref:`dtg_distributor_worker`.\n \n #. Configuration issue isolation\n \n-   * Identify core role using ``rte_eal_lcore_role`` to identify RTE, OFF and\n-     SERVICE. Check performance functions are mapped to run on the cores.\n+   * Identify core role using ``rte_eal_lcore_role`` to identify RTE, OFF,\n+     SERVICE and NON_EAL. Check performance functions are mapped to run on the\n+     cores.\n \n    * For high-performance execution logic ensure running it on correct NUMA\n      and non-master core.\ndiff --git a/doc/guides/prog_guide/env_abstraction_layer.rst b/doc/guides/prog_guide/env_abstraction_layer.rst\nindex 48a2fec066..f64ae953d1 100644\n--- a/doc/guides/prog_guide/env_abstraction_layer.rst\n+++ b/doc/guides/prog_guide/env_abstraction_layer.rst\n@@ -564,9 +564,13 @@ It's also compatible with the pattern of corelist('-l') option.\n non-EAL pthread support\n ~~~~~~~~~~~~~~~~~~~~~~~\n \n-It is possible to use the DPDK execution context with any user pthread (aka. Non-EAL pthreads).\n-In a non-EAL pthread, the *_lcore_id* is always LCORE_ID_ANY which identifies that it is not an EAL thread with a valid, unique, *_lcore_id*.\n-Some libraries will use an alternative unique ID (e.g. TID), some will not be impacted at all, and some will work but with limitations (e.g. timer and mempool libraries).\n+It is possible to use the DPDK execution context with any user pthread (aka. non-EAL pthreads).\n+There are two kinds of non-EAL pthreads:\n+\n+- a registered non-EAL pthread with a valid *_lcore_id* that was successfully assigned by calling ``rte_thread_register()``,\n+- a non registered non-EAL pthread with a LCORE_ID_ANY,\n+\n+For non registered non-EAL pthread (with a LCORE_ID_ANY *_lcore_id*), some libraries will use an alternative unique ID (e.g. TID), some will not be impacted at all, and some will work but with limitations (e.g. timer and mempool libraries).\n \n All these impacts are mentioned in :ref:`known_issue_label` section.\n \n@@ -613,9 +617,9 @@ Known Issues\n + rte_mempool\n \n   The rte_mempool uses a per-lcore cache inside the mempool.\n-  For non-EAL pthreads, ``rte_lcore_id()`` will not return a valid number.\n-  So for now, when rte_mempool is used with non-EAL pthreads, the put/get operations will bypass the default mempool cache and there is a performance penalty because of this bypass.\n-  Only user-owned external caches can be used in a non-EAL context in conjunction with ``rte_mempool_generic_put()`` and ``rte_mempool_generic_get()`` that accept an explicit cache parameter.\n+  For unregistered non-EAL pthreads, ``rte_lcore_id()`` will not return a valid number.\n+  So for now, when rte_mempool is used with unregistered non-EAL pthreads, the put/get operations will bypass the default mempool cache and there is a performance penalty because of this bypass.\n+  Only user-owned external caches can be used in an unregistered non-EAL context in conjunction with ``rte_mempool_generic_put()`` and ``rte_mempool_generic_get()`` that accept an explicit cache parameter.\n \n + rte_ring\n \n@@ -660,15 +664,15 @@ Known Issues\n \n + rte_timer\n \n-  Running  ``rte_timer_manage()`` on a non-EAL pthread is not allowed. However, resetting/stopping the timer from a non-EAL pthread is allowed.\n+  Running  ``rte_timer_manage()`` on an unregistered non-EAL pthread is not allowed. However, resetting/stopping the timer from a non-EAL pthread is allowed.\n \n + rte_log\n \n-  In non-EAL pthreads, there is no per thread loglevel and logtype, global loglevels are used.\n+  In unregistered non-EAL pthreads, there is no per thread loglevel and logtype, global loglevels are used.\n \n + misc\n \n-  The debug statistics of rte_ring, rte_mempool and rte_timer are not supported in a non-EAL pthread.\n+  The debug statistics of rte_ring, rte_mempool and rte_timer are not supported in an unregistered non-EAL pthread.\n \n cgroup control\n ~~~~~~~~~~~~~~\ndiff --git a/doc/guides/prog_guide/mempool_lib.rst b/doc/guides/prog_guide/mempool_lib.rst\nindex f8b430d656..e3e1f940be 100644\n--- a/doc/guides/prog_guide/mempool_lib.rst\n+++ b/doc/guides/prog_guide/mempool_lib.rst\n@@ -103,7 +103,7 @@ The maximum size of the cache is static and is defined at compilation time (CONF\n Alternatively to the internal default per-lcore local cache, an application can create and manage external caches through the ``rte_mempool_cache_create()``, ``rte_mempool_cache_free()`` and ``rte_mempool_cache_flush()`` calls.\n These user-owned caches can be explicitly passed to ``rte_mempool_generic_put()`` and ``rte_mempool_generic_get()``.\n The ``rte_mempool_default_cache()`` call returns the default internal cache if any.\n-In contrast to the default caches, user-owned caches can be used by non-EAL threads too.\n+In contrast to the default caches, user-owned caches can be used by unregistered non-EAL threads too.\n \n Mempool Handlers\n ------------------------\ndiff --git a/lib/librte_eal/common/eal_common_lcore.c b/lib/librte_eal/common/eal_common_lcore.c\nindex 86d32a3dd7..a61824a779 100644\n--- a/lib/librte_eal/common/eal_common_lcore.c\n+++ b/lib/librte_eal/common/eal_common_lcore.c\n@@ -6,13 +6,15 @@\n #include <limits.h>\n #include <string.h>\n \n-#include <rte_errno.h>\n-#include <rte_log.h>\n-#include <rte_eal.h>\n-#include <rte_lcore.h>\n #include <rte_common.h>\n #include <rte_debug.h>\n+#include <rte_eal.h>\n+#include <rte_errno.h>\n+#include <rte_lcore.h>\n+#include <rte_log.h>\n+#include <rte_spinlock.h>\n \n+#include \"eal_memcfg.h\"\n #include \"eal_private.h\"\n #include \"eal_thread.h\"\n \n@@ -220,3 +222,43 @@ rte_socket_id_by_idx(unsigned int idx)\n \t}\n \treturn config->numa_nodes[idx];\n }\n+\n+static rte_spinlock_t lcore_lock = RTE_SPINLOCK_INITIALIZER;\n+\n+unsigned int\n+eal_lcore_non_eal_allocate(void)\n+{\n+\tstruct rte_config *cfg = rte_eal_get_configuration();\n+\tunsigned int lcore_id;\n+\n+\tif (cfg->process_type == RTE_PROC_SECONDARY ||\n+\t\t\t!eal_mcfg_forbid_multiprocess()) {\n+\t\tRTE_LOG(ERR, EAL, \"Multiprocess in use, cannot allocate new lcore.\\n\");\n+\t\treturn RTE_MAX_LCORE;\n+\t}\n+\trte_spinlock_lock(&lcore_lock);\n+\tfor (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) {\n+\t\tif (cfg->lcore_role[lcore_id] != ROLE_OFF)\n+\t\t\tcontinue;\n+\t\tcfg->lcore_role[lcore_id] = ROLE_NON_EAL;\n+\t\tcfg->lcore_count++;\n+\t\tbreak;\n+\t}\n+\tif (lcore_id == RTE_MAX_LCORE)\n+\t\tRTE_LOG(DEBUG, EAL, \"No lcore available.\\n\");\n+\trte_spinlock_unlock(&lcore_lock);\n+\treturn lcore_id;\n+}\n+\n+void\n+eal_lcore_non_eal_release(unsigned int lcore_id)\n+{\n+\tstruct rte_config *cfg = rte_eal_get_configuration();\n+\n+\trte_spinlock_lock(&lcore_lock);\n+\tif (cfg->lcore_role[lcore_id] == ROLE_NON_EAL) {\n+\t\tcfg->lcore_role[lcore_id] = ROLE_OFF;\n+\t\tcfg->lcore_count--;\n+\t}\n+\trte_spinlock_unlock(&lcore_lock);\n+}\ndiff --git a/lib/librte_eal/common/eal_common_mcfg.c b/lib/librte_eal/common/eal_common_mcfg.c\nindex 49d3ed0ce5..5b42d454e2 100644\n--- a/lib/librte_eal/common/eal_common_mcfg.c\n+++ b/lib/librte_eal/common/eal_common_mcfg.c\n@@ -44,6 +44,42 @@ eal_mcfg_check_version(void)\n \treturn 0;\n }\n \n+enum mp_status {\n+\tMP_UNKNOWN,\n+\tMP_FORBIDDEN,\n+\tMP_ENABLED,\n+};\n+\n+static bool\n+eal_mcfg_set_mp_status(enum mp_status status)\n+{\n+\tstruct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;\n+\tuint8_t expected;\n+\tuint8_t desired;\n+\n+\texpected = MP_UNKNOWN;\n+\tdesired = status;\n+\tif (__atomic_compare_exchange_n(&mcfg->mp_status, &expected, desired,\n+\t\t\tfalse, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST))\n+\t\treturn true;\n+\n+\treturn __atomic_load_n(&mcfg->mp_status, __ATOMIC_RELAXED) == desired;\n+}\n+\n+bool\n+eal_mcfg_forbid_multiprocess(void)\n+{\n+\tassert(rte_eal_get_configuration()->process_type == RTE_PROC_PRIMARY);\n+\treturn eal_mcfg_set_mp_status(MP_FORBIDDEN);\n+}\n+\n+bool\n+eal_mcfg_enable_multiprocess(void)\n+{\n+\tassert(rte_eal_get_configuration()->process_type == RTE_PROC_SECONDARY);\n+\treturn eal_mcfg_set_mp_status(MP_ENABLED);\n+}\n+\n void\n eal_mcfg_update_internal(void)\n {\ndiff --git a/lib/librte_eal/common/eal_common_thread.c b/lib/librte_eal/common/eal_common_thread.c\nindex a7ae0691bf..1cbddc4b5b 100644\n--- a/lib/librte_eal/common/eal_common_thread.c\n+++ b/lib/librte_eal/common/eal_common_thread.c\n@@ -236,3 +236,36 @@ rte_ctrl_thread_create(pthread_t *thread, const char *name,\n \tpthread_join(*thread, NULL);\n \treturn -ret;\n }\n+\n+void\n+rte_thread_register(void)\n+{\n+\tunsigned int lcore_id;\n+\trte_cpuset_t cpuset;\n+\n+\t/* EAL init flushes all lcores, we can't register before. */\n+\tassert(internal_config.init_complete == 1);\n+\tif (pthread_getaffinity_np(pthread_self(), sizeof(cpuset),\n+\t\t\t&cpuset) != 0)\n+\t\tCPU_ZERO(&cpuset);\n+\tlcore_id = eal_lcore_non_eal_allocate();\n+\tif (lcore_id >= RTE_MAX_LCORE)\n+\t\tlcore_id = LCORE_ID_ANY;\n+\trte_thread_init(lcore_id, &cpuset);\n+\tif (lcore_id != LCORE_ID_ANY)\n+\t\tRTE_LOG(DEBUG, EAL, \"Registered non-EAL thread as lcore %u.\\n\",\n+\t\t\tlcore_id);\n+}\n+\n+void\n+rte_thread_unregister(void)\n+{\n+\tunsigned int lcore_id = rte_lcore_id();\n+\n+\tif (lcore_id != LCORE_ID_ANY)\n+\t\teal_lcore_non_eal_release(lcore_id);\n+\trte_thread_uninit();\n+\tif (lcore_id != LCORE_ID_ANY)\n+\t\tRTE_LOG(DEBUG, EAL, \"Unregistered non-EAL thread (was lcore %u).\\n\",\n+\t\t\tlcore_id);\n+}\ndiff --git a/lib/librte_eal/common/eal_memcfg.h b/lib/librte_eal/common/eal_memcfg.h\nindex 583fcb5953..340e523c6a 100644\n--- a/lib/librte_eal/common/eal_memcfg.h\n+++ b/lib/librte_eal/common/eal_memcfg.h\n@@ -41,6 +41,8 @@ struct rte_mem_config {\n \trte_rwlock_t memory_hotplug_lock;\n \t/**< Indicates whether memory hotplug request is in progress. */\n \n+\tuint8_t mp_status; /**< Indicates whether multiprocess can be used. */\n+\n \t/* memory segments and zones */\n \tstruct rte_fbarray memzones; /**< Memzone descriptors. */\n \n@@ -91,6 +93,14 @@ eal_mcfg_wait_complete(void);\n int\n eal_mcfg_check_version(void);\n \n+/* mark primary process as not supporting multi-process. */\n+bool\n+eal_mcfg_forbid_multiprocess(void);\n+\n+/* instruct primary process that a secondary process attached once. */\n+bool\n+eal_mcfg_enable_multiprocess(void);\n+\n /* set mem config as complete */\n void\n eal_mcfg_complete(void);\ndiff --git a/lib/librte_eal/common/eal_private.h b/lib/librte_eal/common/eal_private.h\nindex 0592fcd694..73238ff157 100644\n--- a/lib/librte_eal/common/eal_private.h\n+++ b/lib/librte_eal/common/eal_private.h\n@@ -396,6 +396,24 @@ uint64_t get_tsc_freq(void);\n  */\n uint64_t get_tsc_freq_arch(void);\n \n+/**\n+ * Allocate a free lcore to associate to a non-EAL thread.\n+ *\n+ * @return\n+ *   - the id of a lcore with role ROLE_NON_EAL on success.\n+ *   - RTE_MAX_LCORE if none was available.\n+ */\n+unsigned int eal_lcore_non_eal_allocate(void);\n+\n+/**\n+ * Release the lcore used by a non-EAL thread.\n+ * Counterpart of eal_lcore_non_eal_allocate().\n+ *\n+ * @param lcore_id\n+ *   The lcore with role ROLE_NON_EAL to release.\n+ */\n+void eal_lcore_non_eal_release(unsigned int lcore_id);\n+\n /**\n  * Prepare physical memory mapping\n  * i.e. hugepages on Linux and\ndiff --git a/lib/librte_eal/freebsd/eal.c b/lib/librte_eal/freebsd/eal.c\nindex 13e5de006f..32a3d999b8 100644\n--- a/lib/librte_eal/freebsd/eal.c\n+++ b/lib/librte_eal/freebsd/eal.c\n@@ -424,6 +424,10 @@ rte_config_init(void)\n \t\t}\n \t\tif (rte_eal_config_reattach() < 0)\n \t\t\treturn -1;\n+\t\tif (!eal_mcfg_enable_multiprocess()) {\n+\t\t\tRTE_LOG(ERR, EAL, \"Primary process refused secondary attachment\\n\");\n+\t\t\treturn -1;\n+\t\t}\n \t\teal_mcfg_update_internal();\n \t\tbreak;\n \tcase RTE_PROC_AUTO:\ndiff --git a/lib/librte_eal/include/rte_lcore.h b/lib/librte_eal/include/rte_lcore.h\nindex 3968c40693..43747e88df 100644\n--- a/lib/librte_eal/include/rte_lcore.h\n+++ b/lib/librte_eal/include/rte_lcore.h\n@@ -31,6 +31,7 @@ enum rte_lcore_role_t {\n \tROLE_RTE,\n \tROLE_OFF,\n \tROLE_SERVICE,\n+\tROLE_NON_EAL,\n };\n \n /**\n@@ -67,7 +68,8 @@ rte_lcore_has_role(unsigned int lcore_id, enum rte_lcore_role_t role);\n  *   to run threads with lcore IDs 0, 1, 2 and 3 on physical core 10..\n  *\n  * @return\n- *  Logical core ID (in EAL thread) or LCORE_ID_ANY (in non-EAL thread)\n+ *  Logical core ID (in EAL thread or registered non-EAL thread) or\n+ *  LCORE_ID_ANY (in unregistered non-EAL thread)\n  */\n static inline unsigned\n rte_lcore_id(void)\n@@ -279,6 +281,27 @@ int rte_thread_setname(pthread_t id, const char *name);\n __rte_experimental\n int rte_thread_getname(pthread_t id, char *name, size_t len);\n \n+/**\n+ * Register current non-EAL thread as a lcore.\n+ *\n+ * @note This API is not compatible with the multi-process feature:\n+ * - if a primary process registers a non-EAL thread, then no secondary process\n+ *   will initialise.\n+ * - if a secondary process initialises successfully, trying to register a\n+ *   non-EAL thread from either primary or secondary processes will always end\n+ *   up with the thread getting LCORE_ID_ANY as lcore.\n+ */\n+__rte_experimental\n+void\n+rte_thread_register(void);\n+\n+/**\n+ * Unregister current thread and release lcore if one was associated.\n+ */\n+__rte_experimental\n+void\n+rte_thread_unregister(void);\n+\n /**\n  * Create a control thread.\n  *\ndiff --git a/lib/librte_eal/linux/eal.c b/lib/librte_eal/linux/eal.c\nindex 8894cea50a..1d90d1c0e3 100644\n--- a/lib/librte_eal/linux/eal.c\n+++ b/lib/librte_eal/linux/eal.c\n@@ -514,6 +514,10 @@ rte_config_init(void)\n \t\t}\n \t\tif (rte_eal_config_reattach() < 0)\n \t\t\treturn -1;\n+\t\tif (!eal_mcfg_enable_multiprocess()) {\n+\t\t\tRTE_LOG(ERR, EAL, \"Primary process refused secondary attachment\\n\");\n+\t\t\treturn -1;\n+\t\t}\n \t\teal_mcfg_update_internal();\n \t\tbreak;\n \tcase RTE_PROC_AUTO:\ndiff --git a/lib/librte_eal/rte_eal_version.map b/lib/librte_eal/rte_eal_version.map\nindex 5831eea4b0..39c41d445d 100644\n--- a/lib/librte_eal/rte_eal_version.map\n+++ b/lib/librte_eal/rte_eal_version.map\n@@ -396,6 +396,8 @@ EXPERIMENTAL {\n \n \t# added in 20.08\n \t__rte_trace_mem_per_thread_free;\n+\trte_thread_register;\n+\trte_thread_unregister;\n };\n \n INTERNAL {\ndiff --git a/lib/librte_mempool/rte_mempool.h b/lib/librte_mempool/rte_mempool.h\nindex 652d19f9f1..9e0ee052b3 100644\n--- a/lib/librte_mempool/rte_mempool.h\n+++ b/lib/librte_mempool/rte_mempool.h\n@@ -28,9 +28,9 @@\n  * rte_mempool_get() or rte_mempool_put() are designed to be called from an EAL\n  * thread due to the internal per-lcore cache. Due to the lack of caching,\n  * rte_mempool_get() or rte_mempool_put() performance will suffer when called\n- * by non-EAL threads. Instead, non-EAL threads should call\n- * rte_mempool_generic_get() or rte_mempool_generic_put() with a user cache\n- * created with rte_mempool_cache_create().\n+ * by unregistered non-EAL threads. Instead, unregistered non-EAL threads\n+ * should call rte_mempool_generic_get() or rte_mempool_generic_put() with a\n+ * user cache created with rte_mempool_cache_create().\n  */\n \n #include <stdio.h>\n@@ -1233,7 +1233,7 @@ void rte_mempool_dump(FILE *f, struct rte_mempool *mp);\n /**\n  * Create a user-owned mempool cache.\n  *\n- * This can be used by non-EAL threads to enable caching when they\n+ * This can be used by unregistered non-EAL threads to enable caching when they\n  * interact with a mempool.\n  *\n  * @param size\n@@ -1264,7 +1264,8 @@ rte_mempool_cache_free(struct rte_mempool_cache *cache);\n  * @param lcore_id\n  *   The logical core id.\n  * @return\n- *   A pointer to the mempool cache or NULL if disabled or non-EAL thread.\n+ *   A pointer to the mempool cache or NULL if disabled or unregistered non-EAL\n+ *   thread.\n  */\n static __rte_always_inline struct rte_mempool_cache *\n rte_mempool_default_cache(struct rte_mempool *mp, unsigned lcore_id)\n",
    "prefixes": [
        "v4",
        "6/9"
    ]
}