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 139874C92 for ; Fri, 14 Sep 2018 12:59:53 +0200 (CEST) Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20180914105951euoutp02a8c3135a7738a1db8262f74c4474134f~UPyLoCICM1722317223euoutp02s; Fri, 14 Sep 2018 10:59:51 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20180914105951euoutp02a8c3135a7738a1db8262f74c4474134f~UPyLoCICM1722317223euoutp02s DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1536922792; bh=Na83y14Flfx5BlKdYkfM/2uNbA+eE9uXTzkY4Be9wwM=; h=From:To:Cc:Subject:Date:In-reply-to:References:From; b=r6ejSa7mxVzDjcwqxFtQAWgqxVjAOEyl97Fil/fzqcMh2CHGAwkbQ94lHgI586ZAJ 52rfPv+J7fL1x1sFyXQR7W0aUU9lBPXvaB+t99fWq/SGxlHjGt3OleftRhruIrg2/P C+EsUMmVlg+wuJQBHvDK1TEKcFyHFu8gkMFvIXIA= Received: from eusmges2new.samsung.com (unknown [203.254.199.244]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20180914105951eucas1p1f07f8239e9c1b0a14cf1c4fc766b497b~UPyLP1WtJ0515305153eucas1p1K; Fri, 14 Sep 2018 10:59:51 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges2new.samsung.com (EUCPMTA) with SMTP id 27.6D.04294.7A49B9B5; Fri, 14 Sep 2018 11:59:51 +0100 (BST) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20180914105950eucas1p1391d6eccd8ccd5a03e7f742f1d12bb9d~UPyKaMZ7P0514605146eucas1p1I; Fri, 14 Sep 2018 10:59:50 +0000 (GMT) X-AuditID: cbfec7f4-84fff700000010c6-dc-5b9b94a79136 Received: from eusync1.samsung.com ( [203.254.199.211]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id 0B.9A.04128.6A49B9B5; Fri, 14 Sep 2018 11:59:50 +0100 (BST) Received: from imaximets.rnd.samsung.ru ([106.109.129.180]) by eusync1.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTPA id <0PF1002IVL6ZB130@eusync1.samsung.com>; Fri, 14 Sep 2018 11:59:50 +0100 (BST) From: Ilya Maximets To: dev@dpdk.org Cc: Jingjing Wu , Konstantin Ananyev , Wenzhuo Lu , Beilei Xing , Qi Zhang , Xiao Wang , Bruce Richardson , Stephen Hemminger , Keith Wiles , Ilya Maximets Date: Fri, 14 Sep 2018 14:01:08 +0300 Message-id: <20180914110109.29900-2-i.maximets@samsung.com> X-Mailer: git-send-email 2.17.1 In-reply-to: <20180914110109.29900-1-i.maximets@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrKIsWRmVeSWpSXmKPExsWy7djPc7rLp8yONvi+TcCi+0MLk8WNVfYW 7z5tZ7K40v6T3WLmgs+MFlePf2e2eP9nEYvF9A39bBaL78hZbD3zl9Fi//PD7A7cHr8WLGX1 WLznJZNHz8l5TB59W1YxBrBEcdmkpOZklqUW6dslcGXcer+bseC+bsXKltmsDYwvVLoYOTkk BEwk7uyZwgZiCwmsYJR41iTexcgFZH9mlOh4fYYNpmjWzYMsEIlljBLnPjQyQTjNTBJfV71k B6liE9CROLX6CCOILSIgIPG5czEbSBGzwBxmicZVe4AcDg5hAXuJLS+TQGpYBFQlvncfYwWx eQWsJVZ1/ITaJi+xesMBZhCbU8BG4tqlIywQ8QVsEuvPyoGMkRBwkbg10w0iLCzx6vgWdghb RuLy5G6o8nqJ+y0vGUFOkBDoYJSYfugfE0QC6ITX58AamAX4JCZtm84MMZNXoqNNCKLEQ2LZ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7gff9u6w3vN9MmrL5RXcdduXjdDddL5siK78/+PtLNdW7FS iaU4I9FQi7moOBEAGeVu/ygCAAA= X-CMS-MailID: 20180914105950eucas1p1391d6eccd8ccd5a03e7f742f1d12bb9d X-Msg-Generator: CA CMS-TYPE: 201P X-CMS-RootMailID: 20180914105950eucas1p1391d6eccd8ccd5a03e7f742f1d12bb9d References: <20180903144311eucas1p2b6499c49dbd0d54334e973113cdc5ad6~Q6vBsFYRm1033710337eucas1p2D@eucas1p2.samsung.com> <20180914110109.29900-1-i.maximets@samsung.com> Subject: [dpdk-dev] [PATCH v2 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: Fri, 14 Sep 2018 10:59:53 -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 | 24 +++++++++ .../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, 80 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..c6344ca87 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,28 @@ 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) { + /* + * Sleep was interrupted. Flip the index, so the 'remainder' + * will become the 'request' for a next call. + */ + 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