From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mailout2.w1.samsung.com (mailout2.w1.samsung.com [210.118.77.12]) by dpdk.org (Postfix) with ESMTP id 8419A5F2E for ; Mon, 3 Sep 2018 16:46:18 +0200 (CEST) Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20180903144617euoutp02455b9242b6a8600ed29c50af30e3e98c~Q6xvFSb4i0226802268euoutp02V for ; Mon, 3 Sep 2018 14:46:17 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20180903144617euoutp02455b9242b6a8600ed29c50af30e3e98c~Q6xvFSb4i0226802268euoutp02V DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1535985977; bh=AHXkTKWAMEGt6H5X0LCekT+rZUu+9Rd/UFakd5yqq6E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=b/l/C3/6ehXnhNWgQl9uIXlqWIIQj8PfDxsBIzDeNAYGjzS29zcWT34iQoP1Hsb+r MgHV0o/N/go4XxYdl0w05H+RpLfVUkYlEVEfPU3cEb2nfyYhDz3Vfa70cQ5B1z9icb raM5f3G41HYwYBc3LocB5MeFt78080hFBRDz0iRE= Received: from eusmges1new.samsung.com (unknown [203.254.199.242]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20180903144616eucas1p1cb5501c3c1d3e189010d7bf73ac2072b~Q6xuc4LNg1414514145eucas1p17; Mon, 3 Sep 2018 14:46:16 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges1new.samsung.com (EUCPMTA) with SMTP id 1D.D2.04441.8394D8B5; Mon, 3 Sep 2018 15:46:16 +0100 (BST) Received: from eusmtrp1.samsung.com (unknown [182.198.249.138]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20180903144615eucas1p1d7377fa285a86f522f29c2a9528a638e~Q6xtl-i3s2361123611eucas1p1Q; Mon, 3 Sep 2018 14:46:15 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eusmtrp1.samsung.com (KnoxPortal) with ESMTP id 20180903144615eusmtrp16a7d3562fd23c99163796d9088a49a09~Q6xtTnQUa1765817658eusmtrp1W; Mon, 3 Sep 2018 14:46:15 +0000 (GMT) X-AuditID: cbfec7f2-5e3ff70000001159-42-5b8d4938a8da Received: from eusmtip2.samsung.com ( [203.254.199.222]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id EF.C7.04128.7394D8B5; Mon, 3 Sep 2018 15:46:15 +0100 (BST) Received: from imaximets.rnd.samsung.ru (unknown [106.109.129.180]) by eusmtip2.samsung.com (KnoxPortal) with ESMTPA id 20180903144614eusmtip250cb6f54c77977fa1d04b72cdbcb3461~Q6xspiPTR0651306513eusmtip2E; Mon, 3 Sep 2018 14:46:14 +0000 (GMT) From: Ilya Maximets To: dev@dpdk.org Cc: Jingjing Wu , Konstantin Ananyev , Wenzhuo Lu , Beilei Xing , Qi Zhang , Xiao Wang , Bruce Richardson , Ilya Maximets Date: Mon, 3 Sep 2018 17:47:42 +0300 X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180903144311eucas1p2b6499c49dbd0d54334e973113cdc5ad6~Q6vBsFYRm1033710337eucas1p2D@eucas1p2.samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrNIsWRmVeSWpSXmKPExsWy7djP87oWnr3RBjPOSlh0f2hhsrixyt7i 3aftTBZX2n+yW8xc8JnR4v2fRSwW0zf0s1lsPfOX0WL/88PsDpwevxYsZfVYvOclk0ffllWM AcxRXDYpqTmZZalF+nYJXBmbny1hLbiiU/Fv/znGBsZWlS5GTg4JAROJZX13WEBsIYEVjBIT /3hD2F8YJV6/ju9i5AKyPzNK7HsxhQmmYfHvG2wQieWMEg/e/GKEcH4wSkzo+cYOUsUmoCNx avURRhBbREBA4nPnYrAOZoGjTBLXuqYzgySEBewl7qz/D1bEIqAqMW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gg8xCnAwKvHw/tDtjRZiTSwrrsw9 xCjBwawkwtvoDhTiTUmsrEotyo8vKs1JLT7EaAp01ERmKdHkfGBM5ZXEG5oamltYGpobmxub WSiJ8543qIwSEkhPLEnNTk0tSC2C6WPi4JRqYNxV7tL889SxHOHZZz8miCnkcr3Z/OVlrJ7J GaXr7DPvfz+UslQ6szJh0sqNb7M3Fn9/blt0wf6B/pz6WlaxG9eulwS9lI2ZVPN1q7AXH2/W guojy/5u8N252HdzS4Tz1Tf/4nls5b6L/ysM4c+z9DnxZrW+4nqvUxbNvXdSGJbweKvmGP5X TFNiKc5INNRiLipOBAB6VCGucQIAAA== Message-Id: <20180903144615eucas1p1d7377fa285a86f522f29c2a9528a638e~Q6xtl-i3s2361123611eucas1p1Q@eucas1p1.samsung.com> X-CMS-MailID: 20180903144615eucas1p1d7377fa285a86f522f29c2a9528a638e X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" X-RootMTR: 20180903144615eucas1p1d7377fa285a86f522f29c2a9528a638e X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20180903144615eucas1p1d7377fa285a86f522f29c2a9528a638e References: <20180903144311eucas1p2b6499c49dbd0d54334e973113cdc5ad6~Q6vBsFYRm1033710337eucas1p2D@eucas1p2.samsung.com> Subject: [dpdk-dev] [PATCH v1 1/2] eal: add nanosleep based delay function X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 03 Sep 2018 14:46:18 -0000 Add a new rte_delay_us_sleep() function that uses nanosleep(). This function can be used by applications to not implement their own nanosleep() based callback and by internal DPDK code if CPU non-blocking delay needed. Signed-off-by: Ilya Maximets --- lib/librte_eal/common/eal_common_timer.c | 19 +++++++ .../common/include/generic/rte_cycles.h | 11 ++++ lib/librte_eal/rte_eal_version.map | 1 + test/test/autotest_data.py | 6 +++ test/test/meson.build | 1 + test/test/test_cycles.c | 51 ++++++++++++++----- 6 files changed, 75 insertions(+), 14 deletions(-) diff --git a/lib/librte_eal/common/eal_common_timer.c b/lib/librte_eal/common/eal_common_timer.c index 2e2b770fb..4a00525ca 100644 --- a/lib/librte_eal/common/eal_common_timer.c +++ b/lib/librte_eal/common/eal_common_timer.c @@ -7,9 +7,11 @@ #include #include #include +#include #include #include +#include #include #include #include @@ -31,6 +33,23 @@ rte_delay_us_block(unsigned int us) rte_pause(); } +void __rte_experimental +rte_delay_us_sleep(unsigned int us) +{ + struct timespec wait[2]; + int ind = 0; + + wait[0].tv_sec = 0; + if (us >= US_PER_S) { + wait[0].tv_sec = us / US_PER_S; + us -= wait[0].tv_sec * US_PER_S; + } + wait[0].tv_nsec = 1000 * us; + + while (nanosleep(&wait[ind], &wait[1 - ind]) == EINTR) + ind = 1 - ind; +} + uint64_t rte_get_tsc_hz(void) { diff --git a/lib/librte_eal/common/include/generic/rte_cycles.h b/lib/librte_eal/common/include/generic/rte_cycles.h index 0ff1af504..ac379e878 100644 --- a/lib/librte_eal/common/include/generic/rte_cycles.h +++ b/lib/librte_eal/common/include/generic/rte_cycles.h @@ -13,6 +13,7 @@ */ #include +#include #include #include @@ -157,6 +158,16 @@ rte_delay_ms(unsigned ms) */ void rte_delay_us_block(unsigned int us); +/** + * Delay function that uses system sleep. + * Does not block the CPU core. + * + * @param us + * Number of microseconds to wait. + */ +void __rte_experimental +rte_delay_us_sleep(unsigned int us); + /** * Replace rte_delay_us with user defined function. * diff --git a/lib/librte_eal/rte_eal_version.map b/lib/librte_eal/rte_eal_version.map index 344a43d32..d68777ce0 100644 --- a/lib/librte_eal/rte_eal_version.map +++ b/lib/librte_eal/rte_eal_version.map @@ -270,6 +270,7 @@ EXPERIMENTAL { rte_class_register; rte_class_unregister; rte_ctrl_thread_create; + rte_delay_us_sleep; rte_dev_event_callback_register; rte_dev_event_callback_unregister; rte_dev_event_monitor_start; diff --git a/test/test/autotest_data.py b/test/test/autotest_data.py index f68d9b111..874d0cb53 100644 --- a/test/test/autotest_data.py +++ b/test/test/autotest_data.py @@ -278,6 +278,12 @@ "Func": default_autotest, "Report": None, }, + { + "Name": "Sleep delay", + "Command": "delay_us_sleep_autotest", + "Func": default_autotest, + "Report": None, + }, { "Name": "Rawdev autotest", "Command": "rawdev_autotest", diff --git a/test/test/meson.build b/test/test/meson.build index b1dd6eca2..0078aea30 100644 --- a/test/test/meson.build +++ b/test/test/meson.build @@ -143,6 +143,7 @@ test_names = [ 'cryptodev_dpaa_sec_autotest', 'cycles_autotest', 'debug_autotest', + 'delay_us_sleep_autotest', 'devargs_autotest', 'distributor_autotest', 'distributor_perf_autotest', diff --git a/test/test/test_cycles.c b/test/test/test_cycles.c index 149f60b07..c78e6a5b1 100644 --- a/test/test/test_cycles.c +++ b/test/test/test_cycles.c @@ -23,6 +23,30 @@ * of cycles is correct with regard to the frequency of the timer. */ +static int +check_wait_one_second(void) +{ + uint64_t cycles, prev_cycles; + uint64_t hz = rte_get_timer_hz(); + uint64_t max_inc = (hz / 100); /* 10 ms max between 2 reads */ + + /* check that waiting 1 second is precise */ + prev_cycles = rte_get_timer_cycles(); + rte_delay_us(1000000); + cycles = rte_get_timer_cycles(); + + if ((uint64_t)(cycles - prev_cycles) > (hz + max_inc)) { + printf("delay_us is not accurate: too long\n"); + return -1; + } + if ((uint64_t)(cycles - prev_cycles) < (hz - max_inc)) { + printf("delay_us is not accurate: too short\n"); + return -1; + } + + return 0; +} + static int test_cycles(void) { @@ -43,24 +67,23 @@ test_cycles(void) prev_cycles = cycles; } - /* check that waiting 1 second is precise */ - prev_cycles = rte_get_timer_cycles(); - rte_delay_us(1000000); - cycles = rte_get_timer_cycles(); + return check_wait_one_second(); +} - if ((uint64_t)(cycles - prev_cycles) > (hz + max_inc)) { - printf("delay_us is not accurate: too long\n"); - return -1; - } - if ((uint64_t)(cycles - prev_cycles) < (hz - max_inc)) { - printf("delay_us is not accurate: too short\n"); - return -1; - } +REGISTER_TEST_COMMAND(cycles_autotest, test_cycles); - return 0; +/* + * One second precision test with rte_delay_us_sleep. + */ + +static int +test_delay_us_sleep(void) +{ + rte_delay_us_callback_register(rte_delay_us_sleep); + return check_wait_one_second(); } -REGISTER_TEST_COMMAND(cycles_autotest, test_cycles); +REGISTER_TEST_COMMAND(delay_us_sleep_autotest, test_delay_us_sleep); /* * rte_delay_us_callback test -- 2.17.1