mirror of https://github.com/rusefi/rusefi-1.git
Stack usage is still all over the place #1662
This commit is contained in:
parent
997c316013
commit
4280e3327f
|
@ -119,7 +119,7 @@ static efitimems_t previousWriteReportMs = 0;
|
|||
static ts_channel_s tsChannel;
|
||||
|
||||
// this thread wants a bit extra stack
|
||||
static THD_WORKING_AREA(tunerstudioThreadStack, 3 * UTILITY_THREAD_STACK_SIZE);
|
||||
static THD_WORKING_AREA(tunerstudioThreadStack, CONNECTIVITY_THREAD_STACK);
|
||||
|
||||
static void resetTs(void) {
|
||||
memset(&tsState, 0, sizeof(tsState));
|
||||
|
@ -490,6 +490,8 @@ void runBinaryProtocolLoop(ts_channel_s *tsChannel) {
|
|||
int wasReady = false;
|
||||
|
||||
while (true) {
|
||||
validateStack("communication", STACK_USAGE_COMMUNICATION, 128);
|
||||
|
||||
int isReady = sr5IsReady(tsChannel);
|
||||
if (!isReady) {
|
||||
chThdSleepMilliseconds(10);
|
||||
|
|
|
@ -29,6 +29,8 @@ typedef struct {
|
|||
|
||||
extern tunerstudio_counters_s tsState;
|
||||
|
||||
#define CONNECTIVITY_THREAD_STACK (2 * UTILITY_THREAD_STACK_SIZE)
|
||||
|
||||
/**
|
||||
* handle non CRC wrapped command
|
||||
*/
|
||||
|
|
|
@ -252,7 +252,7 @@ bool isCommandLineConsoleReady(void) {
|
|||
|
||||
#if !defined(EFI_CONSOLE_NO_THREAD)
|
||||
|
||||
static THD_WORKING_AREA(consoleThreadStack, 3 * UTILITY_THREAD_STACK_SIZE);
|
||||
static THD_WORKING_AREA(consoleThreadStack, CONNECTIVITY_THREAD_STACK);
|
||||
static THD_FUNCTION(consoleThreadEntryPoint, arg) {
|
||||
(void) arg;
|
||||
chRegSetThreadName("console thread");
|
||||
|
|
|
@ -118,6 +118,16 @@ static void sayHello(void) {
|
|||
chThdSleepMilliseconds(5);
|
||||
}
|
||||
|
||||
void validateStack(const char*msg, obd_code_e code, int desiredStackUnusedSize) {
|
||||
|
||||
#if CH_DBG_THREADS_PROFILING && CH_DBG_FILL_THREADS
|
||||
int unusedStack = CountFreeStackSpace(chThdGetSelfX()->wabase);
|
||||
if (unusedStack < desiredStackUnusedSize) {
|
||||
warning(code, "Stack low on %s: %d", msg, unusedStack);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#if CH_DBG_THREADS_PROFILING && CH_DBG_FILL_THREADS
|
||||
int CountFreeStackSpace(const void* wabase) {
|
||||
const uint8_t* stackBase = reinterpret_cast<const uint8_t*>(wabase);
|
||||
|
|
|
@ -2089,6 +2089,12 @@ typedef enum {
|
|||
CUSTOM_ERR_6729 = 6729,
|
||||
|
||||
|
||||
STACK_USAGE_COMMUNICATION = 6900,
|
||||
STACK_USAGE_MIL = 6901,
|
||||
STACK_USAGE_BENCH = 6902,
|
||||
STACK_USAGE_STATUS = 6903,
|
||||
STACK_USAGE_4 = 6904,
|
||||
|
||||
// 8000-8050 logging errors
|
||||
CUSTOM_OBD_MMC_ERROR = 8000,
|
||||
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
#if EFI_ENGINE_CONTROL
|
||||
#if !EFI_UNIT_TEST
|
||||
|
||||
#include "os_access.h"
|
||||
#include "flash_main.h"
|
||||
#include "bench_test.h"
|
||||
#include "io_pins.h"
|
||||
|
@ -213,6 +214,8 @@ private:
|
|||
UNUSED(nowNt);
|
||||
setPeriod(50 /* ms */);
|
||||
|
||||
validateStack("Bench", STACK_USAGE_BENCH, 128);
|
||||
|
||||
// naive inter-thread communication - waiting for a flag
|
||||
if (isBenchTestPending) {
|
||||
isBenchTestPending = false;
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
#include "malfunction_central.h"
|
||||
#include "malfunction_indicator.h"
|
||||
#include "efi_gpio.h"
|
||||
#include "os_access.h"
|
||||
#include "periodic_thread_controller.h"
|
||||
|
||||
#define TEST_MIL_CODE FALSE
|
||||
|
@ -87,6 +88,8 @@ private:
|
|||
void PeriodicTask(efitick_t nowNt) override {
|
||||
UNUSED(nowNt);
|
||||
|
||||
validateStack("MIL", STACK_USAGE_MIL, 128);
|
||||
|
||||
if (nowNt - engine->triggerCentral.triggerState.mostRecentSyncTime < MS2NT(500)) {
|
||||
enginePins.checkEnginePin.setValue(1);
|
||||
chThdSleepMilliseconds(500);
|
||||
|
|
|
@ -57,6 +57,8 @@ typedef unsigned int time_t;
|
|||
#define UTILITY_THREAD_STACK_SIZE 400
|
||||
#endif /* UTILITY_THREAD_STACK_SIZE */
|
||||
|
||||
#define getCurrentRemainingStack() getRemainingStack(chThdGetSelfX())
|
||||
|
||||
#define EFI_ERROR_CODE 0xffffffff
|
||||
|
||||
#if EFI_USE_CCM && defined __GNUC__
|
||||
|
@ -94,9 +96,6 @@ typedef unsigned int time_t;
|
|||
#define CCM_OPTIONAL
|
||||
#endif /* EFI_USE_CCM */
|
||||
|
||||
#define getCurrentRemainingStack() getRemainingStack(chThdGetSelfX())
|
||||
|
||||
|
||||
// 168 ticks in microsecond in case of 168MHz 407
|
||||
#define US_TO_NT_MULTIPLIER (CORE_CLOCK / 1000000)
|
||||
|
||||
|
|
|
@ -30,5 +30,6 @@ extern "C"
|
|||
*/
|
||||
EXTERNC int getRemainingStack(thread_t *otp);
|
||||
int CountFreeStackSpace(const void* wabase);
|
||||
void validateStack(const char*msg, obd_code_e code, int stackUnusedSize);
|
||||
|
||||
#define HAS_OS_ACCESS
|
||||
|
|
Loading…
Reference in New Issue