From da2feebc7310cc5d9e3d68c7a0a16ad915d5b75c Mon Sep 17 00:00:00 2001 From: Kevin Schoedel <67607049+kpschoedel@users.noreply.github.com> Date: Thu, 11 Nov 2021 11:29:52 -0500 Subject: [PATCH] Inet: Remove INET_CONFIG_MAX_DROPPABLE_EVENTS (#11675) #### Problem `INET_CONFIG_MAX_DROPPABLE_EVENTS` is not used anywhere; code that used it was removed by PR #1051 _Remove CHIP_SYSTEM_CONFIG_PROVIDE_OBSOLESCENT_INTERFACES_ over a year ago. #### Change overview Remove code controlled by `INET_CONFIG_MAX_DROPPABLE_EVENTS`. #### Testing CI; no changes to functionality. --- src/inet/InetConfig.h | 27 ----------- src/inet/InetLayer.cpp | 99 ---------------------------------------- src/inet/InetLayer.h | 68 --------------------------- src/inet/UDPEndPoint.cpp | 2 - 4 files changed, 196 deletions(-) diff --git a/src/inet/InetConfig.h b/src/inet/InetConfig.h index dc994ebd977268..37793a174b3d82 100644 --- a/src/inet/InetConfig.h +++ b/src/inet/InetConfig.h @@ -113,33 +113,6 @@ #define INET_CONFIG_WILL_OVERRIDE_LWIP_ERROR_FUNCS 0 #endif // INET_CONFIG_WILL_OVERRIDE_LWIP_ERROR_FUNCS -/** - * @def INET_CONFIG_MAX_DROPPABLE_EVENTS - * - * @brief - * This is the maximum number of UDP or raw network transport - * packet events / messages that may be dropped due to packet - * buffer starvation. - * - * In some implementations, there may be a shared event / message - * queue for the InetLayer used by other system events / messages. - * - * If the length of that queue is considerably longer than the - * number of packet buffers available, it may lead to buffer - * exhaustion. As a result, using the queue itself to implement - * backpressure is insufficient, and we need an external mechanism - * to prevent buffer starvation in the rest of the system and - * getting into deadlock situations. - * - * For both UDP and raw network transport traffic we can easily - * drop incoming packets without impacting the correctness of - * higher level protocols. - * - */ -#ifndef INET_CONFIG_MAX_DROPPABLE_EVENTS -#define INET_CONFIG_MAX_DROPPABLE_EVENTS 0 -#endif // INET_CONFIG_MAX_DROPPABLE_EVENTS - /** * @def INET_CONFIG_NUM_TCP_ENDPOINTS * diff --git a/src/inet/InetLayer.cpp b/src/inet/InetLayer.cpp index 54436d62e87d8a..7f5481b888511b 100644 --- a/src/inet/InetLayer.cpp +++ b/src/inet/InetLayer.cpp @@ -89,101 +89,6 @@ namespace Inet { */ InetLayer::InetLayer() {} -#if INET_CONFIG_MAX_DROPPABLE_EVENTS && CHIP_SYSTEM_CONFIG_USE_LWIP - -#if CHIP_SYSTEM_CONFIG_NO_LOCKING - -CHIP_ERROR InetLayer::InitQueueLimiter(void) -{ - mDroppableEvents = 0; - return CHIP_NO_ERROR; -} - -bool InetLayer::CanEnqueueDroppableEvent(void) -{ - if (__sync_add_and_fetch(&mDroppableEvents, 1) <= INET_CONFIG_MAX_DROPPABLE_EVENTS) - { - return true; - } - else - { - __sync_add_and_fetch(&mDroppableEvents, -1); - return false; - } -} - -void InetLayer::DroppableEventDequeued(void) -{ - __sync_add_and_fetch(&mDroppableEvents, -1); -} - -#elif CHIP_SYSTEM_CONFIG_FREERTOS_LOCKING - -CHIP_ERROR InetLayer::InitQueueLimiter(void) -{ - const unsigned portBASE_TYPE maximum = INET_CONFIG_MAX_DROPPABLE_EVENTS; - const unsigned portBASE_TYPE initial = INET_CONFIG_MAX_DROPPABLE_EVENTS; - -#if (configSUPPORT_STATIC_ALLOCATION == 1) - mDroppableEvents = xSemaphoreCreateCountingStatic(maximum, initial, &mDroppableEventsObj); -#else - mDroppableEvents = xSemaphoreCreateCounting(maximum, initial); -#endif - - if (mDroppableEvents != NULL) - return CHIP_NO_ERROR; - else - return CHIP_ERROR_NO_MEMORY; -} - -bool InetLayer::CanEnqueueDroppableEvent(void) -{ - if (xSemaphoreTake(mDroppableEvents, 0) != pdTRUE) - { - return false; - } - return true; -} - -void InetLayer::DroppableEventDequeued(void) -{ - xSemaphoreGive(mDroppableEvents); -} - -#else // !CHIP_SYSTEM_CONFIG_FREERTOS_LOCKING - -CHIP_ERROR InetLayer::InitQueueLimiter(void) -{ - if (sem_init(&mDroppableEvents, 0, INET_CONFIG_MAX_DROPPABLE_EVENTS) != 0) - { - return CHIP_ERROR_POSIX(errno); - } - return CHIP_NO_ERROR; -} - -bool InetLayer::CanEnqueueDroppableEvent(void) -{ - // Striclty speaking, we should check for EAGAIN. But, other - // errno values probably should signal that that we should drop - // the packet: EINVAL means that the semaphore is not valid (we - // failed initialization), and EINTR should probably also lead to - // dropping a packet. - - if (sem_trywait(&mDroppableEvents) != 0) - { - return false; - } - return true; -} - -void InetLayer::DroppableEventDequeued(void) -{ - sem_post(&mDroppableEvents); -} - -#endif // !CHIP_SYSTEM_CONFIG_FREERTOS_LOCKING -#endif // INET_CONFIG_MAX_DROPPABLE_EVENTS && CHIP_SYSTEM_CONFIG_USE_LWIP - /** * This is the InetLayer explicit initializer. This must be called * and complete successfully before the InetLayer may be used. @@ -224,10 +129,6 @@ CHIP_ERROR InetLayer::Init(chip::System::Layer & aSystemLayer, void * aContext) mSystemLayer = &aSystemLayer; mContext = aContext; -#if CHIP_SYSTEM_CONFIG_USE_LWIP - ReturnErrorOnFailure(InitQueueLimiter()); -#endif // CHIP_SYSTEM_CONFIG_USE_LWIP - mLayerState.SetInitialized(); return CHIP_NO_ERROR; diff --git a/src/inet/InetLayer.h b/src/inet/InetLayer.h index 57163ee7195c3d..5372f9c388d388 100644 --- a/src/inet/InetLayer.h +++ b/src/inet/InetLayer.h @@ -70,24 +70,6 @@ #include #include -#if INET_CONFIG_MAX_DROPPABLE_EVENTS - -#if CHIP_SYSTEM_CONFIG_POSIX_LOCKING -#include -#include -#endif // CHIP_SYSTEM_CONFIG_POSIX_LOCKING - -#if CHIP_SYSTEM_CONFIG_FREERTOS_LOCKING -#if defined(ESP_PLATFORM) -#include "freertos/FreeRTOS.h" -#else -#include -#endif -#include -#endif // CHIP_SYSTEM_CONFIG_FREERTOS_LOCKING - -#endif // INET_CONFIG_MAX_DROPPABLE_EVENTS - #include namespace chip { @@ -153,56 +135,6 @@ class DLL_EXPORT InetLayer void * GetPlatformData(); void SetPlatformData(void * aPlatformData); -#if CHIP_SYSTEM_CONFIG_USE_LWIP - // In some implementations, there may be a shared event / message - // queue for the InetLayer used by other system events / messages. - // - // If the length of that queue is considerably longer than the - // number of packet buffers available, it may lead to buffer - // exhaustion. As a result, using the queue itself to implement - // backpressure is insufficient, and we need an external mechanism - // to prevent buffer starvation in the rest of the system and - // getting into deadlock situations. - - // For both UDP and raw network transport traffic we can easily - // drop incoming packets without impacting the correctness of - // higher level protocols. - -#if INET_CONFIG_MAX_DROPPABLE_EVENTS - inline static bool IsDroppableEvent(chip::System::EventType type) - { - return -#if INET_CONFIG_ENABLE_UDP_ENDPOINT - type == kInetEvent_UDPDataReceived || -#endif // INET_CONFIG_ENABLE_UDP_ENDPOINT - false; - } - - CHIP_ERROR InitQueueLimiter(void); - bool CanEnqueueDroppableEvent(void); - void DroppableEventDequeued(void); - -#if CHIP_SYSTEM_CONFIG_NO_LOCKING - volatile int32_t mDroppableEvents; -#elif CHIP_SYSTEM_CONFIG_POSIX_LOCKING - sem_t mDroppableEvents; -#elif CHIP_SYSTEM_CONFIG_FREERTOS_LOCKING -#if (configSUPPORT_STATIC_ALLOCATION == 1) - StaticSemaphore_t mDroppableEventsObj; -#endif // (configSUPPORT_STATIC_ALLOCATION == 1) - SemaphoreHandle_t mDroppableEvents; -#endif // CHIP_SYSTEM_CONFIG_FREERTOS_LOCKING - -#else // !INET_CONFIG_MAX_DROPPABLE_EVENTS - - inline static bool IsDroppableEvent(chip::System::EventType aType) { return false; } - - inline CHIP_ERROR InitQueueLimiter(void) { return CHIP_NO_ERROR; } - inline bool CanEnqueueDroppableEvent(void) { return true; } - inline void DroppableEventDequeued(void) { return; } -#endif // !INET_CONFIG_MAX_DROPPABLE_EVENTS -#endif // CHIP_SYSTEM_CONFIG_USE_LWIP - #if INET_CONFIG_ENABLE_TCP_ENDPOINT && INET_TCP_IDLE_CHECK_INTERVAL > 0 static void HandleTCPInactivityTimer(chip::System::Layer * aSystemLayer, void * aAppState); #endif // INET_CONFIG_ENABLE_TCP_ENDPOINT && INET_TCP_IDLE_CHECK_INTERVAL > 0 diff --git a/src/inet/UDPEndPoint.cpp b/src/inet/UDPEndPoint.cpp index 0da5d8e8d6892c..a4caf5575aaf39 100644 --- a/src/inet/UDPEndPoint.cpp +++ b/src/inet/UDPEndPoint.cpp @@ -588,8 +588,6 @@ void UDPEndPoint::LwIPReceiveUDPMessage(void * arg, struct udp_pcb * pcb, struct ep->Retain(); CHIP_ERROR err = lSystemLayer->ScheduleLambda([ep, p = System::LwIPPacketBufferView::UnsafeGetLwIPpbuf(buf)] { ep->HandleDataReceived(System::PacketBufferHandle::Adopt(p)); - InetLayer & lInetLayer = ep->Layer(); - lInetLayer.DroppableEventDequeued(); ep->Release(); }); if (err == CHIP_NO_ERROR)