Skip to content

Commit

Permalink
Defining CHIP_SYSTEM_CONFIG_LWIP_PBUF_FROM_CUSTOM_POOL
Browse files Browse the repository at this point in the history
Some platforms do not use the lwip from third_party/lwip and may not
have LWIP_PBUF_FROM_CUSTOM_POOLS defined in lwip/opt.h. When building
apps with -Wundef cflag enabled, it may fail to find LWIP_PBUF_FROM_CUSTOM_POOLS
hence this option. This defaults to LWIP_PBUF_FROM_CUSTOM_POOLS if
defined, otherwise 0.
  • Loading branch information
shubhamdp committed May 15, 2024
1 parent 82cf04b commit 4781315
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/messaging/ReliableMessageProtocolConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,14 +129,14 @@ namespace chip {
#ifndef CHIP_CONFIG_RMP_RETRANS_TABLE_SIZE
#if CHIP_SYSTEM_CONFIG_USE_LWIP

#if !LWIP_PBUF_FROM_CUSTOM_POOLS && PBUF_POOL_SIZE != 0
#if !CHIP_SYSTEM_CONFIG_LWIP_PBUF_FROM_CUSTOM_POOL && PBUF_POOL_SIZE != 0
// Configure the table size to be less than the number of packet buffers to make sure
// that not all buffers are held by the retransmission entries, in which case the device
// is unable to receive an ACK and hence becomes unavailable until a message times out.
#define CHIP_CONFIG_RMP_RETRANS_TABLE_SIZE std::min(PBUF_POOL_SIZE - 1, CHIP_CONFIG_MAX_EXCHANGE_CONTEXTS)
#else
#define CHIP_CONFIG_RMP_RETRANS_TABLE_SIZE CHIP_CONFIG_MAX_EXCHANGE_CONTEXTS
#endif // !LWIP_PBUF_FROM_CUSTOM_POOLS && PBUF_POOL_SIZE != 0
#endif // !CHIP_SYSTEM_CONFIG_LWIP_PBUF_FROM_CUSTOM_POOL && PBUF_POOL_SIZE != 0

#else // CHIP_SYSTEM_CONFIG_USE_LWIP

Expand Down
17 changes: 17 additions & 0 deletions src/system/SystemConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -771,3 +771,20 @@ struct LwIPEvent;
#define CHIP_SYSTEM_CONFIG_USE_ZEPHYR_EVENTFD 0
#endif
#endif // CHIP_SYSTEM_CONFIG_USE_ZEPHYR_EVENTFD

/**
* @def CHIP_SYSTEM_CONFIG_LWIP_PBUF_FROM_CUSTOM_POOL
*
* @brief
* Enable the use of lwIP pbufs from a custom pool
*
* This config option exist because not all platforms defines LWIP_PBUF_FROM_CUSTOM_POOLS in lwip/opt.h
* Defaults to LWIP_PBUF_FROM_CUSTOM_POOLS if defined, otherwise 0
*/
#ifndef CHIP_SYSTEM_CONFIG_LWIP_PBUF_FROM_CUSTOM_POOL
#if defined(LWIP_PBUF_FROM_CUSTOM_POOLS)
#define CHIP_SYSTEM_CONFIG_LWIP_PBUF_FROM_CUSTOM_POOL LWIP_PBUF_FROM_CUSTOM_POOLS
#else
#define CHIP_SYSTEM_CONFIG_LWIP_PBUF_FROM_CUSTOM_POOL 0
#endif // LWIP_PBUF_FROM_CUSTOM_POOLS
#endif // CHIP_SYSTEM_CONFIG_LWIP_PBUF_FROM_CUSTOM_POOL
4 changes: 2 additions & 2 deletions src/system/SystemPacketBufferInternal.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
*
* True if packet buffers are allocated from an LwIP custom pool.
*/
#if CHIP_SYSTEM_PACKETBUFFER_FROM_LWIP_POOL && !LWIP_PBUF_FROM_CUSTOM_POOLS
#if CHIP_SYSTEM_PACKETBUFFER_FROM_LWIP_POOL && !CHIP_SYSTEM_CONFIG_LWIP_PBUF_FROM_CUSTOM_POOL
#define CHIP_SYSTEM_PACKETBUFFER_FROM_LWIP_STANDARD_POOL 1
#else
#define CHIP_SYSTEM_PACKETBUFFER_FROM_LWIP_STANDARD_POOL 0
Expand All @@ -93,7 +93,7 @@
*
* True if packet buffers are allocated from an LwIP custom pool.
*/
#if CHIP_SYSTEM_PACKETBUFFER_FROM_LWIP_POOL && LWIP_PBUF_FROM_CUSTOM_POOLS
#if CHIP_SYSTEM_PACKETBUFFER_FROM_LWIP_POOL && CHIP_SYSTEM_CONFIG_LWIP_PBUF_FROM_CUSTOM_POOL
#define CHIP_SYSTEM_PACKETBUFFER_FROM_LWIP_CUSTOM_POOL 1
#else
#define CHIP_SYSTEM_PACKETBUFFER_FROM_LWIP_CUSTOM_POOL 0
Expand Down
8 changes: 4 additions & 4 deletions src/system/SystemStats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ namespace System {
namespace Stats {

static const Label sStatsStrings[chip::System::Stats::kNumEntries] = {
#if CHIP_SYSTEM_CONFIG_USE_LWIP && LWIP_PBUF_FROM_CUSTOM_POOLS
#if CHIP_SYSTEM_CONFIG_USE_LWIP && CHIP_SYSTEM_CONFIG_LWIP_PBUF_FROM_CUSTOM_POOL
#define LWIP_PBUF_MEMPOOL(name, num, payload, desc) "SystemLayer_Num" desc,
#include "lwippools.h"
#undef LWIP_PBUF_MEMPOOL
Expand Down Expand Up @@ -107,7 +107,7 @@ bool Difference(Snapshot & result, Snapshot & after, Snapshot & before)

void UpdateLwipPbufCounts(void)
{
#if LWIP_PBUF_FROM_CUSTOM_POOLS
#if CHIP_SYSTEM_CONFIG_LWIP_PBUF_FROM_CUSTOM_POOL
size_t lwip_pool_idx = PBUF_CUSTOM_POOL_IDX_END;
size_t system_idx = 0;

Expand All @@ -119,12 +119,12 @@ void UpdateLwipPbufCounts(void)
system_idx++;
}

#else // LWIP_PBUF_FROM_CUSTOM_POOLS
#else // CHIP_SYSTEM_CONFIG_LWIP_PBUF_FROM_CUSTOM_POOL

chip::System::Stats::GetResourcesInUse()[kSystemLayer_NumPacketBufs] = MEMP_STATS_GET(used, MEMP_PBUF_POOL);
chip::System::Stats::GetHighWatermarks()[kSystemLayer_NumPacketBufs] = MEMP_STATS_GET(max, MEMP_PBUF_POOL);

#endif // LWIP_PBUF_FROM_CUSTOM_POOLS
#endif // CHIP_SYSTEM_CONFIG_LWIP_PBUF_FROM_CUSTOM_POOL
}
#endif // CHIP_SYSTEM_CONFIG_USE_LWIP && LWIP_STATS && MEMP_STATS

Expand Down
2 changes: 1 addition & 1 deletion src/system/SystemStats.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ namespace Stats {

enum
{
#if CHIP_SYSTEM_CONFIG_USE_LWIP && LWIP_PBUF_FROM_CUSTOM_POOLS
#if CHIP_SYSTEM_CONFIG_USE_LWIP && CHIP_SYSTEM_CONFIG_LWIP_PBUF_FROM_CUSTOM_POOL
#define LWIP_PBUF_MEMPOOL(name, num, payload, desc) kSystemLayer_Num##name,
#include "lwippools.h"
#undef LWIP_PBUF_MEMPOOL
Expand Down

0 comments on commit 4781315

Please sign in to comment.