Skip to content
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

Watchdog timer fires when trying to use SPIFFS #32

Closed
smuehlst opened this issue Feb 1, 2022 · 3 comments
Closed

Watchdog timer fires when trying to use SPIFFS #32

smuehlst opened this issue Feb 1, 2022 · 3 comments

Comments

@smuehlst
Copy link

smuehlst commented Feb 1, 2022

I'm trying to use SPIFFS under QEMU in the same manner as I'm already doing it in a program that runs successfully on a Tiny S2 board. When I run the program in QEMU, the watchdog timer fires:

...
I (10453) example: Initializing SPIFFS
E (15303) task_wdt: Task watchdog got triggered. The following tasks did not reset the watchdog in time:
E (15303) task_wdt:  - IDLE (CPU 0)
E (15303) task_wdt: Tasks currently running:
E (15303) task_wdt: CPU 0: main
E (15303) task_wdt: CPU 1: IDLE
E (15303) task_wdt: Print CPU 0 (current core) backtrace

Backtrace:0x40184013:0x3FFB0840 0x40084D95:0x3FFB0860 0x40086A64:0x3FFCDC60 0x40085867:0x3FFCDC80 0x400867E5:0x3FFCDCA0 0x40086892:0x3FFCDCC0 0x400872B5:0x3FFCDCE0 0x4008664A:0x3FFCDD00 0x4017FB29:0x3FFCDD40 0x400E0A25:0x3FFCDD70 0x400E4965:0x3FFCDDA0 0x400E25CA:0x3FFCDDD0 0x400E1009:0x3FFCDE10 0x400E00D4:0x3FFCDE40 0x400E098F:0x3FFCDE80 0x400DB77A:0x3FFCDF50 0x400DBA0D:0x3FFCDFA0 0x401A30E7:0x3FFCE020 0x4008E591:0x3FFCE040

E (15303) task_wdt: Print CPU 1 backtrace

Backtrace:0x40087201:0x3FFB0E40 0x40084D95:0x3FFB0E60 0x4000BFED:0x3FFCF440 0x4008E849:0x3FFCF450 0x401842DF:0x3FFCF470 0x401842EB:0x3FFCF4A0 0x400DAF05:0x3FFCF4C0 0x4008CE6D:0x3FFCF4E0 0x4008E591:0x3FFCF500

By using the xtensa-esp32s3-elf-addr2line utility I was able to decode the addresses to the following stack trace:

0x40184013: task_wdt_isr at E:/Users/stm/Downloads/esp-idf/components/esp_common/src/task_wdt.c:189
0x40084d95: _xt_lowint1 at E:/Users/stm/Downloads/esp-idf/components/freertos/port/xtensa/xtensa_vectors.S:1105
0x40086a64: xt_int_enable_mask at E:/Users/stm/Downloads/esp-idf/components/xtensa/include/xtensa/xtensa_api.h:170
 (inlined by) intr_cntrl_ll_enable_int_mask at E:/Users/stm/Downloads/esp-idf/components/hal/esp32/include/hal/interrupt_controller_ll.h:100
 (inlined by) interrupt_controller_hal_enable_int_mask at E:/Users/stm/Downloads/esp-idf/components/hal/include/hal/interrupt_controller_hal.h:192
 (inlined by) esp_intr_noniram_enable at E:/Users/stm/Downloads/esp-idf/components/esp_system/intr_alloc.c:815
0x40085867: spi_flash_enable_interrupts_caches_and_other_cpu at E:/Users/stm/Downloads/esp-idf/components/spi_flash/cache_utils.c:204
0x400867e5: cache_enable at E:/Users/stm/Downloads/esp-idf/components/spi_flash/spi_flash_os_func_app.c:63
0x40086892: spi1_end at E:/Users/stm/Downloads/esp-idf/components/spi_flash/spi_flash_os_func_app.c:111
0x400872b5: spiflash_end_default at E:/Users/stm/Downloads/esp-idf/components/spi_flash/esp_flash_api.c:125
0x4008664a: esp_flash_read at E:/Users/stm/Downloads/esp-idf/components/spi_flash/esp_flash_api.c:681
0x4017fb29: esp_partition_read at E:/Users/stm/Downloads/esp-idf/components/spi_flash/partition.c:419
0x400e0a25: spiffs_api_read at E:/Users/stm/Downloads/esp-idf/components/spiffs/spiffs_api.c:36
0x400e4965: spiffs_phys_rd at E:/Users/stm/Downloads/esp-idf/components/spiffs/spiffs/src/spiffs_cache.c:146
0x400e25ca: spiffs_obj_lu_scan at E:/Users/stm/Downloads/esp-idf/components/spiffs/spiffs/src/spiffs_nucleus.c:366 (discriminator 4)
0x400e1009: SPIFFS_mount at E:/Users/stm/Downloads/esp-idf/components/spiffs/spiffs/src/spiffs_hydrogen.c:134
0x400e00d4: esp_spiffs_init at E:/Users/stm/Downloads/esp-idf/components/spiffs/esp_spiffs.c:246
0x400e098f: esp_vfs_spiffs_register at E:/Users/stm/Downloads/esp-idf/components/spiffs/esp_spiffs.c:379
0x400db77a: app_init_spiffs at E:\Users\stm\Documents\GIT\esp32-pdflib\esp-qemu-sdcard\build/../main/sd_card_example_main.c:133
0x400dba0d: app_main at E:\Users\stm\Documents\GIT\esp32-pdflib\esp-qemu-sdcard\build/../main/sd_card_example_main.c:242 (discriminator 13)
0x401a30e7: main_task at E:/Users/stm/Downloads/esp-idf/components/freertos/port/port_common.c:133 (discriminator 2)
0x4008e591: vPortTaskWrapper at E:/Users/stm/Downloads/esp-idf/components/freertos/port/xtensa/port.c:168

