Re: Task with statically allocated stack
On Sat, Feb 6, 2021 at 7:38 AM Gregory Nutt wrote: > > > I am using NuttX-v10.0.1. > > This is fixed in 625eef20f00fbe9bdb4995ad9dfb24b71227e954, which came at > a > > later time. > > Hmm.. I guess I still don't understand the failure. That change was: > > #ifdef CONFIG_STACK_COLORATION > - if (tcb->pid != 0) > -{ > - memset(tcb->stack_alloc_ptr, 0xaa, stack_size); > -} > + memset(tcb->stack_alloc_ptr, 0xaa, stack_size); > #endif > > pid == 0 is the startup, IDLE thread. That is not the thread that you > are creating. So there is more involved. > > It isn't a right to place to check pid == 0 here, because sched set pid to the real value after arm_usestack return. PR has more info: https://github.com/apache/incubator-nuttx/pull/2077 > > I just tried master, which brought the expected results. > > Well that is really all that is important, > > >
Re: Task with statically allocated stack
I am using NuttX-v10.0.1. This is fixed in 625eef20f00fbe9bdb4995ad9dfb24b71227e954, which came at a later time. Hmm.. I guess I still don't understand the failure. That change was: #ifdef CONFIG_STACK_COLORATION - if (tcb->pid != 0) - { - memset(tcb->stack_alloc_ptr, 0xaa, stack_size); - } + memset(tcb->stack_alloc_ptr, 0xaa, stack_size); #endif pid == 0 is the startup, IDLE thread. That is not the thread that you are creating. So there is more involved. I just tried master, which brought the expected results. Well that is really all that is important,
Re: Task with statically allocated stack
Well.. it's not strange at all :) I am using NuttX-v10.0.1. This is fixed in 625eef20f00fbe9bdb4995ad9dfb24b71227e954, which came at a later time. I just tried master, which brought the expected results. Thank you. Στις Σάβ, 6 Φεβ 2021 στις 5:27 μ.μ., ο/η Gregory Nutt έγραψε: > On 2/6/2021 9:13 AM, Fotis Panagiotopoulos wrote: > > Indeed I was expecting arm_usestack() to do the colorization, but > > apparently it doesn't. > > That is what is confusing because it does do the coloration: > > https://github.com/apache/incubator-nuttx/blob/master/arch/arm/src/common/arm_usestack.c#L153 > > >
Re: Task with statically allocated stack
On 2/6/2021 9:13 AM, Fotis Panagiotopoulos wrote: Indeed I was expecting arm_usestack() to do the colorization, but apparently it doesn't. That is what is confusing because it does do the coloration: https://github.com/apache/incubator-nuttx/blob/master/arch/arm/src/common/arm_usestack.c#L153
Re: Task with statically allocated stack
And the reason arm_usestack() fails to color the stack is because the following check fails: if (tcb->pid != 0) During the task initialization, pid is still 0 so stack is not colored. Στις Σάβ, 6 Φεβ 2021 στις 5:13 μ.μ., ο/η Fotis Panagiotopoulos < f.j.pa...@gmail.com> έγραψε: > Indeed I was expecting arm_usestack() to do the colorization, but > apparently it doesn't. > > I cannot have my application code to colorize the stack, as a call to > arm_stack_color() is needed. This is not exposed to the application as far > as i can tell. > > > Also Assuming ARM it has to be 8 byte aligned. So you need attributes on > > your variable called stack to set the alignment. > Indeed I have actually aligned the stack, but didn't include it in the > example code. > > > Στις Σάβ, 6 Φεβ 2021 στις 4:49 μ.μ., ο/η David Sidrane < > david.sidr...@nscdg.com> έγραψε: > >> You have to init the memory used for the stack: >> >> Have a look in the normal tasking init , and you will see the call out to >> init the stack, that you neeed to call. >> >> Also Assuming ARM it has to be 8 byte aligned. So you need attributes on >> your variable called stack to set the alignment. >> >> David >> -Original Message- >> From: Fotis Panagiotopoulos [mailto:f.j.pa...@gmail.com] >> Sent: Saturday, February 06, 2021 6:08 AM >> To: dev@nuttx.apache.org >> Subject: Task with statically allocated stack >> >> Hi, >> >> I am trying to create a new task using a statically allocated stack. >> >> Here is my code: >> >> static struct task_tcb_s tcb; >> static uint8_t stack[CONFIG_NETWORK_THREAD_STACKSIZE] >> >> void start_my_thread() >> { >> memset(, 0, sizeof(struct task_tcb_s)); >> tcb.cmn.flags = TCB_FLAG_TTYPE_TASK; >> >> int ret = nxtask_init(, "Network", >> CONFIG_NETWORK_THREAD_PRIORITY, >> stack, CONFIG_NETWORK_THREAD_STACKSIZE, network_th, NULL); >> if (ret < 0) >> { >> //error handling... >> } >> >> nxtask_activate(); >> } >> >> >> This new thread seems to be working OK (I haven't done any extensive >> testing yet), but running ps in nsh yields: >> >> 5 80 FIFO Task--- Ready 008156 008156 >> 100.0%! Network >> >> The stack is always reported as 100% full. I tried increasing it to >> excessive numbers but it still. >> I believe that I have configured something wrong? Or this is not the >> correct way to init a task with a static stack? >> >
Re: Task with statically allocated stack
Indeed I was expecting arm_usestack() to do the colorization, but apparently it doesn't. I cannot have my application code to colorize the stack, as a call to arm_stack_color() is needed. This is not exposed to the application as far as i can tell. > Also Assuming ARM it has to be 8 byte aligned. So you need attributes on > your variable called stack to set the alignment. Indeed I have actually aligned the stack, but didn't include it in the example code. Στις Σάβ, 6 Φεβ 2021 στις 4:49 μ.μ., ο/η David Sidrane < david.sidr...@nscdg.com> έγραψε: > You have to init the memory used for the stack: > > Have a look in the normal tasking init , and you will see the call out to > init the stack, that you neeed to call. > > Also Assuming ARM it has to be 8 byte aligned. So you need attributes on > your variable called stack to set the alignment. > > David > -Original Message- > From: Fotis Panagiotopoulos [mailto:f.j.pa...@gmail.com] > Sent: Saturday, February 06, 2021 6:08 AM > To: dev@nuttx.apache.org > Subject: Task with statically allocated stack > > Hi, > > I am trying to create a new task using a statically allocated stack. > > Here is my code: > > static struct task_tcb_s tcb; > static uint8_t stack[CONFIG_NETWORK_THREAD_STACKSIZE] > > void start_my_thread() > { > memset(, 0, sizeof(struct task_tcb_s)); > tcb.cmn.flags = TCB_FLAG_TTYPE_TASK; > > int ret = nxtask_init(, "Network", CONFIG_NETWORK_THREAD_PRIORITY, > stack, CONFIG_NETWORK_THREAD_STACKSIZE, network_th, NULL); > if (ret < 0) > { > //error handling... > } > > nxtask_activate(); > } > > > This new thread seems to be working OK (I haven't done any extensive > testing yet), but running ps in nsh yields: > > 5 80 FIFO Task--- Ready 008156 008156 > 100.0%! Network > > The stack is always reported as 100% full. I tried increasing it to > excessive numbers but it still. > I believe that I have configured something wrong? Or this is not the > correct way to init a task with a static stack? >
Re: Task with statically allocated stack
You have to init the memory used for the stack: Have a look in the normal tasking init , and you will see the call out to init the stack, that you neeed to call. arm_usestack() should be called in this case and won't that initialize (colorize) the stack?
RE: Task with statically allocated stack
You have to init the memory used for the stack: Have a look in the normal tasking init , and you will see the call out to init the stack, that you neeed to call. Also Assuming ARM it has to be 8 byte aligned. So you need attributes on your variable called stack to set the alignment. David -Original Message- From: Fotis Panagiotopoulos [mailto:f.j.pa...@gmail.com] Sent: Saturday, February 06, 2021 6:08 AM To: dev@nuttx.apache.org Subject: Task with statically allocated stack Hi, I am trying to create a new task using a statically allocated stack. Here is my code: static struct task_tcb_s tcb; static uint8_t stack[CONFIG_NETWORK_THREAD_STACKSIZE] void start_my_thread() { memset(, 0, sizeof(struct task_tcb_s)); tcb.cmn.flags = TCB_FLAG_TTYPE_TASK; int ret = nxtask_init(, "Network", CONFIG_NETWORK_THREAD_PRIORITY, stack, CONFIG_NETWORK_THREAD_STACKSIZE, network_th, NULL); if (ret < 0) { //error handling... } nxtask_activate(); } This new thread seems to be working OK (I haven't done any extensive testing yet), but running ps in nsh yields: 5 80 FIFO Task--- Ready 008156 008156 100.0%! Network The stack is always reported as 100% full. I tried increasing it to excessive numbers but it still. I believe that I have configured something wrong? Or this is not the correct way to init a task with a static stack?