mirror of https://github.com/rusefi/ChibiOS.git
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:
parent
c93d99ee3a
commit
e4401ac0c3
|
@ -91,9 +91,7 @@
|
||||||
/**
|
/**
|
||||||
* @brief Port-related fields added to the OS instance structure.
|
* @brief Port-related fields added to the OS instance structure.
|
||||||
*/
|
*/
|
||||||
#define PORT_INSTANCE_EXTRA_FIELDS \
|
#define PORT_INSTANCE_EXTRA_FIELDS
|
||||||
/* Core associated to this OS instance.*/ \
|
|
||||||
uint32_t core_id;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Reschedule message sent through IPC FIFOs.
|
* @brief Reschedule message sent through IPC FIFOs.
|
||||||
|
@ -291,12 +289,6 @@
|
||||||
asm module.*/
|
asm module.*/
|
||||||
#if !defined(_FROM_ASM_)
|
#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.
|
* @brief Type of stack and memory alignment enforcement.
|
||||||
* @note In this architecture the stack alignment is enforced to 64 bits,
|
* @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.
|
* @brief Returns a core index.
|
||||||
* @return The core identifier from 0 to @p PORT_CORES_NUMBER - 1.
|
* @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;
|
return SIO->CPUID;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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.
|
* @brief Type of a thread structure.
|
||||||
*/
|
*/
|
||||||
typedef struct ch_thread thread_t;
|
typedef struct ch_thread thread_t;
|
||||||
|
|
|
@ -44,6 +44,16 @@
|
||||||
/* Module data structures and types. */
|
/* 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.
|
* @brief Type of a Virtual Timer callback function.
|
||||||
*/
|
*/
|
||||||
|
@ -129,12 +139,10 @@ struct ch_thread {
|
||||||
#if (CH_CFG_USE_REGISTRY == TRUE) || defined(__DOXYGEN__)
|
#if (CH_CFG_USE_REGISTRY == TRUE) || defined(__DOXYGEN__)
|
||||||
ch_queue_t rqueue; /**< @brief Registry queue element. */
|
ch_queue_t rqueue; /**< @brief Registry queue element. */
|
||||||
#endif
|
#endif
|
||||||
#if (CH_CFG_SMP_MODE != FALSE) || defined(__DOXYGEN__)
|
|
||||||
/**
|
/**
|
||||||
* @brief OS instance owner of this thread.
|
* @brief OS instance owner of this thread.
|
||||||
*/
|
*/
|
||||||
os_instance_t *owner;
|
os_instance_t *owner;
|
||||||
#endif
|
|
||||||
#if (CH_CFG_USE_REGISTRY == TRUE) || defined(__DOXYGEN__)
|
#if (CH_CFG_USE_REGISTRY == TRUE) || defined(__DOXYGEN__)
|
||||||
/**
|
/**
|
||||||
* @brief Thread name or @p NULL.
|
* @brief Thread name or @p NULL.
|
||||||
|
@ -352,10 +360,14 @@ struct ch_os_instance {
|
||||||
virtual_timers_list_t vtlist;
|
virtual_timers_list_t vtlist;
|
||||||
#if (CH_CFG_USE_REGISTRY == TRUE) || defined(__DOXYGEN__)
|
#if (CH_CFG_USE_REGISTRY == TRUE) || defined(__DOXYGEN__)
|
||||||
/**
|
/**
|
||||||
* @brief Registry header.
|
* @brief Registry header.
|
||||||
*/
|
*/
|
||||||
ch_queue_t reglist;
|
ch_queue_t reglist;
|
||||||
#endif
|
#endif
|
||||||
|
/**
|
||||||
|
* @brief Core associated to this instance.
|
||||||
|
*/
|
||||||
|
core_id_t core_id;
|
||||||
/**
|
/**
|
||||||
* @brief Main thread descriptor.
|
* @brief Main thread descriptor.
|
||||||
*/
|
*/
|
||||||
|
@ -390,11 +402,14 @@ struct ch_os_instance {
|
||||||
CH_CFG_OS_INSTANCE_EXTRA_FIELDS
|
CH_CFG_OS_INSTANCE_EXTRA_FIELDS
|
||||||
};
|
};
|
||||||
|
|
||||||
#if (CH_CFG_SMP_MODE != FALSE) || defined(__DOXYGEN__)
|
|
||||||
/**
|
/**
|
||||||
* @brief Type of system data structure.
|
* @brief Type of system data structure.
|
||||||
*/
|
*/
|
||||||
typedef struct ch_system {
|
typedef struct ch_system {
|
||||||
|
/**
|
||||||
|
* @brief Operating system state.
|
||||||
|
*/
|
||||||
|
system_state_t state;
|
||||||
/**
|
/**
|
||||||
* @brief Initialized OS instances or @p NULL.
|
* @brief Initialized OS instances or @p NULL.
|
||||||
*/
|
*/
|
||||||
|
@ -406,7 +421,6 @@ typedef struct ch_system {
|
||||||
/* Extra fields from configuration.*/
|
/* Extra fields from configuration.*/
|
||||||
CH_CFG_SYSTEM_EXTRA_FIELDS
|
CH_CFG_SYSTEM_EXTRA_FIELDS
|
||||||
} ch_system_t;
|
} ch_system_t;
|
||||||
#endif
|
|
||||||
|
|
||||||
/*===========================================================================*/
|
/*===========================================================================*/
|
||||||
/* Module macros. */
|
/* Module macros. */
|
||||||
|
|
|
@ -291,9 +291,7 @@
|
||||||
/*===========================================================================*/
|
/*===========================================================================*/
|
||||||
|
|
||||||
#if !defined(__DOXYGEN__)
|
#if !defined(__DOXYGEN__)
|
||||||
#if CH_CFG_SMP_MODE != FALSE
|
|
||||||
extern ch_system_t ch_system;
|
extern ch_system_t ch_system;
|
||||||
#endif
|
|
||||||
extern os_instance_t ch;
|
extern os_instance_t ch;
|
||||||
extern stkalign_t ch_idle_thread_wa[];
|
extern stkalign_t ch_idle_thread_wa[];
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -95,9 +95,7 @@ static thread_t *__sch_ready_behind(os_instance_t *oip, thread_t *tp) {
|
||||||
chDbgAssert((tp->state != CH_STATE_READY) &&
|
chDbgAssert((tp->state != CH_STATE_READY) &&
|
||||||
(tp->state != CH_STATE_FINAL),
|
(tp->state != CH_STATE_FINAL),
|
||||||
"invalid state");
|
"invalid state");
|
||||||
#if CH_CFG_SMP_MODE != FALSE
|
|
||||||
chDbgAssert(tp->owner == oip, "invalid core");
|
chDbgAssert(tp->owner == oip, "invalid core");
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Tracing the event.*/
|
/* Tracing the event.*/
|
||||||
__trace_ready(tp, tp->u.rdymsg);
|
__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) &&
|
chDbgAssert((tp->state != CH_STATE_READY) &&
|
||||||
(tp->state != CH_STATE_FINAL),
|
(tp->state != CH_STATE_FINAL),
|
||||||
"invalid state");
|
"invalid state");
|
||||||
#if CH_CFG_SMP_MODE != FALSE
|
|
||||||
chDbgAssert(tp->owner == oip, "invalid core");
|
chDbgAssert(tp->owner == oip, "invalid core");
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Tracing the event.*/
|
/* Tracing the event.*/
|
||||||
__trace_ready(tp, tp->u.rdymsg);
|
__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,
|
void chSchObjectInit(os_instance_t *oip,
|
||||||
const os_instance_config_t *oicp) {
|
const os_instance_config_t *oicp) {
|
||||||
|
core_id_t core_id;
|
||||||
|
|
||||||
#if CH_CFG_SMP_MODE != FALSE
|
|
||||||
/* Registering into the global system structure.*/
|
/* Registering into the global system structure.*/
|
||||||
{
|
#if CH_CFG_SMP_MODE != FALSE
|
||||||
code_id_t core_id = port_get_core_id();
|
core_id = port_get_core_id();
|
||||||
|
#else
|
||||||
chDbgAssert(ch_system.instances[core_id] == NULL, "instance already registered");
|
core_id = 0U;
|
||||||
|
|
||||||
ch_system.instances[core_id] = oip;
|
|
||||||
}
|
|
||||||
#endif
|
#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 initialization for the current instance.*/
|
||||||
port_init(oip);
|
port_init(oip);
|
||||||
|
@ -434,9 +430,7 @@ void chSchGoSleepS(tstate_t newstate) {
|
||||||
chDbgCheckClassS();
|
chDbgCheckClassS();
|
||||||
|
|
||||||
chDbgAssert(otp != chSysGetIdleThreadX(), "sleeping in idle thread");
|
chDbgAssert(otp != chSysGetIdleThreadX(), "sleeping in idle thread");
|
||||||
#if CH_CFG_SMP_MODE != FALSE
|
|
||||||
chDbgAssert(otp->owner == oip, "invalid core");
|
chDbgAssert(otp->owner == oip, "invalid core");
|
||||||
#endif
|
|
||||||
|
|
||||||
/* New state.*/
|
/* New state.*/
|
||||||
otp->state = newstate;
|
otp->state = newstate;
|
||||||
|
|
|
@ -39,12 +39,10 @@
|
||||||
/* Module exported variables. */
|
/* Module exported variables. */
|
||||||
/*===========================================================================*/
|
/*===========================================================================*/
|
||||||
|
|
||||||
#if (CH_CFG_SMP_MODE != FALSE) || defined(__DOXYGEN__)
|
|
||||||
/**
|
/**
|
||||||
* @brief System root object.
|
* @brief System root object.
|
||||||
*/
|
*/
|
||||||
ch_system_t ch_system;
|
ch_system_t ch_system;
|
||||||
#endif
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Default OS instance.
|
* @brief Default OS instance.
|
||||||
|
@ -85,20 +83,16 @@ THD_WORKING_AREA(ch_idle_thread_wa, PORT_IDLE_THREAD_STACK_SIZE);
|
||||||
* @special
|
* @special
|
||||||
*/
|
*/
|
||||||
void chSysInit(void) {
|
void chSysInit(void) {
|
||||||
|
unsigned i;
|
||||||
|
|
||||||
#if CH_CFG_SMP_MODE != FALSE
|
/* System object initialization.*/
|
||||||
{
|
ch_system.state = ch_state_initializing;
|
||||||
unsigned i;
|
for (i = 0U; i < PORT_CORES_NUMBER; i++) {
|
||||||
|
ch_system.instances[i] = NULL;
|
||||||
/* 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();
|
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
/* User system initialization hook.*/
|
||||||
|
CH_CFG_SYSTEM_INIT_HOOK();
|
||||||
|
|
||||||
/* OS library modules.*/
|
/* OS library modules.*/
|
||||||
__oslib_init();
|
__oslib_init();
|
||||||
|
@ -129,6 +123,7 @@ void chSysInit(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* It is alive now.*/
|
/* It is alive now.*/
|
||||||
|
ch_system.state = ch_state_running;
|
||||||
chSysUnlock();
|
chSysUnlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -94,12 +94,7 @@ thread_t *__thd_object_init(os_instance_t *oip,
|
||||||
tp->hdr.pqueue.prio = prio;
|
tp->hdr.pqueue.prio = prio;
|
||||||
tp->state = CH_STATE_WTSTART;
|
tp->state = CH_STATE_WTSTART;
|
||||||
tp->flags = CH_FLAG_MODE_STATIC;
|
tp->flags = CH_FLAG_MODE_STATIC;
|
||||||
|
|
||||||
#if CH_CFG_SMP_MODE != FALSE
|
|
||||||
tp->owner = oip;
|
tp->owner = oip;
|
||||||
#else
|
|
||||||
(void)oip;
|
|
||||||
#endif
|
|
||||||
#if CH_CFG_TIME_QUANTUM > 0
|
#if CH_CFG_TIME_QUANTUM > 0
|
||||||
tp->ticks = (tslices_t)CH_CFG_TIME_QUANTUM;
|
tp->ticks = (tslices_t)CH_CFG_TIME_QUANTUM;
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -38,7 +38,7 @@
|
||||||
/* Module exported variables. */
|
/* Module exported variables. */
|
||||||
/*===========================================================================*/
|
/*===========================================================================*/
|
||||||
|
|
||||||
#if !defined(_CHIBIOS_NIL_) || defined(__DOXYGEN__)
|
#if !defined(__CHIBIOS_NIL__) || defined(__DOXYGEN__)
|
||||||
/**
|
/**
|
||||||
* @brief Shell termination event source.
|
* @brief Shell termination event source.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -154,17 +154,29 @@ static void cmd_threads(BaseSequentialStream *chp, int argc, char *argv[]) {
|
||||||
shellUsage(chp, "threads");
|
shellUsage(chp, "threads");
|
||||||
return;
|
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();
|
tp = chRegFirstThread();
|
||||||
do {
|
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)
|
#if (CH_DBG_ENABLE_STACK_CHECK == TRUE) || (CH_CFG_USE_DYNAMIC == TRUE)
|
||||||
uint32_t stklimit = (uint32_t)tp->wabase;
|
uint32_t stklimit = (uint32_t)tp->wabase;
|
||||||
#else
|
#else
|
||||||
uint32_t stklimit = 0U;
|
uint32_t stklimit = 0U;
|
||||||
#endif
|
#endif
|
||||||
chprintf(chp, "%08lx %08lx %08lx %4lu %4lu %9s %12s" SHELL_NEWLINE_STR,
|
chprintf(chp, "%4lu %08lx %08lx %08lx %4lu %4lu %9s %12s" SHELL_NEWLINE_STR,
|
||||||
stklimit, (uint32_t)tp->ctx.sp, (uint32_t)tp,
|
core_id,
|
||||||
(uint32_t)tp->refs - 1, (uint32_t)tp->hdr.pqueue.prio, states[tp->state],
|
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->name == NULL ? "" : tp->name);
|
||||||
tp = chRegNextThread(tp);
|
tp = chRegNextThread(tp);
|
||||||
} while (tp != NULL);
|
} while (tp != NULL);
|
||||||
|
|
Loading…
Reference in New Issue