espressif / esp-idf

Espressif IoT Development Framework. Official development framework for Espressif SoCs.
Apache License 2.0
13.23k stars 7.18k forks source link

mDNS should be configurable via KConfig (IDFGH-2027) #4217

Closed atanisoft closed 4 years ago

atanisoft commented 4 years ago

Environment

Problem Description

mDNS task runs at a very low priority and pinned to core 0 (PRO_CPU). It would be good to make these options configurable via KConfig:

  1. task priority
  2. task pinned to core (0, 1, floating)
  3. mdns_service_add timeout (used here)
  4. expose MDNS_TIMER_PERIOD_US

Expected Behavior

Calling mdns_service_add should not timeout due to higher priority task running on the same core.

Actual Behavior

mdns_service_add returns ESP_FAIL on first call as seen in https://github.com/atanisoft/ESP32CommandStation/issues/26. When the API returns ESP_FAIL I've added a workaround to reschedule the call to mdns_service_add at a later time which returns ESP_OK.

Even with mdns_service_add() returning ESP_OK the service description is not seen from other devices (rPi as example):

pi@RPi-JMRI:~/openmrn $ avahi-browse -a -t -k
+  wlan0 IPv6 _openlcb-can._tcp                             _openlcb-can._tcp    local
+  wlan0 IPv4 _openlcb-can._tcp                             _openlcb-can._tcp    local
+  wlan0 IPv6 RPI-JMRI                                      _device-info._tcp    local
+  wlan0 IPv4 RPI-JMRI                                      _device-info._tcp    local
+  wlan0 IPv6 RPI-JMRI                                      _smb._tcp            local
+  wlan0 IPv4 RPI-JMRI                                      _smb._tcp            local

Steps to repropduce

in app_main() set the current task priority higher than 1 and not call vTaskDelay(), inside the code call mdns_service_add() and verify the return value.

Code to reproduce this issue

https://github.com/atanisoft/ESP32CommandStation/tree/development can be used to reproduce this by using PlatformIO to compile/flash it to the ESP32 using the default configuration settings.

no1seman commented 4 years ago

+1 and also need to make task stack size configurable

atanisoft commented 4 years ago

make task stack size configurable

I'm not certain it can be shrunk much unfortunately. There doesn't seem to be much need to increase it. But if you have a usecase for adjusting it then I'm all for the extra flexibility, I just haven't found one yet.

no1seman commented 4 years ago

@atanisoft, as for now it defined: #define MDNS_SERVICE_STACK_DEPTH 4096 in my case (4 registered services) I have never seen stack usage more than 50%: image

atanisoft commented 4 years ago

@no1seman makes sense, it could likely be dropped some in your case.

Can you share the code for generating the table with usage percent? I haven't been able to get the percentage to make much sense in my tests.

no1seman commented 4 years ago

@atanisoft , it's impossible for now, because there's to much dependencies in my project, but it's not so hrd to make, just look into tskTCB structure ($IDF_PATH/components/freertos/tasks.c) and you'll be able to make your own.