From: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com> To: dev@dpdk.org Cc: Tyler Retzlaff <roretzla@microsoft.com>, Nick Connolly <nick.connolly@mayadata.io>, Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>, Narcisa Ana Maria Vasile <navasile@linux.microsoft.com>, Dmitry Malloy <dmitrym@microsoft.com>, Pallavi Kadam <pallavi.kadam@intel.com>, Ray Kinsella <mdr@ashroe.eu>, Neil Horman <nhorman@tuxdriver.com> Subject: [dpdk-dev] [PATCH v2 3/7] eal: add sleep API Date: Sun, 21 Feb 2021 04:28:27 +0300 Message-ID: <20210221012831.14643-4-dmitry.kozliuk@gmail.com> (raw) In-Reply-To: <20210221012831.14643-1-dmitry.kozliuk@gmail.com> POSIX sleep(3) is missing from Windows. Add generic rte_thread_sleep() to suspend current OS thread. Signed-off-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com> --- lib/librte_eal/common/eal_common_timer.c | 5 +++-- lib/librte_eal/include/rte_thread.h | 11 +++++++++++ lib/librte_eal/rte_eal_exports.def | 2 ++ lib/librte_eal/unix/rte_thread.c | 10 +++++++++- lib/librte_eal/version.map | 3 +++ lib/librte_eal/windows/eal_thread.c | 9 ++++++++- 6 files changed, 36 insertions(+), 4 deletions(-) diff --git a/lib/librte_eal/common/eal_common_timer.c b/lib/librte_eal/common/eal_common_timer.c index 71e0bd035..0e89a4f7d 100644 --- a/lib/librte_eal/common/eal_common_timer.c +++ b/lib/librte_eal/common/eal_common_timer.c @@ -16,6 +16,7 @@ #include <rte_cycles.h> #include <rte_pause.h> #include <rte_eal.h> +#include <rte_thread.h> #include "eal_private.h" #include "eal_memcfg.h" @@ -47,9 +48,9 @@ estimate_tsc_freq(void) #define CYC_PER_10MHZ 1E7 RTE_LOG(WARNING, EAL, "WARNING: TSC frequency estimated roughly" " - clock timings may be less accurate.\n"); - /* assume that the sleep(1) will sleep for 1 second */ + /* assume that the rte_thread_sleep(1) will sleep for 1 second */ uint64_t start = rte_rdtsc(); - sleep(1); + rte_thread_sleep(1); /* Round up to 10Mhz. 1E7 ~ 10Mhz */ return RTE_ALIGN_MUL_NEAR(rte_rdtsc() - start, CYC_PER_10MHZ); } diff --git a/lib/librte_eal/include/rte_thread.h b/lib/librte_eal/include/rte_thread.h index e640ea185..f0c12dd79 100644 --- a/lib/librte_eal/include/rte_thread.h +++ b/lib/librte_eal/include/rte_thread.h @@ -106,6 +106,17 @@ int rte_thread_tls_value_set(rte_tls_key key, const void *value); __rte_experimental void *rte_thread_tls_value_get(rte_tls_key key); +/** + * Suspend current OS thread for the specified time, yielding CPU to scheduler. + * + * @param sec + * Number of seconds to sleep. The system may return control later, + * but not earlier. Zero value always yields the CPU, but control may be + * returned immediately. + */ +__rte_experimental +void rte_thread_sleep(unsigned int sec); + #ifdef __cplusplus } #endif diff --git a/lib/librte_eal/rte_eal_exports.def b/lib/librte_eal/rte_eal_exports.def index 474cf123f..494240b94 100644 --- a/lib/librte_eal/rte_eal_exports.def +++ b/lib/librte_eal/rte_eal_exports.def @@ -334,3 +334,5 @@ EXPORTS rte_mem_map rte_mem_page_size rte_mem_unmap + + rte_thread_sleep diff --git a/lib/librte_eal/unix/rte_thread.c b/lib/librte_eal/unix/rte_thread.c index 86ffeebc9..91babfe88 100644 --- a/lib/librte_eal/unix/rte_thread.c +++ b/lib/librte_eal/unix/rte_thread.c @@ -3,10 +3,12 @@ */ #include <errno.h> -#include <pthread.h> #include <stdlib.h> #include <string.h> +#include <pthread.h> +#include <unistd.h> + #include <rte_common.h> #include <rte_errno.h> #include <rte_log.h> @@ -84,3 +86,9 @@ rte_thread_tls_value_get(rte_tls_key key) } return pthread_getspecific(key->thread_index); } + +void +rte_thread_sleep(unsigned int sec) +{ + sleep(sec); +} diff --git a/lib/librte_eal/version.map b/lib/librte_eal/version.map index fce90a112..106864469 100644 --- a/lib/librte_eal/version.map +++ b/lib/librte_eal/version.map @@ -412,6 +412,9 @@ EXPERIMENTAL { rte_thread_tls_key_delete; rte_thread_tls_value_get; rte_thread_tls_value_set; + + # added in 21.05 + rte_thread_sleep; }; INTERNAL { diff --git a/lib/librte_eal/windows/eal_thread.c b/lib/librte_eal/windows/eal_thread.c index 908e726d1..957792301 100644 --- a/lib/librte_eal/windows/eal_thread.c +++ b/lib/librte_eal/windows/eal_thread.c @@ -11,9 +11,10 @@ #include <rte_per_lcore.h> #include <rte_common.h> #include <rte_memory.h> -#include <eal_thread.h> +#include <rte_thread.h> #include "eal_private.h" +#include "eal_thread.h" #include "eal_windows.h" /* @@ -154,3 +155,9 @@ rte_thread_setname(__rte_unused pthread_t id, __rte_unused const char *name) /* This is a stub, not the expected result */ return 0; } + +void +rte_thread_sleep(unsigned int sec) +{ + return Sleep(MS_PER_S * sec); +} -- 2.29.2
next prev parent reply other threads:[~2021-02-21 1:29 UTC|newest] Thread overview: 132+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-02-20 23:29 [dpdk-dev] [PATCH 0/7] eal/windows: do not expose POSIX symbols Dmitry Kozlyuk 2021-02-20 23:29 ` [dpdk-dev] [PATCH 1/7] eal: add wrappers for POSIX string functions Dmitry Kozlyuk 2021-02-20 23:29 ` [dpdk-dev] [PATCH 2/7] eal: add macro for maximum path length Dmitry Kozlyuk 2021-02-20 23:29 ` [dpdk-dev] [PATCH 3/7] eal: add sleep API Dmitry Kozlyuk 2021-02-20 23:29 ` [dpdk-dev] [PATCH 4/7] eal: add asprintf() internal wrapper Dmitry Kozlyuk 2021-02-20 23:29 ` [dpdk-dev] [PATCH 5/7] lib: remove POSIX dependencies Dmitry Kozlyuk 2021-02-20 23:29 ` [dpdk-dev] [PATCH 6/7] drivers: " Dmitry Kozlyuk 2021-02-20 23:29 ` [dpdk-dev] [PATCH 7/7] eal/windows: do not expose POSIX symbols Dmitry Kozlyuk 2021-02-21 1:28 ` [dpdk-dev] [PATCH v2 0/7] " Dmitry Kozlyuk 2021-02-21 1:28 ` [dpdk-dev] [PATCH v2 1/7] eal: add wrappers for POSIX string functions Dmitry Kozlyuk 2021-02-22 11:47 ` Bruce Richardson 2021-02-22 12:48 ` Nick Connolly 2021-02-22 14:26 ` Bruce Richardson 2021-02-22 18:21 ` Nick Connolly 2021-02-22 22:57 ` Dmitry Kozlyuk 2021-02-23 9:45 ` Bruce Richardson 2021-02-27 20:23 ` Dmitry Kozlyuk 2021-03-01 21:31 ` Nick Connolly 2021-03-02 0:22 ` Dmitry Kozlyuk 2021-03-02 11:27 ` Nick Connolly 2021-03-16 9:51 ` Thomas Monjalon 2021-02-22 18:07 ` Tyler Retzlaff 2021-02-22 18:36 ` Nick Connolly 2021-02-21 1:28 ` [dpdk-dev] [PATCH v2 2/7] eal: add macro for maximum path length Dmitry Kozlyuk 2021-02-21 1:28 ` Dmitry Kozlyuk [this message] 2021-02-21 8:58 ` [dpdk-dev] [PATCH v2 3/7] eal: add sleep API Tal Shnaiderman 2021-02-21 1:28 ` [dpdk-dev] [PATCH v2 4/7] eal: add asprintf() internal wrapper Dmitry Kozlyuk 2021-02-21 1:28 ` [dpdk-dev] [PATCH v2 5/7] lib: remove POSIX dependencies Dmitry Kozlyuk 2021-02-21 1:28 ` [dpdk-dev] [PATCH v2 6/7] drivers: " Dmitry Kozlyuk 2021-02-21 8:59 ` Tal Shnaiderman 2021-02-21 15:54 ` Andrew Rybchenko 2021-02-21 17:05 ` Dmitry Kozlyuk 2021-02-21 1:28 ` [dpdk-dev] [PATCH v2 7/7] eal/windows: do not expose POSIX symbols Dmitry Kozlyuk 2021-02-21 8:59 ` Tal Shnaiderman 2021-02-21 10:24 ` Dmitry Kozlyuk 2021-02-21 11:58 ` Tal Shnaiderman 2021-02-21 14:33 ` Dmitry Kozlyuk 2021-02-21 14:28 ` [dpdk-dev] [PATCH v3 0/7] " Dmitry Kozlyuk 2021-02-21 14:28 ` [dpdk-dev] [PATCH v3 1/7] eal: add wrappers for POSIX string functions Dmitry Kozlyuk 2021-02-23 7:11 ` Andrew Rybchenko 2021-02-23 21:53 ` Nick Connolly 2021-02-24 7:21 ` Andrew Rybchenko 2021-03-04 6:47 ` [dpdk-dev] [EXTERNAL] " Khoa To 2021-02-21 14:28 ` [dpdk-dev] [PATCH v3 2/7] eal: add macro for maximum path length Dmitry Kozlyuk 2021-03-04 6:47 ` [dpdk-dev] [EXTERNAL] " Khoa To 2021-02-21 14:28 ` [dpdk-dev] [PATCH v3 3/7] eal: add sleep API Dmitry Kozlyuk 2021-02-23 22:06 ` Nick Connolly 2021-03-04 6:47 ` [dpdk-dev] [EXTERNAL] " Khoa To 2021-02-21 14:28 ` [dpdk-dev] [PATCH v3 4/7] eal: add asprintf() internal wrapper Dmitry Kozlyuk 2021-03-04 6:48 ` [dpdk-dev] [EXTERNAL] " Khoa To 2021-02-21 14:28 ` [dpdk-dev] [PATCH v3 5/7] lib: remove POSIX dependencies Dmitry Kozlyuk 2021-03-04 6:48 ` [dpdk-dev] [EXTERNAL] " Khoa To 2021-02-21 14:28 ` [dpdk-dev] [PATCH v3 6/7] drivers: " Dmitry Kozlyuk 2021-03-04 6:49 ` [dpdk-dev] [EXTERNAL] " Khoa To 2021-02-21 14:28 ` [dpdk-dev] [PATCH v3 7/7] eal/windows: do not expose POSIX symbols Dmitry Kozlyuk 2021-03-04 6:49 ` [dpdk-dev] [EXTERNAL] " Khoa To 2021-03-04 6:46 ` [dpdk-dev] [EXTERNAL] [PATCH v3 0/7] " Khoa To 2021-03-06 0:04 ` [dpdk-dev] [PATCH v4 0/4] " Dmitry Kozlyuk 2021-03-06 0:04 ` [dpdk-dev] [PATCH v4 1/4] eal: add sleep API Dmitry Kozlyuk 2021-03-06 0:04 ` [dpdk-dev] [PATCH v4 2/4] eal: add asprintf() internal wrapper Dmitry Kozlyuk 2021-03-06 15:27 ` Lance Richardson 2021-03-06 0:04 ` [dpdk-dev] [PATCH v4 3/4] build: indicate usage at build time for public headers Dmitry Kozlyuk 2021-03-16 9:59 ` Thomas Monjalon 2021-03-06 0:05 ` [dpdk-dev] [PATCH v4 4/4] eal/windows: do not expose POSIX symbols Dmitry Kozlyuk 2021-03-17 19:23 ` [dpdk-dev] [PATCH v4 0/4] " Ranjit Menon 2021-03-20 11:27 ` [dpdk-dev] [PATCH v5 0/5] " Dmitry Kozlyuk 2021-03-20 11:27 ` [dpdk-dev] [PATCH v5 1/5] eal: add sleep API Dmitry Kozlyuk 2021-03-22 8:57 ` Kinsella, Ray 2021-03-20 11:27 ` [dpdk-dev] [PATCH v5 2/5] eal/windows: hide asprintf() shim Dmitry Kozlyuk 2021-03-20 11:27 ` [dpdk-dev] [PATCH v5 3/5] eal: make OS shims internal Dmitry Kozlyuk 2021-03-20 11:27 ` [dpdk-dev] [PATCH v5 4/5] net: provide IP-related API on any OS Dmitry Kozlyuk 2021-03-20 11:27 ` [dpdk-dev] [PATCH v5 5/5] net: replace Windows networking shim Dmitry Kozlyuk 2021-03-20 13:05 ` [dpdk-dev] [PATCH v6 0/5] eal/windows: do not expose POSIX symbols Dmitry Kozlyuk 2021-03-20 13:05 ` [dpdk-dev] [PATCH v6 1/5] eal: add sleep API Dmitry Kozlyuk 2021-03-20 13:05 ` [dpdk-dev] [PATCH v6 2/5] eal/windows: hide asprintf() shim Dmitry Kozlyuk 2021-03-26 9:04 ` Thomas Monjalon 2021-03-20 13:05 ` [dpdk-dev] [PATCH v6 3/5] eal: make OS shims internal Dmitry Kozlyuk 2021-03-26 9:12 ` Thomas Monjalon 2021-03-31 21:05 ` Nick Connolly 2021-03-31 21:19 ` Thomas Monjalon 2021-03-31 21:45 ` Nick Connolly 2021-03-31 21:55 ` Thomas Monjalon 2021-04-01 23:10 ` Dmitry Kozlyuk 2021-04-01 23:18 ` Thomas Monjalon 2021-03-20 13:05 ` [dpdk-dev] [PATCH v6 4/5] net: provide IP-related API on any OS Dmitry Kozlyuk 2021-03-26 9:22 ` Thomas Monjalon 2021-03-20 13:05 ` [dpdk-dev] [PATCH v6 5/5] net: replace Windows networking shim Dmitry Kozlyuk 2021-03-26 9:28 ` Thomas Monjalon 2021-04-01 23:03 ` Dmitry Kozlyuk 2021-04-03 23:41 ` [dpdk-dev] [PATCH v7 0/5] eal/windows: do not expose POSIX symbols Dmitry Kozlyuk 2021-04-03 23:41 ` [dpdk-dev] [PATCH v7 1/5] eal: add sleep API Dmitry Kozlyuk 2021-04-06 14:34 ` Morten Brørup 2021-04-06 23:29 ` Dmitry Kozlyuk 2021-04-07 7:31 ` Morten Brørup 2021-04-29 17:09 ` Tyler Retzlaff 2021-04-03 23:41 ` [dpdk-dev] [PATCH v7 2/5] eal/windows: hide asprintf() shim Dmitry Kozlyuk 2021-04-10 7:05 ` Nick Connolly 2021-04-03 23:41 ` [dpdk-dev] [PATCH v7 3/5] eal: make OS shims internal Dmitry Kozlyuk 2021-04-03 23:41 ` [dpdk-dev] [PATCH v7 4/5] net: work around s_addr macro on Windows Dmitry Kozlyuk 2021-04-03 23:41 ` [dpdk-dev] [PATCH v7 5/5] net: provide IP-related API on any OS Dmitry Kozlyuk 2021-04-07 22:22 ` [dpdk-dev] [PATCH v8 0/4] eal/windows: do not expose POSIX symbols Dmitry Kozlyuk 2021-04-07 22:22 ` [dpdk-dev] [PATCH v8 1/4] eal/windows: hide asprintf() shim Dmitry Kozlyuk 2021-04-07 22:22 ` [dpdk-dev] [PATCH v8 2/4] eal: make OS shims internal Dmitry Kozlyuk 2021-04-07 22:22 ` [dpdk-dev] [PATCH v8 3/4] net: work around s_addr macro on Windows Dmitry Kozlyuk 2021-04-08 11:26 ` Olivier Matz 2021-04-07 22:22 ` [dpdk-dev] [PATCH v8 4/4] net: provide IP-related API on any OS Dmitry Kozlyuk 2021-04-08 11:45 ` Olivier Matz 2021-04-08 19:51 ` Dmitry Kozlyuk 2021-04-09 13:33 ` Olivier Matz 2021-04-14 21:47 ` Thomas Monjalon 2021-04-10 22:47 ` [dpdk-dev] [PATCH v9 0/4] eal/windows: do not expose POSIX symbols Dmitry Kozlyuk 2021-04-10 22:47 ` [dpdk-dev] [PATCH v9 1/4] eal/windows: hide asprintf() shim Dmitry Kozlyuk 2021-04-10 22:47 ` [dpdk-dev] [PATCH v9 2/4] eal: make OS shims internal Dmitry Kozlyuk 2021-04-14 21:33 ` Thomas Monjalon 2021-04-10 22:47 ` [dpdk-dev] [PATCH v9 3/4] net: work around s_addr macro on Windows Dmitry Kozlyuk 2021-04-10 22:47 ` [dpdk-dev] [PATCH v9 4/4] net: provide IP-related API on any OS Dmitry Kozlyuk 2021-04-13 4:46 ` [dpdk-dev] [PATCH v9 0/4] eal/windows: do not expose POSIX symbols Ranjit Menon 2021-04-13 7:00 ` Dmitry Kozlyuk 2021-04-14 21:12 ` Thomas Monjalon 2021-04-14 21:34 ` Ranjit Menon 2021-04-14 21:42 ` Thomas Monjalon 2021-04-14 21:47 ` Ranjit Menon 2021-04-14 22:08 ` Dmitry Kozlyuk 2021-04-14 22:58 ` Thomas Monjalon 2021-04-14 22:06 ` [dpdk-dev] [PATCH v10 " Dmitry Kozlyuk 2021-04-14 22:06 ` [dpdk-dev] [PATCH v10 1/4] eal/windows: hide asprintf() shim Dmitry Kozlyuk 2021-04-14 22:06 ` [dpdk-dev] [PATCH v10 2/4] eal: make OS shims internal Dmitry Kozlyuk 2021-04-14 22:06 ` [dpdk-dev] [PATCH v10 3/4] net: work around s_addr macro on Windows Dmitry Kozlyuk 2021-04-14 22:06 ` [dpdk-dev] [PATCH v10 4/4] net: provide IP-related API on any OS Dmitry Kozlyuk 2021-04-14 22:50 ` [dpdk-dev] [PATCH v10 0/4] eal/windows: do not expose POSIX symbols Ranjit Menon 2021-04-14 23:57 ` Thomas Monjalon 2021-03-17 19:19 ` [dpdk-dev] [PATCH 0/7] " Ranjit Menon
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=20210221012831.14643-4-dmitry.kozliuk@gmail.com \ --to=dmitry.kozliuk@gmail.com \ --cc=dev@dpdk.org \ --cc=dmitrym@microsoft.com \ --cc=mdr@ashroe.eu \ --cc=navasile@linux.microsoft.com \ --cc=nhorman@tuxdriver.com \ --cc=nick.connolly@mayadata.io \ --cc=pallavi.kadam@intel.com \ --cc=roretzla@microsoft.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
DPDK patches and discussions This inbox may be cloned and mirrored by anyone: git clone --mirror https://inbox.dpdk.org/dev/0 dev/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 dev dev/ https://inbox.dpdk.org/dev \ dev@dpdk.org public-inbox-index dev Example config snippet for mirrors. Newsgroup available over NNTP: nntp://inbox.dpdk.org/inbox.dpdk.dev AGPL code for this site: git clone https://public-inbox.org/public-inbox.git