Memory optimization in RTCS

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Memory optimization in RTCS

863 Views
antonychen2008
Contributor II

Hello,

 

I am using MQX and RTCS on an K60 processor. when I debug, I found a memory error  message. where connecting a new socket reports an error with available TCP/IP buffers. With TAD, it reports to 95% full.

how can I optimized this? Are there any tips?

 

Thanks

 

0 Kudos
1 Reply

860 Views
danielchen
NXP TechSupport
NXP TechSupport

With TAD, you can see that every new TCP socket connection needs extra 500+4392x2+148=9432B as follows:

MQX -> Lightweight Memory Block Summary
Size (Decimal) Owner Type
500 0x10001 TCP Control Block;RTCS/TCP
4392 0x10001 TCP Tx Window;RTCS/TCP
4392 0x10001 TCP Rx Window;RTCS/TCP
148 0x10001 TCP Send Clock;RTCS/TCP
(TCP/IP Task id is 0x10001)

The default OPT_TBSIZE and OPT_RBSIZE are 4380 bytes. If you call setsockopt() to reduce these two, for example, to a quarter like 1095 bytes, the memory usage to open a new TCP socket will drop from 16% to 4.7% as follows:

MQX -> Lightweight Memory Block Summary
Size (Decimal) Owner Type
500 -> 500 0x10001 TCP Control Block;RTCS/TCP
4392 -> 1108 0x10001 TCP Tx Window;RTCS/TCP
4392 -> 1108 0x10001 TCP Rx Window;RTCS/TCP
148 -> 84 0x10001 TCP Send Clock;RTCS/TCP

If the problem persists please set a slower number, try next:
uint_32 value;

value = 256;
setsockopt(sock, SOL_TCP,OPT_TBSIZE,&value,sizeof(value));
setsockopt(sock, SOL_TCP,OPT_RBSIZE,&value,sizeof(value));

Also, it might be possible that you need more PCBs, MSG and sockets. Could you please add the next lines just before call the function RTCS_create() just as the web_hvac does in the C:\Program Files\Freescale\Freescale MQX 3.5\demo\web_hvac\RTCS.c file?
/* runtime RTCS configuration */
_RTCSPCB_init = 4;
_RTCSPCB_grow = 2;
_RTCSPCB_max = 20;
_RTCS_msgpool_init = 4;
_RTCS_msgpool_grow = 2;
_RTCS_msgpool_max = 20;
_RTCS_socket_part_init = 4;
_RTCS_socket_part_grow = 2;
_RTCS_socket_part_max = 20;