Merge pull request #1293 from Kijewski/issue-1287

core: only store the stack size for DEVELHELP (implementation)
dev/timer
René Kijewski 9 years ago
commit a5fe9078c8

@ -72,7 +72,10 @@ typedef struct tcb_t {
const char *name; /**< thread's name */
char *stack_start; /**< thread's stack start address */
#ifdef DEVELHELP
int stack_size; /**< thread's stack size */
#endif
} tcb_t;
#endif /* TCB_H_ */

@ -130,6 +130,7 @@ int thread_wakeup(kernel_pid_t pid);
*/
kernel_pid_t thread_getpid(void);
#ifdef DEVELHELP
/**
* @brief Measures the stack usage of a stack
*
@ -140,6 +141,7 @@ kernel_pid_t thread_getpid(void);
* @return the amount of unused space of the thread's stack
*/
int thread_measure_stack_free(char *stack);
#endif
/* @} */
#endif /* __THREAD_H */

@ -92,6 +92,7 @@ int thread_wakeup(kernel_pid_t pid)
}
}
#ifdef DEVELHELP
int thread_measure_stack_free(char *stack)
{
unsigned int *stackp = (unsigned int *)stack;
@ -105,11 +106,14 @@ int thread_measure_stack_free(char *stack)
int space_free = (unsigned int)stackp - (unsigned int)stack;
return space_free;
}
#endif
kernel_pid_t thread_create(char *stack, int stacksize, char priority, int flags, void *(*function)(void *arg), void *arg, const char *name)
{
/* allocate our thread control block at the top of our stackspace */
#ifdef DEVELHELP
int total_stacksize = stacksize;
#endif
stacksize -= sizeof(tcb_t);
/* align tcb address on 32bit boundary */
@ -131,6 +135,7 @@ kernel_pid_t thread_create(char *stack, int stacksize, char priority, int flags,
return -EINVAL;
}
#ifdef DEVELHELP
if (flags & CREATE_STACKTEST) {
/* assign each int of the stack the value of it's address */
unsigned int *stackmax = (unsigned int *)((char *)stack + stacksize);
@ -145,6 +150,7 @@ kernel_pid_t thread_create(char *stack, int stacksize, char priority, int flags,
/* create stack guard */
*stack = (unsigned int)stack;
}
#endif
if (!inISR()) {
dINT();
@ -174,7 +180,10 @@ kernel_pid_t thread_create(char *stack, int stacksize, char priority, int flags,
cb->sp = thread_stack_init(function, arg, stack, stacksize);
cb->stack_start = stack;
#ifdef DEVELHELP
cb->stack_size = total_stacksize;
#endif
cb->priority = priority;
cb->status = 0;

@ -41,9 +41,15 @@ void thread_print_all(void)
{
const char queued_name[] = {'_', 'Q'};
int i;
int overall_stacksz = 0;
#ifdef DEVELHELP
int overall_stacksz = 0, overall_used = 0;
#endif
printf("\tpid | %-21s| %-9sQ | pri | stack ( used) location"
printf("\tpid | %-21s| %-9sQ | pri | "
#ifdef DEVELHELP
"stack ( used) "
#endif
"location"
#if SCHEDSTATISTICS
" | runtime | switches"
#endif
@ -57,19 +63,30 @@ void thread_print_all(void)
int state = p->status; /* copy state */
const char *sname = state_names[state]; /* get state name */
const char *queued = &queued_name[(int)(state >= STATUS_ON_RUNQUEUE)]; /* get queued flag */
#ifdef DEVELHELP
int stacksz = p->stack_size; /* get stack size */
overall_stacksz += stacksz;
stacksz -= thread_measure_stack_free(p->stack_start);
overall_used += stacksz;
#endif
#if SCHEDSTATISTICS
int runtime_ticks = sched_pidlist[i].runtime_ticks / (hwtimer_now()/1000UL + 1);
double runtime_ticks = sched_pidlist[i].runtime_ticks / (double) hwtimer_now() * 100;
int switches = sched_pidlist[i].schedules;
#endif
overall_stacksz += stacksz;
stacksz -= thread_measure_stack_free(p->stack_start);
printf("\t%3" PRIkernel_pid " | %-21s| %-8s %.1s | %3i | %5i (%5i) %p"
printf("\t%3u | %-21s| %-8s %.1s | %3i | "
#ifdef DEVELHELP
"%5i (%5i) "
#endif
"%p"
#if SCHEDSTATISTICS
" | %4d/1k | %8d"
" | %6.3f%% | %8d"
#endif
"\n",
p->pid, p->name, sname, queued, p->priority, p->stack_size, stacksz, p->stack_start
p->pid, p->name, sname, queued, p->priority,
#ifdef DEVELHELP
p->stack_size, stacksz,
#endif
p->stack_start
#if SCHEDSTATISTICS
, runtime_ticks, switches
#endif
@ -77,5 +94,8 @@ void thread_print_all(void)
}
}
printf("\t%5s %-21s|%13s%6s %5i\n", "|", "SUM", "|", "|", overall_stacksz);
#ifdef DEVELHELP
printf("\t%5s %-21s|%13s%6s %5i (%5i)\n", "|", "SUM", "|", "|",
overall_stacksz, overall_used);
#endif
}

Loading…
Cancel
Save