mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: "Daniel Glöckner" <dg@emlix.com>
To: barebox@lists.infradead.org
Cc: "Daniel Glöckner" <dg@emlix.com>
Subject: [PATCH v2 04/10] Introduce idle slice
Date: Thu, 14 May 2020 20:21:52 +0200	[thread overview]
Message-ID: <76fd510b47399354e06406a6bb82f562d350d4cf.1589477005.git.dg@emlix.com> (raw)
In-Reply-To: <cover.1589477005.git.dg@emlix.com>
In-Reply-To: <cover.1589477005.git.dg@emlix.com>

Some code can't foresee which resources will be used by its poller. This
is the case especially in pollers that will execute arbitrary commands
input by the user. With this commit a special slice is introduced that is
released only when Barebox is waiting for console input and only when it
is doing that outside of any command. Code that wants to depend on the
idle slice must select CONFIG_IDLE_SLICE to make it available.

Signed-off-by: Daniel Glöckner <dg@emlix.com>
---
 common/Kconfig             |  4 ++++
 common/binfmt.c            |  3 +++
 common/command.c           |  3 +++
 common/console_countdown.c |  3 +++
 common/poller.c            |  2 ++
 common/slice.c             | 24 ++++++++++++++++++++++++
 include/slice.h            | 10 ++++++++++
 lib/readline.c             |  8 +++++++-
 8 files changed, 56 insertions(+), 1 deletion(-)

diff --git a/common/Kconfig b/common/Kconfig
index 400c0553c..2fa9140de 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -913,6 +913,10 @@ config BAREBOXCRC32_TARGET
 config POLLER
 	bool "generic polling infrastructure"
 
+config IDLE_SLICE
+	bool
+	default n
+
 config STATE
 	bool "generic state infrastructure"
 	select CRC32
diff --git a/common/binfmt.c b/common/binfmt.c
index f2ff62458..899f270d4 100644
--- a/common/binfmt.c
+++ b/common/binfmt.c
@@ -10,6 +10,7 @@
 #include <malloc.h>
 #include <command.h>
 #include <errno.h>
+#include <slice.h>
 
 static LIST_HEAD(binfmt_hooks);
 
@@ -23,7 +24,9 @@ static int binfmt_run(char *file, int argc, char **argv)
 		if (b->type != type)
 			continue;
 
+		idle_slice_acquire();
 		ret = b->hook(b, file, argc, argv);
+		idle_slice_release();
 		if (ret != -ERESTARTNOHAND)
 			return ret;
 	}
diff --git a/common/command.c b/common/command.c
index 49845938a..2b10248f5 100644
--- a/common/command.c
+++ b/common/command.c
@@ -30,6 +30,7 @@
 #include <init.h>
 #include <complete.h>
 #include <getopt.h>
+#include <slice.h>
 
 LIST_HEAD(command_list);
 EXPORT_SYMBOL(command_list);
