optimization config option LWIP_TCPIP_CORE_LOCKING

This commit is contained in:
xueyunfei 2020-12-29 16:10:37 +08:00 committed by David Čermák
parent f40bbb01f2
commit 0d07569fff
4 changed files with 28 additions and 3 deletions

View File

@ -101,11 +101,13 @@ extern sys_thread_t g_lwip_task;
static const char *TAG = "esp_netif_lwip"; static const char *TAG = "esp_netif_lwip";
static sys_sem_t api_sync_sem = NULL;
static sys_sem_t api_lock_sem = NULL;
static bool tcpip_initialized = false; static bool tcpip_initialized = false;
static esp_netif_t *s_last_default_esp_netif = NULL; static esp_netif_t *s_last_default_esp_netif = NULL;
#if !LWIP_TCPIP_CORE_LOCKING
static sys_sem_t api_sync_sem = NULL;
static sys_sem_t api_lock_sem = NULL;
/** /**
* @brief Api callback from tcpip thread used to call esp-netif * @brief Api callback from tcpip thread used to call esp-netif
* function in lwip task context * function in lwip task context
@ -124,6 +126,7 @@ static void esp_netif_api_cb(void *api_msg)
sys_sem_signal(&api_sync_sem); sys_sem_signal(&api_sync_sem);
} }
#endif
/** /**
* @brief Initiates a tcpip remote call if called from another task * @brief Initiates a tcpip remote call if called from another task
@ -136,6 +139,7 @@ static inline esp_err_t esp_netif_lwip_ipc_call(esp_netif_api_fn fn, esp_netif_t
.data = data, .data = data,
.api_fn = fn .api_fn = fn
}; };
#if !LWIP_TCPIP_CORE_LOCKING
if (g_lwip_task != xTaskGetCurrentTaskHandle()) { if (g_lwip_task != xTaskGetCurrentTaskHandle()) {
ESP_LOGD(TAG, "check: remote, if=%p fn=%p\n", netif, fn); ESP_LOGD(TAG, "check: remote, if=%p fn=%p\n", netif, fn);
sys_arch_sem_wait(&api_lock_sem, 0); sys_arch_sem_wait(&api_lock_sem, 0);
@ -143,6 +147,7 @@ static inline esp_err_t esp_netif_lwip_ipc_call(esp_netif_api_fn fn, esp_netif_t
sys_sem_signal(&api_lock_sem); sys_sem_signal(&api_lock_sem);
return msg.ret; return msg.ret;
} }
#endif /* !LWIP_TCPIP_CORE_LOCKING */
ESP_LOGD(TAG, "check: local, if=%p fn=%p\n", netif, fn); ESP_LOGD(TAG, "check: local, if=%p fn=%p\n", netif, fn);
return fn(&msg); return fn(&msg);
} }
@ -324,6 +329,7 @@ esp_err_t esp_netif_init(void)
ESP_LOGD(TAG, "LwIP stack has been initialized"); ESP_LOGD(TAG, "LwIP stack has been initialized");
} }
#if !LWIP_TCPIP_CORE_LOCKING
if (!api_sync_sem) { if (!api_sync_sem) {
if (ERR_OK != sys_sem_new(&api_sync_sem, 0)) { if (ERR_OK != sys_sem_new(&api_sync_sem, 0)) {
ESP_LOGE(TAG, "esp netif api sync sem init fail"); ESP_LOGE(TAG, "esp netif api sync sem init fail");
@ -337,6 +343,7 @@ esp_err_t esp_netif_init(void)
return ESP_FAIL; return ESP_FAIL;
} }
} }
#endif
ESP_LOGD(TAG, "esp-netif has been successfully initialized"); ESP_LOGD(TAG, "esp-netif has been successfully initialized");
return ESP_OK; return ESP_OK;

View File

