-
Notifications
You must be signed in to change notification settings - Fork 319
Separate tasks for frequency ramps and fan controller #1217
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
base: master
Are you sure you want to change the base?
Conversation
| xTaskCreate(create_jobs_task, "stratum miner", 3072, (void *) &GLOBAL_STATE, 10, NULL); | ||
| xTaskCreate(ASIC_task, "asic", 2048, (void *) &GLOBAL_STATE, 10, NULL); | ||
| xTaskCreate(ASIC_result_task, "asic result", 4096, (void *) &GLOBAL_STATE, 15, NULL); | ||
| xTaskCreate(statistics_task, "statistics", 2048, (void *) &GLOBAL_STATE, 3, NULL); |
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.
Stack size of a lot of tasks had to be reduced, we're running out of heap with that many tasks. Not sure how to make that bigger. It also needs to have some general error handling, the xTaskCreate fails silently if we run into this again.
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.
that silent crash can get catched with a handler for every task, and then check after task create !handler
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.
Good that you mentioned, I wanted to add this. I think it's a good thing do add anyways, as the results are very puzzling, depending on which tasks were actually started and which weren't.
I'm also looking at increasing the FreeRTOS heap space, as this is quite constrained with the number of tasks we have.
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.
This is interesting reading material: espressif/esp-idf#11216 (comment)
TLDR: xTaskCreate always uses internal memory. This is by design. When a task does a NVS or SPI Flash write, it disables cache which makes the task switcher unable to execute anything else, rebooting the system. So, for those tasks, the stack can't be in SPI ram. All tasks that write to NVS or Flash need to be internal.
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.
well that nvs stuff get used way to much. for that settings loading it would be enough to read it in main.c setup once and fill a struct with it or whatever. saving happen there only in the http_server.c except the highest diff. but that could get deligated to queue and saving run in a own singel run task
…split-power-management-task
|
There are some conflicts now |
…split-power-management-task
Conflicts resolved, but I'm still testing. Sometimes it goes straight to overheat mode when booting cold. Not sure what's happening there. And I also want to simplify the frequency controller, by adjusting a single step on each iteration instead of doing a loop within an eternal task. |
FWIW the ASIC thermal diode will not read correctly until ASIC core voltage is on. |
Responsibilities are indeed not properly separated between the tasks, so there's some things happening out of order. I've set the PR to draft for now. Same with overheat mode, that's being overridden because of bad separation in the current code. |
…split-power-management-task
…split-power-management-task
|
about heap
|
|
There's also Currently, NVS is used also as a message bus between tasks. It might be better to use GlobalState for that, and have a single NVS writer task. That way all the other tasks can leverage PSRAM. Only other exception would be the OTA flash task, as that one also has to be in internal memory. |
WantClue
left a comment
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.
concept ack
Fixes #1210
This changes quite a lot. Two tasks are extracted from power management: a fan controller task and an asic management task for frequency and voltage changes. This stops frequency ramps - including the initial one at startup - to no longer block the power management task, including overheat checks.
The startup sequence is materially changed by this PR. The initial frequency ramp is done after the asic has been completely initialised and the fan controller is already running. This means that the full fan blast at startup is almost completely eliminated.
This PR also increases the frequency of fan controller to 10/sec and tuned the PID to be a lot less aggressive, and removing the startup sequence. These changes might be better done as a separate PR, depending on testing, but on my device the controller is oscillating a lot less.
🚨 This works on my Gamma, but needs a lot more testing, especially from a cold start. Proceed at your own risk! 🚨
Future improvements for this PR are to simplify the ASIC management task by adjusting a single frequency step on each tick, instead of delegating it to do_frequency_ramp.
It also needs more code cleanups, I'm not satisfied with the header file structure, especially the
PowerManagementModulestruct and how this is included throughout the application viaglobal_state.h.One open problem currently (also without this PR) is that changing the frequency through the BAP port will block the BAP handler as it's doing a blocking call to
do_frequency_transition. The BAP handler should just set a new desired frequency, and the asic management calls the set_frequency function.