Skip to content

Commit

Permalink
Inet/(TCP/UDP)Endpoints: Migrate from SystemPool to BitMapObjectPool (#…
Browse files Browse the repository at this point in the history
…11428)

* Migrate inet/endpoints to BitMapPool

* Remove atomic
  • Loading branch information
kghost authored Nov 8, 2021
1 parent a93a7da commit 5c73522
Show file tree
Hide file tree
Showing 26 changed files with 143 additions and 427 deletions.
1 change: 1 addition & 0 deletions src/app/tests/integration/chip_im_initiator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,7 @@ int main(int argc, char * argv[])
chip::DeviceLayer::PlatformMgr().RunEventLoop();

chip::app::InteractionModelEngine::GetInstance()->Shutdown();
gTransportManager.Close();
ShutdownChip();
exit:
if (err != CHIP_NO_ERROR || (gCommandRespCount != kMaxCommandMessageCount + kTotalFailureCommandMessageCount))
Expand Down
2 changes: 1 addition & 1 deletion src/app/tests/integration/chip_im_responder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ int main(int argc, char * argv[])
}

chip::app::InteractionModelEngine::GetInstance()->Shutdown();

gTransportManager.Close();
ShutdownChip();

return EXIT_SUCCESS;
Expand Down
9 changes: 3 additions & 6 deletions src/include/platform/CHIPDeviceEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,9 @@ typedef void (*AsyncWorkFunct)(intptr_t arg);
#include <ble/BleConfig.h>
#include <inet/InetLayer.h>
#include <lib/support/LambdaBridge.h>
#include <system/SystemEvent.h>
#include <system/SystemLayer.h>
#include <system/SystemPacketBuffer.h>

