From e4401ac0c3a5bc13993dbab3c8033f2de6b60c40 Mon Sep 17 00:00:00 2001 From: Giovanni Di Sirio Date: Wed, 14 Apr 2021 10:15:37 +0000 Subject: [PATCH] The variable ch_system is not available in all configurations, "owner" is always present in thread structures, shell enhanced to show the core id. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@14173 27425a3e-05d8-49a3-a47f-9c15f0e5edd8 --- os/common/ports/ARMv6-M-RP2/chcore.h | 12 ++---------- os/rt/include/chearly.h | 8 ++++++-- os/rt/include/chobjects.h | 24 +++++++++++++++++++----- os/rt/include/chsys.h | 2 -- os/rt/src/chschd.c | 22 ++++++++-------------- os/rt/src/chsys.c | 23 +++++++++-------------- os/rt/src/chthreads.c | 5 ----- os/various/shell/shell.c | 2 +- os/various/shell/shell_cmd.c | 20 ++++++++++++++++---- 9 files changed, 61 insertions(+), 57 deletions(-) diff --git a/os/common/ports/ARMv6-M-RP2/chcore.h b/os/common/ports/ARMv6-M-RP2/chcore.h index f823483dd..0971905aa 100644 --- a/os/common/ports/ARMv6-M-RP2/chcore.h +++ b/os/common/ports/ARMv6-M-RP2/chcore.h @@ -91,9 +91,7 @@ /** * @brief Port-related fields added to the OS instance structure. */ -#define PORT_INSTANCE_EXTRA_FIELDS \ - /* Core associated to this OS instance.*/ \ - uint32_t core_id; +#define PORT_INSTANCE_EXTRA_FIELDS /** * @brief Reschedule message sent through IPC FIFOs. @@ -291,12 +289,6 @@ asm module.*/ #if !defined(_FROM_ASM_) -/** - * @brief Type of a core identifier. - * @note Core identifiers have ranges from 0 to @p PORT_CORES_NUMBER - 1. - */ -typedef uint32_t code_id_t; - /** * @brief Type of stack and memory alignment enforcement. * @note In this architecture the stack alignment is enforced to 64 bits, @@ -675,7 +667,7 @@ __STATIC_FORCEINLINE rtcnt_t port_rt_get_counter_value(void) { * @brief Returns a core index. * @return The core identifier from 0 to @p PORT_CORES_NUMBER - 1. */ -__STATIC_INLINE code_id_t port_get_core_id(void) { +__STATIC_INLINE core_id_t port_get_core_id(void) { return SIO->CPUID; } diff --git a/os/rt/include/chearly.h b/os/rt/include/chearly.h index edb6b6591..0ff664412 100644 --- a/os/rt/include/chearly.h +++ b/os/rt/include/chearly.h @@ -45,8 +45,12 @@ /*===========================================================================*/ /** - * @extends threads_queue_t - * + * @brief Type of a core identifier. + * @note Core identifiers have ranges from 0 to @p PORT_CORES_NUMBER - 1. + */ +typedef unsigned core_id_t; + +/** * @brief Type of a thread structure. */ typedef struct ch_thread thread_t; diff --git a/os/rt/include/chobjects.h b/os/rt/include/chobjects.h index 94d436ffd..14943dd55 100644 --- a/os/rt/include/chobjects.h +++ b/os/rt/include/chobjects.h @@ -44,6 +44,16 @@ /* Module data structures and types. */ /*===========================================================================*/ +/** + * @brief Global state of the operating system. + */ +typedef enum { + ch_state_uninit = 0, + ch_state_initializing = 1, + ch_state_running = 2, + ch_state_halted = 3 +} system_state_t; + /** * @brief Type of a Virtual Timer callback function. */ @@ -129,12 +139,10 @@ struct ch_thread { #if (CH_CFG_USE_REGISTRY == TRUE) || defined(__DOXYGEN__) ch_queue_t rqueue; /**< @brief Registry queue element. */ #endif -#if (CH_CFG_SMP_MODE != FALSE) || defined(__DOXYGEN__) /** * @brief OS instance owner of this thread. */ os_instance_t *owner; -#endif #if (CH_CFG_USE_REGISTRY == TRUE) || defined(__DOXYGEN__) /** * @brief Thread name or @p NULL. @@ -352,10 +360,14 @@ struct ch_os_instance { virtual_timers_list_t vtlist; #if (CH_CFG_USE_REGISTRY == TRUE) || defined(__DOXYGEN__) /** - * @brief Registry header. + * @brief Registry header. */ ch_queue_t reglist; #endif + /** + * @brief Core associated to this instance. + */ + core_id_t core_id; /** * @brief Main thread descriptor. */ @@ -390,11 +402,14 @@ struct ch_os_instance { CH_CFG_OS_INSTANCE_EXTRA_FIELDS }; -#if (CH_CFG_SMP_MODE != FALSE) || defined(__DOXYGEN__) /** * @brief Type of system data structure. */ typedef struct ch_system { + /** + * @brief Operating system state. + */ + system_state_t state; /** * @brief Initialized OS instances or @p NULL. */ @@ -406,7 +421,6 @@ typedef struct ch_system { /* Extra fields from configuration.*/ CH_CFG_SYSTEM_EXTRA_FIELDS } ch_system_t; -#endif /*===========================================================================*/ /* Module macros. */ diff --git a/os/rt/include/chsys.h b/os/rt/include/chsys.h index a29fd7e3f..0ac858be9 100644 --- a/os/rt/include/chsys.h +++ b/os/rt/include/chsys.h @@ -291,9 +291,7 @@ /*===========================================================================*/ #if !defined(__DOXYGEN__) -#if CH_CFG_SMP_MODE != FALSE extern ch_system_t ch_system; -#endif extern os_instance_t ch; extern stkalign_t ch_idle_thread_wa[]; #endif diff --git a/os/rt/src/chschd.c b/os/rt/src/chschd.c index 665618917..374208bee 100644 --- a/os/rt/src/chschd.c +++ b/os/rt/src/chschd.c @@ -95,9 +95,7 @@ static thread_t *__sch_ready_behind(os_instance_t *oip, thread_t *tp) { chDbgAssert((tp->state != CH_STATE_READY) && (tp->state != CH_STATE_FINAL), "invalid state"); -#if CH_CFG_SMP_MODE != FALSE chDbgAssert(tp->owner == oip, "invalid core"); -#endif /* Tracing the event.*/ __trace_ready(tp, tp->u.rdymsg); @@ -132,9 +130,7 @@ static thread_t *__sch_ready_ahead(os_instance_t *oip, thread_t *tp) { chDbgAssert((tp->state != CH_STATE_READY) && (tp->state != CH_STATE_FINAL), "invalid state"); -#if CH_CFG_SMP_MODE != FALSE chDbgAssert(tp->owner == oip, "invalid core"); -#endif /* Tracing the event.*/ __trace_ready(tp, tp->u.rdymsg); @@ -299,17 +295,17 @@ void ch_sch_prio_insert(ch_queue_t *tp, ch_queue_t *qp) { */ void chSchObjectInit(os_instance_t *oip, const os_instance_config_t *oicp) { + core_id_t core_id; -#if CH_CFG_SMP_MODE != FALSE /* Registering into the global system structure.*/ - { - code_id_t core_id = port_get_core_id(); - - chDbgAssert(ch_system.instances[core_id] == NULL, "instance already registered"); - - ch_system.instances[core_id] = oip; - } +#if CH_CFG_SMP_MODE != FALSE + core_id = port_get_core_id(); +#else + core_id = 0U; #endif + chDbgAssert(ch_system.instances[core_id] == NULL, "instance already registered"); + ch_system.instances[core_id] = oip; + oip->core_id = core_id; /* Port initialization for the current instance.*/ port_init(oip); @@ -434,9 +430,7 @@ void chSchGoSleepS(tstate_t newstate) { chDbgCheckClassS(); chDbgAssert(otp != chSysGetIdleThreadX(), "sleeping in idle thread"); -#if CH_CFG_SMP_MODE != FALSE chDbgAssert(otp->owner == oip, "invalid core"); -#endif /* New state.*/ otp->state = newstate; diff --git a/os/rt/src/chsys.c b/os/rt/src/chsys.c index 944f78884..4a72096ee 100644 --- a/os/rt/src/chsys.c +++ b/os/rt/src/chsys.c @@ -39,12 +39,10 @@ /* Module exported variables. */ /*===========================================================================*/ -#if (CH_CFG_SMP_MODE != FALSE) || defined(__DOXYGEN__) /** * @brief System root object. */ ch_system_t ch_system; -#endif /** * @brief Default OS instance. @@ -85,20 +83,16 @@ THD_WORKING_AREA(ch_idle_thread_wa, PORT_IDLE_THREAD_STACK_SIZE); * @special */ void chSysInit(void) { + unsigned i; -#if CH_CFG_SMP_MODE != FALSE - { - unsigned i; - - /* System object initialization.*/ - for (i = 0U; i < PORT_CORES_NUMBER; i++) { - ch_system.instances[i] = NULL; - } - - /* User system initialization hook.*/ - CH_CFG_SYSTEM_INIT_HOOK(); + /* System object initialization.*/ + ch_system.state = ch_state_initializing; + for (i = 0U; i < PORT_CORES_NUMBER; i++) { + ch_system.instances[i] = NULL; } -#endif + + /* User system initialization hook.*/ + CH_CFG_SYSTEM_INIT_HOOK(); /* OS library modules.*/ __oslib_init(); @@ -129,6 +123,7 @@ void chSysInit(void) { } /* It is alive now.*/ + ch_system.state = ch_state_running; chSysUnlock(); } diff --git a/os/rt/src/chthreads.c b/os/rt/src/chthreads.c index 038ec5278..d4f60fc1d 100644 --- a/os/rt/src/chthreads.c +++ b/os/rt/src/chthreads.c @@ -94,12 +94,7 @@ thread_t *__thd_object_init(os_instance_t *oip, tp->hdr.pqueue.prio = prio; tp->state = CH_STATE_WTSTART; tp->flags = CH_FLAG_MODE_STATIC; - -#if CH_CFG_SMP_MODE != FALSE tp->owner = oip; -#else - (void)oip; -#endif #if CH_CFG_TIME_QUANTUM > 0 tp->ticks = (tslices_t)CH_CFG_TIME_QUANTUM; #endif diff --git a/os/various/shell/shell.c b/os/various/shell/shell.c index 19db9aae3..b293b39fd 100644 --- a/os/various/shell/shell.c +++ b/os/various/shell/shell.c @@ -38,7 +38,7 @@ /* Module exported variables. */ /*===========================================================================*/ -#if !defined(_CHIBIOS_NIL_) || defined(__DOXYGEN__) +#if !defined(__CHIBIOS_NIL__) || defined(__DOXYGEN__) /** * @brief Shell termination event source. */ diff --git a/os/various/shell/shell_cmd.c b/os/various/shell/shell_cmd.c index bc7668620..c11173dad 100644 --- a/os/various/shell/shell_cmd.c +++ b/os/various/shell/shell_cmd.c @@ -154,17 +154,29 @@ static void cmd_threads(BaseSequentialStream *chp, int argc, char *argv[]) { shellUsage(chp, "threads"); return; } - chprintf(chp, "stklimit stack addr refs prio state name\r\n" SHELL_NEWLINE_STR); + chprintf(chp, "core stklimit stack addr refs prio state name" SHELL_NEWLINE_STR); tp = chRegFirstThread(); do { + core_id_t core_id; + +#if !defined(__CHIBIOS_NIL__) + core_id = tp->owner->core_id; +#else + core_id = 0U; +#endif #if (CH_DBG_ENABLE_STACK_CHECK == TRUE) || (CH_CFG_USE_DYNAMIC == TRUE) uint32_t stklimit = (uint32_t)tp->wabase; #else uint32_t stklimit = 0U; #endif - chprintf(chp, "%08lx %08lx %08lx %4lu %4lu %9s %12s" SHELL_NEWLINE_STR, - stklimit, (uint32_t)tp->ctx.sp, (uint32_t)tp, - (uint32_t)tp->refs - 1, (uint32_t)tp->hdr.pqueue.prio, states[tp->state], + chprintf(chp, "%4lu %08lx %08lx %08lx %4lu %4lu %9s %12s" SHELL_NEWLINE_STR, + core_id, + stklimit, + (uint32_t)tp->ctx.sp, + (uint32_t)tp, + (uint32_t)tp->refs - 1, + (uint32_t)tp->hdr.pqueue.prio, + states[tp->state], tp->name == NULL ? "" : tp->name); tp = chRegNextThread(tp); } while (tp != NULL);