Should SPIFFS work under QEMU? Are additional command line options for QEMU necessary?

I'm using ESP-IDF v4.3.2.

@igrr
Copy link
Member

igrr commented Feb 1, 2022

Hi @smuehlst, I think SPI flash emulation in QEMU works slower than it does on the real chip. For this reason the same operation which doesn't trigger the task watchdog on the real chip may trigger it in QEMU.

There are several things you could do: disable watchdogs in QEMU (see wiki), increase task watchdog timeout in sdkconfig when building for QEMU, or change some sdkconfig options for yielding periodically during flash operations.

Ideally, SPI flash emulation speed in QEMU could be improved,.but I haven't found any obvious ways to do this, so far.

@smuehlst
Copy link
Author

smuehlst commented Feb 2, 2022

Hi @igrr, thanks for your suggestions.

I had already tried to disable the watchdogs according to the instructions in the Wiki by passing the option -global driver=timer.esp32.timg,property=wdt_disable,value=true. In this case the watchdog does not fire, but the program apparently hangs in the SPIFFS initialisation.

This is my SPIFFS initialisation function that I have more or less copied from one of the ESP-IDF examples, and that works on a real ESP32 board:

#define SPIFFS_MOUNT_POINT "/spiffs"

static void app_init_spiffs(void)
{
    ESP_LOGI(TAG, "Initializing SPIFFS");

    esp_vfs_spiffs_conf_t const conf = {
      .base_path = SPIFFS_MOUNT_POINT,
      .partition_label = NULL,
      .max_files = 5,
      .format_if_mount_failed = false
    };

    // Use settings defined above to initialize and mount SPIFFS filesystem.
    // Note: esp_vfs_spiffs_register is an all-in-one convenience function.
    esp_err_t ret = esp_vfs_spiffs_register(&conf);

    if (ret != ESP_OK) {
        if (ret == ESP_FAIL) {
            ESP_LOGE(TAG, "Failed to mount or format filesystem");
        } else if (ret == ESP_ERR_NOT_FOUND) {
            ESP_LOGE(TAG, "Failed to find SPIFFS partition");
        } else {
            ESP_LOGE(TAG, "Failed to initialize SPIFFS (%s)", esp_err_to_name(ret));
        }
        return;
    }

    size_t total = 0, used = 0;
    ret = esp_spiffs_info(NULL, &total, &used);
    if (ret != ESP_OK) {
        ESP_LOGE(TAG, "Failed to get SPIFFS partition information (%s)", esp_err_to_name(ret));
    } else {
        ESP_LOGI(TAG, "Partition size: total: %d, used: %d", total, used);
    }
}

In the QEMU output I see Initializing SPIFFS, and then nothing happens anymore, although I have enabled all the SPIFFS debug options in the sdkconfig file except "Enable SPIFFS Filesystem Visualization".

Are maybe additional settings in the sdkconfig file necessary to make SPIFFS work under QEMU?

@smuehlst
Copy link
Author

smuehlst commented Feb 2, 2022

@igrr I have to correct myself: It just takes a really long time to initialise SPIFFS, on my machine approx. 60 seconds, and then everything proceeds as expected. I was just too impatient, I'm sorry for that.

