[PATCH 1/3] commands: sleep: add support for running without pollers
Ahmad Fatoum
a.fatoum at pengutronix.de
Tue Jul 1 01:52:49 PDT 2025
This is useful to test how different parts of barebox behave when
pollers are delayed too much.
Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
commands/sleep.c | 42 +++++++++++++++++++++++++++++++++++-------
common/console.c | 13 +++++++++----
include/stdio.h | 6 ++++++
3 files changed, 50 insertions(+), 11 deletions(-)
diff --git a/commands/sleep.c b/commands/sleep.c
index 641dbb230ad5..bb9baf079404 100644
--- a/commands/sleep.c
+++ b/commands/sleep.c
@@ -7,15 +7,28 @@
#include <command.h>
#include <complete.h>
#include <clock.h>
+#include <getopt.h>
static int do_sleep(int argc, char *argv[])
{
uint64_t start, delay;
+ bool blocking = false;
+ int opt;
- if (argc != 2)
+ while((opt = getopt(argc, argv, "b")) > 0) {
+ switch(opt) {
+ case 'b':
+ blocking = true;
+ break;
+ default:
+ return COMMAND_ERROR_USAGE;
+ }
+ }
+
+ if (argc - optind != 1)
return COMMAND_ERROR_USAGE;
- delay = simple_strtoul(argv[1], NULL, 10);
+ delay = simple_strtoul(argv[optind], NULL, 10);
if (!strcmp(argv[0], "msleep"))
delay *= MSECOND;
@@ -23,9 +36,17 @@ static int do_sleep(int argc, char *argv[])
delay *= SECOND;
start = get_time_ns();
- while (!is_timeout(start, delay)) {
- if (ctrlc())
- return 1;
+
+ if (blocking) {
+ while (!is_timeout_non_interruptible(start, delay)) {
+ if (ctrlc_non_interruptible())
+ return 1;
+ }
+ } else {
+ while (!is_timeout(start, delay)) {
+ if (ctrlc())
+ return 1;
+ }
}
return 0;
@@ -33,11 +54,18 @@ static int do_sleep(int argc, char *argv[])
static const char * const sleep_aliases[] = { "msleep", NULL};
+BAREBOX_CMD_HELP_START(sleep)
+BAREBOX_CMD_HELP_TEXT("delay execution for n seconds or n mseconds if invoked as msleep")
+BAREBOX_CMD_HELP_TEXT("")
+BAREBOX_CMD_HELP_TEXT("Options:")
+BAREBOX_CMD_HELP_OPT ("-b", "For development: busy loop while inhibiting pollers from running")
+BAREBOX_CMD_HELP_END
+
BAREBOX_CMD_START(sleep)
.cmd = do_sleep,
.aliases = sleep_aliases,
- BAREBOX_CMD_DESC("delay execution for n seconds or n mseconds if invoked as msleep")
- BAREBOX_CMD_OPTS("SECONDS")
+ BAREBOX_CMD_DESC("delay execution for specified time")
+ BAREBOX_CMD_OPTS("[-b] SECONDS")
BAREBOX_CMD_GROUP(CMD_GRP_SCRIPT)
BAREBOX_CMD_COMPLETE(command_var_complete)
BAREBOX_CMD_END
diff --git a/common/console.c b/common/console.c
index 424290b6cd10..24f1500a6558 100644
--- a/common/console.c
+++ b/common/console.c
@@ -648,13 +648,10 @@ void ctrlc_handled(void)
ctrlc_abort = 0;
}
-/* test if ctrl-c was pressed */
-int ctrlc(void)
+int ctrlc_non_interruptible(void)
{
int ret = 0;
- resched();
-
if (!ctrlc_allowed)
return 0;
@@ -673,6 +670,14 @@ int ctrlc(void)
return ret;
}
+EXPORT_SYMBOL(ctrlc_non_interruptible);
+
+/* test if ctrl-c was pressed */
+int ctrlc(void)
+{
+ resched();
+ return ctrlc_non_interruptible();
+}
EXPORT_SYMBOL(ctrlc);
static int console_ctrlc_init(void)
diff --git a/include/stdio.h b/include/stdio.h
index dcaed71dae05..cec303461ba3 100644
--- a/include/stdio.h
+++ b/include/stdio.h
@@ -59,6 +59,7 @@ void console_flush(void);
int vprintf(const char *fmt, va_list args);
int ctrlc(void);
+int ctrlc_non_interruptible(void);
void ctrlc_handled(void);
#else
static inline int tstc(void)
@@ -91,6 +92,11 @@ static inline int ctrlc (void)
return 0;
}
+int ctrlc_non_interruptible(void)
+{
+ return 0;
+}
+
static inline void ctrlc_handled(void)
{
}
--
2.39.5
More information about the barebox
mailing list