summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke T. Shumaker <lukeshu@lukeshu.com>2024-11-21 23:57:23 -0700
committerLuke T. Shumaker <lukeshu@lukeshu.com>2024-11-23 13:56:51 -0700
commitca8d254d39e84cbe3374cbc76a5e21efae88e7a0 (patch)
tree30ae0f4888767bfd4b4b6d54cba3aade95371642
parent60230d7862a9a87b4ef5531d0a549172335a2e3f (diff)
libcr: Track coroutine names
-rw-r--r--cmd/sbc_harness/config/config.h1
-rw-r--r--cmd/srv9p/config/config.h1
-rw-r--r--libcr/coroutine.c12
3 files changed, 13 insertions, 1 deletions
diff --git a/cmd/sbc_harness/config/config.h b/cmd/sbc_harness/config/config.h
index 98fc156..85170cc 100644
--- a/cmd/sbc_harness/config/config.h
+++ b/cmd/sbc_harness/config/config.h
@@ -73,6 +73,7 @@
/* COROUTINE ******************************************************************/
#define CONFIG_COROUTINE_DEFAULT_STACK_SIZE (2*1024)
+#define CONFIG_COROUTINE_NAME_LEN 16
#define CONFIG_COROUTINE_MEASURE_STACK 1 /* bool */
#define CONFIG_COROUTINE_PROTECT_STACK 1 /* bool */
#define CONFIG_COROUTINE_DEBUG 0 /* bool */
diff --git a/cmd/srv9p/config/config.h b/cmd/srv9p/config/config.h
index 80c8125..82be297 100644
--- a/cmd/srv9p/config/config.h
+++ b/cmd/srv9p/config/config.h
@@ -46,6 +46,7 @@
/* COROUTINE ******************************************************************/
#define CONFIG_COROUTINE_DEFAULT_STACK_SIZE (32*1024)
+#define CONFIG_COROUTINE_NAME_LEN 16
#define CONFIG_COROUTINE_MEASURE_STACK 1 /* bool */
#define CONFIG_COROUTINE_PROTECT_STACK 1 /* bool */
#define CONFIG_COROUTINE_DEBUG 0 /* bool */
diff --git a/libcr/coroutine.c b/libcr/coroutine.c
index 9cadc55..45dcb39 100644
--- a/libcr/coroutine.c
+++ b/libcr/coroutine.c
@@ -7,6 +7,7 @@
#include <setjmp.h> /* for setjmp(), longjmp(), jmp_buf */
#include <stdint.h> /* for uint8_t */
#include <stdlib.h> /* for aligned_alloc(), free() */
+#include <string.h> /* for strncpy(), memset() */
#include <libmisc/assert.h>
@@ -23,6 +24,9 @@
#ifndef CONFIG_COROUTINE_DEFAULT_STACK_SIZE
#error config.h must define CONFIG_COROUTINE_DEFAULT_STACK_SIZE
#endif
+#ifndef CONFIG_COROUTINE_NAME_LEN
+ #error config.h must define CONFIG_COROUTINE_NAME_LEN
+#endif
#ifndef CONFIG_COROUTINE_NUM
#error config.h must define CONFIG_COROUTINE_NUM
#endif
@@ -365,6 +369,7 @@ struct coroutine {
#if CONFIG_COROUTINE_VALGRIND
unsigned stack_id;
#endif
+ char name[CONFIG_COROUTINE_NAME_LEN];
};
/* constants ******************************************************************/
@@ -474,7 +479,7 @@ static inline void assert_cid(cid_t cid) {
/* coroutine_add() ************************************************************/
cid_t coroutine_add_with_stack_size(size_t stack_size,
- const char [[gnu::unused]] *name,
+ const char *name,
cr_fn_t fn, void *args) {
static cid_t last_created = 0;
cid_t parent = coroutine_running;
@@ -501,6 +506,11 @@ cid_t coroutine_add_with_stack_size(size_t stack_size,
last_created = child;
+ if (name)
+ strncpy(coroutine_table[child-1].name, name, sizeof(coroutine_table[child-1].name));
+ else
+ memset(coroutine_table[child-1].name, 0, sizeof(coroutine_table[child-1].name));
+
coroutine_table[child-1].stack_size = stack_size;
coroutine_table[child-1].stack =
aligned_alloc(CR_PLAT_STACK_ALIGNMENT, stack_size);