DPDK patches and discussions
 help / color / mirror / Atom feed
From: Shijith Thotton <sthotton@marvell.com>
To: Erik Gabriel Carrillo <erik.g.carrillo@intel.com>
Cc: Shijith Thotton <sthotton@marvell.com>,
	Pavan Nikhilesh <pbhagavatula@marvell.com>,
	Jerin Jacob <jerinj@marvell.com>, <dev@dpdk.org>
Subject: [dpdk-dev] [PATCH 2/3] test/event: add unit tests for periodic timer
Date: Tue, 9 Mar 2021 02:15:42 +0530	[thread overview]
Message-ID: <20210308204543.2903723-3-sthotton@marvell.com> (raw)
In-Reply-To: <20210308204543.2903723-1-sthotton@marvell.com>

Add tests to arm and cancel periodic timer.

Signed-off-by: Shijith Thotton <sthotton@marvell.com>
---
 app/test/test_event_timer_adapter.c | 136 +++++++++++++++++++++++++---
 1 file changed, 123 insertions(+), 13 deletions(-)

diff --git a/app/test/test_event_timer_adapter.c b/app/test/test_event_timer_adapter.c
index b536ddef4..20be46da3 100644
--- a/app/test/test_event_timer_adapter.c
+++ b/app/test/test_event_timer_adapter.c
@@ -283,7 +283,7 @@ test_port_conf_cb(uint16_t id, uint8_t event_dev_id, uint8_t *event_port_id,
 }
 
 static int
