From: bernie Date: Sat, 17 Nov 2007 15:31:03 +0000 (+0000) Subject: Compute the CONFIG_PROC_DEFSTACKSIZE constant dynamically X-Git-Tag: 1.0.0~240 X-Git-Url: https://codewiz.org/gitweb?a=commitdiff_plain;h=a38f52e713ae8e7c6acdd0062ac8fb4e3e59186a;p=bertos.git Compute the CONFIG_PROC_DEFSTACKSIZE constant dynamically Also rename CONFIG_KERN_DEFSTACKSIZE to CONFIG_PROC_DEFSTACKSIZE git-svn-id: https://src.develer.com/svnoss/bertos/trunk@1002 38d2e660-2303-0410-9eaa-f027e97ec537 --- diff --git a/config_kern.h b/config_kern.h index e5cc71cb..1edbabe9 100644 --- a/config_kern.h +++ b/config_kern.h @@ -97,11 +97,36 @@ #define CONFIG_KERN_QUANTUM 50 /**< Time sharing quantum in timer ticks. */ #if (ARCH & ARCH_EMUL) - #define CONFIG_KERN_DEFSTACKSIZE 65536 + /* We need a large stack because system libraries are bloated */ + #define CONFIG_PROC_DEFSTACKSIZE 65536 #else - #define CONFIG_KERN_DEFSTACKSIZE 1024 /**< Default stack size for each thread. */ + /** + * Default stack size for each thread, in bytes. + * + * The goal here is to allow a minimal task to save all of its + * registers twice, plus push a maximum of 32 variables on the + * stack. + * + * The actual size computed by the default formula is: + * AVR: 102 + * i386: 156 + * ARM: 164 + * x86_64: 184 + * + * Note that on most 16bit architectures, interrupts will also + * run on the stack of the currently running process. Nested + * interrupts will greatly increases the amount of stack space + * required per process. Use irqmanager to minimize stack + * usage. + */ + #define CONFIG_PROC_DEFSTACKSIZE \ + (CPU_SAVED_REGS_CNT * 2 * sizeof(cpu_stack_t) \ + + 32 * sizeof(int)) #endif +/* OBSOLETE */ +#define CONFIG_KERN_DEFSTACKSIZE CONFIG_PROC_DEFSTACKSIZE + /* Memory fill codes to help debugging */ #if CONFIG_KERN_MONITOR #define CONFIG_KERN_STACKFILLCODE 0xA5A5 diff --git a/kern/proc.c b/kern/proc.c index fc3bfe81..f86e1ad9 100644 --- a/kern/proc.c +++ b/kern/proc.c @@ -149,14 +149,14 @@ struct Process *proc_new_with_name(UNUSED(const char *, name), void (*entry)(voi /* Ignore stack provided by caller and use the large enough default instead. */ stack_base = (cpustack_t *)LIST_HEAD(&StackFreeList); REMOVE(LIST_HEAD(&StackFreeList)); - stacksize = CONFIG_KERN_DEFSTACKSIZE; + stacksize = CONFIG_PROC_DEFSTACKSIZE; #elif CONFIG_KERN_HEAP /* Did the caller provide a stack for us? */ if (!stack_base) { /* Did the caller specify the desired stack size? */ if (!stacksize) - stacksize = CONFIG_KERN_DEFSTACKSIZE + sizeof(Process); + stacksize = CONFIG_PROC_DEFSTACKSIZE + sizeof(Process); /* Allocate stack dinamically */ if (!(stack_base = heap_alloc(stacksize))) @@ -328,7 +328,7 @@ void proc_exit(void) #warning This is wrong /* Reinsert process stack in free list */ ADDHEAD(&StackFreeList, (Node *)(CurrentProcess->stack - - (CONFIG_KERN_DEFSTACKSIZE / sizeof(cpustack_t)))); + - (CONFIG_PROC_DEFSTACKSIZE / sizeof(cpustack_t)))); /* * NOTE: At this point the first two words of what used diff --git a/kern/proc_test.c b/kern/proc_test.c index b88d215c..4c2f3126 100644 --- a/kern/proc_test.c +++ b/kern/proc_test.c @@ -28,8 +28,8 @@ static void NORETURN proc_test_thread2(void) } } -static cpustack_t proc_test_stack1[CONFIG_KERN_DEFSTACKSIZE/sizeof(cpustack_t)]; -static cpustack_t proc_test_stack2[CONFIG_KERN_DEFSTACKSIZE/sizeof(cpustack_t)]; +static cpustack_t proc_test_stack1[CONFIG_PROC_DEFSTACKSIZE / sizeof(cpustack_t)]; +static cpustack_t proc_test_stack2[CONFIG_PROC_DEFSTACKSIZE / sizeof(cpustack_t)]; /** * Proc scheduling test