Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tl321x_retention: add config for packet buffer optimization #354

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion config/telink/chip-module/Kconfig.defaults
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ config HEAP_MEM_POOL_SIZE

# need to enlarge to 21000 , to pass TC_RR_1.1
config COMMON_LIBC_MALLOC_ARENA_SIZE
default 21000 if SOC_RISCV_TELINK_TL321X || SOC_SERIES_RISCV_TELINK_B9X_RETENTION
default 12288 if SOC_RISCV_TELINK_TL321X || SOC_SERIES_RISCV_TELINK_B9X_RETENTION
default 12288

config NET_IPV6_MLD
Expand Down Expand Up @@ -329,6 +329,16 @@ config OPENTHREAD_CSMABACKOFF_OPTIMIZATION
default n if SOC_SERIES_RISCV_TELINK_TLX_RETENTION || SOC_SERIES_RISCV_TELINK_B9X_RETENTION
default n

config ZEPHYR_NETBUFFER_OPTIMIZATION
bool "move the net buffer from iram to dram"
default y if SOC_SERIES_RISCV_TELINK_TLX_RETENTION || SOC_SERIES_RISCV_TELINK_B9X_RETENTION
default n

config CHIP_PACKETBUFFER_OPTIMIZATION
bool "move the packet buffer from iram to dram"
default y if SOC_SERIES_RISCV_TELINK_TLX_RETENTION || SOC_SERIES_RISCV_TELINK_B9X_RETENTION
default n

config OPENTHREAD_THREAD_STACK_SIZE
default 2400 if PM || SOC_RISCV_TELINK_TL321X

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ extern "C" void otSysProcessDrivers(otInstance * aInstance);
#if CHIP_DEVICE_CONFIG_THREAD_ENABLE_CLI
extern "C" void otAppCliInit(otInstance * aInstance);
#endif
#if defined(CONFIG_CHIP_PACKETBUFFER_OPTIMIZATION) && CONFIG_CHIP_PACKETBUFFER_OPTIMIZATION
extern "C" {
extern char packetBufferThreadFlag;
}
#endif /* CONFIG_CHIP_PACKETBUFFER_OPTIMIZATION */

