Skip to content

Commit

Permalink
Adjusted stack size for TimerService.
Browse files Browse the repository at this point in the history
  • Loading branch information
PerMalmberg committed Nov 5, 2018
1 parent 396d234 commit e8b3b90
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 26 deletions.
30 changes: 17 additions & 13 deletions lib/smooth/core/Task.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ namespace smooth
start_condition.wait(lock,
[this]
{
return !!started;
return started.load();
});
}
}
Expand Down Expand Up @@ -171,19 +171,23 @@ namespace smooth
void Task::print_stack_status()
{
#ifdef ESP_PLATFORM
// https://docs.espressif.com/projects/esp-idf/en/latest/api-reference/system/freertos.html?highlight=uxTaskGetStackHighWaterMark
auto minimum_free_stack_in_bytes = uxTaskGetStackHighWaterMark(nullptr);
Format msg("Minumum free stack: {1}/{2}",
UInt32(minimum_free_stack_in_bytes),
UInt32(stack_size));

if (minimum_free_stack_in_bytes <= 256)
{
Log::warning(name, msg);
}
else
if(status_print_enabled)
{
Log::info(name, msg);
// https://docs.espressif.com/projects/esp-idf/en/latest/api-reference/system/freertos.html?highlight=uxTaskGetStackHighWaterMark
auto minimum_free_stack_in_bytes = uxTaskGetStackHighWaterMark(nullptr);
Format msg("Minimum free stack: {1} of {2} => {3} used.",
UInt32(minimum_free_stack_in_bytes),
UInt32(stack_size),
UInt32(stack_size - minimum_free_stack_in_bytes));

if (minimum_free_stack_in_bytes <= 256)
{
Log::warning(name, msg);
}
else
{
Log::info(name, msg);
}
}
#endif
}
Expand Down
26 changes: 13 additions & 13 deletions lib/smooth/core/timer/TimerService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,19 @@ namespace smooth
{
TimerService::TimerService()
: Task("TimerService",
2048,
TIMER_SERVICE_PRIO,
milliseconds(0)),
cmp([](SharedTimer left, SharedTimer right)
{
// We want the timer with the least time left to be first in the list
return left->expires_at() > right->expires_at();
}),
queue(cmp),
guard(),
processed()
1024 * 3,
TIMER_SERVICE_PRIO,
milliseconds(0)),
cmp([](SharedTimer left, SharedTimer right) {
// We want the timer with the least time left to be first in the list
return left->expires_at() > right->expires_at();
}),
queue(cmp),
guard(),
processed()
{
// Disable status printing to conserve stack size.
disable_status_print();
}


Expand Down Expand Up @@ -106,8 +107,7 @@ namespace smooth

cond.wait_until(lock,
timer->expires_at(),
[current_queue_length, this]()
{
[current_queue_length, this]() {
// Wake up if a timer has been added or removed.
return current_queue_length != queue.size();
});
Expand Down
2 changes: 2 additions & 0 deletions lib/smooth/include/smooth/core/Task.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ namespace smooth
}

void print_stack_status();
void disable_status_print() { status_print_enabled = false; }

private:
void exec();
Expand All @@ -96,6 +97,7 @@ namespace smooth
std::condition_variable start_condition{};
smooth::core::timer::ElapsedTime status_report_timer{};
std::vector<smooth::core::ipc::IPolledTaskQueue*> polled_queues{};
bool status_print_enabled = true;
};
}
}

0 comments on commit e8b3b90

Please sign in to comment.