From ca8d254d39e84cbe3374cbc76a5e21efae88e7a0 Mon Sep 17 00:00:00 2001 From: "Luke T. Shumaker" Date: Thu, 21 Nov 2024 23:57:23 -0700 Subject: libcr: Track coroutine names --- cmd/sbc_harness/config/config.h | 1 + cmd/srv9p/config/config.h | 1 + libcr/coroutine.c | 12 +++++++++++- 3 files changed, 13 insertions(+), 1 deletion(-) 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 /* for setjmp(), longjmp(), jmp_buf */ #include /* for uint8_t */ #include /* for aligned_alloc(), free() */ +#include /* for strncpy(), memset() */ #include @@ -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); -- cgit v1.2.3-2-g168b