namespace chip {
namespace DeviceLayer {
Expand Down Expand Up @@ -371,6 +376,13 @@ bool GenericThreadStackManagerImpl_OpenThread<ImplClass>::_IsThreadAttached()
Impl()->LockThreadStack();
curRole = otThreadGetDeviceRole(mOTInst);
Impl()->UnlockThreadStack();
#if defined(CONFIG_CHIP_PACKETBUFFER_OPTIMIZATION) && CONFIG_CHIP_PACKETBUFFER_OPTIMIZATION
if((curRole != OT_DEVICE_ROLE_DISABLED && curRole != OT_DEVICE_ROLE_DETACHED))
{
if(packetBufferThreadFlag==0)
packetBufferThreadFlag = 1;
}
#endif /* CONFIG_CHIP_PACKETBUFFER_OPTIMIZATION */

return (curRole != OT_DEVICE_ROLE_DISABLED && curRole != OT_DEVICE_ROLE_DETACHED);
}
Expand Down
7 changes: 6 additions & 1 deletion src/platform/telink/BLEManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@

extern "C" {
extern __attribute__((noinline)) void telink_bt_blc_mac_init(uint8_t * bt_mac);
#if defined(CONFIG_CHIP_PACKETBUFFER_OPTIMIZATION) && CONFIG_CHIP_PACKETBUFFER_OPTIMIZATION
extern char packetBufferBLEFlag;
#endif /* CONFIG_CHIP_PACKETBUFFER_OPTIMIZATION */
}

#if defined(CONFIG_PM) && !defined(CONFIG_CHIP_ENABLE_PM_DURING_BLE)
Expand Down Expand Up @@ -951,7 +954,9 @@ void BLEManagerImpl::SwitchToIeee802154(void)
// Deinit BLE
bt_disable();
mBLERadioInitialized = false;

#if defined(CONFIG_CHIP_PACKETBUFFER_OPTIMIZATION) && CONFIG_CHIP_PACKETBUFFER_OPTIMIZATION
packetBufferBLEFlag = 1;
#endif /* CONFIG_CHIP_PACKETBUFFER_OPTIMIZATION */
#if defined(CONFIG_PM) && !defined(CONFIG_CHIP_ENABLE_PM_DURING_BLE)
pm_policy_state_lock_put(PM_STATE_SUSPEND_TO_IDLE, PM_ALL_SUBSTATES);
#endif
Expand Down
9 changes: 9 additions & 0 deletions src/platform/telink/SystemPlatformConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,13 @@ struct ChipDeviceEvent;
#endif // CHIP_SYSTEM_CONFIG_USE_POSIX_TIME_FUNCTS

#if defined(CONFIG_SOC_RISCV_TELINK_TL321X) || defined(CONFIG_SOC_SERIES_RISCV_TELINK_B9X_RETENTION)
#if defined(CONFIG_CHIP_PACKETBUFFER_OPTIMIZATION) && CONFIG_CHIP_PACKETBUFFER_OPTIMIZATION
#define CHIP_SYSTEM_PACKETBUFFER_FROM_CHIP_HEAP 0
#define CHIP_SYSTEM_PACKETBUFFER_FROM_CHIP_POOL 1
#else /* !CONFIG_CHIP_PACKETBUFFER_OPTIMIZATION */
#define CHIP_SYSTEM_PACKETBUFFER_FROM_CHIP_HEAP 1
#define CHIP_SYSTEM_PACKETBUFFER_FROM_CHIP_POOL 0
#endif /* CONFIG_CHIP_PACKETBUFFER_OPTIMIZATION */
#define CHIP_SYSTEM_CONFIG_POOL_USE_HEAP 1
#define CHIP_SYSTEM_CONFIG_PACKETBUFFER_CAPACITY_MAX 1280
#endif
Expand All @@ -56,7 +61,11 @@ struct ChipDeviceEvent;

// Reduce packet buffer pool size (default 15) to reduce ram consumption
#if defined CONFIG_PM || defined CONFIG_SOC_RISCV_TELINK_TL321X
#if defined(CONFIG_CHIP_PACKETBUFFER_OPTIMIZATION) && CONFIG_CHIP_PACKETBUFFER_OPTIMIZATION
#define CHIP_SYSTEM_CONFIG_PACKETBUFFER_POOL_SIZE 6
#else /* !CONFIG_CHIP_PACKETBUFFER_OPTIMIZATION */
#define CHIP_SYSTEM_CONFIG_PACKETBUFFER_POOL_SIZE 0
#endif /* CONFIG_CHIP_PACKETBUFFER_OPTIMIZATION */
#else
#define CHIP_SYSTEM_CONFIG_PACKETBUFFER_POOL_SIZE 8
#endif
Expand Down
52 changes: 52 additions & 0 deletions src/system/SystemPacketBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,17 @@
#include <stdlib.h>
#include <string.h>
#include <utility>
#if defined(CONFIG_CHIP_PACKETBUFFER_OPTIMIZATION) && CONFIG_CHIP_PACKETBUFFER_OPTIMIZATION
extern "C"
{
char packetBufferBLEFlag=0;
char packetBufferThreadFlag=0;
extern unsigned int _RAMCODE_BLE_VMA_START;
extern unsigned int _RAMCODE_BLE_LMA_START;

}
#endif /* CONFIG_CHIP_PACKETBUFFER_OPTIMIZATION */


#if CHIP_SYSTEM_CONFIG_USE_LWIP
#include <lwip/mem.h>
Expand All @@ -66,7 +77,12 @@ namespace System {
// Pool allocation for PacketBuffer objects.
//

#if defined(CONFIG_CHIP_PACKETBUFFER_OPTIMIZATION) && CONFIG_CHIP_PACKETBUFFER_OPTIMIZATION
PacketBuffer::BufferPoolElement * PacketBuffer::sFreeRetentionList;
__attribute__((section(".bss"))) PacketBuffer::BufferPoolElement PacketBuffer::sBufferPool[CHIP_SYSTEM_CONFIG_PACKETBUFFER_POOL_SIZE];
#else /* !CONFIG_CHIP_PACKETBUFFER_OPTIMIZATION */
PacketBuffer::BufferPoolElement PacketBuffer::sBufferPool[CHIP_SYSTEM_CONFIG_PACKETBUFFER_POOL_SIZE];
#endif /* CONFIG_CHIP_PACKETBUFFER_OPTIMIZATION */

PacketBuffer * PacketBuffer::sFreeList = PacketBuffer::BuildFreeList();

Expand Down Expand Up @@ -104,6 +120,27 @@ PacketBuffer * PacketBuffer::BuildFreeList()
return static_cast<PacketBuffer *>(lHead);
}

#if defined(CONFIG_CHIP_PACKETBUFFER_OPTIMIZATION) && CONFIG_CHIP_PACKETBUFFER_OPTIMIZATION
PacketBuffer * PacketBuffer::BuildRetentionFreeList()
{
pbuf * lHead = nullptr;

for (int i = 0; i < CHIP_SYSTEM_CONFIG_PACKETBUFFER_POOL_SIZE; i++)
{
pbuf * lCursor = &sFreeRetentionList[i].Header;
lCursor->next = lHead;
lCursor->ref = 0;
lHead = lCursor;
}

#if !CHIP_SYSTEM_CONFIG_NO_LOCKING
Mutex::Init(sBufferPoolMutex);
#endif // !CHIP_SYSTEM_CONFIG_NO_LOCKING

return static_cast<PacketBuffer *>(lHead);
}
#endif /* CONFIG_CHIP_PACKETBUFFER_OPTIMIZATION */

#elif CHIP_SYSTEM_PACKETBUFFER_FROM_CHIP_HEAP
//
// Heap allocation for PacketBuffer objects.
Expand Down Expand Up @@ -510,6 +547,21 @@ void PacketBuffer::AddRef()

PacketBufferHandle PacketBufferHandle::New(size_t aAvailableSize, uint16_t aReservedSize)
{
#if defined(CONFIG_CHIP_PACKETBUFFER_OPTIMIZATION) && CONFIG_CHIP_PACKETBUFFER_OPTIMIZATION
if(packetBufferBLEFlag==1)
{
packetBufferBLEFlag = 0;
packetBufferThreadFlag = 2;
PacketBuffer::sFreeRetentionList = (PacketBuffer::BufferPoolElement *)&_RAMCODE_BLE_VMA_START;
PacketBuffer::sFreeList = PacketBuffer::BuildRetentionFreeList();
}
else if(packetBufferThreadFlag==1)
{
packetBufferThreadFlag = 2;
PacketBuffer::sFreeRetentionList = (PacketBuffer::BufferPoolElement *)&_RAMCODE_BLE_VMA_START;
PacketBuffer::sFreeList = PacketBuffer::BuildRetentionFreeList();
}
#endif /* CONFIG_CHIP_PACKETBUFFER_OPTIMIZATION */
// Sanity check for kStructureSize to ensure that it matches the PacketBuffer size.
static_assert(PacketBuffer::kStructureSize == sizeof(PacketBuffer), "PacketBuffer size mismatch");
// Setting a static upper bound on kStructureSize to ensure the summation of all the sizes does not overflow.
Expand Down
4 changes: 4 additions & 0 deletions src/system/SystemPacketBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,10 @@ class DLL_EXPORT PacketBuffer : private pbuf
static BufferPoolElement sBufferPool[CHIP_SYSTEM_CONFIG_PACKETBUFFER_POOL_SIZE];
static PacketBuffer * sFreeList;
static PacketBuffer * BuildFreeList();
#if defined(CONFIG_CHIP_PACKETBUFFER_OPTIMIZATION) && CONFIG_CHIP_PACKETBUFFER_OPTIMIZATION
static BufferPoolElement * sFreeRetentionList;
static PacketBuffer * BuildRetentionFreeList();
#endif /* CONFIG_CHIP_PACKETBUFFER_OPTIMIZATION */
#endif // CHIP_SYSTEM_PACKETBUFFER_FROM_CHIP_POOL || defined(DOXYGEN)

#if CHIP_SYSTEM_PACKETBUFFER_HAS_CHECK
Expand Down
Loading