Improvements in sockets allocation.
This commit is contained in:
parent
cf15d6b63a
commit
9b4d784307
@ -44,7 +44,7 @@ CONFIG_NET_ARP_SEND=y
|
||||
CONFIG_NET_ICMP=y
|
||||
CONFIG_NET_ICMP_SOCKET=y
|
||||
CONFIG_NET_MAX_LISTENPORTS=8
|
||||
CONFIG_NET_NACTIVESOCKETS=12
|
||||
CONFIG_NET_PREALLOC_DEVIF_CALLBACKS=12
|
||||
CONFIG_NET_SOCKOPTS=y
|
||||
CONFIG_NET_TCP=y
|
||||
CONFIG_NET_TCPBACKLOG=y
|
||||
|
@ -35,7 +35,7 @@ CONFIG_NETDEV_IFINDEX=y
|
||||
CONFIG_NETDEV_LATEINIT=y
|
||||
CONFIG_NET_CAN=y
|
||||
CONFIG_NET_CAN_ERRORS=y
|
||||
CONFIG_NET_NACTIVESOCKETS=16
|
||||
CONFIG_NET_PREALLOC_DEVIF_CALLBACKS=16
|
||||
CONFIG_NET_SOCKOPTS=y
|
||||
CONFIG_NET_STATISTICS=y
|
||||
CONFIG_NSH_BUILTIN_APPS=y
|
||||
|
@ -83,7 +83,7 @@ CONFIG_NET_BROADCAST=y
|
||||
CONFIG_NET_ETH_PKTSIZE=1518
|
||||
CONFIG_NET_ICMP=y
|
||||
CONFIG_NET_ICMP_SOCKET=y
|
||||
CONFIG_NET_NACTIVESOCKETS=32
|
||||
CONFIG_NET_PREALLOC_DEVIF_CALLBACKS=32
|
||||
CONFIG_NET_STATISTICS=y
|
||||
CONFIG_NET_TCP=y
|
||||
CONFIG_NET_TCP_DELAYED_ACK=y
|
||||
|
@ -57,7 +57,7 @@ CONFIG_NET_BROADCAST=y
|
||||
CONFIG_NET_ETH_PKTSIZE=1518
|
||||
CONFIG_NET_ICMP=y
|
||||
CONFIG_NET_ICMP_SOCKET=y
|
||||
CONFIG_NET_NACTIVESOCKETS=32
|
||||
CONFIG_NET_PREALLOC_DEVIF_CALLBACKS=32
|
||||
CONFIG_NET_STATISTICS=y
|
||||
CONFIG_NET_TCP=y
|
||||
CONFIG_NET_TCP_DELAYED_ACK=y
|
||||
|
@ -110,7 +110,7 @@ CONFIG_NET_BROADCAST=y
|
||||
CONFIG_NET_ETH_PKTSIZE=1518
|
||||
CONFIG_NET_ICMP=y
|
||||
CONFIG_NET_ICMP_SOCKET=y
|
||||
CONFIG_NET_NACTIVESOCKETS=32
|
||||
CONFIG_NET_PREALLOC_DEVIF_CALLBACKS=32
|
||||
CONFIG_NET_STATISTICS=y
|
||||
CONFIG_NET_TCP=y
|
||||
CONFIG_NET_TCP_DELAYED_ACK=y
|
||||
|
@ -64,7 +64,7 @@ CONFIG_NET_BROADCAST=y
|
||||
CONFIG_NET_ETH_PKTSIZE=1518
|
||||
CONFIG_NET_ICMP=y
|
||||
CONFIG_NET_ICMP_SOCKET=y
|
||||
CONFIG_NET_NACTIVESOCKETS=32
|
||||
CONFIG_NET_PREALLOC_DEVIF_CALLBACKS=32
|
||||
CONFIG_NET_STATISTICS=y
|
||||
CONFIG_NET_TCP=y
|
||||
CONFIG_NET_TCP_DELAYED_ACK=y
|
||||
|
@ -84,7 +84,7 @@ CONFIG_NET_BROADCAST=y
|
||||
CONFIG_NET_ETH_PKTSIZE=1518
|
||||
CONFIG_NET_ICMP=y
|
||||
CONFIG_NET_ICMP_SOCKET=y
|
||||
CONFIG_NET_NACTIVESOCKETS=32
|
||||
CONFIG_NET_PREALLOC_DEVIF_CALLBACKS=32
|
||||
CONFIG_NET_STATISTICS=y
|
||||
CONFIG_NET_TCP=y
|
||||
CONFIG_NET_TCP_DELAYED_ACK=y
|
||||
|
@ -52,7 +52,7 @@ CONFIG_NET_BROADCAST=y
|
||||
CONFIG_NET_ETH_PKTSIZE=1518
|
||||
CONFIG_NET_ICMP=y
|
||||
CONFIG_NET_ICMP_SOCKET=y
|
||||
CONFIG_NET_NACTIVESOCKETS=32
|
||||
CONFIG_NET_PREALLOC_DEVIF_CALLBACKS=32
|
||||
CONFIG_NET_STATISTICS=y
|
||||
CONFIG_NET_TCP=y
|
||||
CONFIG_NET_TCP_DELAYED_ACK=y
|
||||
|
@ -83,7 +83,7 @@ CONFIG_NET_BROADCAST=y
|
||||
CONFIG_NET_ETH_PKTSIZE=1518
|
||||
CONFIG_NET_ICMP=y
|
||||
CONFIG_NET_ICMP_SOCKET=y
|
||||
CONFIG_NET_NACTIVESOCKETS=32
|
||||
CONFIG_NET_PREALLOC_DEVIF_CALLBACKS=32
|
||||
CONFIG_NET_STATISTICS=y
|
||||
CONFIG_NET_TCP=y
|
||||
CONFIG_NET_TCP_DELAYED_ACK=y
|
||||
|
@ -52,7 +52,7 @@ CONFIG_NET_BROADCAST=y
|
||||
CONFIG_NET_ETH_PKTSIZE=1518
|
||||
CONFIG_NET_ICMP=y
|
||||
CONFIG_NET_ICMP_SOCKET=y
|
||||
CONFIG_NET_NACTIVESOCKETS=32
|
||||
CONFIG_NET_PREALLOC_DEVIF_CALLBACKS=32
|
||||
CONFIG_NET_STATISTICS=y
|
||||
CONFIG_NET_TCP=y
|
||||
CONFIG_NET_TCP_DELAYED_ACK=y
|
||||
|
@ -415,16 +415,6 @@
|
||||
# define CONFIG_NET_MAX_LISTENPORTS 20
|
||||
#endif
|
||||
|
||||
/* Define the maximum number of concurrently active UDP and TCP
|
||||
* ports. This number must be greater than the number of open
|
||||
* sockets in order to support multi-threaded read/write operations.
|
||||
*/
|
||||
|
||||
#ifndef CONFIG_NET_NACTIVESOCKETS
|
||||
# define CONFIG_NET_NACTIVESOCKETS (CONFIG_NET_TCP_PREALLOC_CONNS + \
|
||||
CONFIG_NET_UDP_PREALLOC_CONNS)
|
||||
#endif
|
||||
|
||||
/* The initial retransmission timeout counted in timer pulses.
|
||||
* REVISIT: TCP RTO really should be calculated dynamically for each TCP
|
||||
* connection.
|
||||
|
@ -43,8 +43,9 @@
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef CONFIG_NET_ALLOC_CONNS
|
||||
static struct devif_callback_s g_cbprealloc[CONFIG_NET_NACTIVESOCKETS];
|
||||
#if CONFIG_NET_PREALLOC_DEVIF_CALLBACKS > 0
|
||||
static struct devif_callback_s
|
||||
g_cbprealloc[CONFIG_NET_PREALLOC_DEVIF_CALLBACKS];
|
||||
#endif
|
||||
static FAR struct devif_callback_s *g_cbfreelist = NULL;
|
||||
|
||||
@ -164,11 +165,24 @@ static void devif_callback_free(FAR struct net_driver_s *dev,
|
||||
}
|
||||
}
|
||||
|
||||
/* Put the structure into the free list */
|
||||
/* If this is a preallocated or a batch allocated callback store it in
|
||||
* the free callbacks list. Else free it.
|
||||
*/
|
||||
|
||||
#if CONFIG_NET_ALLOC_DEVIF_CALLBACKS == 1
|
||||
if (cb < g_cbprealloc || cb >= (g_cbprealloc +
|
||||
CONFIG_NET_PREALLOC_DEVIF_CALLBACKS))
|
||||
{
|
||||
kmm_free(cb);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
cb->nxtconn = g_cbfreelist;
|
||||
cb->nxtdev = NULL;
|
||||
g_cbfreelist = cb;
|
||||
}
|
||||
|
||||
cb->nxtconn = g_cbfreelist;
|
||||
cb->nxtdev = NULL;
|
||||
g_cbfreelist = cb;
|
||||
net_unlock();
|
||||
}
|
||||
}
|
||||
@ -230,10 +244,10 @@ static bool devif_event_trigger(uint16_t events, uint16_t triggers)
|
||||
|
||||
void devif_callback_init(void)
|
||||
{
|
||||
#ifndef CONFIG_NET_ALLOC_CONNS
|
||||
#if CONFIG_NET_PREALLOC_DEVIF_CALLBACKS > 0
|
||||
int i;
|
||||
|
||||
for (i = 0; i < CONFIG_NET_NACTIVESOCKETS; i++)
|
||||
for (i = 0; i < CONFIG_NET_PREALLOC_DEVIF_CALLBACKS; i++)
|
||||
{
|
||||
g_cbprealloc[i].nxtconn = g_cbfreelist;
|
||||
g_cbfreelist = &g_cbprealloc[i];
|
||||
@ -263,7 +277,7 @@ FAR struct devif_callback_s *
|
||||
FAR struct devif_callback_s **list_tail)
|
||||
{
|
||||
FAR struct devif_callback_s *ret;
|
||||
#ifdef CONFIG_NET_ALLOC_CONNS
|
||||
#if CONFIG_NET_ALLOC_DEVIF_CALLBACKS > 0
|
||||
int i;
|
||||
#endif
|
||||
|
||||
@ -290,14 +304,14 @@ FAR struct devif_callback_s *
|
||||
|
||||
/* Allocate the callback entry from heap */
|
||||
|
||||
#ifdef CONFIG_NET_ALLOC_CONNS
|
||||
#if CONFIG_NET_ALLOC_DEVIF_CALLBACKS > 0
|
||||
if (g_cbfreelist == NULL)
|
||||
{
|
||||
ret = kmm_zalloc(sizeof(struct devif_callback_s) *
|
||||
CONFIG_NET_NACTIVESOCKETS);
|
||||
CONFIG_NET_ALLOC_DEVIF_CALLBACKS);
|
||||
if (ret != NULL)
|
||||
{
|
||||
for (i = 0; i < CONFIG_NET_NACTIVESOCKETS; i++)
|
||||
for (i = 0; i < CONFIG_NET_ALLOC_DEVIF_CALLBACKS; i++)
|
||||
{
|
||||
ret[i].nxtconn = g_cbfreelist;
|
||||
g_cbfreelist = &ret[i];
|
||||
|
@ -5,13 +5,36 @@
|
||||
|
||||
menu "Socket Support"
|
||||
|
||||
config NET_NACTIVESOCKETS
|
||||
int "Max socket operations"
|
||||
config NET_PREALLOC_DEVIF_CALLBACKS
|
||||
int "Preallocated socket callbacks"
|
||||
default 16 if !DEFAULT_SMALL
|
||||
default 4 if DEFAULT_SMALL
|
||||
---help---
|
||||
Maximum number of concurrent socket operations (recv, send,
|
||||
connection monitoring, etc.). Default: 16
|
||||
Number of preallocated socket callbacks (all tasks).
|
||||
|
||||
This number of callbacks will be pre-allocated during system boot.
|
||||
If dynamic callbacks allocation is enabled, more callbacks may be
|
||||
allocated at a later time, as the system needs them. Else this
|
||||
will be the maximum number of callbacks available to the system
|
||||
at all times.
|
||||
|
||||
Set to 0 to disable (and rely only on dynamic allocations).
|
||||
|
||||
config NET_ALLOC_DEVIF_CALLBACKS
|
||||
int "Dynamic socket callbacks allocation"
|
||||
default 0
|
||||
---help---
|
||||
Dynamic memory allocations for socket callbacks.
|
||||
|
||||
When set to 0 all dynamic allocations are disabled.
|
||||
|
||||
When set to 1 a new callback will be allocated every time, and
|
||||
it will be free'd when no longer needed.
|
||||
|
||||
Setting this to 2 or more will allocate the callbacks in batches
|
||||
(with batch size equal to this config). When a callback is no
|
||||
longer needed, it will be returned to the free callbacks pool,
|
||||
and it will never be deallocated!
|
||||
|
||||
config NET_SOCKOPTS
|
||||
bool "Socket options"
|
||||
|
Loading…
x
Reference in New Issue
Block a user