@smuehlst smuehlst closed this as completed Feb 2, 2022
igrr pushed a commit that referenced this issue Aug 2, 2022
Include the qtest reproducer provided by Alexander Bulekov
in https://gitlab.com/qemu-project/qemu/-/issues/542.
Without the previous commit, we get:

  $ make check-qtest-i386
  ...
  Running test tests/qtest/intel-hda-test
  AddressSanitizer:DEADLYSIGNAL
  =================================================================
  ==1580408==ERROR: AddressSanitizer: stack-overflow on address 0x7ffc3d566fe0
      #0 0x63d297cf in address_space_translate_internal softmmu/physmem.c:356
      #1 0x63d27260 in flatview_do_translate softmmu/physmem.c:499:15
      #2 0x63d27af5 in flatview_translate softmmu/physmem.c:565:15
      #3 0x63d4ce84 in flatview_write softmmu/physmem.c:2850:10
      #4 0x63d4cb18 in address_space_write softmmu/physmem.c:2950:18
      #5 0x63d4d387 in address_space_rw softmmu/physmem.c:2960:16
      #6 0x62ae12f2 in dma_memory_rw_relaxed include/sysemu/dma.h:89:12
      #7 0x62ae104a in dma_memory_rw include/sysemu/dma.h:132:12
      #8 0x62ae6157 in dma_memory_write include/sysemu/dma.h:173:12
      #9 0x62ae5ec0 in stl_le_dma include/sysemu/dma.h:275:1
      #10 0x62ae5ba2 in stl_le_pci_dma include/hw/pci/pci.h:871:1
      #11 0x62ad59a6 in intel_hda_response hw/audio/intel-hda.c:372:12
      #12 0x62ad2afb in hda_codec_response hw/audio/intel-hda.c:107:5
      #13 0x62aec4e1 in hda_audio_command hw/audio/hda-codec.c:655:5
      #14 0x62ae05d9 in intel_hda_send_command hw/audio/intel-hda.c:307:5
      #15 0x62adff54 in intel_hda_corb_run hw/audio/intel-hda.c:342:9
      #16 0x62adc13b in intel_hda_set_corb_wp hw/audio/intel-hda.c:548:5
      #17 0x62ae5942 in intel_hda_reg_write hw/audio/intel-hda.c:977:9
      #18 0x62ada10a in intel_hda_mmio_write hw/audio/intel-hda.c:1054:5
      #19 0x63d8f383 in memory_region_write_accessor softmmu/memory.c:492:5
      #20 0x63d8ecc1 in access_with_adjusted_size softmmu/memory.c:554:18
      #21 0x63d8d5d6 in memory_region_dispatch_write softmmu/memory.c:1504:16
      #22 0x63d5e85e in flatview_write_continue softmmu/physmem.c:2812:23
      #23 0x63d4d05b in flatview_write softmmu/physmem.c:2854:12
      #24 0x63d4cb18 in address_space_write softmmu/physmem.c:2950:18
      #25 0x63d4d387 in address_space_rw softmmu/physmem.c:2960:16
      #26 0x62ae12f2 in dma_memory_rw_relaxed include/sysemu/dma.h:89:12
      #27 0x62ae104a in dma_memory_rw include/sysemu/dma.h:132:12
      #28 0x62ae6157 in dma_memory_write include/sysemu/dma.h:173:12
      #29 0x62ae5ec0 in stl_le_dma include/sysemu/dma.h:275:1
      #30 0x62ae5ba2 in stl_le_pci_dma include/hw/pci/pci.h:871:1
      #31 0x62ad59a6 in intel_hda_response hw/audio/intel-hda.c:372:12
      #32 0x62ad2afb in hda_codec_response hw/audio/intel-hda.c:107:5
      #33 0x62aec4e1 in hda_audio_command hw/audio/hda-codec.c:655:5
      #34 0x62ae05d9 in intel_hda_send_command hw/audio/intel-hda.c:307:5
      #35 0x62adff54 in intel_hda_corb_run hw/audio/intel-hda.c:342:9
      #36 0x62adc13b in intel_hda_set_corb_wp hw/audio/intel-hda.c:548:5
      #37 0x62ae5942 in intel_hda_reg_write hw/audio/intel-hda.c:977:9
      #38 0x62ada10a in intel_hda_mmio_write hw/audio/intel-hda.c:1054:5
      #39 0x63d8f383 in memory_region_write_accessor softmmu/memory.c:492:5
      #40 0x63d8ecc1 in access_with_adjusted_size softmmu/memory.c:554:18
      #41 0x63d8d5d6 in memory_region_dispatch_write softmmu/memory.c:1504:16
      #42 0x63d5e85e in flatview_write_continue softmmu/physmem.c:2812:23
      #43 0x63d4d05b in flatview_write softmmu/physmem.c:2854:12
      #44 0x63d4cb18 in address_space_write softmmu/physmem.c:2950:18
      #45 0x63d4d387 in address_space_rw softmmu/physmem.c:2960:16
      #46 0x62ae12f2 in dma_memory_rw_relaxed include/sysemu/dma.h:89:12
      qemu#47 0x62ae104a in dma_memory_rw include/sysemu/dma.h:132:12
      #48 0x62ae6157 in dma_memory_write include/sysemu/dma.h:173:12
      ...
  SUMMARY: AddressSanitizer: stack-overflow softmmu/physmem.c:356 in address_space_translate_internal
  ==1580408==ABORTING
  Broken pipe
  Aborted (core dumped)

Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Acked-by: Thomas Huth <thuth@redhat.com>
Message-Id: <20211218160912.1591633-4-philmd@redhat.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants