Skip to content

Commit

Permalink
Improve naming of thread stacksize/priority constants
Browse files Browse the repository at this point in the history
As discussed in #2725, this commit renames a number of stacksize constants to
better convey their intended usage. In addition, constants for thread priority
are given a `THREAD_` prefix. Changes are:

* KERNEL_CONF_STACKSIZE_PRINTF renamed to THREAD_EXTRA_STACKSIZE_PRINTF
* KERNEL_CONF_STACKSIZE_DEFAULT renamed to THREAD_STACKSIZE_DEFAULT
* KERNEL_CONF_STACKSIZE_IDLE renamed to THREAD_STACKSIZE_IDLE
* KERNEL_CONF_STACKSIZE_MAIN renamed to THREAD_STACKSIZE_MAIN
* Move thread stacksizes from kernel.h to thread.h, since the prefix changed
* PRIORITY_MIN renamed to THREAD_PRIORITY_MIN
* PRIORITY_IDLE renamed to THREAD_PRIORITY_IDLE
* PRIORITY_MAIN renamed to THREAD_PRIORITY_MAIN
* Move thread priorities from kernel.h to thread.h since the prefix has changed
* MINIMUM_STACK_SIZE renamed to THREAD_STACKSIZE_MINIMUM for consistency
  • Loading branch information
x3ro committed May 20, 2015
1 parent b0e73b9 commit 426170b
Show file tree
Hide file tree
Showing 95 changed files with 638 additions and 320 deletions.
63 changes: 63 additions & 0 deletions boards/iot-lab_M3/auto_init_ng_netif/netif_board.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* Copyright (C) 2015 Freie Universität Berlin
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/

/**
* @ingroup boards_iot-lab_M3
* @{
*
* @file
* @brief Network device initialization code
*
* @author Hauke Petersen <[email protected]>
*
* @}
*/

#include <stdio.h>

#include "board.h"
#include "auto_init.h"
#include "ng_at86rf2xx.h"
#include "net/ng_nomac.h"
#include "net/ng_netbase.h"

#define ENABLE_DEBUG (0)
#include "debug.h"

/**
* @brief Define stack parameters for the MAC layer thread
* @{
*/
#define MAC_STACKSIZE (THREAD_STACKSIZE_DEFAULT)
#define MAC_PRIO (THREAD_PRIORITY_MAIN - 3)
/** @} */

/**
* @brief Device descriptor for the Atmel radio
*/
static ng_at86rf2xx_t radio;

/**
* @brief Stack for the MAC layer thread
*/
static char nomac_stack[MAC_STACKSIZE];


