Skip to content

Commit

Permalink
Inet: Remove INET_CONFIG_MAX_DROPPABLE_EVENTS (#11675)
Browse files Browse the repository at this point in the history
#### 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.
  • Loading branch information
kpschoedel authored and pull[bot] committed Mar 31, 2022
1 parent 077a4ec commit da2feeb
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 196 deletions.
27 changes: 0 additions & 27 deletions src/inet/InetConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
99 changes: 0 additions & 99 deletions src/inet/InetLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
Expand Down
68 changes: 0 additions & 68 deletions src/inet/InetLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,24 +70,6 @@
#include <lib/support/DLLUtil.h>
#include <lib/support/ObjectLifeCycle.h>

#if INET_CONFIG_MAX_DROPPABLE_EVENTS

#if CHIP_SYSTEM_CONFIG_POSIX_LOCKING
#include <pthread.h>
#include <semaphore.h>
#endif // CHIP_SYSTEM_CONFIG_POSIX_LOCKING

#if CHIP_SYSTEM_CONFIG_FREERTOS_LOCKING
#if defined(ESP_PLATFORM)
#include "freertos/FreeRTOS.h"
#else
#include <FreeRTOS.h>
#endif
#include <semphr.h>
#endif // CHIP_SYSTEM_CONFIG_FREERTOS_LOCKING

#endif // INET_CONFIG_MAX_DROPPABLE_EVENTS

#include <stdint.h>

namespace chip {
Expand Down Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions src/inet/UDPEndPoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit da2feeb

Please sign in to comment.