diff options
Diffstat (limited to 'nuttx/net/iob')
-rw-r--r-- | nuttx/net/iob/Kconfig | 22 | ||||
-rw-r--r-- | nuttx/net/iob/iob.h | 11 | ||||
-rw-r--r-- | nuttx/net/iob/iob_add_queue.c | 2 | ||||
-rw-r--r-- | nuttx/net/iob/iob_alloc.c | 78 | ||||
-rw-r--r-- | nuttx/net/iob/iob_alloc_qentry.c | 2 | ||||
-rw-r--r-- | nuttx/net/iob/iob_clone.c | 6 | ||||
-rw-r--r-- | nuttx/net/iob/iob_concat.c | 2 | ||||
-rwxr-xr-x | nuttx/net/iob/iob_contig.c | 2 | ||||
-rw-r--r-- | nuttx/net/iob/iob_copyin.c | 6 | ||||
-rw-r--r-- | nuttx/net/iob/iob_copyout.c | 2 | ||||
-rw-r--r-- | nuttx/net/iob/iob_free.c | 2 | ||||
-rw-r--r-- | nuttx/net/iob/iob_free_chain.c | 2 | ||||
-rw-r--r-- | nuttx/net/iob/iob_free_qentry.c | 2 | ||||
-rw-r--r-- | nuttx/net/iob/iob_free_queue.c | 2 | ||||
-rw-r--r-- | nuttx/net/iob/iob_initialize.c | 9 | ||||
-rw-r--r-- | nuttx/net/iob/iob_pack.c | 2 | ||||
-rw-r--r-- | nuttx/net/iob/iob_remove_queue.c | 2 | ||||
-rw-r--r-- | nuttx/net/iob/iob_test.c | 6 | ||||
-rw-r--r-- | nuttx/net/iob/iob_trimhead.c | 2 | ||||
-rw-r--r-- | nuttx/net/iob/iob_trimtail.c | 2 |
20 files changed, 112 insertions, 52 deletions
diff --git a/nuttx/net/iob/Kconfig b/nuttx/net/iob/Kconfig index ea6a851cd..b8481ab9e 100644 --- a/nuttx/net/iob/Kconfig +++ b/nuttx/net/iob/Kconfig @@ -14,7 +14,9 @@ if NET_IOB config IOB_NBUFFERS int "Number of pre-allocated network I/O buffers" - default 24 + default 24 if (NET_TCP_WRITE_BUFFERS && !NET_TCP_READAHEAD) || (!NET_TCP_WRITE_BUFFERS && NET_TCP_READAHEAD) + default 36 if NET_TCP_WRITE_BUFFERS && NET_TCP_READAHEAD + default 8 if !NET_TCP_WRITE_BUFFERS && !NET_TCP_READAHEAD ---help--- Each packet is represented by a series of small I/O buffers in a chain. This setting determines the number of preallocated I/O @@ -30,7 +32,8 @@ config IOB_BUFSIZE config IOB_NCHAINS int "Number of pre-allocated I/O buffer chain heads" - default 0 + default 0 if !NET_TCP_READAHEAD + default 8 if NET_TCP_READAHEAD ---help--- These tiny nodes are used as "containers" to support queueing of I/O buffer chains. This will limit the number of I/O transactions @@ -42,7 +45,20 @@ config IOB_NCHAINS I/O buffer chain containers that also carry a payload of usage specific information. -config NET_IOB_DEBUG +config IOB_THROTTLE + int "I/O buffer throttle value" + default 0 if !NET_TCP_WRITE_BUFFERS || !NET_TCP_READAHEAD + default 8 if NET_TCP_WRITE_BUFFERS && !NET_TCP_READAHEAD + depends on NET_TCP_WRITE_BUFFERS && !NET_TCP_READAHEAD + ---help--- + TCP write buffering and read-ahead buffer use the same pool of free + I/O buffers. In order to prevent uncontrolled incoming TCP packets + from hogging all of the available, pre-allocated I/O buffers, a + throttling value is required. This throttle value assures that + I/O buffers will be denied to the read-ahead logic before TCP writes + are halted. + +config IOB_DEBUG bool "Force I/O buffer debug" default n depends on DEBUG diff --git a/nuttx/net/iob/iob.h b/nuttx/net/iob/iob.h index 03ea6d14d..3b5eaf9e4 100644 --- a/nuttx/net/iob/iob.h +++ b/nuttx/net/iob/iob.h @@ -64,12 +64,19 @@ extern FAR struct iob_s *g_iob_freelist; /* A list of all free, unallocated I/O buffer queue containers */ +#if CONFIG_IOB_NCHAINS > 0 extern FAR struct iob_qentry_s *g_iob_freeqlist; +#endif /* Counting semaphores that tracks the number of free IOBs/qentries */ -extern sem_t g_iob_sem; -extern sem_t g_qentry_sem; +extern sem_t g_iob_sem; /* Counts free I/O buffers */ +#if CONFIG_IOB_THROTTLE > 0 +extern sem_t g_throttle_sem; /* Counts available I/O buffers when throttled */ +#endif +#if CONFIG_IOB_NCHAINS > 0 +extern sem_t g_qentry_sem; /* Counts free I/O buffer queue containers */ +#endif /**************************************************************************** * Public Data diff --git a/nuttx/net/iob/iob_add_queue.c b/nuttx/net/iob/iob_add_queue.c index f915b49a0..99e0f6ff4 100644 --- a/nuttx/net/iob/iob_add_queue.c +++ b/nuttx/net/iob/iob_add_queue.c @@ -39,7 +39,7 @@ #include <nuttx/config.h> -#if defined(CONFIG_DEBUG) && defined(CONFIG_NET_IOB_DEBUG) +#if defined(CONFIG_DEBUG) && defined(CONFIG_IOB_DEBUG) /* Force debug output (from this file only) */ # undef CONFIG_DEBUG_NET diff --git a/nuttx/net/iob/iob_alloc.c b/nuttx/net/iob/iob_alloc.c index be6491dbb..672d1e2e7 100644 --- a/nuttx/net/iob/iob_alloc.c +++ b/nuttx/net/iob/iob_alloc.c @@ -39,7 +39,7 @@ #include <nuttx/config.h> -#if defined(CONFIG_DEBUG) && defined(CONFIG_NET_IOB_DEBUG) +#if defined(CONFIG_DEBUG) && defined(CONFIG_IOB_DEBUG) /* Force debug output (from this file only) */ # undef CONFIG_DEBUG_NET @@ -83,34 +83,59 @@ * ****************************************************************************/ -static FAR struct iob_s *iob_tryalloc(void) +static FAR struct iob_s *iob_tryalloc(bool throttled) { FAR struct iob_s *iob; irqstate_t flags; +#if CONFIG_IOB_THROTTLE > 0 + FAR sem_t *sem; + int semcount; +#endif + +#if CONFIG_IOB_THROTTLE > 0 + /* Select the semaphore count to check. */ + + sem = (throttled ? : &g_throttled_sem, &g_iob_sem); +#endif /* We don't know what context we are called from so we use extreme measures * to protect the free list: We disable interrupts very briefly. */ flags = irqsave(); - iob = g_iob_freelist; - if (iob) + +#if CONFIG_IOB_THROTTLE > 0 + /* If there are free I/O buffers for this allocation */ + + DEBUGVERIFY(sem_getvalue(sem, semcount)); + if (semcount > 0) +#endif { - /* Remove the I/O buffer from the free list and decrement the counting - * semaphore that tracks the number of free IOBs. - */ + /* Take the I/O buffer from the head of the free list */ - g_iob_freelist = iob->io_flink; - DEBUGVERIFY(sem_trywait(&g_iob_sem)); - irqrestore(flags); + iob = g_iob_freelist; + if (iob) + { + /* Remove the I/O buffer from the free list and decrement the + * counting semaphore(s) that tracks the number of available + * IOBs. + */ + + g_iob_freelist = iob->io_flink; + DEBUGVERIFY(sem_trywait(&g_iob_sem)); +#if CONFIG_IOB_THROTTLE > 0 + DEBUGVERIFY(sem_trywait(&g_throttle_sem)); +#endif + irqrestore(flags); - /* Put the I/O buffer in a known state */ + /* Put the I/O buffer in a known state */ - iob->io_flink = NULL; /* Not in a chain */ - iob->io_len = 0; /* Length of the data in the entry */ - iob->io_offset = 0; /* Offset to the beginning of data */ - iob->io_pktlen = 0; /* Total length of the packet */ - return iob; + iob->io_flink = NULL; /* Not in a chain */ + iob->io_len = 0; /* Length of the data in the entry */ + iob->io_offset = 0; /* Offset to the beginning of data */ + iob->io_pktlen = 0; /* Total length of the packet */ + return iob; + } } irqrestore(flags); @@ -126,12 +151,21 @@ static FAR struct iob_s *iob_tryalloc(void) * ****************************************************************************/ -static FAR struct iob_s *iob_allocwait(void) +static FAR struct iob_s *iob_allocwait(bool throttled) { FAR struct iob_s *iob; irqstate_t flags; + FAR sem_t *sem; int ret; +#if CONFIG_IOB_THROTTLE > 0 + /* Select the semaphore count to check. */ + + sem = (throttled ? : &g_throttled_sem, &g_iob_sem); +#else + sem = &g_iob_sem; +#endif + /* The following must be atomic; interrupt must be disabled so that there * is no conflict with interrupt level I/O buffer allocations. This is * not as bad as it sounds because interrupts will be re-enabled while @@ -145,7 +179,7 @@ static FAR struct iob_s *iob_allocwait(void) * will be decremented atomically. */ - iob = iob_tryalloc(); + iob = iob_tryalloc(throttled); if (!iob) { /* If not successful, then the semaphore count was less than or @@ -154,7 +188,7 @@ static FAR struct iob_s *iob_allocwait(void) * count will be incremented. */ - ret = sem_wait(&g_iob_sem); + ret = sem_wait(sem); /* When we wake up from wait, an I/O buffer was returned to * the free list. However, if there are concurrent allocations @@ -182,7 +216,7 @@ static FAR struct iob_s *iob_allocwait(void) * ****************************************************************************/ -FAR struct iob_s *iob_alloc(void) +FAR struct iob_s *iob_alloc(bool throttled) { /* Were we called from the interrupt level? */ @@ -190,12 +224,12 @@ FAR struct iob_s *iob_alloc(void) { /* Yes, then try to allocate an I/O buffer without waiting */ - return iob_tryalloc(); + return iob_tryalloc(throttled); } else { /* Then allocate an I/O buffer, waiting as necessary */ - return iob_allocwait(); + return iob_allocwait(throttled); } } diff --git a/nuttx/net/iob/iob_alloc_qentry.c b/nuttx/net/iob/iob_alloc_qentry.c index 43813a269..f75d21009 100644 --- a/nuttx/net/iob/iob_alloc_qentry.c +++ b/nuttx/net/iob/iob_alloc_qentry.c @@ -39,7 +39,7 @@ #include <nuttx/config.h> -#if defined(CONFIG_DEBUG) && defined(CONFIG_NET_IOB_DEBUG) +#if defined(CONFIG_DEBUG) && defined(CONFIG_IOB_DEBUG) /* Force debug output (from this file only) */ # undef CONFIG_DEBUG_NET diff --git a/nuttx/net/iob/iob_clone.c b/nuttx/net/iob/iob_clone.c index ce83400d4..1162b87dd 100644 --- a/nuttx/net/iob/iob_clone.c +++ b/nuttx/net/iob/iob_clone.c @@ -39,7 +39,7 @@ #include <nuttx/config.h> -#if defined(CONFIG_DEBUG) && defined(CONFIG_NET_IOB_DEBUG) +#if defined(CONFIG_DEBUG) && defined(CONFIG_IOB_DEBUG) /* Force debug output (from this file only) */ # undef CONFIG_DEBUG_NET @@ -87,7 +87,7 @@ * ****************************************************************************/ -int iob_clone(FAR struct iob_s *iob1, FAR struct iob_s *iob2) +int iob_clone(FAR struct iob_s *iob1, FAR struct iob_s *iob2, bool throttled) { FAR uint8_t *src; FAR uint8_t *dest; @@ -177,7 +177,7 @@ int iob_clone(FAR struct iob_s *iob1, FAR struct iob_s *iob2) * destination I/O buffer chain. */ - next = iob_alloc(); + next = iob_alloc(throttled); if (!next) { ndbg("Failed to allocate an I/O buffer/n"); diff --git a/nuttx/net/iob/iob_concat.c b/nuttx/net/iob/iob_concat.c index 68d35c480..ecaa33b87 100644 --- a/nuttx/net/iob/iob_concat.c +++ b/nuttx/net/iob/iob_concat.c @@ -39,7 +39,7 @@ #include <nuttx/config.h> -#if defined(CONFIG_DEBUG) && defined(CONFIG_NET_IOB_DEBUG) +#if defined(CONFIG_DEBUG) && defined(CONFIG_IOB_DEBUG) /* Force debug output (from this file only) */ # undef CONFIG_DEBUG_NET diff --git a/nuttx/net/iob/iob_contig.c b/nuttx/net/iob/iob_contig.c index 6af1b9c99..9c3a6306b 100755 --- a/nuttx/net/iob/iob_contig.c +++ b/nuttx/net/iob/iob_contig.c @@ -39,7 +39,7 @@ #include <nuttx/config.h> -#if defined(CONFIG_DEBUG) && defined(CONFIG_NET_IOB_DEBUG) +#if defined(CONFIG_DEBUG) && defined(CONFIG_IOB_DEBUG) /* Force debug output (from this file only) */ # undef CONFIG_DEBUG_NET diff --git a/nuttx/net/iob/iob_copyin.c b/nuttx/net/iob/iob_copyin.c index c7e4d39f7..1cfd1f697 100644 --- a/nuttx/net/iob/iob_copyin.c +++ b/nuttx/net/iob/iob_copyin.c @@ -39,7 +39,7 @@ #include <nuttx/config.h> -#if defined(CONFIG_DEBUG) && defined(CONFIG_NET_IOB_DEBUG) +#if defined(CONFIG_DEBUG) && defined(CONFIG_IOB_DEBUG) /* Force debug output (from this file only) */ # undef CONFIG_DEBUG_NET @@ -90,7 +90,7 @@ ****************************************************************************/ int iob_copyin(FAR struct iob_s *iob, FAR const uint8_t *src, - unsigned int len, unsigned int offset) + unsigned int len, unsigned int offset, bool throttled) { FAR struct iob_s *head = iob; FAR struct iob_s *next; @@ -206,7 +206,7 @@ int iob_copyin(FAR struct iob_s *iob, FAR const uint8_t *src, { /* Yes.. allocate a new buffer */ - next = iob_alloc(); + next = iob_alloc(throttled); if (next == NULL) { ndbg("ERROR: Failed to allocate I/O buffer\n"); diff --git a/nuttx/net/iob/iob_copyout.c b/nuttx/net/iob/iob_copyout.c index 2db050d31..300b63df8 100644 --- a/nuttx/net/iob/iob_copyout.c +++ b/nuttx/net/iob/iob_copyout.c @@ -39,7 +39,7 @@ #include <nuttx/config.h> -#if defined(CONFIG_DEBUG) && defined(CONFIG_NET_IOB_DEBUG) +#if defined(CONFIG_DEBUG) && defined(CONFIG_IOB_DEBUG) /* Force debug output (from this file only) */ # undef CONFIG_DEBUG_NET diff --git a/nuttx/net/iob/iob_free.c b/nuttx/net/iob/iob_free.c index 68c7fb264..ada8a7fe6 100644 --- a/nuttx/net/iob/iob_free.c +++ b/nuttx/net/iob/iob_free.c @@ -39,7 +39,7 @@ #include <nuttx/config.h> -#if defined(CONFIG_DEBUG) && defined(CONFIG_NET_IOB_DEBUG) +#if defined(CONFIG_DEBUG) && defined(CONFIG_IOB_DEBUG) /* Force debug output (from this file only) */ # undef CONFIG_DEBUG_NET diff --git a/nuttx/net/iob/iob_free_chain.c b/nuttx/net/iob/iob_free_chain.c index d09a0ca97..2534bde10 100644 --- a/nuttx/net/iob/iob_free_chain.c +++ b/nuttx/net/iob/iob_free_chain.c @@ -39,7 +39,7 @@ #include <nuttx/config.h> -#if defined(CONFIG_DEBUG) && defined(CONFIG_NET_IOB_DEBUG) +#if defined(CONFIG_DEBUG) && defined(CONFIG_IOB_DEBUG) /* Force debug output (from this file only) */ # undef CONFIG_DEBUG_NET diff --git a/nuttx/net/iob/iob_free_qentry.c b/nuttx/net/iob/iob_free_qentry.c index 3f5a517b9..f93f16f8f 100644 --- a/nuttx/net/iob/iob_free_qentry.c +++ b/nuttx/net/iob/iob_free_qentry.c @@ -39,7 +39,7 @@ #include <nuttx/config.h> -#if defined(CONFIG_DEBUG) && defined(CONFIG_NET_IOB_DEBUG) +#if defined(CONFIG_DEBUG) && defined(CONFIG_IOB_DEBUG) /* Force debug output (from this file only) */ # undef CONFIG_DEBUG_NET diff --git a/nuttx/net/iob/iob_free_queue.c b/nuttx/net/iob/iob_free_queue.c index f23394d45..cf7ffff0c 100644 --- a/nuttx/net/iob/iob_free_queue.c +++ b/nuttx/net/iob/iob_free_queue.c @@ -39,7 +39,7 @@ #include <nuttx/config.h> -#if defined(CONFIG_DEBUG) && defined(CONFIG_NET_IOB_DEBUG) +#if defined(CONFIG_DEBUG) && defined(CONFIG_IOB_DEBUG) /* Force debug output (from this file only) */ # undef CONFIG_DEBUG_NET diff --git a/nuttx/net/iob/iob_initialize.c b/nuttx/net/iob/iob_initialize.c index 319e75b8a..8971f8d63 100644 --- a/nuttx/net/iob/iob_initialize.c +++ b/nuttx/net/iob/iob_initialize.c @@ -39,7 +39,7 @@ #include <nuttx/config.h> -#if defined(CONFIG_DEBUG) && defined(CONFIG_NET_IOB_DEBUG) +#if defined(CONFIG_DEBUG) && defined(CONFIG_IOB_DEBUG) /* Force debug output (from this file only) */ # undef CONFIG_DEBUG_NET @@ -88,9 +88,12 @@ FAR struct iob_qentry_s *g_iob_freeqlist; /* Counting semaphores that tracks the number of free IOBs/qentries */ -sem_t g_iob_sem; +sem_t g_iob_sem; /* Counts free I/O buffers */ +#if CONFIG_IOB_THROTTLE > 0 +sem_t g_throttle_sem; /* Counts available I/O buffers when throttled */ +#endif #if CONFIG_IOB_NCHAINS > 0 -sem_t g_qentry_sem; +sem_t g_qentry_sem; /* Counts free I/O buffer queue containers */ #endif /**************************************************************************** diff --git a/nuttx/net/iob/iob_pack.c b/nuttx/net/iob/iob_pack.c index f129e7357..4765e8e59 100644 --- a/nuttx/net/iob/iob_pack.c +++ b/nuttx/net/iob/iob_pack.c @@ -39,7 +39,7 @@ #include <nuttx/config.h> -#if defined(CONFIG_DEBUG) && defined(CONFIG_NET_IOB_DEBUG) +#if defined(CONFIG_DEBUG) && defined(CONFIG_IOB_DEBUG) /* Force debug output (from this file only) */ # undef CONFIG_DEBUG_NET diff --git a/nuttx/net/iob/iob_remove_queue.c b/nuttx/net/iob/iob_remove_queue.c index e8ee794e3..f516ad047 100644 --- a/nuttx/net/iob/iob_remove_queue.c +++ b/nuttx/net/iob/iob_remove_queue.c @@ -39,7 +39,7 @@ #include <nuttx/config.h> -#if defined(CONFIG_DEBUG) && defined(CONFIG_NET_IOB_DEBUG) +#if defined(CONFIG_DEBUG) && defined(CONFIG_IOB_DEBUG) /* Force debug output (from this file only) */ # undef CONFIG_DEBUG_NET diff --git a/nuttx/net/iob/iob_test.c b/nuttx/net/iob/iob_test.c index 7171db3cd..5c58852cf 100644 --- a/nuttx/net/iob/iob_test.c +++ b/nuttx/net/iob/iob_test.c @@ -121,7 +121,7 @@ int main(int argc, char **argv) int i; iob_initialize(); - iob = iob_alloc(); + iob = iob_alloc(false); for (i = 0; i < 4096; i++) { @@ -129,11 +129,11 @@ int main(int argc, char **argv) } memset(buffer2, 0xff, 4096); - iob_copyin(iob, buffer2, 47, 0); + iob_copyin(iob, buffer2, 47, 0, false); printf("Copy IN: 47, offset 0\n"); dump_chain(iob); - iob_copyin(iob, buffer1, 4096, 47); + iob_copyin(iob, buffer1, 4096, 47, false); printf("Copy IN: 4096, offset 47\n"); dump_chain(iob); diff --git a/nuttx/net/iob/iob_trimhead.c b/nuttx/net/iob/iob_trimhead.c index 6ea684b9a..bb3997c69 100644 --- a/nuttx/net/iob/iob_trimhead.c +++ b/nuttx/net/iob/iob_trimhead.c @@ -39,7 +39,7 @@ #include <nuttx/config.h> -#if defined(CONFIG_DEBUG) && defined(CONFIG_NET_IOB_DEBUG) +#if defined(CONFIG_DEBUG) && defined(CONFIG_IOB_DEBUG) /* Force debug output (from this file only) */ # undef CONFIG_DEBUG_NET diff --git a/nuttx/net/iob/iob_trimtail.c b/nuttx/net/iob/iob_trimtail.c index c87de712f..c436550a8 100644 --- a/nuttx/net/iob/iob_trimtail.c +++ b/nuttx/net/iob/iob_trimtail.c @@ -39,7 +39,7 @@ #include <nuttx/config.h> -#if defined(CONFIG_DEBUG) && defined(CONFIG_NET_IOB_DEBUG) +#if defined(CONFIG_DEBUG) && defined(CONFIG_IOB_DEBUG) /* Force debug output (from this file only) */ # undef CONFIG_DEBUG_NET |