void auto_init_ng_netif(void)
{
/* initialize the radio */
DEBUG("Initializing AT86RF231 radio\n");
ng_at86rf2xx_init(&radio, AT86RF231_SPI, AT86RF231_SPI_CLK,
AT86RF231_CS, AT86RF231_INT,
AT86RF231_SLEEP, AT86RF231_RESET);
/* starting NOMAC */
DEBUG("Starting the MAC layer\n");
ng_nomac_init(nomac_stack, sizeof(nomac_stack), MAC_PRIO, "at86rf233",
(ng_netdev_t *)(&radio));
DEBUG("Auto init of on-board radio complete\n");
}
11 changes: 5 additions & 6 deletions boards/qemu-i386/include/cpu-conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,11 @@ extern "C" {

/* FIXME: This file is just a filler. The numbers are entirely random ... */

#define KERNEL_CONF_STACKSIZE_DEFAULT (8192)
#define KERNEL_CONF_STACKSIZE_IDLE (8192)
#define KERNEL_CONF_STACKSIZE_PRINTF (8192)
#define KERNEL_CONF_STACKSIZE_PRINTF_FLOAT (8192)

#define MINIMUM_STACK_SIZE (8192)
#define THREAD_STACKSIZE_DEFAULT (8192)
#define THREAD_STACKSIZE_IDLE (8192)
#define THREAD_EXTRA_STACKSIZE_PRINTF (8192)
#define THREAD_EXTRA_STACKSIZE_PRINTF_FLOAT (8192)
#define THREAD_STACKSIZE_MINIMUM (8192)

#define UART0_BUFSIZE (16)

Expand Down
4 changes: 2 additions & 2 deletions boards/samr21-xpro/auto_init_ng_netif/netif_board.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
* @brief Define stack parameters for the MAC layer thread
* @{
*/
#define MAC_STACKSIZE (KERNEL_CONF_STACKSIZE_DEFAULT)
#define MAC_PRIO (PRIORITY_MAIN - 3)
#define MAC_STACKSIZE (THREAD_STACKSIZE_DEFAULT)
#define MAC_PRIO (THREAD_PRIORITY_MAIN - 3)
/** @} */

/**
Expand Down
2 changes: 1 addition & 1 deletion core/include/debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ extern "C" {
#include "cpu-conf.h"
#define DEBUG_PRINT(...) \
do { \
if ((sched_active_thread == NULL) || (sched_active_thread->stack_size > KERNEL_CONF_STACKSIZE_PRINTF)) { \
if ((sched_active_thread == NULL) || (sched_active_thread->stack_size > THREAD_EXTRA_STACKSIZE_PRINTF)) { \
printf(__VA_ARGS__); \
} \
else { \
Expand Down
50 changes: 0 additions & 50 deletions core/include/kernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,57 +37,7 @@
extern "C" {
#endif

/**
* @def KERNEL_CONF_STACKSIZE_DEFAULT
* @brief A reasonable default stack size that will suffice most smaller tasks
*/
#ifndef KERNEL_CONF_STACKSIZE_DEFAULT
#error KERNEL_CONF_STACKSIZE_DEFAULT must be defined per CPU
#endif

/**
* @def KERNEL_CONF_STACKSIZE_IDLE
* @brief Size of the idle task's stack in bytes
*/
#ifndef KERNEL_CONF_STACKSIZE_IDLE
#error KERNEL_CONF_STACKSIZE_IDLE must be defined per CPU
#endif

/**
* @def KERNEL_CONF_STACKSIZE_PRINTF
* @ingroup conf
* @brief Size of the task's printf stack in bytes
*/
#ifndef KERNEL_CONF_STACKSIZE_PRINTF
#error KERNEL_CONF_STACKSIZE_PRINTF must be defined per CPU
#endif

/**
* @def KERNEL_CONF_STACKSIZE_MAIN
* @brief Size of the main task's stack in bytes
*/
#ifndef KERNEL_CONF_STACKSIZE_MAIN
#define KERNEL_CONF_STACKSIZE_MAIN (KERNEL_CONF_STACKSIZE_DEFAULT + KERNEL_CONF_STACKSIZE_PRINTF)
#endif

/* ------------------------------------------------------------------------- */
/**
* @def PRIORITY_MIN
* @brief Least priority a thread can have
*/
#define PRIORITY_MIN (SCHED_PRIO_LEVELS-1)

/**
* @def PRIORITY_IDLE
* @brief Priority of the idle thread
*/
#define PRIORITY_IDLE PRIORITY_MIN

/**
* @def PRIORITY_MAIN
* @brief Priority of the main thread
*/
#define PRIORITY_MAIN (PRIORITY_MIN - (SCHED_PRIO_LEVELS/2))

/**
* @def LPM_PREVENT_SLEEP_UART
Expand Down
57 changes: 54 additions & 3 deletions core/include/thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,64 @@
*/
#define STATUS_NOT_FOUND (-1)

/**
* @def THREAD_STACKSIZE_DEFAULT
* @brief A reasonable default stack size that will suffice most smaller tasks
*/
#ifndef THREAD_STACKSIZE_DEFAULT
#error THREAD_STACKSIZE_DEFAULT must be defined per CPU
#endif

/**
* @def THREAD_STACKSIZE_IDLE
* @brief Size of the idle task's stack in bytes
*/
#ifndef THREAD_STACKSIZE_IDLE
#error THREAD_STACKSIZE_IDLE must be defined per CPU
#endif

/**
* @def THREAD_EXTRA_STACKSIZE_PRINTF
* @ingroup conf
* @brief Size of the task's printf stack in bytes
*/
#ifndef THREAD_EXTRA_STACKSIZE_PRINTF
#error THREAD_EXTRA_STACKSIZE_PRINTF must be defined per CPU
#endif

/**
* @def THREAD_STACKSIZE_MAIN
* @brief Size of the main task's stack in bytes
*/
#ifndef THREAD_STACKSIZE_MAIN
#define THREAD_STACKSIZE_MAIN (THREAD_STACKSIZE_DEFAULT + THREAD_EXTRA_STACKSIZE_PRINTF)
#endif

/**
* @brief Minimum stack size
*/
#ifndef MINIMUM_STACK_SIZE
#define MINIMUM_STACK_SIZE (sizeof(tcb_t))
#ifndef THREAD_STACKSIZE_MINIMUM
#define THREAD_STACKSIZE_MINIMUM (sizeof(tcb_t))
#endif

/**
* @def THREAD_PRIORITY_MIN
* @brief Least priority a thread can have
*/
#define THREAD_PRIORITY_MIN (SCHED_PRIO_LEVELS-1)

/**
* @def THREAD_PRIORITY_IDLE
* @brief Priority of the idle thread
*/
#define THREAD_PRIORITY_IDLE (THREAD_PRIORITY_MIN)

/**
* @def THREAD_PRIORITY_MAIN
* @brief Priority of the main thread
*/
#define THREAD_PRIORITY_MAIN (THREAD_PRIORITY_MIN - (SCHED_PRIO_LEVELS/2))

/**
* @brief Creates a new thread
*
Expand All @@ -56,7 +107,7 @@
* A low value for *priority* number means the thread having a high priority
* with 0 being the highest possible priority.
*
* The lowest possible priority is *PRIORITY_IDLE - 1*. The value is depending
* The lowest possible priority is *THREAD_PRIORITY_IDLE - 1*. The value is depending
* on the platforms architecture, e.g. 30 in 32-bit systems, 14 in 16-bit systems.
*
*
Expand Down
12 changes: 6 additions & 6 deletions core/kernel_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ static void *idle_thread(void *arg)
const char *main_name = "main";
const char *idle_name = "idle";

static char main_stack[KERNEL_CONF_STACKSIZE_MAIN];
static char idle_stack[KERNEL_CONF_STACKSIZE_IDLE];
static char main_stack[THREAD_STACKSIZE_MAIN];
static char idle_stack[THREAD_STACKSIZE_IDLE];

void kernel_init(void)
{
Expand All @@ -86,12 +86,12 @@ void kernel_init(void)

hwtimer_init();

if (thread_create(idle_stack, sizeof(idle_stack), PRIORITY_IDLE, CREATE_WOUT_YIELD | CREATE_STACKTEST, idle_thread, NULL, idle_name) < 0) {
LOG_ERROR("kernel_init(): error creating idle task.\n");
if (thread_create(idle_stack, sizeof(idle_stack), THREAD_PRIORITY_IDLE, CREATE_WOUT_YIELD | CREATE_STACKTEST, idle_thread, NULL, idle_name) < 0) {
printf("kernel_init(): error creating idle task.\n");
}

if (thread_create(main_stack, sizeof(main_stack), PRIORITY_MAIN, CREATE_WOUT_YIELD | CREATE_STACKTEST, main_trampoline, NULL, main_name) < 0) {
LOG_ERROR("kernel_init(): error creating main task.\n");
if (thread_create(main_stack, sizeof(main_stack), THREAD_PRIORITY_MAIN, CREATE_WOUT_YIELD | CREATE_STACKTEST, main_trampoline, NULL, main_name) < 0) {
printf("kernel_init(): error creating main task.\n");
}

LOG_INFO("kernel_init(): jumping into first task...\n");
Expand Down
4 changes: 2 additions & 2 deletions core/msg.c
Original file line number Diff line number Diff line change
Expand Up @@ -351,15 +351,15 @@ static int _msg_receive(msg_t *m, int block)
*m = *sender_msg;

/* remove sender from queue */
uint16_t sender_prio = PRIORITY_IDLE;
uint16_t sender_prio = THREAD_PRIORITY_IDLE;
if (sender->status != STATUS_REPLY_BLOCKED) {
sender->wait_data = NULL;
sched_set_status(sender, STATUS_PENDING);
sender_prio = sender->priority;
}

restoreIRQ(state);
if (sender_prio < PRIORITY_IDLE) {
if (sender_prio < THREAD_PRIORITY_IDLE) {
sched_switch(sender_prio);
}
return 1;
Expand Down
8 changes: 4 additions & 4 deletions cpu/atmega2560/include/cpu-conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ extern "C" {
* size tested sucessfully even with pretty small stacks.k
* @{
*/
#define KERNEL_CONF_STACKSIZE_PRINTF (128)
#define THREAD_EXTRA_STACKSIZE_PRINTF (128)

#ifndef KERNEL_CONF_STACKSIZE_DEFAULT
#define KERNEL_CONF_STACKSIZE_DEFAULT (256)
#ifndef THREAD_STACKSIZE_DEFAULT
#define THREAD_STACKSIZE_DEFAULT (256)
#endif

#define KERNEL_CONF_STACKSIZE_IDLE (128)
#define THREAD_STACKSIZE_IDLE (128)
/** @} */

/**
Expand Down
8 changes: 4 additions & 4 deletions cpu/cc2538/include/cpu-conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ extern "C" {
* @name Kernel configuration
* @{
*/
#define KERNEL_CONF_STACKSIZE_PRINTF 1024
#define THREAD_EXTRA_STACKSIZE_PRINTF 1024

#ifndef KERNEL_CONF_STACKSIZE_DEFAULT
#define KERNEL_CONF_STACKSIZE_DEFAULT 1024
#ifndef THREAD_STACKSIZE_DEFAULT
#define THREAD_STACKSIZE_DEFAULT 1024
#endif

#define KERNEL_CONF_STACKSIZE_IDLE 512
#define THREAD_STACKSIZE_IDLE 512
/** @} */

/**
Expand Down
8 changes: 4 additions & 4 deletions cpu/k60/include/cpu-conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,13 @@ extern "C"
* TODO: Tune this
* @{
*/
#define KERNEL_CONF_STACKSIZE_PRINTF (1024)
#define THREAD_EXTRA_STACKSIZE_PRINTF (1024)

#ifndef KERNEL_CONF_STACKSIZE_DEFAULT
#define KERNEL_CONF_STACKSIZE_DEFAULT (1024)
#ifndef THREAD_STACKSIZE_DEFAULT
#define THREAD_STACKSIZE_DEFAULT (1024)
#endif

#define KERNEL_CONF_STACKSIZE_IDLE (256)
#define THREAD_STACKSIZE_IDLE (256)
/** @} */

/**
Expand Down
8 changes: 4 additions & 4 deletions cpu/kw2x/include/cpu-conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ extern "C"
*
* @{
*/
#define KERNEL_CONF_STACKSIZE_PRINTF (1024)
#define THREAD_EXTRA_STACKSIZE_PRINTF (1024)

#ifndef KERNEL_CONF_STACKSIZE_DEFAULT
#define KERNEL_CONF_STACKSIZE_DEFAULT (1024)
#ifndef THREAD_STACKSIZE_DEFAULT
#define THREAD_STACKSIZE_DEFAULT (1024)
#endif

#define KERNEL_CONF_STACKSIZE_IDLE (256)
#define THREAD_STACKSIZE_IDLE (256)
/** @} */

/**
Expand Down
8 changes: 4 additions & 4 deletions cpu/lpc1768/include/cpu-conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ extern "C" {
* TODO: measure and adjust for the Cortex-M3
* @{
*/
#define KERNEL_CONF_STACKSIZE_PRINTF (1024)
#define THREAD_EXTRA_STACKSIZE_PRINTF (1024)

#ifndef KERNEL_CONF_STACKSIZE_DEFAULT
#define KERNEL_CONF_STACKSIZE_DEFAULT (1024)
#ifndef THREAD_STACKSIZE_DEFAULT
#define THREAD_STACKSIZE_DEFAULT (1024)
#endif

#define KERNEL_CONF_STACKSIZE_IDLE (256)
#define THREAD_STACKSIZE_IDLE (256)
/** @} */

/**
Expand Down
10 changes: 5 additions & 5 deletions cpu/lpc2387/include/cpu-conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ extern "C" {
* @name Kernel configuration
* @{
*/
#define KERNEL_CONF_STACKSIZE_PRINTF_FLOAT (4096)
#define KERNEL_CONF_STACKSIZE_PRINTF (2048)
#define THREAD_EXTRA_STACKSIZE_PRINTF_FLOAT (4096)
#define THREAD_EXTRA_STACKSIZE_PRINTF (2048)

#ifndef KERNEL_CONF_STACKSIZE_DEFAULT
#define KERNEL_CONF_STACKSIZE_DEFAULT (512)
#ifndef THREAD_STACKSIZE_DEFAULT
#define THREAD_STACKSIZE_DEFAULT (512)
#endif

#define KERNEL_CONF_STACKSIZE_IDLE (160)
#define THREAD_STACKSIZE_IDLE (160)
/** @} */

/**
Expand Down
Loading

0 comments on commit 426170b

Please sign in to comment.