Merge pull request #16818 from kaspar030/core_ps_interface
core/thread: add getters for thread_t
This commit is contained in:
commit
6c739935d8
@ -507,6 +507,17 @@ static inline thread_status_t thread_get_status(const thread_t *thread)
|
|||||||
return thread->status;
|
return thread->status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a thread's priority
|
||||||
|
*
|
||||||
|
* @param thread thread to work on
|
||||||
|
* @returns priority of thread
|
||||||
|
*/
|
||||||
|
static inline uint8_t thread_get_priority(const thread_t *thread)
|
||||||
|
{
|
||||||
|
return thread->priority;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns if a thread is active (currently running or waiting to be scheduled)
|
* Returns if a thread is active (currently running or waiting to be scheduled)
|
||||||
*
|
*
|
||||||
@ -526,6 +537,81 @@ static inline bool thread_is_active(const thread_t *thread)
|
|||||||
*/
|
*/
|
||||||
const char *thread_state_to_string(thread_status_t state);
|
const char *thread_state_to_string(thread_status_t state);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get start address (lowest) of a thread's stack.
|
||||||
|
*
|
||||||
|
* @param thread thread to work on
|
||||||
|
* @returns current stack pointer, or NULL if not available
|
||||||
|
*/
|
||||||
|
static inline void *thread_get_stackstart(const thread_t *thread)
|
||||||
|
{
|
||||||
|
#if defined(DEVELHELP) || defined(SCHED_TEST_STACK) \
|
||||||
|
|| defined(MODULE_MPU_STACK_GUARD)
|
||||||
|
return thread->stack_start;
|
||||||
|
#else
|
||||||
|
(void)thread;
|
||||||
|
return NULL;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get stored Stack Pointer of thread.
|
||||||
|
*
|
||||||
|
* *Only provides meaningful value if the thread is not currently running!*.
|
||||||
|
*
|
||||||
|
* @param thread thread to work on
|
||||||
|
* @returns current stack pointer
|
||||||
|
*/
|
||||||
|
static inline void *thread_get_sp(const thread_t *thread)
|
||||||
|
{
|
||||||
|
return thread->sp;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get size of a thread's stack.
|
||||||
|
*
|
||||||
|
* @param thread thread to work on
|
||||||
|
* @returns thread stack size, or 0 if not available
|
||||||
|
*/
|
||||||
|
static inline size_t thread_get_stacksize(const thread_t *thread)
|
||||||
|
{
|
||||||
|
#if defined(DEVELHELP)
|
||||||
|
return thread->stack_size;
|
||||||
|
#else
|
||||||
|
(void)thread;
|
||||||
|
return 0;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get PID of thread.
|
||||||
|
*
|
||||||
|
* This is a simple getter for thread->pid.
|
||||||
|
*
|
||||||
|
* @param thread thread to work on
|
||||||
|
* @returns thread pid
|
||||||
|
*/
|
||||||
|
static inline kernel_pid_t thread_getpid_of(const thread_t *thread)
|
||||||
|
{
|
||||||
|
return thread->pid;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get name of thread.
|
||||||
|
*
|
||||||
|
* @param thread thread to work on
|
||||||
|
* @returns thread name or NULL if not available
|
||||||
|
*/
|
||||||
|
static inline const char *thread_get_name(const thread_t *thread)
|
||||||
|
{
|
||||||
|
#if defined(CONFIG_THREAD_NAMES)
|
||||||
|
return thread->name;
|
||||||
|
#else
|
||||||
|
(void)thread;
|
||||||
|
return NULL;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
16
sys/ps/ps.c
16
sys/ps/ps.c
@ -95,9 +95,9 @@ void ps(void)
|
|||||||
const char *sname = thread_state_to_string(state); /* get state name */
|
const char *sname = thread_state_to_string(state); /* get state name */
|
||||||
const char *queued = thread_is_active(p) ? "Q" : "_"; /* get queued flag */
|
const char *queued = thread_is_active(p) ? "Q" : "_"; /* get queued flag */
|
||||||
#ifdef DEVELHELP
|
#ifdef DEVELHELP
|
||||||
int stacksz = p->stack_size; /* get stack size */
|
int stacksz = thread_get_stacksize(p); /* get stack size */
|
||||||
overall_stacksz += stacksz;
|
overall_stacksz += stacksz;
|
||||||
int stack_free = thread_measure_stack_free(p->stack_start);
|
int stack_free = thread_measure_stack_free(thread_get_stackstart(p));
|
||||||
stacksz -= stack_free;
|
stacksz -= stack_free;
|
||||||
overall_used += stacksz;
|
overall_used += stacksz;
|
||||||
#endif
|
#endif
|
||||||
@ -115,20 +115,20 @@ void ps(void)
|
|||||||
#endif
|
#endif
|
||||||
" | %-8s %.1s | %3i"
|
" | %-8s %.1s | %3i"
|
||||||
#ifdef DEVELHELP
|
#ifdef DEVELHELP
|
||||||
" | %6i (%5i) (%5i) | %10p | %10p "
|
" | %6" PRIu32 " (%5i) (%5i) | %10p | %10p "
|
||||||
#endif
|
#endif
|
||||||
#ifdef MODULE_SCHEDSTATISTICS
|
#ifdef MODULE_SCHEDSTATISTICS
|
||||||
" | %2d.%03d%% | %8u | %10"PRIu32" "
|
" | %2d.%03d%% | %8u | %10"PRIu32" "
|
||||||
#endif
|
#endif
|
||||||
"\n",
|
"\n",
|
||||||
p->pid,
|
thread_getpid_of(p),
|
||||||
#ifdef CONFIG_THREAD_NAMES
|
#ifdef CONFIG_THREAD_NAMES
|
||||||
p->name,
|
thread_get_name(p),
|
||||||
#endif
|
#endif
|
||||||
sname, queued, p->priority
|
sname, queued, thread_get_priority(p)
|
||||||
#ifdef DEVELHELP
|
#ifdef DEVELHELP
|
||||||
, p->stack_size, stacksz, stack_free,
|
, (uint32_t)thread_get_stacksize(p), stacksz, stack_free,
|
||||||
(void *)p->stack_start, (void *)p->sp
|
thread_get_stackstart(p), thread_get_sp(p)
|
||||||
#endif
|
#endif
|
||||||
#ifdef MODULE_SCHEDSTATISTICS
|
#ifdef MODULE_SCHEDSTATISTICS
|
||||||
, runtime_major, runtime_minor, switches, xtimer_usec_from_ticks(xtimer_ticks)
|
, runtime_major, runtime_minor, switches, xtimer_usec_from_ticks(xtimer_ticks)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user