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
This commit is contained in:
Giovanni Di Sirio 2021-04-14 10:15:37 +00:00
parent c93d99ee3a
commit e4401ac0c3
9 changed files with 61 additions and 57 deletions

View File

@ -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;
}

View File

@ -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;

View File

@ -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.
@ -356,6 +364,10 @@ struct ch_os_instance {
*/
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. */

View File

@ -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

View File

@ -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;

View File

@ -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) {
#if CH_CFG_SMP_MODE != FALSE
{
unsigned i;
/* System object initialization.*/
ch_system.state = ch_state_initializing;
for (i = 0U; i < PORT_CORES_NUMBER; i++) {
ch_system.instances[i] = NULL;
}
/* User system initialization hook.*/
CH_CFG_SYSTEM_INIT_HOOK();
}
#endif
/* OS library modules.*/
__oslib_init();
@ -129,6 +123,7 @@ void chSysInit(void) {
}
/* It is alive now.*/
ch_system.state = ch_state_running;
chSysUnlock();
}

View File

@ -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

View File

@ -38,7 +38,7 @@
/* Module exported variables. */
/*===========================================================================*/
#if !defined(_CHIBIOS_NIL_) || defined(__DOXYGEN__)
#if !defined(__CHIBIOS_NIL__) || defined(__DOXYGEN__)
/**
* @brief Shell termination event source.
*/

View File

@ -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);