From patchwork Mon Jun 27 16:56:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tyler Retzlaff X-Patchwork-Id: 113480 X-Patchwork-Delegate: david.marchand@redhat.com Return-Path: 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]) by inbox.dpdk.org (Postfix) with ESMTP id 8B143A054F; Mon, 27 Jun 2022 18:56:43 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 5132542B81; Mon, 27 Jun 2022 18:56:17 +0200 (CEST) Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by mails.dpdk.org (Postfix) with ESMTP id 9702740685 for ; Mon, 27 Jun 2022 18:56:09 +0200 (CEST) Received: by linux.microsoft.com (Postfix, from userid 1086) id 4214E20CD170; Mon, 27 Jun 2022 09:56:08 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 4214E20CD170 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1656348968; bh=zeHqsHFqZMlHno0wQqyQ0Rw0Havhv99bdHBA8u0g8bw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=j7iVyZGukM5zVlj3rGygSE3ePBEP8R84vh9XWfqGF81FKVpwFQm7ku+mjOfi1BmmQ NLPjXb0q7fw90qlL5FkiwauUneCHR1W2+J22yzzIJAhajdHI8exbq0+rEjP6RQk6NU XJCT1D8ba8JTUo/+oV+AHmH+Md24g5l9T+wwuQiU= From: Tyler Retzlaff To: dev@dpdk.org Cc: thomas@monjalon.net, dmitry.kozliuk@gmail.com, anatoly.burakov@intel.com, Tyler Retzlaff , Narcisa Vasile Subject: [PATCH v4 5/6] test/threads: add tests for thread attributes API Date: Mon, 27 Jun 2022 09:56:05 -0700 Message-Id: <1656348966-10194-6-git-send-email-roretzla@linux.microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1656348966-10194-1-git-send-email-roretzla@linux.microsoft.com> References: <1654783134-13303-1-git-send-email-roretzla@linux.microsoft.com> <1656348966-10194-1-git-send-email-roretzla@linux.microsoft.com> X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org test basic functionality and demonstrate use of following thread attributes api. additionally, test attributes are processed when supplied to rte_thread_create(). * rte_thread_attr_init * rte_thread_attr_set_affinity * rte_thread_attr_get_affinity * rte_thread_attr_set_priority Signed-off-by: Narcisa Vasile Signed-off-by: Tyler Retzlaff --- app/test/test_threads.c | 73 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 72 insertions(+), 1 deletion(-) diff --git a/app/test/test_threads.c b/app/test/test_threads.c index 1077373..3c22cec 100644 --- a/app/test/test_threads.c +++ b/app/test/test_threads.c @@ -17,7 +17,9 @@ static uint32_t thread_main(void *arg) { - *(rte_thread_t *)arg = rte_thread_self(); + if (arg != NULL) + *(rte_thread_t *)arg = rte_thread_self(); + __atomic_store_n(&thread_id_ready, 1, __ATOMIC_RELEASE); while (__atomic_load_n(&thread_id_ready, __ATOMIC_ACQUIRE) == 1) @@ -166,6 +168,73 @@ return 0; } +static int +test_thread_attributes_affinity(void) +{ + rte_thread_t thread_id; + rte_thread_attr_t attr; + rte_cpuset_t cpuset0; + rte_cpuset_t cpuset1; + + RTE_TEST_ASSERT(rte_thread_attr_init(&attr) == 0, + "Failed to initialize thread attributes"); + + CPU_ZERO(&cpuset0); + RTE_TEST_ASSERT(rte_thread_get_affinity_by_id(rte_thread_self(), &cpuset0) == 0, + "Failed to get thread affinity"); + RTE_TEST_ASSERT(rte_thread_attr_set_affinity(&attr, &cpuset0) == 0, + "Failed to set thread attributes affinity"); + RTE_TEST_ASSERT(rte_thread_attr_get_affinity(&attr, &cpuset1) == 0, + "Failed to get thread attributes affinity"); + RTE_TEST_ASSERT(memcmp(&cpuset0, &cpuset1, sizeof(rte_cpuset_t)) == 0, + "Affinity should be stable"); + + thread_id_ready = 0; + RTE_TEST_ASSERT(rte_thread_create(&thread_id, &attr, thread_main, NULL) == 0, + "Failed to create attributes affinity thread."); + + while (__atomic_load_n(&thread_id_ready, __ATOMIC_ACQUIRE) == 0) + ; + + RTE_TEST_ASSERT(rte_thread_get_affinity_by_id(thread_id, &cpuset1) == 0, + "Failed to get attributes thread affinity"); + RTE_TEST_ASSERT(memcmp(&cpuset0, &cpuset1, sizeof(rte_cpuset_t)) == 0, + "Failed to apply affinity attributes"); + + __atomic_store_n(&thread_id_ready, 2, __ATOMIC_RELEASE); + + return 0; +} + +static int +test_thread_attributes_priority(void) +{ + rte_thread_t thread_id; + rte_thread_attr_t attr; + enum rte_thread_priority priority; + + RTE_TEST_ASSERT(rte_thread_attr_init(&attr) == 0, + "Failed to initialize thread attributes"); + RTE_TEST_ASSERT(rte_thread_attr_set_priority(&attr, RTE_THREAD_PRIORITY_NORMAL) == 0, + "Failed to set thread attributes priority"); + + thread_id_ready = 0; + RTE_TEST_ASSERT(rte_thread_create(&thread_id, &attr, thread_main, NULL) == 0, + "Failed to create attributes priority thread."); + + while (__atomic_load_n(&thread_id_ready, __ATOMIC_ACQUIRE) == 0) + ; + + RTE_TEST_ASSERT(rte_thread_get_priority(thread_id, &priority) == 0, + "Failed to get thread priority"); + RTE_TEST_ASSERT(priority == RTE_THREAD_PRIORITY_NORMAL, + "Failed to apply priority attributes"); + + __atomic_store_n(&thread_id_ready, 2, __ATOMIC_RELEASE); + + return 0; +} + static struct unit_test_suite threads_test_suite = { .suite_name = "threads autotest", .setup = NULL, @@ -175,6 +244,8 @@ TEST_CASE(test_thread_create_detach), TEST_CASE(test_thread_affinity), TEST_CASE(test_thread_priority), + TEST_CASE(test_thread_attributes_affinity), + TEST_CASE(test_thread_attributes_priority), TEST_CASES_END() } };