@ -52,7 +52,11 @@
#define ESP_TASK_TIMER_PRIO (ESP_TASK_PRIO_MAX - 3) #define ESP_TASK_TIMER_PRIO (ESP_TASK_PRIO_MAX - 3)
#define ESP_TASK_TIMER_STACK (CONFIG_ESP_TIMER_TASK_STACK_SIZE + TASK_EXTRA_STACK_SIZE) #define ESP_TASK_TIMER_STACK (CONFIG_ESP_TIMER_TASK_STACK_SIZE + TASK_EXTRA_STACK_SIZE)
#define ESP_TASKD_EVENT_PRIO (ESP_TASK_PRIO_MAX - 5) #define ESP_TASKD_EVENT_PRIO (ESP_TASK_PRIO_MAX - 5)
#if CONFIG_LWIP_TCPIP_CORE_LOCKING
#define ESP_TASKD_EVENT_STACK (CONFIG_ESP_SYSTEM_EVENT_TASK_STACK_SIZE + TASK_EXTRA_STACK_SIZE + 2048)
#else
#define ESP_TASKD_EVENT_STACK (CONFIG_ESP_SYSTEM_EVENT_TASK_STACK_SIZE + TASK_EXTRA_STACK_SIZE) #define ESP_TASKD_EVENT_STACK (CONFIG_ESP_SYSTEM_EVENT_TASK_STACK_SIZE + TASK_EXTRA_STACK_SIZE)
#endif /* CONFIG_LWIP_TCPIP_CORE_LOCKING */
#define ESP_TASK_TCPIP_PRIO (ESP_TASK_PRIO_MAX - 7) #define ESP_TASK_TCPIP_PRIO (ESP_TASK_PRIO_MAX - 7)
#define ESP_TASK_TCPIP_STACK (CONFIG_LWIP_TCPIP_TASK_STACK_SIZE + TASK_EXTRA_STACK_SIZE) #define ESP_TASK_TCPIP_STACK (CONFIG_LWIP_TCPIP_TASK_STACK_SIZE + TASK_EXTRA_STACK_SIZE)
#define ESP_TASK_MAIN_PRIO (ESP_TASK_PRIO_MIN + 1) #define ESP_TASK_MAIN_PRIO (ESP_TASK_PRIO_MIN + 1)

View File

@ -15,6 +15,16 @@ menu "LWIP"
could be used to convert network interface index to name could be used to convert network interface index to name
instead of IDF specific esp-netif APIs (such as esp_netif_get_netif_impl_name()) instead of IDF specific esp-netif APIs (such as esp_netif_get_netif_impl_name())
config LWIP_TCPIP_CORE_LOCKING
bool "Enable tcpip core locking"
default n
help
If Enable tcpip core locking,Creates a global mutex that is held
during TCPIP thread operations.Can be locked by client code to perform
lwIP operations without changing into TCPIP thread using callbacks.
See LOCK_TCPIP_CORE() and UNLOCK_TCPIP_CORE().
If disable tcpip core locking,TCP IP will perform tasks through context switching
config LWIP_DNS_SUPPORT_MDNS_QUERIES config LWIP_DNS_SUPPORT_MDNS_QUERIES
bool "Enable mDNS queries in resolving host name" bool "Enable mDNS queries in resolving host name"

View File

@ -595,7 +595,7 @@
* LWIP_TCPIP_CORE_LOCKING: (EXPERIMENTAL!) * LWIP_TCPIP_CORE_LOCKING: (EXPERIMENTAL!)
* Don't use it if you're not an active lwIP project member * Don't use it if you're not an active lwIP project member
*/ */
#define LWIP_TCPIP_CORE_LOCKING 0 #define LWIP_TCPIP_CORE_LOCKING CONFIG_LWIP_TCPIP_CORE_LOCKING
/* /*
------------------------------------ ------------------------------------
@ -1044,7 +1044,11 @@
#define CHECKSUM_CHECK_ICMP CONFIG_LWIP_CHECKSUM_CHECK_ICMP #define CHECKSUM_CHECK_ICMP CONFIG_LWIP_CHECKSUM_CHECK_ICMP
#define LWIP_NETCONN_FULLDUPLEX 1 #define LWIP_NETCONN_FULLDUPLEX 1
#if LWIP_TCPIP_CORE_LOCKING
#define LWIP_NETCONN_SEM_PER_THREAD 0
#else
#define LWIP_NETCONN_SEM_PER_THREAD 1 #define LWIP_NETCONN_SEM_PER_THREAD 1
#endif /* LWIP_TCPIP_CORE_LOCKING */
#define LWIP_DHCP_MAX_NTP_SERVERS CONFIG_LWIP_DHCP_MAX_NTP_SERVERS #define LWIP_DHCP_MAX_NTP_SERVERS CONFIG_LWIP_DHCP_MAX_NTP_SERVERS
#define LWIP_TIMEVAL_PRIVATE 0 #define LWIP_TIMEVAL_PRIVATE 0