Browse Source

core: move optional tcb members to DEVELHELP

dev/timer
Oleg Hahm 8 years ago
parent
commit
9a61d8cf1c
  1. 5
      core/include/tcb.h
  2. 20
      core/include/thread.h
  3. 9
      core/thread.c
  4. 4
      cpu/native/irq_cpu.c
  5. 4
      examples/riot_and_cpp/main.cpp
  6. 17
      sys/ps/ps.c
  7. 4
      tests/posix_semaphore/main.c
  8. 2
      tests/pthread_rwlock/main.c
  9. 9
      tests/queue_fairness/main.c
  10. 4
      tests/sizeof_tcb/main.c
  11. 14
      tests/thread_msg_seq/main.c

5
core/include/tcb.h

@ -74,10 +74,11 @@ typedef struct tcb_t {
cib_t msg_queue; /**< message queue */
msg_t *msg_array; /**< memory holding messages */
const char *name; /**< thread's name */
#if defined DEVELHELP || defined(SCHED_TEST_STACK)
char *stack_start; /**< thread's stack start address */
#endif
#ifdef DEVELHELP
const char *name; /**< thread's name */
int stack_size; /**< thread's stack size */
#endif
} tcb_t;

20
core/include/thread.h

@ -106,16 +106,6 @@ volatile tcb_t *thread_get(kernel_pid_t pid);
*/
int thread_getstatus(kernel_pid_t pid);
/**
* @brief Returns the name of a process
*
* @param[in] pid the PID of the thread to get the name from
*
* @return the threads name
* @return `NULL` if pid is unknown
*/
const char *thread_getname(kernel_pid_t pid);
/**
* @brief Puts the current thread into sleep mode. Has to be woken up externally.
*/
@ -156,6 +146,16 @@ static inline kernel_pid_t thread_getpid(void)
}
#ifdef DEVELHELP
/**
* @brief Returns the name of a process
*
* @param[in] pid the PID of the thread to get the name from
*
* @return the threads name
* @return `NULL` if pid is unknown
*/
const char *thread_getname(kernel_pid_t pid);
/**
* @brief Measures the stack usage of a stack
*

9
core/thread.c

@ -46,11 +46,13 @@ int thread_getstatus(kernel_pid_t pid)
return t ? t->status : STATUS_NOT_FOUND;
}
#ifdef DEVELHELP
const char *thread_getname(kernel_pid_t pid)
{
volatile tcb_t *t = thread_get(pid);
return t ? t->name : NULL;
}
#endif
void thread_sleep(void)
{
@ -113,6 +115,8 @@ kernel_pid_t thread_create(char *stack, int stacksize, char priority, int flags,
#ifdef DEVELHELP
int total_stacksize = stacksize;
#else
(void) name;
#endif
/* align the stack on a 16/32bit boundary */
@ -174,10 +178,11 @@ kernel_pid_t thread_create(char *stack, int stacksize, char priority, int flags,
cb->pid = pid;
cb->sp = thread_stack_init(function, arg, stack, stacksize);
cb->stack_start = stack;
#ifdef DEVELHELP
cb->stack_start = stack;
cb->stack_size = total_stacksize;
cb->name = name;
#endif
cb->priority = priority;
@ -186,8 +191,6 @@ kernel_pid_t thread_create(char *stack, int stacksize, char priority, int flags,
cb->rq_entry.next = NULL;
cb->rq_entry.prev = NULL;
cb->name = name;
cb->wait_data = NULL;
cb->msg_waiters.first = NULL;

4
cpu/native/irq_cpu.c

@ -84,13 +84,14 @@ void print_thread_sigmask(ucontext_t *cp)
}
}
#ifdef DEVELHELP
void print_sigmasks(void)
{
ucontext_t *p;
//tcb_t *cb = NULL;
for (int i = 0; i < MAXTHREADS; i++) {
if (sched_threads[i] != NULL) {
ucontext_t *p;
printf("%s:\n", sched_threads[i]->name);
//print_thread_sigmask(sched_threads[i]->sp);
p = (ucontext_t *)(sched_threads[i]->stack_start);
@ -99,6 +100,7 @@ void print_sigmasks(void)
}
}
}
#endif
void native_print_signals(void)
{

4
examples/riot_and_cpp/main.cpp

@ -51,7 +51,7 @@ int main()
/* create thread A */
thread_create(threadA_stack, sizeof(threadA_stack), 0, CREATE_WOUT_YIELD, threadA_func, NULL, "thread A");
printf("******** Hello, you're in thread %s ********\n", thread_getname(thread_getpid()));
printf("******** Hello, you're in thread #%" PRIkernel_pid " ********\n", sched_active_pid);
printf("We'll test C++ class and methods here!\n");
cpp_class cpp_obj;
@ -86,7 +86,7 @@ void *threadA_func(void *)
int day = 13, month = 6, year = 2014;
int ret_day;
printf("\n******** Hello, now you're in %s ********\n", thread_getname(thread_getpid()));
printf("******** Hello, you're in thread #%" PRIkernel_pid " ********\n", sched_active_pid);
printf("We'll test some C functions here!\n");
printf("\n-= hello function =-\n");

17
sys/ps/ps.c

@ -73,20 +73,23 @@ void thread_print_all(void)
double runtime_ticks = sched_pidlist[i].runtime_ticks / (double) hwtimer_now() * 100;
int switches = sched_pidlist[i].schedules;
#endif
printf("\t%3u | %-21s| %-8s %.1s | %3i | "
printf("\t%3u | "
#ifdef DEVELHELP
"%5i (%5i) "
"%-21s| %5i (%5i) "
#endif
"%p"
"%-8s %.1s | %3i"
#if SCHEDSTATISTICS
" | %6.3f%% | %8d"
" | %p | %6.3f%% | %8d"
#endif
"\n",
p->pid, p->name, sname, queued, p->priority,
p->pid,
#ifdef DEVELHELP
p->stack_size, stacksz,
p->name,
#endif
sname, queued, p->priority
#ifdef DEVELHELP
, p->stack_size, stacksz, p->stack_start
#endif
p->stack_start
#if SCHEDSTATISTICS
, runtime_ticks, switches
#endif

4
tests/posix_semaphore/main.c

@ -123,7 +123,11 @@ static void *priority_sema_thread(void *arg)
{
(void) arg;
sem_wait(&s);
#ifdef DEVELHELP
printf("Thread '%s' woke up.\n", thread_getname(thread_getpid()));
#else
printf("Thread with PID '%" PRIkernel_pid "' woke up.\n", thread_getpid());
#endif
return NULL;
}

2
tests/pthread_rwlock/main.c

@ -54,7 +54,7 @@ static pthread_rwlock_t rwlock;
static volatile unsigned counter;
#define PRINTF(FMT, ...) \
printf("%c%" PRIkernel_pid " (prio=%u): " FMT "\n", sched_active_thread->name[0], sched_active_pid, sched_active_thread->priority, __VA_ARGS__)
printf("%c%" PRIkernel_pid " (prio=%u): " FMT "\n", __func__[0], sched_active_pid, sched_active_thread->priority, __VA_ARGS__)
static void do_sleep(int factor)
{

9
tests/queue_fairness/main.c

@ -35,17 +35,16 @@ static kernel_pid_t parent_pid = KERNEL_PID_UNDEF;
static void *child_fun(void *arg)
{
(void) arg;
printf("Start of %s.\n", sched_active_thread->name);
printf("Start of %s.\n", (char*) arg);
for (int i = 0; i < NUM_ITERATIONS; ++i) {
msg_t m;
m.type = i + 1;
m.content.ptr = (void *) sched_active_thread->name;
m.content.ptr = (char*) arg;
msg_send(&m, parent_pid);
}
printf("End of %s.\n", sched_active_thread->name);
printf("End of %s.\n", (char*) arg);
return NULL;
}
@ -61,7 +60,7 @@ int main(void)
PRIORITY_MAIN + 1,
CREATE_WOUT_YIELD | CREATE_STACKTEST,
child_fun,
NULL,
names[i],
names[i]);
}

4
tests/sizeof_tcb/main.c

@ -40,8 +40,12 @@ int main(void)
P(msg_waiters);
P(msg_queue);
P(msg_array);
#ifdef DEVELHELP
P(name);
#endif
#if defined(DEVELHELP) || defined(SCHED_TEST_STACK)
P(stack_start);
#endif
#ifdef DEVELHELP
P(stack_size);

14
tests/thread_msg_seq/main.c

@ -34,18 +34,16 @@ kernel_pid_t p_main = KERNEL_PID_UNDEF, p1 = KERNEL_PID_UNDEF,
void *sub_thread(void *arg)
{
(void) arg;
kernel_pid_t pid = thread_getpid();
printf("THREAD %s (pid:%" PRIkernel_pid ") start\n", thread_getname(pid), pid);
printf("THREAD %s (pid:%" PRIkernel_pid ") start\n", (char*) arg, pid);
msg_t msg;
msg.content.ptr = (char*)thread_getname(pid);
msg.content.ptr = (char*) arg;
msg_send(&msg, p_main);
printf("THREAD %s (pid:%" PRIkernel_pid ") end.\n", thread_getname(pid), pid);
printf("THREAD %s (pid:%" PRIkernel_pid ") end.\n", (char*) arg, pid);
return NULL;
}
@ -59,13 +57,13 @@ int main(void)
p1 = thread_create(t1_stack, sizeof(t1_stack), PRIORITY_MAIN - 1,
CREATE_WOUT_YIELD | CREATE_STACKTEST,
sub_thread, NULL, "nr1");
sub_thread, "nr1", "nr1");
p2 = thread_create(t2_stack, sizeof(t2_stack), PRIORITY_MAIN - 1,
CREATE_WOUT_YIELD | CREATE_STACKTEST,
sub_thread, NULL, "nr2");
sub_thread, "nr2", "nr2");
p3 = thread_create(t3_stack, sizeof(t3_stack), PRIORITY_MAIN - 1,
CREATE_WOUT_YIELD | CREATE_STACKTEST,
sub_thread, NULL, "nr3");
sub_thread, "nr3", "nr3");
puts("THREADS CREATED\n");
for(int i = 0; i < 3; i++) {

Loading…
Cancel
Save