summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorIlya Maximets <i.maximets@samsung.com>2018-10-10 17:12:19 +0300
committerFerruh Yigit <ferruh.yigit@intel.com>2018-10-26 22:14:06 +0200
commita51639cc720aa17922d4b479e9961169f3a36c64 (patch)
tree31c4f9e5d18232248939d158189226617795a257 /test
parentb9788afec528f03a252d206e7426cb301c162ee5 (diff)
downloaddpdk-a51639cc720aa17922d4b479e9961169f3a36c64.zip
dpdk-a51639cc720aa17922d4b479e9961169f3a36c64.tar.gz
dpdk-a51639cc720aa17922d4b479e9961169f3a36c64.tar.xz
eal: add nanosleep based delay function
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 <i.maximets@samsung.com> Reviewed-by: Ferruh Yigit <ferruh.yigit@intel.com>
Diffstat (limited to 'test')
-rw-r--r--test/test/autotest_data.py6
-rw-r--r--test/test/meson.build1
-rw-r--r--test/test/test_cycles.c51
3 files changed, 44 insertions, 14 deletions
diff --git a/test/test/autotest_data.py b/test/test/autotest_data.py
index 0df686a..e7df68f 100644
--- a/test/test/autotest_data.py
+++ b/test/test/autotest_data.py
@@ -279,6 +279,12 @@ parallel_test_list = [
"Report": None,
},
{
+ "Name": "Sleep delay",
+ "Command": "delay_us_sleep_autotest",
+ "Func": default_autotest,
+ "Report": None,
+ },
+ {
"Name": "Rawdev autotest",
"Command": "rawdev_autotest",
"Func": default_autotest,
diff --git a/test/test/meson.build b/test/test/meson.build
index 1c1fcd7..b707547 100644
--- a/test/test/meson.build
+++ b/test/test/meson.build
@@ -149,6 +149,7 @@ test_names = [
'cryptodev_octeontx_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 149f60b..c78e6a5 100644
--- a/test/test/test_cycles.c
+++ b/test/test/test_cycles.c
@@ -24,6 +24,30 @@
*/
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)
{
unsigned i;
@@ -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