From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 06/12] poller: command: add new coroutine check
Date: Mon, 15 Feb 2021 11:36:59 +0100 [thread overview]
Message-ID: <20210215103704.32537-7-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20210215103704.32537-1-a.fatoum@pengutronix.de>
The poller command can already counts how many pollers can execute
serially in a second. Add a new -c options that additionally
registers a poller that does non-blockingly sleep via poller_yield.
A system with working coroutines and enabled CONFIG_POLLER_YIELD should
show that the poller yielded exactly 4 times during considerably more
poller_call()s. For example:
barebox@Embest MarS Board i.MX6Dual:/ poller -c
Poller yield #1
Poller yield #2
Poller yield #3
Poller yield #4
295066 poller calls in 1s
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
common/poller.c | 41 +++++++++++++++++++++++++++++++++++------
1 file changed, 35 insertions(+), 6 deletions(-)
diff --git a/common/poller.c b/common/poller.c
index 592dc0a11a39..a63af0e792a6 100644
--- a/common/poller.c
+++ b/common/poller.c
@@ -187,8 +187,9 @@ void poller_call(void)
#include <command.h>
#include <getopt.h>
+#include <clock.h>
-static void poller_time(void)
+static int poller_time(void)
{
uint64_t start = get_time_ns();
int i = 0;
@@ -202,7 +203,7 @@ static void poller_time(void)
while (!is_timeout(start, SECOND))
i++;
- printf("%d poller calls in 1s\n", i);
+ return i;
}
static void poller_info(void)
@@ -226,20 +227,48 @@ BAREBOX_CMD_HELP_TEXT("")
BAREBOX_CMD_HELP_TEXT("Options:")
BAREBOX_CMD_HELP_OPT ("-i", "Print information about registered pollers")
BAREBOX_CMD_HELP_OPT ("-t", "measure how many pollers we run in 1s")
+BAREBOX_CMD_HELP_OPT ("-c", "run coroutine test")
BAREBOX_CMD_HELP_END
+static void poller_coroutine(struct poller_struct *poller)
+{
+ volatile u64 start;
+ volatile int i = 0;
+
+ for (;;) {
+ start = get_time_ns();
+ while (!is_timeout_non_interruptible(start, 225 * MSECOND))
+ __poller_yield(active_poller);
+
+ printf("Poller yield #%d\n", ++i);
+ }
+}
+
static int do_poller(int argc, char *argv[])
{
- int opt;
+ struct poller_struct poller = {};
+ int ret, opt;
- while ((opt = getopt(argc, argv, "it")) > 0) {
+ while ((opt = getopt(argc, argv, "itc")) > 0) {
switch (opt) {
case 'i':
poller_info();
return 0;
+ case 'c':
+ if (!IS_ENABLED(CONFIG_POLLER_YIELD)) {
+ printf("CONFIG_POLLER_YIELD support not compiled in\n");
+ return -ENOSYS;
+ }
+
+ poller.func = poller_coroutine;
+ ret = poller_register(&poller, "poller-coroutine-test");
+ if (ret)
+ return ret;
+
+ /* fallthrough */
case 't':
- poller_time();
- return 0;
+ printf("%d poller calls in 1s\n", poller_time());
+ return poller.func ? poller_unregister(&poller) : 0;
}
}
--
2.29.2
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2021-02-15 10:41 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-02-15 10:36 [PATCH 00/12] poller: run pollers as proper coroutines (green threads) Ahmad Fatoum
2021-02-15 10:36 ` [PATCH 01/12] common: add coroutine support Ahmad Fatoum
2021-02-15 10:36 ` [PATCH 02/12] poller: run pollers as proper coroutines if architecture supports it Ahmad Fatoum
2021-02-15 10:36 ` [PATCH 03/12] ARM: asm: setjmp: annotate setjmp/longjmp for GCC Ahmad Fatoum
2021-02-15 10:36 ` [PATCH 04/12] ARM: asm: setjmp: implement coroutine dependency initjmp() Ahmad Fatoum
2021-02-15 10:36 ` [PATCH 05/12] sandbox: asm: implement setjmp/longjmp/initjmp Ahmad Fatoum
2021-02-15 10:36 ` Ahmad Fatoum [this message]
2021-02-15 10:37 ` [PATCH 07/12] slice: have assert_command_context() yield until true if possible Ahmad Fatoum
2021-02-15 10:37 ` [PATCH 08/12] poller: implement basic Linux-like completion API Ahmad Fatoum
2021-02-15 10:37 ` [PATCH 09/12] include: add kthread wrappers for pollers Ahmad Fatoum
2021-02-15 12:31 ` Sascha Hauer
2021-02-15 10:37 ` [PATCH 10/12] usbgadget: ums: run gadget loop in a background coroutine if possible Ahmad Fatoum
2021-02-15 10:37 ` [PATCH 11/12] usbgadget: refactor usbgadget_register to accept array Ahmad Fatoum
2021-02-15 10:37 ` [PATCH 12/12] usbgadget: multi: wire mass storage gadget into composite gadget Ahmad Fatoum
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=20210215103704.32537-7-a.fatoum@pengutronix.de \
--to=a.fatoum@pengutronix.de \
--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