You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by GitBox <gi...@apache.org> on 2020/08/09 06:09:24 UTC

[GitHub] [incubator-nuttx] sebastianene07 edited a comment on pull request #1009: arch/sim: Add support for preemptive scheduling in the simulator build

sebastianene07 edited a comment on pull request #1009:
URL: https://github.com/apache/incubator-nuttx/pull/1009#issuecomment-671011407


   > > > Yes, sigsetjmp/siglongjmp can't be used cross the thread. As you and @patacongo investigate ucontext support on all host which we care about, so I am thinking to implement the preemption by ucontext. But even we use ucontext API, the current implementation may still hang in SMP mode.
   > > 
   > > 
   > > > Anyway, I refine your patch more clean(only irq part), here:
   > > > https://github.com/xiaoxiang781216/incubator-nuttx/commits/preempt
   > > > We can try switch to ucontext API and see whether SMP can work correctly. If not, the context switch logic may have to redesign like other real hardware platform.
   > > 
   > > 
   > > Thanks for looking on it & cleaning it up ! The current PR solves the problem with the 'fake interrupts' generated from idle task and doesn't affect other configurations if the `SIM_PREEMPTIBLE` config is off. Adding back the `ucontext API ` involves more changes like:
   > > 
   > > 1. modify the way arguments are passed in a new task (we need to call `makecontext` function and provide the task arguments. I saw `up_initial_state` is called before `nxtask_setup_stackargs` so we don't have the arguments in the TCB to be able to call `makecontext` from there.)
   > > 2. Adjusting the stack size for tasks (for example on OSX the stack needs to be ~128K)
   > > 
   > > These changes are not present in my initial version of the patch and I think is better to have a separate PR for this as it will involve some big changes and it will be an improvement of my current work. What do you think ?
   > 
   > Since sigsetjmp/siglongjmp can't work with SMP, we have to use ucontext API anyway. If we implement two context switch solution, this will make the code logic much complex but without benefit. I prefer to provide a solution work in all configuration.
   
   I implemented a solution with `ucontext` here : https://github.com/sebastianene07/incubator-nuttx/tree/sene/simulator_support_preemptive_scheduling_with_ucontext but it needs some cleanup. With this solution I was able to run the `sim:ostest` config with `SMP` option on and `SIM_PREEMPTIBLE`.
   Some notes on this implementation:
   - I implemented the handler that verifies if we are running in interrupt context by creating an alternative stack for the signals
   - for all the tasks in `up_initial_state` I used stack memory allocated from the host heap to prevent re-adjusting of all the stacks
    
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org