summaryrefslogtreecommitdiffstats
path: root/commands
diff options
context:
space:
mode:
authorAhmad Fatoum <a.fatoum@pengutronix.de>2021-06-28 09:07:32 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2021-06-28 14:44:31 +0200
commit0f621c63d7c3396010001c043e190b628d7b2982 (patch)
tree67940fa50a0cb247609ced947e48b129c2138172 /commands
parent997cca0f15dcc8b8c96f542ac66c2eaad353f88e (diff)
downloadbarebox-0f621c63d7c3396010001c043e190b628d7b2982.tar.gz
barebox-0f621c63d7c3396010001c043e190b628d7b2982.tar.xz
bthread: add options to create and delete dummy bthreads
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> Link: https://lore.barebox.org/20210628070732.16812-3-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'commands')
-rw-r--r--commands/bthread.c27
1 files changed, 26 insertions, 1 deletions
diff --git a/commands/bthread.c b/commands/bthread.c
index ce3db2d3d2..aaade46e92 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