I'm using ESP32-C6-DevkitC-1 and ESP-IDF and C++. Every time I write some piece of code and it takes some time to compute the FreeRTOS just complains in the Serial console output. The only solution to this problem I found if I put somewhere a 10 ms delay it will stop complaining.
So I went ahead into the idf.py menuconfig and disable all the log error messages and even then it was complaining about that it was trying to do a Task Switch and it couldn't because one of the tasks is blocking the Task Switch because it was still computing something.
But I didn't create any tasks at all. The code was run from the main function so I'm just confused as how to use FreeRTOS effectively and to full speed, because I cannot afford to put 10 ms delays everywhere.
Are these FreeRTOS error messages even something to worry about?
So I wrote this to test things out:
- #include <iostream>
- #include <cstdint>
- #include <chrono>
- #include <vector>
- #include <algorithm>
- std::chrono::milliseconds prime_test(const uint32_t stopper) {
- const auto start = std::chrono::high_resolution_clock::now();
- auto end = start;
- for(uint32_t number = 2; number < stopper; ) {
- const auto chunk_start = std::chrono::high_resolution_clock::now();
- std::vector<uint32_t> primes;
- primes.reserve(512);
- size_t index = 0;
- for(; number < stopper; number++) {
- uint32_t divisor = (number - 1);
- for(; divisor > 1; divisor--) {
- if((number % divisor) == 0) {
- break;
- }
- }
- if(divisor == 1) {
- try {
- primes.push_back(number);
- } catch(...) {
- std::cerr << "ERROR: prime_test(" << stopper << "): failed to primes.push_back(number)\n";
- break;
- }
- }
- }
- const auto chunk_end = std::chrono::high_resolution_clock::now();
- end += (chunk_end - chunk_start);
- std::find_if(primes.begin(), primes.end(), [print_index = 0, index](const uint32_t element) mutable {
- if(index == 0 || element != 0) {
- std::printf("primes[%zu]: %lu\n", print_index++, element);
- return false;
- } else {
- return true;
- }
- });
- std::cout << "prime_test(): calcation chunk duration: " << chunk_end - chunk_start << std::endl;
- }
- return std::chrono::duration_cast<std::chrono::milliseconds>(end - start);
- }
- extern "C" void app_main() {
- std::cout << "prime_test(40'000): " << prime_test(40'000) << std::endl;;
- }
Can somebody please try and run this and confirm to me if I'm doing something wrong with FreeRTOS. Is this normal performance for an EPS32C6 at default 160 MHz clock? Can I improve the performance somehow without changing the code by configuring FreeRTOS somehow? By changing the tickrate of FreeRTOS? Anyone? Please help.
Thanks in advance!