nuttx icon indicating copy to clipboard operation
nuttx copied to clipboard

Schedule policy for stm32f4discovery(stm32f407)

Open nopnop2002 opened this issue 1 year ago • 4 comments

I'm using Nuttx V10.2. I believe nutxx's standard scheduling policy is FIFO. However, with STM32F407, if two tasks with the same priority are started, the RR scheduling policy will be applied.

This is that logging. Two tasks with the same priority started running on 4808Tick.

task_create name:myTask1 priority:100
task_create name:myTask2 priority:100
myTask1 start PID:12 loop:50000000 wait:0 system_timer:4808
myTask2 start PID:13 loop:50000000 wait:0 system_timer:4808
nsh> ps
  PID PRI POLICY   TYPE    NPX STATE    EVENT     SIGMASK   STACK COMMAND
    0   0 FIFO     Kthread N-- Ready              00000000 001000 Idle Task
    2 100 RR       Task    --- Running            00000000 002032 init
   12 100 RR       Task    --- Ready              00000000 002008 myTask1 50000000 0
   13 100 RR       Task    --- Ready              00000000 002008 myTask2 50000000 0
nsh> myTask1 end PID:12 system_timer:5336
myTask2 end PID:13 system_timer:5344

nopnop2002 avatar Jan 05 '24 07:01 nopnop2002

@nopnop2002 by default RR is selected to this board:

CONFIG_RR_INTERVAL=200

If you want to disable it set the value to 0:

CONFIG_RR_INTERVAL=0

Please consider helping, adding the documentation to make the scheduling policy FIFO vs RR clear.

Could you please close this issue? (since it is a configuration detail)

acassis avatar Jan 05 '24 16:01 acassis

@xiaoxiang781216 @patacongo @pkarashchenko I think it the default config is prone to error. It should be better to have CONFIG_SCHED_FIFO, CONFIG_SCHED_RR, CONFIG_SCHED_SPORADIC, etc

What do you think?

acassis avatar Jan 05 '24 16:01 acassis

@acassis

Thanks for your comment.

I changed the CONFIG_RR_INTERVAL value to 0 and built again.

CONFIG_RR_INTERVAL=0

POLICY has changed to FIFO.

nsh> ps
  PID GROUP PRI POLICY   TYPE    NPX STATE    EVENT     SIGMASK   STACK COMMAND
    0     0   0 FIFO     Kthread N-- Ready              00000000 001000 Idle Task
    2     2 100 FIFO     Task    --- Running            00000000 002000 nsh_main

It is now correctly scheduled as FIFO.

nsh> task_test test2
task_create name:myTask1 priority:100
task_create name:myTask2 priority:100
myTask1 start PID:5 loop:50000000 wait:0 system_timer:887
myTask1 end PID:5 system_timer:1156
myTask2 start PID:6 loop:50000000 wait:0 system_timer:1156
myTask2 end PID:6 system_timer:1425
nsh>

by default RR is selected to this board:

This is not mentioned in any documentation.

https://nuttx.apache.org/docs/latest/reference/user/02_task_scheduling.html

By default, NuttX performs strict priority scheduling: Tasks of higher priority have exclusive access to the CPU until they become blocked. 
At that time, the CPU is available to tasks of lower priority. 
Tasks of equal priority are scheduled FIFO.

nopnop2002 avatar Jan 05 '24 23:01 nopnop2002

@nopnop2002 thank you for pointing it, so our documentation is incorrect. If you can help, please modify the right documentation file at nuttx/Documentation/ and submit a PR to fix it.

BTW, I will reopen it, because setting RR_INTERVAL to 0 fix the issue, but the issue is deeper (documentation, better Kconfig symbol usage, etc)

acassis avatar Jan 06 '24 23:01 acassis