-
-
Notifications
You must be signed in to change notification settings - Fork 346
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reduce Host emulator CPU load #2472
Conversation
Simplify build by using cmake for lwip only, sming glue built as regular sming library Pull out common linux/Windows code Service using event timer rather than polled timer Remove LWIP_SERVICE_INTERVAL and adjust interval dynamically
Code required by both CMake and sming library builds
Time is absolute so must base on system clock. Because this wasn't done will always succeed. Change parameter to microseconds.
return false; | ||
} | ||
|
||
extern CSemaphore host_main_loop_semaphore; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mikee47 Can you move this line to the beginning of the file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll need to rewrite this using functions anyway.
As you know from CI the Windows run keeps stalling. It happens because the Windows pthreads library uses a mutex to guard semaphores. If that mutex is locked when the main thread is suspended, the next call to sem_post() results in a deadlock. Oh, the joys of multithreading.
@@ -271,6 +271,7 @@ int main(int argc, char* argv[]) | |||
return 1; | |||
} | |||
|
|||
extern void host_init_bootloader(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mikee47 Can you move this line to the beginning of the file or a separate header file?
lwip_initialised = host_lwip_init(&config.lwip); | ||
if(lwip_initialised) { | ||
if(host_lwip_init(config.lwip)) { | ||
extern void host_wifi_lwip_init_complete(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mikee47 Can you move this line to the beginning of the file or a separate header file?
905e28b
to
1467b7a
Compare
Time structure same as sem_timedwait Consistent with example code
Investigating cause of Windows deadlock. May have other uses.
Replace global semaphore with `host_thread_wait` and `host_thread_kick`
1467b7a
to
fe91169
Compare
@mikee47 this PR looks much better now. Shall I merge it or you would like to add something? |
@slaff All done thanks |
This PR improves Host performance by using efficient waiting for tasks & timers rather than just looping.
Running the
HttpServer_ConfigNetwork
example sees a drop from 100% CPU usage to < 2% running in linux. Difference in Windows is less pronounced as the lwip layer incorporates a 1ms wait.LWIP is now serviced using an event timer. The interval is adjusted dynamically which allows good file transfer performance and reduced CPU usage when idle.