namespace chip {
namespace DeviceLayer {
Expand All @@ -331,12 +334,6 @@ struct ChipDeviceEvent final
ChipDevicePlatformEvent Platform;
LambdaBridge LambdaEvent;
struct
{
::chip::System::EventType Type;
::chip::System::Object * Target;
uintptr_t Argument;
} ChipSystemLayerEvent;
struct
{
AsyncWorkFunct WorkFunct;
intptr_t Arg;
Expand Down
23 changes: 0 additions & 23 deletions src/include/platform/internal/GenericPlatformManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,11 +221,6 @@ void GenericPlatformManagerImpl<ImplClass>::_DispatchEvent(const ChipDeviceEvent
// Do nothing for no-op events.
break;

case DeviceEventType::kChipSystemLayerEvent:
// If the event is a CHIP System or Inet Layer event, deliver it to the System::Layer event handler.
Impl()->DispatchEventToSystemLayer(event);
break;

case DeviceEventType::kChipLambdaEvent:
event->LambdaEvent();
break;
Expand Down Expand Up @@ -259,24 +254,6 @@ void GenericPlatformManagerImpl<ImplClass>::_DispatchEvent(const ChipDeviceEvent
#endif // CHIP_PROGRESS_LOGGING
}

template <class ImplClass>
void GenericPlatformManagerImpl<ImplClass>::DispatchEventToSystemLayer(const ChipDeviceEvent * event)
{
// TODO(#788): remove ifdef LWIP once System::Layer event APIs are generally available
#if CHIP_SYSTEM_CONFIG_USE_LWIP
CHIP_ERROR err = CHIP_NO_ERROR;

// Invoke the System Layer's event handler function.
err = static_cast<System::LayerImplLwIP &>(SystemLayer())
.HandleEvent(*event->ChipSystemLayerEvent.Target, event->ChipSystemLayerEvent.Type,
event->ChipSystemLayerEvent.Argument);
if (err != CHIP_NO_ERROR)
{
ChipLogError(DeviceLayer, "Error handling CHIP System Layer event (type %d): %s", event->Type, ErrorStr(err));
}
#endif
}

template <class ImplClass>
void GenericPlatformManagerImpl<ImplClass>::DispatchEventToDeviceLayer(const ChipDeviceEvent * event)
{
Expand Down
1 change: 0 additions & 1 deletion src/include/platform/internal/GenericPlatformManagerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ class GenericPlatformManagerImpl

// ===== Support methods that can be overridden by the implementation subclass.

void DispatchEventToSystemLayer(const ChipDeviceEvent * event);
void DispatchEventToDeviceLayer(const ChipDeviceEvent * event);
void DispatchEventToApplication(const ChipDeviceEvent * event);
static void HandleMessageLayerActivityChanged(bool messageLayerIsActive);
Expand Down
1 change: 0 additions & 1 deletion src/inet/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ static_library("inet") {
"InetInterface.h",
"InetLayer.cpp",
"InetLayer.h",
"InetLayerEvents.h",
"arpa-inet-compatibility.h",
]

Expand Down
22 changes: 0 additions & 22 deletions src/inet/EndPointBasis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,6 @@ void EndPointBasis::InitEndPointBasis(InetLayer & aInetLayer, void * aAppState)
mLwIPEndPointType = LwIPEndPointType::Unknown;
}

void EndPointBasis::DeferredFree(System::Object::ReleaseDeferralErrorTactic aTactic)
{
if (!CHIP_SYSTEM_CONFIG_USE_SOCKETS || (mVoid != nullptr))
{
DeferredRelease(static_cast<System::LayerLwIP *>(Layer().SystemLayer()), aTactic);
}
else
{
Release();
}
}

#endif // CHIP_SYSTEM_CONFIG_USE_LWIP

#if CHIP_SYSTEM_CONFIG_USE_SOCKETS
Expand All @@ -62,11 +50,6 @@ void EndPointBasis::InitEndPointBasis(InetLayer & aInetLayer, void * aAppState)
mSocket = kInvalidSocketFd;
}

void EndPointBasis::DeferredFree(System::Object::ReleaseDeferralErrorTactic aTactic)
{
Release();
}

#endif // CHIP_SYSTEM_CONFIG_USE_SOCKETS

#if CHIP_SYSTEM_CONFIG_USE_NETWORK_FRAMEWORK
Expand All @@ -77,11 +60,6 @@ void EndPointBasis::InitEndPointBasis(InetLayer & aInetLayer, void * aAppState)
mInetLayer = &aInetLayer;
}

void EndPointBasis::DeferredFree(System::Object::ReleaseDeferralErrorTactic aTactic)
{
Release();
}

#endif // CHIP_SYSTEM_CONFIG_USE_NETWORK_FRAMEWORK

} // namespace Inet
Expand Down
7 changes: 3 additions & 4 deletions src/inet/EndPointBasis.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@

#include <inet/IPAddress.h>
#include <lib/support/DLLUtil.h>
#include <system/SystemObject.h>

#if CHIP_SYSTEM_CONFIG_USE_SOCKETS
#include <system/SocketEvents.h>
Expand All @@ -51,7 +50,7 @@ class InetLayer;
/**
* Basis of internet transport endpoint classes.
*/
class DLL_EXPORT EndPointBasis : public System::Object
class DLL_EXPORT EndPointBasis
{
public:
/**
Expand All @@ -68,12 +67,13 @@ class DLL_EXPORT EndPointBasis : public System::Object
*/
bool IsCreatedByInetLayer(const InetLayer & aInetLayer) const { return mInetLayer == &aInetLayer; }

void * AppState;

private:
InetLayer * mInetLayer; /**< Pointer to the InetLayer object that owns this object. */

protected:
void InitEndPointBasis(InetLayer & aInetLayer, void * aAppState = nullptr);
void DeferredFree(System::Object::ReleaseDeferralErrorTactic aTactic);

#if CHIP_SYSTEM_CONFIG_USE_NETWORK_FRAMEWORK
nw_parameters_t mParameters;
Expand All @@ -91,7 +91,6 @@ class DLL_EXPORT EndPointBasis : public System::Object
/** Encapsulated LwIP protocol control block */
union
{
const void * mVoid; /**< An untyped protocol control buffer reference */
#if INET_CONFIG_ENABLE_UDP_ENDPOINT
udp_pcb * mUDP; /**< User datagram protocol (UDP) control */
#endif // INET_CONFIG_ENABLE_UDP_ENDPOINT
Expand Down
1 change: 0 additions & 1 deletion src/inet/Inet.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
#include <inet/InetError.h>
#include <inet/InetInterface.h>
#include <inet/InetLayer.h>
#include <inet/InetLayerEvents.h>

#if INET_CONFIG_ENABLE_TCP_ENDPOINT
#include <inet/TCPEndPoint.h>
Expand Down
1 change: 0 additions & 1 deletion src/inet/InetInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
#include "InetInterface.h"

#include "InetLayer.h"
#include "InetLayerEvents.h"

#include <lib/support/CHIPMemString.h>
#include <lib/support/CodeUtils.h>
Expand Down
88 changes: 3 additions & 85 deletions src/inet/InetLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,18 +79,6 @@
namespace chip {
namespace Inet {

void InetLayer::UpdateSnapshot(chip::System::Stats::Snapshot & aSnapshot)
{
#if INET_CONFIG_ENABLE_TCP_ENDPOINT
TCPEndPoint::sPool.GetStatistics(aSnapshot.mResourcesInUse[chip::System::Stats::kInetLayer_NumTCPEps],
aSnapshot.mHighWatermarks[chip::System::Stats::kInetLayer_NumTCPEps]);
#endif // INET_CONFIG_ENABLE_TCP_ENDPOINT
#if INET_CONFIG_ENABLE_UDP_ENDPOINT
UDPEndPoint::sPool.GetStatistics(aSnapshot.mResourcesInUse[chip::System::Stats::kInetLayer_NumUDPEps],
aSnapshot.mHighWatermarks[chip::System::Stats::kInetLayer_NumUDPEps]);
#endif // INET_CONFIG_ENABLE_UDP_ENDPOINT
}

/**
* This is the InetLayer default constructor.
*
Expand All @@ -99,17 +87,7 @@ void InetLayer::UpdateSnapshot(chip::System::Stats::Snapshot & aSnapshot)
* method must be called successfully prior to using the object.
*
*/
InetLayer::InetLayer()
{
#if CHIP_SYSTEM_CONFIG_USE_LWIP
if (!sInetEventHandlerDelegate.IsInitialized())
sInetEventHandlerDelegate.Init(HandleInetLayerEvent);
#endif // CHIP_SYSTEM_CONFIG_USE_LWIP
}

#if CHIP_SYSTEM_CONFIG_USE_LWIP
chip::System::LayerLwIP::EventHandlerDelegate InetLayer::sInetEventHandlerDelegate;
#endif // CHIP_SYSTEM_CONFIG_USE_LWIP
InetLayer::InetLayer() {}

#if INET_CONFIG_MAX_DROPPABLE_EVENTS && CHIP_SYSTEM_CONFIG_USE_LWIP

Expand Down Expand Up @@ -248,8 +226,6 @@ CHIP_ERROR InetLayer::Init(chip::System::Layer & aSystemLayer, void * aContext)

#if CHIP_SYSTEM_CONFIG_USE_LWIP
ReturnErrorOnFailure(InitQueueLimiter());

static_cast<System::LayerLwIP *>(mSystemLayer)->AddEventHandlerDelegate(sInetEventHandlerDelegate);
#endif // CHIP_SYSTEM_CONFIG_USE_LWIP

mLayerState.SetInitialized();
Expand Down Expand Up @@ -453,7 +429,7 @@ CHIP_ERROR InetLayer::NewTCPEndPoint(TCPEndPoint ** retEndPoint)

VerifyOrReturnError(mLayerState.IsInitialized(), CHIP_ERROR_INCORRECT_STATE);

*retEndPoint = TCPEndPoint::sPool.TryCreate();
*retEndPoint = TCPEndPoint::sPool.CreateObject();
if (*retEndPoint == nullptr)
{
ChipLogError(Inet, "%s endpoint pool FULL", "TCP");
Expand Down Expand Up @@ -493,7 +469,7 @@ CHIP_ERROR InetLayer::NewUDPEndPoint(UDPEndPoint ** retEndPoint)

VerifyOrReturnError(mLayerState.IsInitialized(), CHIP_ERROR_INCORRECT_STATE);

*retEndPoint = UDPEndPoint::sPool.TryCreate();
*retEndPoint = UDPEndPoint::sPool.CreateObject();
if (*retEndPoint == nullptr)
{
ChipLogError(Inet, "%s endpoint pool FULL", "UDP");
Expand Down Expand Up @@ -609,64 +585,6 @@ void InetLayer::HandleTCPInactivityTimer(chip::System::Layer * aSystemLayer, voi
}
#endif // INET_CONFIG_ENABLE_TCP_ENDPOINT && INET_TCP_IDLE_CHECK_INTERVAL > 0

#if CHIP_SYSTEM_CONFIG_USE_LWIP
CHIP_ERROR InetLayer::HandleInetLayerEvent(chip::System::Object & aTarget, chip::System::EventType aEventType, uintptr_t aArgument)
{
assertChipStackLockedByCurrentThread();

VerifyOrReturnError(INET_IsInetEvent(aEventType), CHIP_ERROR_UNEXPECTED_EVENT);

// Dispatch the event according to its type.
switch (aEventType)
{
#if INET_CONFIG_ENABLE_TCP_ENDPOINT
case kInetEvent_TCPConnectComplete:
static_cast<TCPEndPoint &>(aTarget).HandleConnectComplete(static_cast<CHIP_ERROR>(aArgument));
break;

case kInetEvent_TCPConnectionReceived:
static_cast<TCPEndPoint &>(aTarget).HandleIncomingConnection(reinterpret_cast<TCPEndPoint *>(aArgument));
break;

case kInetEvent_TCPDataReceived:
static_cast<TCPEndPoint &>(aTarget).HandleDataReceived(
System::PacketBufferHandle::Adopt(reinterpret_cast<chip::System::PacketBuffer *>(aArgument)));
break;

case kInetEvent_TCPDataSent:
static_cast<TCPEndPoint &>(aTarget).HandleDataSent(static_cast<uint16_t>(aArgument));
break;

case kInetEvent_TCPError:
static_cast<TCPEndPoint &>(aTarget).HandleError(static_cast<CHIP_ERROR>(aArgument));
break;
#endif // INET_CONFIG_ENABLE_TCP_ENDPOINT

#if INET_CONFIG_ENABLE_UDP_ENDPOINT
case kInetEvent_UDPDataReceived:
static_cast<UDPEndPoint &>(aTarget).HandleDataReceived(
System::PacketBufferHandle::Adopt(reinterpret_cast<chip::System::PacketBuffer *>(aArgument)));
break;
#endif // INET_CONFIG_ENABLE_UDP_ENDPOINT

default:
return CHIP_ERROR_UNEXPECTED_EVENT;
}

// If the event was droppable, record the fact that it has been dequeued.
if (IsDroppableEvent(aEventType))
{
EndPointBasis & lBasis = static_cast<EndPointBasis &>(aTarget);
InetLayer & lInetLayer = lBasis.Layer();

lInetLayer.DroppableEventDequeued();
}

return CHIP_NO_ERROR;
}

#endif // CHIP_SYSTEM_CONFIG_USE_LWIP

/**
* Reset the members of the IPPacketInfo object.
*
Expand Down
7 changes: 0 additions & 7 deletions src/inet/InetLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
#include <inet/IPPrefix.h>
#include <inet/InetError.h>
#include <inet/InetInterface.h>
#include <inet/InetLayerEvents.h>

#if INET_CONFIG_ENABLE_TCP_ENDPOINT
#include <inet/TCPEndPoint.h>
Expand Down Expand Up @@ -151,16 +150,10 @@ class DLL_EXPORT InetLayer
CHIP_ERROR GetLinkLocalAddr(InterfaceId link, IPAddress * llAddr);
bool MatchLocalIPv6Subnet(const IPAddress & addr);

static void UpdateSnapshot(chip::System::Stats::Snapshot & aSnapshot);

void * GetPlatformData();
void SetPlatformData(void * aPlatformData);

#if CHIP_SYSTEM_CONFIG_USE_LWIP
static CHIP_ERROR HandleInetLayerEvent(chip::System::Object & aTarget, chip::System::EventType aEventType, uintptr_t aArgument);

static chip::System::LayerLwIP::EventHandlerDelegate sInetEventHandlerDelegate;

// In some implementations, there may be a shared event / message
// queue for the InetLayer used by other system events / messages.
//
Expand Down
Loading

0 comments on commit 5c73522

Please sign in to comment.