[PATCH v5 1/3] eal: add rte control thread create API
David Marchand
david.marchand at redhat.com
Tue Feb 7 14:12:18 CET 2023
On Tue, Jan 31, 2023 at 9:30 PM Tyler Retzlaff
<roretzla at linux.microsoft.com> wrote:
>
> Add rte_control_thread_create API as a replacement for
> rte_ctrl_thread_create to allow deprecation of the use of platform
> specific types in DPDK public API.
>
> Duplicate the rte_ctrl_thread_create test adapted to use
> rte_control_thread create to keep both APIs under test until
> rte_ctrl_thread_create is removed.
>
> Signed-off-by: Tyler Retzlaff <roretzla at linux.microsoft.com>
> Acked-by: Morten Brørup <mb at smartsharesystems.com>
> Reviewed-by: Mattias Rönnblom <mattias.ronnblom at ericsson.com>
> ---
> app/test/test_lcores.c | 41 ++++++++++++++++++
> lib/eal/common/eal_common_thread.c | 85 ++++++++++++++++++++++++++++++++++----
> lib/eal/include/rte_thread.h | 33 +++++++++++++++
> lib/eal/version.map | 1 +
> 4 files changed, 152 insertions(+), 8 deletions(-)
>
> diff --git a/app/test/test_lcores.c b/app/test/test_lcores.c
> index 5b43aa5..9766f78 100644
> --- a/app/test/test_lcores.c
> +++ b/app/test/test_lcores.c
> @@ -353,6 +353,18 @@ static void *ctrl_thread_loop(void *arg)
> return NULL;
> }
>
> +static uint32_t control_thread_loop(void *arg)
> +{
> + struct thread_context *t = arg;
> +
> + printf("Control thread running successfully\n");
> +
> + /* Set the thread state to DONE */
> + t->state = Thread_DONE;
> +
> + return 0;
> +}
> +
> static int
> test_ctrl_thread(void)
> {
> @@ -380,6 +392,32 @@ static void *ctrl_thread_loop(void *arg)
> }
>
> static int
> +test_control_thread(void)
> +{
> + struct thread_context ctrl_thread_context;
> + struct thread_context *t;
> +
> + /* Create one control thread */
> + t = &ctrl_thread_context;
> + t->state = Thread_INIT;
> + if (rte_control_thread_create(&t->id, "test_control_threads",
> + NULL, control_thread_loop, t) != 0)
> + return -1;
> +
> + /* Wait till the control thread exits.
> + * This also acts as the barrier such that the memory operations
> + * in control thread are visible to this thread.
> + */
> + rte_thread_join(t->id, NULL);
> +
> + /* Check if the control thread set the correct state */
> + if (t->state != Thread_DONE)
> + return -1;
> +
> + return 0;
> +}
> +
> +static int
> test_lcores(void)
> {
> unsigned int eal_threads_count = 0;
> @@ -409,6 +447,9 @@ static void *ctrl_thread_loop(void *arg)
> if (test_ctrl_thread() < 0)
> return TEST_FAILED;
>
> + if (test_control_thread() < 0)
> + return TEST_FAILED;
> +
> return TEST_SUCCESS;
> }
>
Afair, the "legacy" API test being in test_lcores.c is mainly a side
effect of the API being defined in rte_lcore.h.
The new API is genuinely located in rte_thread.h and there is no
consideration over lcores: control thread are just "specialised"
rte_thread objects.
I'd rather see this test in app/test/test_threads.c with other
rte_thread API tests.
I think something like below would be enough, wdyt?
If you are fine with it and there is no other comment on this patch, I
plan to do this change before applying.
diff --git a/app/test/test_threads.c b/app/test/test_threads.c
index e0f18e4329..cc0bb69190 100644
--- a/app/test/test_threads.c
+++ b/app/test/test_threads.c
@@ -232,6 +232,31 @@ test_thread_attributes_priority(void)
return 0;
}
+static int
+test_control_thread_create_join(void)
+{
+ rte_thread_t thread_id;
+ rte_thread_t thread_main_id;
+
+ thread_id_ready = 0;
+ RTE_TEST_ASSERT(rte_control_thread_create(&thread_id,
"test_control_threads", NULL,
+ thread_main, &thread_main_id) == 0,
+ "Failed to create thread.");
+
+ while (__atomic_load_n(&thread_id_ready, __ATOMIC_ACQUIRE) == 0)
+ ;
+
+ RTE_TEST_ASSERT(rte_thread_equal(thread_id, thread_main_id) != 0,
+ "Unexpected thread id.");
+
+ __atomic_store_n(&thread_id_ready, 2, __ATOMIC_RELEASE);
+
+ RTE_TEST_ASSERT(rte_thread_join(thread_id, NULL) == 0,
+ "Failed to join thread.");
+
+ return 0;
+}
+
static struct unit_test_suite threads_test_suite = {
.suite_name = "threads autotest",
.setup = NULL,
@@ -243,6 +268,7 @@ static struct unit_test_suite threads_test_suite = {
TEST_CASE(test_thread_priority),
TEST_CASE(test_thread_attributes_affinity),
TEST_CASE(test_thread_attributes_priority),
+ TEST_CASE(test_control_thread_create_join),
TEST_CASES_END()
}
};
--
David Marchand
More information about the dev
mailing list