-_timdev_setup(uint64_t max_tmo_ns, uint64_t bkt_tck_ns)
+_timdev_setup(uint64_t max_tmo_ns, uint64_t bkt_tck_ns, uint64_t flags)
 {
 	struct rte_event_timer_adapter_info info;
 	struct rte_event_timer_adapter_conf config = {
@@ -292,7 +292,7 @@ _timdev_setup(uint64_t max_tmo_ns, uint64_t bkt_tck_ns)
 		.timer_tick_ns = bkt_tck_ns,
 		.max_tmo_ns = max_tmo_ns,
 		.nb_timers = MAX_TIMERS * 10,
-		.flags = RTE_EVENT_TIMER_ADAPTER_F_ADJUST_RES,
+		.flags = flags,
 	};
 	uint32_t caps = 0;
 	const char *pool_name = "timdev_test_pool";
@@ -301,6 +301,13 @@ _timdev_setup(uint64_t max_tmo_ns, uint64_t bkt_tck_ns)
 
 	TEST_ASSERT_SUCCESS(rte_event_timer_adapter_caps_get(evdev, &caps),
 				"failed to get adapter capabilities");
+
+	if (flags & RTE_EVENT_TIMER_ADAPTER_F_PERIODIC &&
+	    !(caps & RTE_EVENT_TIMER_ADAPTER_CAP_PERIODIC)) {
+		printf("Adapter does not support periodic timers\n");
+		return TEST_SKIPPED;
+	}
+
 	if (!(caps & RTE_EVENT_TIMER_ADAPTER_CAP_INTERNAL_PORT)) {
 		timdev = rte_event_timer_adapter_create_ext(&config,
 							    test_port_conf_cb,
@@ -338,42 +345,72 @@ _timdev_setup(uint64_t max_tmo_ns, uint64_t bkt_tck_ns)
 static int
 timdev_setup_usec(void)
 {
+	uint64_t flags = RTE_EVENT_TIMER_ADAPTER_F_ADJUST_RES;
+
 	return using_services ?
 		/* Max timeout is 10,000us and bucket interval is 100us */
-		_timdev_setup(1E7, 1E5) :
+		_timdev_setup(1E7, 1E5, flags) :
 		/* Max timeout is 100us and bucket interval is 1us */
-		_timdev_setup(1E5, 1E3);
+		_timdev_setup(1E5, 1E3, flags);
 }
 
 static int
 timdev_setup_usec_multicore(void)
 {
+	uint64_t flags = RTE_EVENT_TIMER_ADAPTER_F_ADJUST_RES;
+
 	return using_services ?
 		/* Max timeout is 10,000us and bucket interval is 100us */
-		_timdev_setup(1E7, 1E5) :
+		_timdev_setup(1E7, 1E5, flags) :
 		/* Max timeout is 100us and bucket interval is 1us */
-		_timdev_setup(1E5, 1E3);
+		_timdev_setup(1E5, 1E3, flags);
 }
 
 static int
 timdev_setup_msec(void)
 {
-	/* Max timeout is 2 mins, and bucket interval is 100 ms */
-	return _timdev_setup(180 * NSECPERSEC, NSECPERSEC / 10);
+	uint64_t flags = RTE_EVENT_TIMER_ADAPTER_F_ADJUST_RES;
+
+	/* Max timeout is 3 mins, and bucket interval is 100 ms */
+	return _timdev_setup(180 * NSECPERSEC, NSECPERSEC / 10, flags);
+}
+
+static int
+timdev_setup_msec_periodic(void)
+{
+	uint64_t flags = RTE_EVENT_TIMER_ADAPTER_F_ADJUST_RES |
+			 RTE_EVENT_TIMER_ADAPTER_F_PERIODIC;
+
+	/* Periodic mode with 100 ms resolution */
+	return _timdev_setup(0, NSECPERSEC / 10, flags);
 }
 
 static int
 timdev_setup_sec(void)
 {
+	uint64_t flags = RTE_EVENT_TIMER_ADAPTER_F_ADJUST_RES;
+
 	/* Max timeout is 100sec and bucket interval is 1sec */
-	return _timdev_setup(1E11, 1E9);
+	return _timdev_setup(1E11, 1E9, flags);
+}
+
+static int
+timdev_setup_sec_periodic(void)
+{
+	uint64_t flags = RTE_EVENT_TIMER_ADAPTER_F_ADJUST_RES |
+			 RTE_EVENT_TIMER_ADAPTER_F_PERIODIC;
+
+	/* Periodic mode with 1 sec resolution */
+	return _timdev_setup(0, NSECPERSEC, flags);
 }
 
 static int
 timdev_setup_sec_multicore(void)
 {
+	uint64_t flags = RTE_EVENT_TIMER_ADAPTER_F_ADJUST_RES;
+
 	/* Max timeout is 100sec and bucket interval is 1sec */
-	return _timdev_setup(1E11, 1E9);
+	return _timdev_setup(1E11, 1E9, flags);
 }
 
 static void
@@ -513,6 +550,18 @@ test_timer_arm(void)
 	return TEST_SUCCESS;
 }
 
+static inline int
+test_timer_arm_periodic(void)
+{
+	TEST_ASSERT_SUCCESS(_arm_timers(1, MAX_TIMERS),
+			    "Failed to arm timers");
+	/* With a resolution of 100ms and wait time of 1sec,
+	 * there will be 10 * MAX_TIMERS periodic timer triggers */
+	TEST_ASSERT_SUCCESS(_wait_timer_triggers(1, 10 * MAX_TIMERS, 0),
+			    "Timer triggered count doesn't match arm count");
+	return TEST_SUCCESS;
+}
+
 static int
 _arm_wrapper(void *arg)
 {
@@ -588,6 +637,19 @@ test_timer_arm_burst(void)
 	return TEST_SUCCESS;
 }
 
+static inline int
+test_timer_arm_burst_periodic(void)
+{
+	TEST_ASSERT_SUCCESS(_arm_timers_burst(1, MAX_TIMERS),
+			    "Failed to arm timers");
+	/* With a resolution of 100ms and wait time of 1sec,
+	 * there will be 10 * MAX_TIMERS periodic timer triggers */
+	TEST_ASSERT_SUCCESS(_wait_timer_triggers(1, 10 * MAX_TIMERS, 0),
+			    "Timer triggered count doesn't match arm count");
+
+	return TEST_SUCCESS;
+}
+
 static int
 _arm_wrapper_burst(void *arg)
 {
@@ -612,6 +674,48 @@ test_timer_arm_burst_multicore(void)
 	return TEST_SUCCESS;
 }
 
+static inline int
+test_timer_cancel_periodic(void)
+{
+	uint64_t i;
+	struct rte_event_timer *ev_tim;
+	const struct rte_event_timer tim = {
+		.ev.op = RTE_EVENT_OP_NEW,
+		.ev.queue_id = 0,
+		.ev.sched_type = RTE_SCHED_TYPE_ATOMIC,
+		.ev.priority = RTE_EVENT_DEV_PRIORITY_NORMAL,
+		.ev.event_type =  RTE_EVENT_TYPE_TIMER,
+		.state = RTE_EVENT_TIMER_NOT_ARMED,
+		.timeout_ticks = CALC_TICKS(1),
+	};
+
+	for (i = 0; i < MAX_TIMERS; i++) {
+		TEST_ASSERT_SUCCESS(rte_mempool_get(eventdev_test_mempool,
+					(void **)&ev_tim),
+				"mempool alloc failed");
+		*ev_tim = tim;
+		ev_tim->ev.event_ptr = ev_tim;
+
+		TEST_ASSERT_EQUAL(rte_event_timer_arm_burst(timdev, &ev_tim,
+					1), 1, "Failed to arm timer %d",
+				rte_errno);
+
+		rte_delay_us(100 + (i % 5000));
+
+		TEST_ASSERT_EQUAL(rte_event_timer_cancel_burst(timdev,
+					&ev_tim, 1), 1,
+				"Failed to cancel event timer %d", rte_errno);
+		rte_mempool_put(eventdev_test_mempool, ev_tim);
+	}
+
+
+	TEST_ASSERT_SUCCESS(_wait_timer_triggers(30, MAX_TIMERS,
+				MAX_TIMERS),
+		"Timer triggered count doesn't match arm, cancel count");
+
+	return TEST_SUCCESS;
+}
+
 static inline int
 test_timer_cancel(void)
 {
@@ -1028,9 +1132,9 @@ adapter_lookup(void)
 static int
 adapter_start(void)
 {
-	TEST_ASSERT_SUCCESS(_timdev_setup(180 * NSECPERSEC,
-			NSECPERSEC / 10),
-			"Failed to start adapter");
+	TEST_ASSERT_SUCCESS(_timdev_setup(180 * NSECPERSEC, NSECPERSEC / 10,
+					  RTE_EVENT_TIMER_ADAPTER_F_ADJUST_RES),
+			    "Failed to start adapter");
 	TEST_ASSERT_EQUAL(rte_event_timer_adapter_start(timdev), -EALREADY,
 			"Timer adapter started without call to stop.");
 
@@ -1786,10 +1890,16 @@ static struct unit_test_suite event_timer_adptr_functional_testsuite  = {
 				test_timer_state),
 		TEST_CASE_ST(timdev_setup_usec, timdev_teardown,
 				test_timer_arm),
+		TEST_CASE_ST(timdev_setup_msec_periodic, timdev_teardown,
+				test_timer_arm_periodic),
 		TEST_CASE_ST(timdev_setup_usec, timdev_teardown,
 				test_timer_arm_burst),
+		TEST_CASE_ST(timdev_setup_msec_periodic, timdev_teardown,
+				test_timer_arm_burst_periodic),
 		TEST_CASE_ST(timdev_setup_sec, timdev_teardown,
 				test_timer_cancel),
+		TEST_CASE_ST(timdev_setup_sec_periodic, timdev_teardown,
+				test_timer_cancel_periodic),
 		TEST_CASE_ST(timdev_setup_sec, timdev_teardown,
 				test_timer_cancel_random),
 		TEST_CASE_ST(timdev_setup_usec_multicore, timdev_teardown,
-- 
2.25.1


  parent reply	other threads:[~2021-03-08 20:46 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-08 20:45 [dpdk-dev] [PATCH 0/3] periodic mode for event timer adapter Shijith Thotton
2021-03-08 20:45 ` [dpdk-dev] [PATCH 1/3] eventdev: introduce adapter flags for periodic mode Shijith Thotton
2021-03-09 20:04   ` Carrillo, Erik G
2021-03-10  9:14     ` Shijith Thotton
2021-03-11 20:47       ` Carrillo, Erik G
2021-03-12 15:30   ` Carrillo, Erik G
2021-03-14 16:49     ` Shijith Thotton
2021-03-08 20:45 ` Shijith Thotton [this message]
2021-03-08 20:45 ` [dpdk-dev] [PATCH 3/3] event/octeontx2: add timer periodic mode support Shijith Thotton
2021-03-14 16:45 ` [dpdk-dev] [PATCH v2 0/3] periodic mode for event timer adapter Shijith Thotton
2021-03-14 16:45   ` [dpdk-dev] [PATCH v2 1/3] eventdev: introduce adapter flags for periodic mode Shijith Thotton
2021-03-16 19:04     ` Carrillo, Erik G
2021-03-17  6:10       ` Shijith Thotton
2021-03-14 16:45   ` [dpdk-dev] [PATCH v2 2/3] test/event: add unit tests for periodic timer Shijith Thotton
2021-03-14 16:45   ` [dpdk-dev] [PATCH v2 3/3] event/octeontx2: add timer periodic mode support Shijith Thotton
2021-03-17  8:04   ` [dpdk-dev] [PATCH v3 0/3] periodic mode for event timer adapter Shijith Thotton
2021-03-17  8:04     ` [dpdk-dev] [PATCH v3 1/3] eventdev: introduce adapter flags for periodic mode Shijith Thotton
2021-03-17 18:07       ` Carrillo, Erik G
2021-03-22  9:50         ` Jerin Jacob
2021-03-17  8:04     ` [dpdk-dev] [PATCH v3 2/3] test/event: add unit tests for periodic timer Shijith Thotton
2021-03-17 18:11       ` Carrillo, Erik G
2021-03-17  8:04     ` [dpdk-dev] [PATCH v3 3/3] event/octeontx2: add timer periodic mode support Shijith Thotton
2021-03-21 14:43       ` Pavan Nikhilesh Bhagavatula

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210308204543.2903723-3-sthotton@marvell.com \
    --to=sthotton@marvell.com \
    --cc=dev@dpdk.org \
    --cc=erik.g.carrillo@intel.com \
    --cc=jerinj@marvell.com \
    --cc=pbhagavatula@marvell.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).