@@ -72,7 +73,9 @@ int execute_command(int argc, char **argv)
 	/* Look up command in command table */
 	if ((cmdtp = find_cmd(argv[0]))) {
 		/* OK - call function to do the command */
+		idle_slice_acquire();
 		ret = cmdtp->cmd(argc, argv);
+		idle_slice_release();
 		if (ret == COMMAND_ERROR_USAGE) {
 			barebox_cmd_usage(cmdtp);
 			ret = COMMAND_ERROR;
diff --git a/common/console_countdown.c b/common/console_countdown.c
index 8d09894c3..f161cf7df 100644
--- a/common/console_countdown.c
+++ b/common/console_countdown.c
@@ -22,6 +22,7 @@
 #include <errno.h>
 #include <console_countdown.h>
 #include <stdio.h>
+#include <slice.h>
 
 static bool console_countdown_timeout_abort;
 
@@ -59,6 +60,7 @@ int console_countdown(int timeout_s, unsigned flags, const char *keys,
 	if (!(flags & CONSOLE_COUNTDOWN_SILENT))
 		printf("%4d", countdown--);
 
+	idle_slice_release();
 	do {
 		if (tstc()) {
 			key = getchar();
@@ -91,6 +93,7 @@ int console_countdown(int timeout_s, unsigned flags, const char *keys,
 	ret = 0;
 
  out:
+	idle_slice_acquire();
 	if (!(flags & CONSOLE_COUNTDOWN_SILENT))
 		printf("\n");
 	if (key && out_key)
diff --git a/common/poller.c b/common/poller.c
index cccffcb88..60a3461b2 100644
--- a/common/poller.c
+++ b/common/poller.c
@@ -116,7 +116,9 @@ void poller_call(void)
 			continue;
 
 		slice_acquire(&poller->slice);
+		idle_slice_acquire();
 		poller->func(poller);
+		idle_slice_release();
 		slice_release(&poller->slice);
 	}
 }
diff --git a/common/slice.c b/common/slice.c
index b4460335d..960bb2ff8 100644
--- a/common/slice.c
+++ b/common/slice.c
@@ -3,6 +3,7 @@
 #define pr_fmt(fmt) "slice: " fmt
 
 #include <common.h>
+#include <init.h>
 #include <slice.h>
 
 /*
@@ -221,6 +222,29 @@ void slice_init(struct slice *slice, const char *name)
 	list_add_tail(&slice->list, &slices);
 }
 
+#ifdef CONFIG_IDLE_SLICE
+struct slice idle_slice;
+
+void idle_slice_acquire(void)
+{
+	slice_acquire(&idle_slice);
+}
+
+void idle_slice_release(void)
+{
+	slice_release(&idle_slice);
+}
+
+static int idle_slice_init(void)
+{
+	slice_init(&idle_slice, "idle");
+	slice_acquire(&idle_slice);
+	return 0;
+}
+
+pure_initcall(idle_slice_init);
+#endif
+
 #if defined CONFIG_CMD_SLICE
 
 #include <command.h>
diff --git a/include/slice.h b/include/slice.h
index 4874f1afc..068daaa7c 100644
--- a/include/slice.h
+++ b/include/slice.h
@@ -28,4 +28,14 @@ void slice_init(struct slice *slice, const char *name);
 
 void slice_debug_acquired(struct slice *slice);
 
+#ifdef CONFIG_IDLE_SLICE
+extern struct slice idle_slice;
+
+void idle_slice_acquire(void);
+void idle_slice_release(void);
+#else
+static inline void idle_slice_acquire(void) {}
+static inline void idle_slice_release(void) {}
+#endif
+
 #endif /* __SLICE_H */
diff --git a/lib/readline.c b/lib/readline.c
index 3d16c1838..709efb375 100644
--- a/lib/readline.c
+++ b/lib/readline.c
@@ -3,6 +3,7 @@
 #include <init.h>
 #include <libbb.h>
 #include <poller.h>
+#include <slice.h>
 #include <ratp_bb.h>
 #include <xfuncs.h>
 #include <complete.h>
@@ -200,11 +201,16 @@ int readline(const char *prompt, char *buf, int len)
 	puts (prompt);
 
 	while (1) {
+		idle_slice_release();
 		while (!tstc()) {
 			poller_call();
-			if (IS_ENABLED(CONFIG_CONSOLE_RATP))
+			if (IS_ENABLED(CONFIG_CONSOLE_RATP)) {
+				idle_slice_acquire();
 				barebox_ratp_command_run();
+				idle_slice_release();
+			}
 		}
+		idle_slice_acquire();
 
 		ichar = read_key();
 
-- 
2.17.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  parent reply	other threads:[~2020-05-14 18:22 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-14 18:21 [PATCH v2 00/10] Support for Fastboot over UDP Daniel Glöckner
2020-05-14 18:21 ` [PATCH v2 01/10] Remove CONFIG_SLICE Daniel Glöckner
2020-05-14 18:21 ` [PATCH v2 02/10] net: fixed-link phys are never acquired Daniel Glöckner
2020-05-14 18:21 ` [PATCH v2 03/10] poller: adapt remaining users to API change Daniel Glöckner
2020-05-14 18:21 ` Daniel Glöckner [this message]
2020-05-20  6:03   ` [PATCH v2 04/10] Introduce idle slice Sascha Hauer
2020-05-14 18:21 ` [PATCH v2 05/10] ratp: use poller to run ratp commands Daniel Glöckner
2020-05-14 18:21 ` [PATCH v2 06/10] fastboot: split generic code from USB gadget Daniel Glöckner
2020-05-14 18:21 ` [PATCH v2 07/10] defconfigs: update renamed fastboot options Daniel Glöckner
2020-05-14 18:21 ` [PATCH v2 08/10] fastboot: rename usbgadget.fastboot_* variables to fastboot.* Daniel Glöckner
2020-05-20  4:55   ` Sascha Hauer
2020-05-14 18:21 ` [PATCH v2 09/10] fastboot net: implement fastboot over UDP Daniel Glöckner
2020-05-20  5:52   ` Sascha Hauer
2020-05-20  6:57     ` Daniel Glöckner
2020-05-20  8:14       ` Sascha Hauer
2020-05-20  8:17   ` Sascha Hauer
2020-05-14 18:21 ` [PATCH v2 10/10] fastboot: don't close fd 0 when downloading to ram Daniel Glöckner

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=76fd510b47399354e06406a6bb82f562d350d4cf.1589477005.git.dg@emlix.com \
    --to=dg@emlix.com \
    --cc=barebox@lists.infradead.org \
    /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