From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id BA63FA0032; Wed, 14 Sep 2022 11:26:38 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id D757D42B72; Wed, 14 Sep 2022 11:26:28 +0200 (CEST) Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by mails.dpdk.org (Postfix) with ESMTP id AC27E42802 for ; Wed, 14 Sep 2022 11:26:25 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1663147585; x=1694683585; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=iPDn5M7HmAVmLELuKMR+oK3Vqd3NucyVVdXDKuUDDes=; b=HxJ3ueP3QlNbTXdWaGH9GsQeN42FQlSQ+uh2vPWbF2ToWJb0Ib2gj3rq QItpKyS+O5dFq5svz6Av6ZaDA13qX9jDTWrGr8suS4K5smG3FHPsHzlu8 x1Mnsqc9reZTZpRs6KAOwyPJz/Jv3HmsgzjJONCD3KMGbLB0VeiNNRjLk ZZ6iIWgs77on3Kv2otEngyCa/hIjPR5Gkw5fAvAsU1m7/YlbAvu3QSPSj 9lsY7BNZT5jBNU2hgWBrSavwmUSmnHa1jA3/nXdw8rnMWUwceCoUZ0elg ZrJXZOdB0DBTaEHnGBfSjhJOoHlRL4vv1inhudHniE1dnkGIntnMDHQGf g==; X-IronPort-AV: E=McAfee;i="6500,9779,10469"; a="384675038" X-IronPort-AV: E=Sophos;i="5.93,315,1654585200"; d="scan'208";a="384675038" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Sep 2022 02:26:24 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.93,315,1654585200"; d="scan'208";a="612446522" Received: from silpixa00401122.ir.intel.com ([10.237.213.42]) by orsmga007.jf.intel.com with ESMTP; 14 Sep 2022 02:26:23 -0700 From: Kevin Laatz To: dev@dpdk.org Cc: anatoly.burakov@intel.com, Kevin Laatz Subject: [PATCH v7 3/4] app/test: add unit tests for lcore poll busyness Date: Wed, 14 Sep 2022 10:29:28 +0100 Message-Id: <20220914092929.1159773-4-kevin.laatz@intel.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220914092929.1159773-1-kevin.laatz@intel.com> References: <24c49429394294cfbf0d9c506b205029bac77c8b.1657890378.git.anatoly.burakov@intel.com> <20220914092929.1159773-1-kevin.laatz@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 Add API unit tests and perf unit tests for the newly added lcore poll busyness feature. Signed-off-by: Kevin Laatz --- app/test/meson.build | 4 + app/test/test_lcore_poll_busyness_api.c | 134 +++++++++++++++++++++++ app/test/test_lcore_poll_busyness_perf.c | 72 ++++++++++++ 3 files changed, 210 insertions(+) create mode 100644 app/test/test_lcore_poll_busyness_api.c create mode 100644 app/test/test_lcore_poll_busyness_perf.c diff --git a/app/test/meson.build b/app/test/meson.build index bf1d81f84a..d543e730a2 100644 --- a/app/test/meson.build +++ b/app/test/meson.build @@ -74,6 +74,8 @@ test_sources = files( 'test_ipsec_perf.c', 'test_kni.c', 'test_kvargs.c', + 'test_lcore_poll_busyness_api.c', + 'test_lcore_poll_busyness_perf.c', 'test_lcores.c', 'test_logs.c', 'test_lpm.c', @@ -192,6 +194,7 @@ fast_tests = [ ['interrupt_autotest', true, true], ['ipfrag_autotest', false, true], ['lcores_autotest', true, true], + ['lcore_poll_busyness_autotest', true, true], ['logs_autotest', true, true], ['lpm_autotest', true, true], ['lpm6_autotest', true, true], @@ -292,6 +295,7 @@ perf_test_names = [ 'trace_perf_autotest', 'ipsec_perf_autotest', 'thash_perf_autotest', + 'lcore_poll_busyness_perf_autotest' ] driver_test_names = [ diff --git a/app/test/test_lcore_poll_busyness_api.c b/app/test/test_lcore_poll_busyness_api.c new file mode 100644 index 0000000000..db76322994 --- /dev/null +++ b/app/test/test_lcore_poll_busyness_api.c @@ -0,0 +1,134 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2022 Intel Corporation + */ + +#include + +#include "test.h" + +/* Arbitrary amount of "work" to simulate busyness with */ +#define WORK 32 +#define TIMESTAMP_ITERS 1000000 + +#define LCORE_POLL_BUSYNESS_NOT_SET -1 + +static int +test_lcore_poll_busyness_enable_disable(void) +{ + int initial_state, curr_state; + bool req_state; + + /* Get the initial state */ + initial_state = rte_lcore_poll_busyness_enabled(); + if (initial_state == -ENOTSUP) + return TEST_SKIPPED; + + /* Set state to the inverse of the initial state and check for the change */ + req_state = !initial_state; + rte_lcore_poll_busyness_enabled_set(req_state); + curr_state = rte_lcore_poll_busyness_enabled(); + if (curr_state != req_state) + return TEST_FAILED; + + /* Now change the state back to the original state. By changing it back, both + * enable and disable will have been tested. + */ + req_state = !curr_state; + rte_lcore_poll_busyness_enabled_set(req_state); + curr_state = rte_lcore_poll_busyness_enabled(); + if (curr_state != req_state) + return TEST_FAILED; + + return TEST_SUCCESS; +} + +static int +test_lcore_poll_busyness_invalid_lcore(void) +{ + int ret; + + /* Check if lcore poll busyness is enabled */ + if (rte_lcore_poll_busyness_enabled() == -ENOTSUP) + return TEST_SKIPPED; + + /* Only lcore_id <= RTE_MAX_LCORE are valid */ + ret = rte_lcore_poll_busyness(RTE_MAX_LCORE); + if (ret != -EINVAL) + return TEST_FAILED; + + return TEST_SUCCESS; +} + +static int +test_lcore_poll_busyness_inactive_lcore(void) +{ + int ret; + + /* Check if lcore poll busyness is enabled */ + if (rte_lcore_poll_busyness_enabled() == -ENOTSUP) + return TEST_SKIPPED; + + /* Use the test thread lcore_id for this test. Since it is not a polling + * application, the busyness is expected to return -1. + * + * Note: this will not work with affinitized cores + */ + ret = rte_lcore_poll_busyness(rte_lcore_id()); + if (ret != LCORE_POLL_BUSYNESS_NOT_SET) + return TEST_FAILED; + + return TEST_SUCCESS; +} + +static void +simulate_lcore_poll_busyness(int iters) +{ + int i; + + for (i = 0; i < iters; i++) + RTE_LCORE_POLL_BUSYNESS_TIMESTAMP(WORK); +} + +/* The test cannot know of an application running to test for valid lcore poll + * busyness data. For this test, we simulate lcore poll busyness for the + * lcore_id of the test thread for testing purposes. + */ +static int +test_lcore_poll_busyness_active_lcore(void) +{ + int ret; + + /* Check if lcore poll busyness is enabled */ + if (rte_lcore_poll_busyness_enabled() == -ENOTSUP) + return TEST_SKIPPED; + + simulate_lcore_poll_busyness(TIMESTAMP_ITERS); + + /* After timestamping with "work" many times, lcore poll busyness should be > 0 */ + ret = rte_lcore_poll_busyness(rte_lcore_id()); + if (ret <= 0) + return TEST_FAILED; + + return TEST_SUCCESS; +} + +static struct unit_test_suite lcore_poll_busyness_tests = { + .suite_name = "lcore poll busyness autotest", + .setup = NULL, + .teardown = NULL, + .unit_test_cases = { + TEST_CASE(test_lcore_poll_busyness_enable_disable), + TEST_CASE(test_lcore_poll_busyness_invalid_lcore), + TEST_CASE(test_lcore_poll_busyness_inactive_lcore), + TEST_CASE(test_lcore_poll_busyness_active_lcore), + TEST_CASES_END() + } +}; + +static int +test_lcore_poll_busyness_api(void) +{ + return unit_test_suite_runner(&lcore_poll_busyness_tests); +} + +REGISTER_TEST_COMMAND(lcore_poll_busyness_autotest, test_lcore_poll_busyness_api); diff --git a/app/test/test_lcore_poll_busyness_perf.c b/app/test/test_lcore_poll_busyness_perf.c new file mode 100644 index 0000000000..5c27d21b00 --- /dev/null +++ b/app/test/test_lcore_poll_busyness_perf.c @@ -0,0 +1,72 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2022 Intel Corporation + */ + +#include +#include + +#include +#include + +#include "test.h" + +/* Arbitrary amount of "work" to simulate busyness with */ +#define WORK 32 +#define TIMESTAMP_ITERS 1000000 +#define TEST_ITERS 10000 + +static void +simulate_lcore_poll_busyness(int iters) +{ + int i; + + for (i = 0; i < iters; i++) + RTE_LCORE_POLL_BUSYNESS_TIMESTAMP(WORK); +} + +static void +test_timestamp_perf(void) +{ + uint64_t start, end, diff; + uint64_t min = UINT64_MAX; + uint64_t max = 0; + uint64_t total = 0; + int i; + + for (i = 0; i < TEST_ITERS; i++) { + start = rte_rdtsc(); + RTE_LCORE_POLL_BUSYNESS_TIMESTAMP(WORK); + end = rte_rdtsc(); + + diff = end - start; + min = RTE_MIN(diff, min); + max = RTE_MAX(diff, max); + total += diff; + } + + printf("### Timestamp perf ###\n"); + printf("Min cycles: %"PRIu64"\n", min); + printf("Avg cycles: %"PRIu64"\n", total / TEST_ITERS); + printf("Max cycles: %"PRIu64"\n", max); + printf("\n"); +} + + +static int +test_lcore_poll_busyness_perf(void) +{ + if (rte_lcore_poll_busyness_enabled() == -ENOTSUP) { + printf("Lcore poll busyness may be disabled...\n"); + return TEST_SKIPPED; + } + + /* Initialize and prime the timestamp struct with simulated "work" for this lcore */ + simulate_lcore_poll_busyness(10000); + + /* Run perf tests */ + test_timestamp_perf(); + + return TEST_SUCCESS; +} + +REGISTER_TEST_COMMAND(lcore_poll_busyness_perf_autotest, test_lcore_poll_busyness_perf); -- 2.31.1