From: Stephen Hemminger <stephen@networkplumber.org>
To: dev@dpdk.org
Cc: Stephen Hemminger <stephen@networkplumber.org>,
Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
Subject: [PATCH v2 1/3] eal/windows: add sleep() shim
Date: Fri, 4 Dec 2026 11:43:57 -0800 [thread overview]
Message-ID: <20261204194956.803171-2-stephen@networkplumber.org> (raw)
In-Reply-To: <20261204194956.803171-1-stephen@networkplumber.org>
Microsoft libc does not provide sleep(), so code that wants to
wait a few seconds has to be wrapped in RTE_EXEC_ENV_WINDOWS
conditionals or use rte_delay_us_sleep() instead.
Add a sleep() to the Windows unistd.h shim, implemented with
rte_delay_us_sleep(). Nothing on Windows interrupts the wait so
it always returns 0, not the number of seconds remaining.
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
lib/eal/windows/include/unistd.h | 22 +++++++++++++++++++---
1 file changed, 19 insertions(+), 3 deletions(-)
diff --git a/lib/eal/windows/include/unistd.h b/lib/eal/windows/include/unistd.h
index f95888f4e1..456eb19718 100644
--- a/lib/eal/windows/include/unistd.h
+++ b/lib/eal/windows/include/unistd.h
@@ -5,13 +5,14 @@
#ifndef _UNISTD_H_
#define _UNISTD_H_
/**
- * This file is added to support common code in eal_common_lcore.c
- * as Microsoft libc does not contain unistd.h. This may be removed
- * in future releases.
+ * This file provides the parts of unistd.h that are used by DPDK
+ * but missing from Microsoft libc.
*/
#include <io.h>
+#include <rte_cycles.h>
+
/*
* Windows appears to be missing STD*_FILENO macros, so define here.
* For simplicity, assume that if STDIN_FILENO is missing, all are,
@@ -30,4 +31,19 @@
#define R_OK 0x04 /* test for read permission */
#endif
+/*
+ * Microsoft libc has no sleep(). Nothing on Windows interrupts the
+ * wait, so unlike POSIX this always sleeps the full time and returns 0
+ * rather than the number of seconds left. Loop a second at a time to
+ * avoid overflowing the microsecond argument.
+ */
+static inline unsigned int
+sleep(unsigned int seconds)
+{
+ while (seconds-- > 0)
+ rte_delay_us_sleep(US_PER_S);
+
+ return 0;
+}
+
#endif /* _UNISTD_H_ */
--
2.53.0
next prev parent reply other threads:[~2026-12-04 19:50 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-17 19:48 [RFC 1/2] app/testpmd: add option to set flow control mode Stephen Hemminger
2026-10-17 19:48 ` [RFC 2/2] app/testpmd: add option to limit run time Stephen Hemminger
2026-12-04 19:43 ` [PATCH v2 0/3] Test pmd enhancements for benchmarking Stephen Hemminger
2026-12-04 19:43 ` Stephen Hemminger [this message]
2026-12-04 19:43 ` [PATCH v2 2/3] app/testpmd: add option to set flow control mode Stephen Hemminger
2026-12-04 19:43 ` [PATCH v2 3/3] app/testpmd: add option to limit run time Stephen Hemminger
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=20261204194956.803171-2-stephen@networkplumber.org \
--to=stephen@networkplumber.org \
--cc=dev@dpdk.org \
--cc=dmitry.kozliuk@gmail.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
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox