From 0e2bd068beec2f20bd35105c5cc3252b2c821f7d Mon Sep 17 00:00:00 2001 From: Marius Vikhammer Date: Mon, 18 Dec 2023 18:04:56 +0800 Subject: [PATCH 1/2] feat(console): added config option for console task affinity --- components/console/esp_console.h | 3 +++ components/console/esp_console_repl.c | 14 +++++++------- .../esp_intr_dump/main/test_esp_intr_dump_main.c | 4 ++++ 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/components/console/esp_console.h b/components/console/esp_console.h index e14eab8084..dff737ba00 100644 --- a/components/console/esp_console.h +++ b/components/console/esp_console.h @@ -13,6 +13,7 @@ extern "C" { #include "sdkconfig.h" #include "esp_heap_caps.h" #include "esp_err.h" +#include "freertos/FreeRTOS.h" // Forward declaration. Definition in linenoise/linenoise.h. typedef struct linenoiseCompletions linenoiseCompletions; @@ -50,6 +51,7 @@ typedef struct { const char *history_save_path; //!< file path used to save history commands, set to NULL won't save to file system uint32_t task_stack_size; //!< repl task stack size uint32_t task_priority; //!< repl task priority + BaseType_t task_core_id; //!< repl task affinity, i.e. which core the task is pinned to const char *prompt; //!< prompt (NULL represents default: "esp> ") size_t max_cmdline_length; //!< maximum length of a command line. If 0, default value will be used } esp_console_repl_config_t; @@ -64,6 +66,7 @@ typedef struct { .history_save_path = NULL, \ .task_stack_size = 4096, \ .task_priority = 2, \ + .task_core_id = tskNO_AFFINITY, \ .prompt = NULL, \ .max_cmdline_length = 0, \ } diff --git a/components/console/esp_console_repl.c b/components/console/esp_console_repl.c index 123572d62f..4f79b7446a 100644 --- a/components/console/esp_console_repl.c +++ b/components/console/esp_console_repl.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2016-2021 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2016-2023 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -106,8 +106,8 @@ esp_err_t esp_console_new_repl_usb_cdc(const esp_console_dev_usb_cdc_config_t *d cdc_repl->repl_com.repl_core.del = esp_console_repl_usb_cdc_delete; /* spawn a single thread to run REPL */ - if (xTaskCreate(esp_console_repl_task, "console_repl", repl_config->task_stack_size, - cdc_repl, repl_config->task_priority, &cdc_repl->repl_com.task_hdl) != pdTRUE) { + if (xTaskCreatePinnedToCore(esp_console_repl_task, "console_repl", repl_config->task_stack_size, + cdc_repl, repl_config->task_priority, &cdc_repl->repl_com.task_hdl, repl_config->task_core_id) != pdTRUE) { ret = ESP_FAIL; goto _exit; } @@ -183,8 +183,8 @@ esp_err_t esp_console_new_repl_usb_serial_jtag(const esp_console_dev_usb_serial_ usb_serial_jtag_repl->repl_com.repl_core.del = esp_console_repl_usb_serial_jtag_delete; /* spawn a single thread to run REPL */ - if (xTaskCreate(esp_console_repl_task, "console_repl", repl_config->task_stack_size, - usb_serial_jtag_repl, repl_config->task_priority, &usb_serial_jtag_repl->repl_com.task_hdl) != pdTRUE) { + if (xTaskCreatePinnedToCore(esp_console_repl_task, "console_repl", repl_config->task_stack_size, + usb_serial_jtag_repl, repl_config->task_priority, &usb_serial_jtag_repl->repl_com.task_hdl, repl_config->task_core_id) != pdTRUE) { ret = ESP_FAIL; goto _exit; } @@ -285,8 +285,8 @@ esp_err_t esp_console_new_repl_uart(const esp_console_dev_uart_config_t *dev_con /* Spawn a single thread to run REPL, we need to pass `uart_repl` to it as * it also requires the uart channel. */ - if (xTaskCreate(esp_console_repl_task, "console_repl", repl_config->task_stack_size, - uart_repl, repl_config->task_priority, &uart_repl->repl_com.task_hdl) != pdTRUE) { + if (xTaskCreatePinnedToCore(esp_console_repl_task, "console_repl", repl_config->task_stack_size, + uart_repl, repl_config->task_priority, &uart_repl->repl_com.task_hdl, repl_config->task_core_id) != pdTRUE) { ret = ESP_FAIL; goto _exit; } diff --git a/tools/test_apps/system/esp_intr_dump/main/test_esp_intr_dump_main.c b/tools/test_apps/system/esp_intr_dump/main/test_esp_intr_dump_main.c index 6c96c0312b..5c20fa4273 100644 --- a/tools/test_apps/system/esp_intr_dump/main/test_esp_intr_dump_main.c +++ b/tools/test_apps/system/esp_intr_dump/main/test_esp_intr_dump_main.c @@ -27,6 +27,10 @@ static void start_console(void) { esp_console_repl_t *repl = NULL; esp_console_repl_config_t repl_config = ESP_CONSOLE_REPL_CONFIG_DEFAULT(); + + /* Pin repl task to ensure all interrupts are allocated on the same core */ + repl_config.task_core_id = 0; + /* Prompt to be printed before each line. * This can be customized, made dynamic, etc. */ From c4f2abbfd3e638281274aa30984b118d07e2cc13 Mon Sep 17 00:00:00 2001 From: Marius Vikhammer Date: Mon, 18 Dec 2023 18:06:58 +0800 Subject: [PATCH 2/2] fix(interrupts): fixed flakey intr dump test --- .../system/esp_intr_dump/main/test_esp_intr_dump_main.c | 3 +++ tools/test_apps/system/esp_intr_dump/pytest_esp_intr_dump.py | 3 +++ 2 files changed, 6 insertions(+) diff --git a/tools/test_apps/system/esp_intr_dump/main/test_esp_intr_dump_main.c b/tools/test_apps/system/esp_intr_dump/main/test_esp_intr_dump_main.c index 5c20fa4273..b32ad8e643 100644 --- a/tools/test_apps/system/esp_intr_dump/main/test_esp_intr_dump_main.c +++ b/tools/test_apps/system/esp_intr_dump/main/test_esp_intr_dump_main.c @@ -140,6 +140,9 @@ static int cmd_intr_alloc(int argc, char **argv) printf("Failed to allocate interrupt (source: %d, flags: 0x%x): %s\n", source_num, flags, esp_err_to_name(ret)); return 1; } + + printf("Allocated %s %s\n", source_str, flags_str); + return 0; } diff --git a/tools/test_apps/system/esp_intr_dump/pytest_esp_intr_dump.py b/tools/test_apps/system/esp_intr_dump/pytest_esp_intr_dump.py index 161b6ef7d0..2b807d80d2 100644 --- a/tools/test_apps/system/esp_intr_dump/pytest_esp_intr_dump.py +++ b/tools/test_apps/system/esp_intr_dump/pytest_esp_intr_dump.py @@ -15,6 +15,7 @@ def test_esp_intr_dump_nonshared(dut: Dut) -> None: dut.expect_exact(PROMPT, timeout=10) dut.write('intr_alloc GPIO LEVEL3\n') + dut.expect_exact('Allocated GPIO LEVEL3') dut.expect_exact(PROMPT) dut.write('intr_dump\n') @@ -27,6 +28,7 @@ def test_esp_intr_dump_shared(dut: Dut) -> None: dut.expect_exact(PROMPT, timeout=10) dut.write('intr_alloc GPIO SHARED\n') + dut.expect_exact('Allocated GPIO SHARED') dut.expect_exact(PROMPT) dut.write('intr_dump\n') @@ -34,6 +36,7 @@ def test_esp_intr_dump_shared(dut: Dut) -> None: dut.expect_exact(PROMPT) dut.write('intr_alloc UART1 SHARED\n') + dut.expect_exact('Allocated UART1 SHARED') dut.expect_exact(PROMPT) dut.write('intr_dump\n')