JanStaschulat edited a comment on issue #2935: URL: https://github.com/apache/incubator-nuttx/issues/2935#issuecomment-788032529
Thanks for your quick feedback. I ran a couple of experiments with this [test program](https://github.com/micro-ROS/nuttx_apps/blob/feature/foxy_rbs_one_sporadic_thread/examples/uros_rbs/main_rbs.c) Some links to the source code: - creation of sporadic thread 1 [here](https://github.com/micro-ROS/nuttx_apps/blob/a60f50b74ccc134b11ad4eecae2b93d78a031d46/examples/uros_rbs/main_rbs.c#L322) - creation of sporadic thread 2 [here](https://github.com/micro-ROS/nuttx_apps/blob/a60f50b74ccc134b11ad4eecae2b93d78a031d46/examples/uros_rbs/main_rbs.c#L355) - creating of fifo thread [here](https://github.com/micro-ROS/nuttx_apps/blob/a60f50b74ccc134b11ad4eecae2b93d78a031d46/examples/uros_rbs/main_rbs.c#L379) - thread 1 worker function [here](https://github.com/micro-ROS/nuttx_apps/blob/a60f50b74ccc134b11ad4eecae2b93d78a031d46/examples/uros_rbs/main_rbs.c#L149) - main thread waits for 10 seconds [here](https://github.com/micro-ROS/nuttx_apps/blob/a60f50b74ccc134b11ad4eecae2b93d78a031d46/examples/uros_rbs/main_rbs.c#L417) The results show, that NuttX does not schedule two sporadic threads according to the specified budgets: - I varied the budget of tread one from 0% to 100% and kept the budget of the sporadic thread two at 30% - I varied the budget of tread two from 0% to 100% and kept the budget of the sporadic thread one at 30% - same priorities for both sporadic threads ``` Experimental Results: Setup: config: thread 1: - SCHED_SPORADIC, - prio high 180, prio low 20, - budget 10ms, period 100ms - max replenishments = 100 thread 2: - FIFO-thread, - prio: 120 thread 3: - SCHED_SPORADIC, - prio high 179, prio low 19, - budget 30ms, period 100ms - max replenishments = 100 - Hardware: - Olimex board (STM32), - NuttX OS Experiment: - callback function in each thread has a busy_loop of 1ms and increments a counter - experiment runs for 10 seconds - at the end the counter values of all threads are reported, e.g. the number of milliseconds the thread could execute in interval of 10 seconds (total 10000 milliseconds) Exp 1: (one sporadic thread and FIFO thread) configuration with - thread 1: sporadic thread with budget = x ms and period=100ms - thread 2: low-prio FIFO thread config result result sporadic 1 sporadic 1 fifo budget(ms) (ms) (ms) --------------------------------- 0 96 9815 10 1074 8837 20 2043 7868 30 3014 6896 40 3985 5925 50 4956 4953 60 5920 3990 70 6899 3010 80 7870 2039 90 8804 1105 100 9910 0 Exp 2 (two sporadic threads and FIFO thread) Keep sporadic thread 2 with 30/100ms budget/period, vary budget of thread 1 from 0 - 100ms configuration with - thread 1: sporadic thread with budget = x ms and period=100ms, prio see above - thread 3: sporadic thread with budget = 30 ms and period=100ms, prio see above - thread 2: low-prio FIFO thread, prio see above config result result result sporadic 1 sporadic 1 sporadic 2 fifo budget(ms) (ms) (ms) (ms) ------------------------------------------ 0 145 981 8784 10 1073 971 7864 20 2044 10 7854 30 3013 0 6895 40 9909 0 0 50 9909 0 0 60 9909 0 0 70 9909 0 0 80 9908 0 0 90 9908 0 0 100 9909 0 0 Exp 3 (two sporadic threads and FIFO thread) Keep sporadic thread 1 with 30/100ms budget, vary budget of thread 2 from 0 - 100ms configuration with - thread 1: sporadic thread with budget = 30 ms and period=100ms, prio see above - thread 3: sporadic thread with budget = x ms and period=100ms, prio see above - thread 2: low-prio FIFO thread, prio see above config result result result sporadic 2 sporadic 1 sporadic 2 fifo budget(ms) (ms) (ms) (ms) ---------------------------------------- 0 5246 4661 0 10 7091 2816 0 20 9132 776 0 30 3015 0 6892 40 3016 9 6883 50 3015 49 6844 60 3016 2311 4581 70 3065 2484 4359 80 3015 48 6845 90 3015 91 6802 100 3053 4726 2128 Exp 4 (two sporadic threads and FIFO thread) Same as Experiment 1, but both sporadic threads with the same priority settings - sporadic 1: high prio 180, low prio 20 - sporadic 2: high prio 180, low prio 20 - fifo : prio 120 config result result result sporadic 1 sporadic 1 sporadic 2 fifo budget(ms) (ms) (ms) (ms) ------------------------------------------ 0 144 981 8784 10 1073 971 7864 20 2044 10 7854 30 3015 0 6892 40 39 3044 6825 50 4957 4950 0 60 4427 1559 3923 70 6880 3028 0 80 7840 2066 0 90 8802 1105 0 100 9861 47 0 Example raw output: Sporadic thread 1: prio high: 180, low: 20, budget: 10000000 pthread_create: budget 0 s 10000000 ns ticks: 10 , period 0 s 100000000 ns ticks 100 thread id 8 sporadic thread 2: at prio high 179 low: 19, budget: 30000000 pthread_create: budget 0 s 30000000 ns ticks: 30 , period 0 s 100000000 ns ticks 100 thread id 9 FIFO thread: prio 120 thread id 10 Result: sporadic 1 1074 ms sporadic 2 19 FIFO 8816 ms ``` Discussion: - NuttX works well with one sporadic thread and one fifo thread - NuttX does not work for - two sporadic threads and a (backround) fifo thread (varied budget of thread 1 and thread 2) - two sporadic threads with the same or with different priority settings - I would have expected, when the budget of sporadic thread is increased, that also the number of ms-counter is increased. This is not the case. - I disagree with the necessity of a third higher priority FIFO thread. Sporadic scheduling is work-conserving: If the processor is idle then a sporadic thread will continue to execute with its low priority, even though its budget is depleted. So the scheduler will either execute the low-level FIFO thread, or when this one is idle(sleeping) then it will execute one of the sporadic threads in its low-priority (if they have depleteted their budget). - I also ran these experiments with 1s/10s granuarity, which also did not work. - ---------------------------------------------------------------- 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: us...@infra.apache.org