summaryrefslogtreecommitdiff
path: root/nuttx/net/iob
diff options
context:
space:
mode:
authorGregory Nutt <gnutt@nuttx.org>2014-06-24 15:38:00 -0600
committerGregory Nutt <gnutt@nuttx.org>2014-06-24 15:38:00 -0600
commitf8f6318244f391e250428ecacae6a0b66feb0bea (patch)
tree306aaa03910542027396fd219512d61e21d48975 /nuttx/net/iob
parentd8d6c72e3b71b7b7324d301432c194c712411df6 (diff)
downloadpx4-nuttx-f8f6318244f391e250428ecacae6a0b66feb0bea.tar.gz
px4-nuttx-f8f6318244f391e250428ecacae6a0b66feb0bea.tar.bz2
px4-nuttx-f8f6318244f391e250428ecacae6a0b66feb0bea.zip
TCP Read-Ahead: Convert to use I/O buffer chains
Diffstat (limited to 'nuttx/net/iob')
-rw-r--r--nuttx/net/iob/Kconfig4
-rw-r--r--nuttx/net/iob/Make.defs4
-rw-r--r--nuttx/net/iob/iob_alloc.c10
-rw-r--r--nuttx/net/iob/iob_alloc_qentry.c32
-rw-r--r--nuttx/net/iob/iob_copyin.c2
-rw-r--r--nuttx/net/iob/iob_free.c3
-rw-r--r--nuttx/net/iob/iob_initialize.c4
-rw-r--r--nuttx/net/iob/iob_remove_queue.c7
8 files changed, 33 insertions, 33 deletions
diff --git a/nuttx/net/iob/Kconfig b/nuttx/net/iob/Kconfig
index b8481ab9e..5bb6e4c6b 100644
--- a/nuttx/net/iob/Kconfig
+++ b/nuttx/net/iob/Kconfig
@@ -48,8 +48,8 @@ config IOB_NCHAINS
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
+ 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
diff --git a/nuttx/net/iob/Make.defs b/nuttx/net/iob/Make.defs
index 205ef72ea..0eb2e0f9b 100644
--- a/nuttx/net/iob/Make.defs
+++ b/nuttx/net/iob/Make.defs
@@ -40,8 +40,8 @@ ifeq ($(CONFIG_NET_IOB),y)
NET_CSRCS += iob_add_queue.c iob_alloc.c iob_alloc_qentry.c iob_clone.c
NET_CSRCS += iob_concat.c iob_copyin.c iob_copyout.c iob_contig.c iob_free.c
NET_CSRCS += iob_free_chain.c iob_free_qentry.c iob_free_queue.c
-NET_CSRCS += iob_initialize.c iob_pack.c iob_remove_queue.c iob_trimhead.c
-NET_CSRCS += iob_trimtail.c
+NET_CSRCS += iob_initialize.c iob_pack.c iob_peek_queue.c iob_remove_queue.c
+NET_CSRCS += iob_trimhead.c iob_trimtail.c
ifeq ($(CONFIG_DEBUG),y)
NET_CSRCS += iob_dump.c
diff --git a/nuttx/net/iob/iob_alloc.c b/nuttx/net/iob/iob_alloc.c
index 672d1e2e7..179908d46 100644
--- a/nuttx/net/iob/iob_alloc.c
+++ b/nuttx/net/iob/iob_alloc.c
@@ -95,7 +95,7 @@ static FAR struct iob_s *iob_tryalloc(bool throttled)
#if CONFIG_IOB_THROTTLE > 0
/* Select the semaphore count to check. */
- sem = (throttled ? : &g_throttled_sem, &g_iob_sem);
+ sem = (throttled ? &g_throttle_sem : &g_iob_sem);
#endif
/* We don't know what context we are called from so we use extreme measures
@@ -107,7 +107,7 @@ static FAR struct iob_s *iob_tryalloc(bool throttled)
#if CONFIG_IOB_THROTTLE > 0
/* If there are free I/O buffers for this allocation */
- DEBUGVERIFY(sem_getvalue(sem, semcount));
+ DEBUGVERIFY(sem_getvalue(sem, &semcount));
if (semcount > 0)
#endif
{
@@ -124,7 +124,9 @@ static FAR struct iob_s *iob_tryalloc(bool throttled)
g_iob_freelist = iob->io_flink;
DEBUGVERIFY(sem_trywait(&g_iob_sem));
#if CONFIG_IOB_THROTTLE > 0
- DEBUGVERIFY(sem_trywait(&g_throttle_sem));
+ //DEBUGVERIFY(sem_trywait(&g_throttle_sem));
+ g_throttle_sem.semcount--;
+ DEBUGASSERT(g_throttle_sem.semcount >= -CONFIG_IOB_THROTTLE);
#endif
irqrestore(flags);
@@ -161,7 +163,7 @@ static FAR struct iob_s *iob_allocwait(bool throttled)
#if CONFIG_IOB_THROTTLE > 0
/* Select the semaphore count to check. */
- sem = (throttled ? : &g_throttled_sem, &g_iob_sem);
+ sem = (throttled ? &g_throttle_sem : &g_iob_sem);
#else
sem = &g_iob_sem;
#endif
diff --git a/nuttx/net/iob/iob_alloc_qentry.c b/nuttx/net/iob/iob_alloc_qentry.c
index f75d21009..8f425adb0 100644
--- a/nuttx/net/iob/iob_alloc_qentry.c
+++ b/nuttx/net/iob/iob_alloc_qentry.c
@@ -105,7 +105,7 @@ static FAR struct iob_qentry_s *iob_tryalloc_qentry(void)
*/
g_iob_freeqlist = iobq->qe_flink;
- DEBVERIFY(sem_trywait(&g_qentry_sem));
+ DEBUGVERIFY(sem_trywait(&g_qentry_sem));
/* Put the I/O buffer in a known state */
@@ -186,32 +186,20 @@ static FAR struct iob_qentry_s *iob_allocwait_qentry(void)
FAR struct iob_qentry_s *iob_alloc_qentry(void)
{
- FAR struct iob_qentry_s *iobq;
- irqstate_t flags;
-
- /* 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.
- */
+ /* Were we called from the interrupt level? */
- flags = irqsave();
- iobq = g_iob_freeqlist;
- if (iobq)
+ if (up_interrupt_context())
{
- /* Remove the I/O buffer chain container from the free list and
- * decrement the counting semaphore that tracks the number of free
- * containers.
- */
-
- g_iob_freeqlist = iobq->qe_flink;
- DEBVERIFY(sem_trywait(&g_qentry_sem));
-
- /* Put the I/O buffer in a known state */
+ /* Yes, then try to allocate an I/O buffer without waiting */
- iobq->qe_head = NULL; /* Nothing is contained */
+ return iob_tryalloc_qentry();
}
+ else
+ {
+ /* Then allocate an I/O buffer, waiting as necessary */
- irqrestore(flags);
- return iobq;
+ return iob_allocwait_qentry();
+ }
}
#endif /* CONFIG_IOB_NCHAINS > 0 */
diff --git a/nuttx/net/iob/iob_copyin.c b/nuttx/net/iob/iob_copyin.c
index 1cfd1f697..75d82023c 100644
--- a/nuttx/net/iob/iob_copyin.c
+++ b/nuttx/net/iob/iob_copyin.c
@@ -223,5 +223,5 @@ int iob_copyin(FAR struct iob_s *iob, FAR const uint8_t *src,
offset = 0;
}
- return 0;
+ return OK;
}
diff --git a/nuttx/net/iob/iob_free.c b/nuttx/net/iob/iob_free.c
index ada8a7fe6..984287600 100644
--- a/nuttx/net/iob/iob_free.c
+++ b/nuttx/net/iob/iob_free.c
@@ -135,6 +135,9 @@ FAR struct iob_s *iob_free(FAR struct iob_s *iob)
/* Signal that an IOB is available */
sem_post(&g_iob_sem);
+#if CONFIG_IOB_THROTTLE > 0
+ sem_post(&g_throttle_sem);
+#endif
irqrestore(flags);
/* And return the I/O buffer after the one that was freed */
diff --git a/nuttx/net/iob/iob_initialize.c b/nuttx/net/iob/iob_initialize.c
index 8971f8d63..647eb0649 100644
--- a/nuttx/net/iob/iob_initialize.c
+++ b/nuttx/net/iob/iob_initialize.c
@@ -131,6 +131,10 @@ void iob_initialize(void)
sem_init(&g_iob_sem, 0, CONFIG_IOB_NBUFFERS);
+#if CONFIG_IOB_THROTTLE > 0
+ sem_init(&g_throttle_sem, 0, CONFIG_IOB_NBUFFERS - CONFIG_IOB_THROTTLE);
+#endif
+
#if CONFIG_IOB_NCHAINS > 0
/* Add each I/O buffer chain queue container to the free list */
diff --git a/nuttx/net/iob/iob_remove_queue.c b/nuttx/net/iob/iob_remove_queue.c
index f516ad047..e134bcd01 100644
--- a/nuttx/net/iob/iob_remove_queue.c
+++ b/nuttx/net/iob/iob_remove_queue.c
@@ -67,10 +67,13 @@
****************************************************************************/
/****************************************************************************
- * Name: iob_add_queue
+ * Name: iob_remove_queue
*
* Description:
- * Remove one I/O buffer chain from the heaqd of a queue.
+ * Remove and return one I/O buffer chain from the head of a queue.
+ *
+ * Returned Value:
+ * Returns a reference to the I/O buffer chain at the head of the queue.
*
****************************************************************************/