From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: bst@pengutronix.de, Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 1/3] commands: sleep: add support for running without pollers
Date: Tue, 1 Jul 2025 10:52:49 +0200 [thread overview]
Message-ID: <20250701085251.148111-1-a.fatoum@pengutronix.de> (raw)
This is useful to test how different parts of barebox behave when
pollers are delayed too much.
Signed-off-by: Ahmad Fatoum <a.fatoum@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
next reply other threads:[~2025-07-01 10:06 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-01 8:52 Ahmad Fatoum [this message]
2025-07-01 8:52 ` [PATCH 2/3] poller: add option to detect delayed poller activation Ahmad Fatoum
2025-07-01 8:52 ` [PATCH 3/3] menu: schedule pollers/workqueues while waiting for menu item selection Ahmad Fatoum
2025-07-01 9:24 ` Bastian Krause
2025-07-02 7:00 ` [PATCH 1/3] commands: sleep: add support for running without pollers Sascha Hauer
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=20250701085251.148111-1-a.fatoum@pengutronix.de \
--to=a.fatoum@pengutronix.de \
--cc=barebox@lists.infradead.org \
--cc=bst@pengutronix.de \
/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