mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 3/3] bthread: add options to create and delete dummy bthreads
Date: Mon, 28 Jun 2021 09:07:32 +0200	[thread overview]
Message-ID: <20210628070732.16812-3-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20210628070732.16812-1-a.fatoum@pengutronix.de>

With few bthread users currently, it can be useful to spin up some
threads to test stuff. Add a new option to add one more thread into the
mix and another to remove one of these dummy threads. Unlike the
existing -v option that can also be stacked, these threads remain active
after command termination unless explicitly removed.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 commands/bthread.c | 27 ++++++++++++++++++++++++++-
 1 file changed, 26 insertions(+), 1 deletion(-)

diff --git a/commands/bthread.c b/commands/bthread.c
index ce3db2d3d292..aaade46e9206 100644
--- a/commands/bthread.c
+++ b/commands/bthread.c
@@ -135,6 +135,8 @@ struct spawn {
 
 static int do_bthread(int argc, char *argv[])
 {
+	static int dummynr;
+	static LIST_HEAD(dummies);
 	LIST_HEAD(spawners);
 	struct spawn *spawner, *tmp;
 	int ret = 0;
@@ -142,8 +144,29 @@ static int do_bthread(int argc, char *argv[])
 	bool time = false;
 	struct arg *arg;
 
-	while ((opt = getopt(argc, argv, "itcv")) > 0) {
+	while ((opt = getopt(argc, argv, "aritcv")) > 0) {
 		switch (opt) {
+		case 'a':
+			spawner = xzalloc(sizeof(*spawner));
+			spawner->bthread = bthread_run(bthread_infinite, NULL,
+						       "dummy%u", dummynr++);
+			if (!spawner->bthread) {
+				free(spawner);
+				ret = -ENOMEM;
+				goto cleanup;
+			}
+
+			list_add(&spawner->list, &dummies);
+			break;
+		case 'r':
+			if (dummynr == 0)
+				return -EINVAL;
+			spawner = list_first_entry(&dummies, struct spawn, list);
+			bthread_cancel(spawner->bthread);
+			list_del(&spawner->list);
+			free(spawner);
+			dummynr--;
+			break;
 		case 'i':
 			bthread_info();
 			break;
@@ -198,6 +221,8 @@ BAREBOX_CMD_HELP_START(bthread)
 	BAREBOX_CMD_HELP_OPT ("-i", "Print information about registered bthreads")
 	BAREBOX_CMD_HELP_OPT ("-t", "measure how many bthreads we currently run in 1s")
 	BAREBOX_CMD_HELP_OPT ("-c", "count maximum context switches in 1s")
+	BAREBOX_CMD_HELP_OPT ("-a", "add a dummy bthread")
+	BAREBOX_CMD_HELP_OPT ("-r", "remove a dummy bthread")
 	BAREBOX_CMD_HELP_OPT ("-v", "verify correct bthread operation")
 BAREBOX_CMD_HELP_END
 
-- 
2.30.2


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


  parent reply	other threads:[~2021-06-28  7:10 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-28  7:07 [PATCH 1/3] bthread: remove thread exit codes Ahmad Fatoum
2021-06-28  7:07 ` [PATCH 2/3] bthread: replace blocking bthread_stop with nonblocking bthread_cancel Ahmad Fatoum
2021-06-28  7:07 ` Ahmad Fatoum [this message]
2021-06-28 12:45 ` [PATCH 1/3] bthread: remove thread exit codes 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=20210628070732.16812-3-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --subject='Re: [PATCH 3/3] bthread: add options to create and delete dummy bthreads' \
    /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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox