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 0396041E9B; Wed, 15 Mar 2023 09:01:35 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id A037740A7A; Wed, 15 Mar 2023 09:01:35 +0100 (CET) Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) by mails.dpdk.org (Postfix) with ESMTP id 0907D400EF for ; Wed, 15 Mar 2023 09:01:33 +0100 (CET) Received: from pps.filterd (m0045851.ppops.net [127.0.0.1]) by mx0b-0016f401.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 32F6Tc1K029003; Wed, 15 Mar 2023 01:01:33 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : cc : subject : date : message-id : mime-version : content-transfer-encoding : content-type; s=pfpt0220; bh=Y6r3+hRghC2hGu6TOZ8oFbCH/VD1XG4oC9+q/hNy94o=; b=DI4F6oiTAAZdGL7N4/uM5t6I3HbQud2OGLCBn2WXEahWeX80j+jjYLAODoet/lpc1nyt Pj6bAzn1xhVIXms0+XW3yfpSVQMbApt08eU9Q2gCI0/S71YaD2c80D07WncglGCkwpGR qrl8/Wn1BkzG7Ht1xC+c29EJBKnP5ET39PYquvd/qvTyWq/TergTXrRtEOdfkFp6ATg8 FTKrLkql+xZceGLKz9lHWT6ICBPxlG8Pa4xHH/uZLLkUh+A7i+GV4moIxTE7bR2hD9Ha o8oXFbwhicV9cezBFpZak3vjSv0lJfO9XbryMHhn+aFhmZ4dJOcKrnAi1ubDu4vHuO38 3w== Received: from dc5-exch01.marvell.com ([199.233.59.181]) by mx0b-0016f401.pphosted.com (PPS) with ESMTPS id 3pb2a8h7dy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Wed, 15 Mar 2023 01:01:33 -0700 Received: from DC5-EXCH01.marvell.com (10.69.176.38) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server (TLS) id 15.0.1497.42; Wed, 15 Mar 2023 01:01:30 -0700 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server id 15.0.1497.42 via Frontend Transport; Wed, 15 Mar 2023 01:01:30 -0700 Received: from localhost.localdomain (unknown [10.28.34.29]) by maili.marvell.com (Postfix) with ESMTP id 867EF5C68F8; Wed, 15 Mar 2023 01:01:16 -0700 (PDT) From: Shijith Thotton To: CC: Shijith Thotton , , , Subject: [PATCH v1] eventdev/timer: use loop to check for timeout events Date: Wed, 15 Mar 2023 13:30:42 +0530 Message-ID: X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Proofpoint-ORIG-GUID: W3PfkSx8N_BkO4Xm-Yx5GYi1P4ts1BLK X-Proofpoint-GUID: W3PfkSx8N_BkO4Xm-Yx5GYi1P4ts1BLK X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-03-15_04,2023-03-14_02,2023-02-09_01 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 Replaced sleep with a function to dequeue timer expiry events until either the expected number of events have been dequeued or the specified time has elapsed. This change closely esembles the behavior of the tested systems. Signed-off-by: Shijith Thotton --- app/test/test_event_timer_adapter.c | 169 +++++++++++----------------- 1 file changed, 68 insertions(+), 101 deletions(-) diff --git a/app/test/test_event_timer_adapter.c b/app/test/test_event_timer_adapter.c index 5e7feec1c7..510bebcf86 100644 --- a/app/test/test_event_timer_adapter.c +++ b/app/test/test_event_timer_adapter.c @@ -57,9 +57,10 @@ static uint64_t global_bkt_tck_ns; static uint64_t global_info_bkt_tck_ns; static volatile uint8_t arm_done; -#define CALC_TICKS(tks) \ - ceil((double)(tks * global_bkt_tck_ns) / global_info_bkt_tck_ns) +#define CALC_TICKS(tks) ceil((double)((tks) * global_bkt_tck_ns) / global_info_bkt_tck_ns) +/* Wait double timeout ticks for software and an extra tick for hardware */ +#define WAIT_TICKS(tks) (using_services ? 2 * (tks) : tks + 1) static bool using_services; static uint32_t test_lcore1; @@ -441,10 +442,31 @@ timdev_teardown(void) rte_mempool_free(eventdev_test_mempool); } +static inline uint16_t +timeout_event_dequeue(struct rte_event *evs, uint64_t nb_evs, uint64_t ticks) +{ + uint16_t ev_cnt = 0; + uint64_t end_cycle; + + if (using_services && nb_evs == MAX_TIMERS) + ticks = 2 * ticks; + + end_cycle = rte_rdtsc() + ticks * global_bkt_tck_ns * rte_get_tsc_hz() / 1E9; + + while (ev_cnt < nb_evs && rte_rdtsc() < end_cycle) { + ev_cnt += rte_event_dequeue_burst(evdev, TEST_PORT_ID, &evs[ev_cnt], nb_evs, 0); + rte_pause(); + } + + return ev_cnt; +} + static inline int test_timer_state(void) { struct rte_event_timer *ev_tim; + const uint64_t max_ticks = 100; + uint64_t ticks, wait_ticks; struct rte_event ev; const struct rte_event_timer tim = { .ev.op = RTE_EVENT_OP_NEW, @@ -455,11 +477,10 @@ test_timer_state(void) .state = RTE_EVENT_TIMER_NOT_ARMED, }; - rte_mempool_get(eventdev_test_mempool, (void **)&ev_tim); *ev_tim = tim; ev_tim->ev.event_ptr = ev_tim; - ev_tim->timeout_ticks = CALC_TICKS(120); + ev_tim->timeout_ticks = CALC_TICKS(max_ticks + 20); TEST_ASSERT_EQUAL(rte_event_timer_arm_burst(timdev, &ev_tim, 1), 0, "Armed timer exceeding max_timeout."); @@ -467,8 +488,9 @@ test_timer_state(void) "Improper timer state set expected %d returned %d", RTE_EVENT_TIMER_ERROR_TOOLATE, ev_tim->state); + ticks = 10; ev_tim->state = RTE_EVENT_TIMER_NOT_ARMED; - ev_tim->timeout_ticks = CALC_TICKS(10); + ev_tim->timeout_ticks = CALC_TICKS(ticks); TEST_ASSERT_EQUAL(rte_event_timer_arm_burst(timdev, &ev_tim, 1), 1, "Failed to arm timer with proper timeout."); @@ -477,14 +499,15 @@ test_timer_state(void) RTE_EVENT_TIMER_ARMED, ev_tim->state); if (!using_services) - rte_delay_us(20); + wait_ticks = 2 * ticks; else - rte_delay_us(1000 + 200); - TEST_ASSERT_EQUAL(rte_event_dequeue_burst(evdev, 0, &ev, 1, 0), 1, - "Armed timer failed to trigger."); + wait_ticks = ticks; + + TEST_ASSERT_EQUAL(timeout_event_dequeue(&ev, 1, WAIT_TICKS(wait_ticks)), 1, + "Armed timer failed to trigger."); ev_tim->state = RTE_EVENT_TIMER_NOT_ARMED; - ev_tim->timeout_ticks = CALC_TICKS(90); + ev_tim->timeout_ticks = CALC_TICKS(max_ticks - 10); TEST_ASSERT_EQUAL(rte_event_timer_arm_burst(timdev, &ev_tim, 1), 1, "Failed to arm timer with proper timeout."); TEST_ASSERT_EQUAL(rte_event_timer_cancel_burst(timdev, &ev_tim, 1), @@ -1208,8 +1231,9 @@ stat_inc_reset_ev_enq(void) int ret, i, n; int num_evtims = MAX_TIMERS; struct rte_event_timer *evtims[num_evtims]; - struct rte_event evs[BATCH_SIZE]; + struct rte_event evs[num_evtims]; struct rte_event_timer_adapter_stats stats; + uint64_t ticks = 5; const struct rte_event_timer init_tim = { .ev.op = RTE_EVENT_OP_NEW, .ev.queue_id = TEST_QUEUE_ID, @@ -1217,7 +1241,7 @@ stat_inc_reset_ev_enq(void) .ev.priority = RTE_EVENT_DEV_PRIORITY_NORMAL, .ev.event_type = RTE_EVENT_TYPE_TIMER, .state = RTE_EVENT_TIMER_NOT_ARMED, - .timeout_ticks = CALC_TICKS(5), // expire in .5 sec + .timeout_ticks = CALC_TICKS(ticks), /**< expire in .5 sec */ }; ret = rte_mempool_get_bulk(eventdev_test_mempool, (void **)evtims, @@ -1242,31 +1266,12 @@ stat_inc_reset_ev_enq(void) "succeeded = %d, rte_errno = %s", num_evtims, ret, rte_strerror(rte_errno)); - rte_delay_ms(1000); - -#define MAX_TRIES num_evtims - int sum = 0; - int tries = 0; - bool done = false; - while (!done) { - sum += rte_event_dequeue_burst(evdev, TEST_PORT_ID, evs, - RTE_DIM(evs), 10); - if (sum >= num_evtims || ++tries >= MAX_TRIES) - done = true; - - rte_delay_ms(10); - } - - TEST_ASSERT_EQUAL(sum, num_evtims, "Expected %d timer expiry events, " - "got %d", num_evtims, sum); - - TEST_ASSERT(tries < MAX_TRIES, "Exceeded max tries"); - - rte_delay_ms(100); + n = timeout_event_dequeue(evs, RTE_DIM(evs), WAIT_TICKS(ticks)); + TEST_ASSERT_EQUAL(n, num_evtims, "Expected %d timer expiry events, got %d", + num_evtims, n); /* Make sure the eventdev is still empty */ - n = rte_event_dequeue_burst(evdev, TEST_PORT_ID, evs, RTE_DIM(evs), - 10); + n = timeout_event_dequeue(evs, 1, WAIT_TICKS(1)); TEST_ASSERT_EQUAL(n, 0, "Dequeued unexpected number of timer expiry " "events from event device"); @@ -1303,6 +1308,7 @@ event_timer_arm(void) struct rte_event_timer_adapter *adapter = timdev; struct rte_event_timer *evtim = NULL; struct rte_event evs[BATCH_SIZE]; + uint64_t ticks = 5; const struct rte_event_timer init_tim = { .ev.op = RTE_EVENT_OP_NEW, .ev.queue_id = TEST_QUEUE_ID, @@ -1310,7 +1316,7 @@ event_timer_arm(void) .ev.priority = RTE_EVENT_DEV_PRIORITY_NORMAL, .ev.event_type = RTE_EVENT_TYPE_TIMER, .state = RTE_EVENT_TIMER_NOT_ARMED, - .timeout_ticks = CALC_TICKS(5), // expire in .5 sec + .timeout_ticks = CALC_TICKS(ticks), /**< expire in .5 sec */ }; rte_mempool_get(eventdev_test_mempool, (void **)&evtim); @@ -1337,10 +1343,7 @@ event_timer_arm(void) TEST_ASSERT_EQUAL(rte_errno, EALREADY, "Unexpected rte_errno value " "after arming already armed timer"); - /* Let timer expire */ - rte_delay_ms(1000); - - n = rte_event_dequeue_burst(evdev, TEST_PORT_ID, evs, RTE_DIM(evs), 0); + n = timeout_event_dequeue(evs, RTE_DIM(evs), WAIT_TICKS(ticks)); TEST_ASSERT_EQUAL(n, 1, "Failed to dequeue expected number of expiry " "events from event device"); @@ -1360,6 +1363,7 @@ event_timer_arm_double(void) struct rte_event_timer_adapter *adapter = timdev; struct rte_event_timer *evtim = NULL; struct rte_event evs[BATCH_SIZE]; + uint64_t ticks = 5; const struct rte_event_timer init_tim = { .ev.op = RTE_EVENT_OP_NEW, .ev.queue_id = TEST_QUEUE_ID, @@ -1367,7 +1371,7 @@ event_timer_arm_double(void) .ev.priority = RTE_EVENT_DEV_PRIORITY_NORMAL, .ev.event_type = RTE_EVENT_TYPE_TIMER, .state = RTE_EVENT_TIMER_NOT_ARMED, - .timeout_ticks = CALC_TICKS(5), // expire in .5 sec + .timeout_ticks = CALC_TICKS(ticks), /**< expire in .5 sec */ }; rte_mempool_get(eventdev_test_mempool, (void **)&evtim); @@ -1387,10 +1391,7 @@ event_timer_arm_double(void) TEST_ASSERT_EQUAL(rte_errno, EALREADY, "Unexpected rte_errno value " "after double-arm"); - /* Let timer expire */ - rte_delay_ms(600); - - n = rte_event_dequeue_burst(evdev, TEST_PORT_ID, evs, RTE_DIM(evs), 0); + n = timeout_event_dequeue(evs, RTE_DIM(evs), WAIT_TICKS(ticks)); TEST_ASSERT_EQUAL(n, 1, "Dequeued incorrect number of expiry events - " "expected: 1, actual: %d", n); @@ -1417,6 +1418,7 @@ event_timer_arm_expiry(void) .ev.event_type = RTE_EVENT_TYPE_TIMER, .state = RTE_EVENT_TIMER_NOT_ARMED, }; + uint64_t ticks = 30; rte_mempool_get(eventdev_test_mempool, (void **)&evtim); if (evtim == NULL) { @@ -1426,7 +1428,7 @@ event_timer_arm_expiry(void) /* Set up an event timer */ *evtim = init_tim; - evtim->timeout_ticks = CALC_TICKS(30), // expire in 3 secs + evtim->timeout_ticks = CALC_TICKS(ticks); /**< expire in 3 secs */ evtim->ev.event_ptr = evtim; ret = rte_event_timer_arm_burst(adapter, &evtim, 1); @@ -1435,17 +1437,10 @@ event_timer_arm_expiry(void) TEST_ASSERT_EQUAL(evtim->state, RTE_EVENT_TIMER_ARMED, "Event " "timer in incorrect state"); - rte_delay_ms(2999); - - n = rte_event_dequeue_burst(evdev, TEST_PORT_ID, evs, RTE_DIM(evs), 0); + n = timeout_event_dequeue(evs, RTE_DIM(evs), ticks - 1); TEST_ASSERT_EQUAL(n, 0, "Dequeued unexpected timer expiry event"); - /* Delay 100 ms to account for the adapter tick window - should let us - * dequeue one event - */ - rte_delay_ms(100); - - n = rte_event_dequeue_burst(evdev, TEST_PORT_ID, evs, RTE_DIM(evs), 0); + n = timeout_event_dequeue(evs, RTE_DIM(evs), WAIT_TICKS(1)); TEST_ASSERT_EQUAL(n, 1, "Dequeued incorrect number (%d) of timer " "expiry events", n); TEST_ASSERT_EQUAL(evs[0].event_type, RTE_EVENT_TYPE_TIMER, @@ -1477,6 +1472,7 @@ event_timer_arm_rearm(void) .ev.event_type = RTE_EVENT_TYPE_TIMER, .state = RTE_EVENT_TIMER_NOT_ARMED, }; + uint64_t ticks = 1; rte_mempool_get(eventdev_test_mempool, (void **)&evtim); if (evtim == NULL) { @@ -1486,7 +1482,7 @@ event_timer_arm_rearm(void) /* Set up a timer */ *evtim = init_tim; - evtim->timeout_ticks = CALC_TICKS(1); // expire in 0.1 sec + evtim->timeout_ticks = CALC_TICKS(ticks); /**< expire in 0.1 sec */ evtim->ev.event_ptr = evtim; /* Arm it */ @@ -1494,10 +1490,7 @@ event_timer_arm_rearm(void) TEST_ASSERT_EQUAL(ret, 1, "Failed to arm event timer: %s\n", rte_strerror(rte_errno)); - /* Add 100ms to account for the adapter tick window */ - rte_delay_ms(100 + 100); - - n = rte_event_dequeue_burst(evdev, TEST_PORT_ID, evs, RTE_DIM(evs), 0); + n = timeout_event_dequeue(evs, RTE_DIM(evs), WAIT_TICKS(ticks)); TEST_ASSERT_EQUAL(n, 1, "Failed to dequeue expected number of expiry " "events from event device"); @@ -1514,10 +1507,7 @@ event_timer_arm_rearm(void) TEST_ASSERT_EQUAL(ret, 1, "Failed to arm event timer: %s\n", rte_strerror(rte_errno)); - /* Add 100ms to account for the adapter tick window */ - rte_delay_ms(100 + 100); - - n = rte_event_dequeue_burst(evdev, TEST_PORT_ID, evs, RTE_DIM(evs), 0); + n = timeout_event_dequeue(evs, RTE_DIM(evs), WAIT_TICKS(ticks)); TEST_ASSERT_EQUAL(n, 1, "Failed to dequeue expected number of expiry " "events from event device"); @@ -1539,7 +1529,8 @@ event_timer_arm_max(void) int ret, i, n; int num_evtims = MAX_TIMERS; struct rte_event_timer *evtims[num_evtims]; - struct rte_event evs[BATCH_SIZE]; + struct rte_event evs[num_evtims]; + uint64_t ticks = 5; const struct rte_event_timer init_tim = { .ev.op = RTE_EVENT_OP_NEW, .ev.queue_id = TEST_QUEUE_ID, @@ -1547,7 +1538,7 @@ event_timer_arm_max(void) .ev.priority = RTE_EVENT_DEV_PRIORITY_NORMAL, .ev.event_type = RTE_EVENT_TYPE_TIMER, .state = RTE_EVENT_TIMER_NOT_ARMED, - .timeout_ticks = CALC_TICKS(5), // expire in .5 sec + .timeout_ticks = CALC_TICKS(ticks), /**< expire in .5 sec */ }; ret = rte_mempool_get_bulk(eventdev_test_mempool, (void **)evtims, @@ -1567,31 +1558,12 @@ event_timer_arm_max(void) "succeeded = %d, rte_errno = %s", num_evtims, ret, rte_strerror(rte_errno)); - rte_delay_ms(1000); - -#define MAX_TRIES num_evtims - int sum = 0; - int tries = 0; - bool done = false; - while (!done) { - sum += rte_event_dequeue_burst(evdev, TEST_PORT_ID, evs, - RTE_DIM(evs), 10); - if (sum >= num_evtims || ++tries >= MAX_TRIES) - done = true; - - rte_delay_ms(10); - } - - TEST_ASSERT_EQUAL(sum, num_evtims, "Expected %d timer expiry events, " - "got %d", num_evtims, sum); - - TEST_ASSERT(tries < MAX_TRIES, "Exceeded max tries"); - - rte_delay_ms(100); + n = timeout_event_dequeue(evs, RTE_DIM(evs), WAIT_TICKS(ticks)); + TEST_ASSERT_EQUAL(n, num_evtims, "Expected %d timer expiry events, got %d", + num_evtims, n); /* Make sure the eventdev is still empty */ - n = rte_event_dequeue_burst(evdev, TEST_PORT_ID, evs, RTE_DIM(evs), - 10); + n = timeout_event_dequeue(evs, 1, WAIT_TICKS(1)); TEST_ASSERT_EQUAL(n, 0, "Dequeued unexpected number of timer expiry " "events from event device"); @@ -1711,6 +1683,7 @@ event_timer_cancel(void) .ev.event_type = RTE_EVENT_TYPE_TIMER, .state = RTE_EVENT_TIMER_NOT_ARMED, }; + uint64_t ticks = 30; rte_mempool_get(eventdev_test_mempool, (void **)&evtim); if (evtim == NULL) { @@ -1728,7 +1701,7 @@ event_timer_cancel(void) /* Set up a timer */ *evtim = init_tim; evtim->ev.event_ptr = evtim; - evtim->timeout_ticks = CALC_TICKS(30); // expire in 3 sec + evtim->timeout_ticks = CALC_TICKS(ticks); /**< expire in 3 sec */ /* Check that cancelling an inited but unarmed timer fails */ ret = rte_event_timer_cancel_burst(adapter, &evtim, 1); @@ -1752,10 +1725,8 @@ event_timer_cancel(void) TEST_ASSERT_EQUAL(evtim->state, RTE_EVENT_TIMER_CANCELED, "evtim in incorrect state"); - rte_delay_ms(3000); - /* Make sure that no expiry event was generated */ - n = rte_event_dequeue_burst(evdev, TEST_PORT_ID, evs, RTE_DIM(evs), 0); + n = timeout_event_dequeue(evs, RTE_DIM(evs), WAIT_TICKS(ticks)); TEST_ASSERT_EQUAL(n, 0, "Dequeued unexpected timer expiry event\n"); rte_mempool_put(eventdev_test_mempool, evtim); @@ -1778,8 +1749,8 @@ event_timer_cancel_double(void) .ev.priority = RTE_EVENT_DEV_PRIORITY_NORMAL, .ev.event_type = RTE_EVENT_TYPE_TIMER, .state = RTE_EVENT_TIMER_NOT_ARMED, - .timeout_ticks = CALC_TICKS(5), // expire in .5 sec }; + uint64_t ticks = 30; rte_mempool_get(eventdev_test_mempool, (void **)&evtim); if (evtim == NULL) { @@ -1790,7 +1761,7 @@ event_timer_cancel_double(void) /* Set up a timer */ *evtim = init_tim; evtim->ev.event_ptr = evtim; - evtim->timeout_ticks = CALC_TICKS(30); // expire in 3 sec + evtim->timeout_ticks = CALC_TICKS(ticks); /**< expire in 3 sec */ ret = rte_event_timer_arm_burst(adapter, &evtim, 1); TEST_ASSERT_EQUAL(ret, 1, "Failed to arm event timer: %s\n", @@ -1812,10 +1783,8 @@ event_timer_cancel_double(void) TEST_ASSERT_EQUAL(rte_errno, EALREADY, "Unexpected rte_errno value " "after double-cancel: rte_errno = %d", rte_errno); - rte_delay_ms(3000); - /* Still make sure that no expiry event was generated */ - n = rte_event_dequeue_burst(evdev, TEST_PORT_ID, evs, RTE_DIM(evs), 0); + n = timeout_event_dequeue(evs, RTE_DIM(evs), WAIT_TICKS(ticks)); TEST_ASSERT_EQUAL(n, 0, "Dequeued unexpected timer expiry event\n"); rte_mempool_put(eventdev_test_mempool, evtim); @@ -1973,9 +1942,7 @@ test_timer_ticks_remaining(void) rte_delay_ms(100); } - rte_delay_ms(100); - - TEST_ASSERT_EQUAL(rte_event_dequeue_burst(evdev, 0, &ev, 1, 0), 1, + TEST_ASSERT_EQUAL(timeout_event_dequeue(&ev, 1, WAIT_TICKS(1)), 1, "Armed timer failed to trigger."); TEST_ASSERT_EQUAL(ev_tim->state, RTE_EVENT_TIMER_NOT_ARMED, "Improper timer state set expected %d returned %d", -- 2.25.1