Replies: 4 comments 4 replies
-
I usually avoid loops like:
Instead I use:
|
Beta Was this translation helpful? Give feedback.
-
@rkompass The ESP32 / IDF scheduler's interval is in the order of 20ms. I think you'll need to run the test for much longer to see a more even distribution. |
Beta Was this translation helpful? Give feedback.
-
Perhaps related: I found that
leads to:
So this indicates that thread 1 had a break of about 9.9 seconds!! Was it only active in the beginning and the end of the 10s total duration?
which would mean the longest interval between time slices is > 130 ms. But my point, if you are still reading this @jimmo : Could it be that the threads are scheduled by some variant of |
Beta Was this translation helpful? Give feedback.
-
Hello rkompass, import _thread
import time
from machine import freq
freq(240_000_000)
flag = False
ret = [0, 0, 0]
def th_perf(i):
global ret
while not flag:
pass
n = 0
while flag:
n +=1
time.sleep_ms(0)
ret[i] = n
_thread.start_new_thread(th_perf, (2,))
_thread.start_new_thread(th_perf, (0,))
_thread.start_new_thread(th_perf, (1,))
flag = True
time.sleep(1)
flag = False
time.sleep_ms(50)
print('Thread performance: {:d} {:d} {:d} iterations'.format(ret[0], ret[1], ret[2]))
Thread distribution seems to be equal. Ok the performance is worse. I guess the IDF scheduler needs a little bit time to run all the threads, with eaqual time slots, however, I have no idea why. |
Beta Was this translation helpful? Give feedback.
-
In testing how an idle loop (waiting for a flag) in a thread impairs the other threads performance I observed that as long as there is only one other thread it almost doesn't.
But with 3 threads is does (~50%) and the other two threads are very unevenly distributed.
Also with 2 or 3 identical computing threads the resources are very unevenly distributed, so that the first and third thread get ~49 % and the second only 1% !
Perhaps this is a bug? Should I raise an issue?
The following ran on an esp32:
Result:
Thread performance: 1804861 30301 1567005 iterations
.Beta Was this translation helpful? Give feedback.
All reactions