diff --git a/Documentation/NuttxPortingGuide.html b/Documentation/NuttxPortingGuide.html index c1db0c7eebb..58bc32c0417 100644 --- a/Documentation/NuttxPortingGuide.html +++ b/Documentation/NuttxPortingGuide.html @@ -12,7 +12,7 @@

NuttX RTOS Porting Guide

-

Last Updated: February 7, 2017

+

Last Updated: May 20, 2017

@@ -178,6 +178,14 @@ 4.11.2 LED Definitions
4.11.3 Common LED interfaces + 4.12 I/O Buffer Management + 5.0 NuttX File System
6.0 NuttX Device Drivers @@ -4172,6 +4180,428 @@ void board_autoled_off(int led); +

4.12 I/O Buffer Management

+ +NuttX supports generic I/O buffer management (IOB) logic. +This logic was originally added to support network I/O buffering, but has been generalized to meet buffering requirements by all device drivers. +At the time of this writing, IOBs are currently used not only be networking but also by logic in drivers/syslog and drivers/wireless. +This objectives of this feature are: + +
    +
  1. + Provide common I/O buffer management logic for all drivers, +
  2. +
  3. + Support I/O buffer allocation from both the tasking and interrupt level contexts. +
  4. +
  5. + Use a fixed amount of pre-allocated memory. +
  6. +
  7. + No costly, non-deterministic dynamic memory allocation. +
  8. +
  9. + When the fixed number of pre-allocated I/O buffers is exhausted, further attempts to allocate memory from tasking logic will cause the task to block and wait until a an I/O buffer to be freed. +
  10. +
  11. + Each I/O buffer should be small, but can be chained together to support buffering of larger thinks such as full size network packets. +
  12. +
  13. + Support throttling logic to prevent lower priority tasks from hogging all available I/O buffering. +
  14. +
+ +

4.12.1 Configuration Options

+ +
+
CONFIG_MM_IOB +
Enables generic I/O buffer support. This setting will build the common I/O buffer (IOB) support library. + +
CONFIG_IOB_NBUFFERS +
Number of pre-allocated I/O buffers. Each packet is represented by a series of small I/O buffers in a chain. This setting determines the number of preallocated I/O buffers available for packet data. + + The default value is setup for network support. The default is 8 buffers if neither TCP read-ahead or TCP write buffering is enabled (neither CONFIG_NET_TCP_WRITE_BUFFERS nor CONFIG_NET_TCP_READAHEAD), 24 if only write buffering is enabled, and 36 if both read-ahead and write buffering are enabled. + +
CONFIG_IOB_BUFSIZE +
Payload size of one I/O buffer. Each packet is represented by a series of small I/O buffers in a chain. This setting determines the data payload each preallocated I/O buffer. The default value is 196 bytes. + +
CONFIG_IOB_NCHAINS +
Number of pre-allocated I/O buffer chain heads. These tiny nodes are used as containers to support queueing of I/O buffer chains. This will limit the number of I/O transactions that can be in-flight at any give time. The default value of zero disables this features. + +
These generic I/O buffer chain containers are not currently used by any logic in NuttX. That is because their other other specialized I/O buffer chain containers that also carry a payload of usage specific information. + + The default value is zero if nether TCP nor UDP read-ahead buffering is enabled (i.e., neither CONFIG_NET_TCP_READAHEAD && !CONFIG_NET_UDP_READAHEAD or eight if either is enabled. + +
CONFIG_IOB_THROTTLE +
I/O buffer throttle value. 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. + + The default 0 if neither TCP write buffering nor TCP reada-ahead buffering is enabled. Otherwise, the default is 8. + +
CONFIG_IOB_DEBUG +
Force I/O buffer debug. This option will force debug output from I/O buffer logic. This is not normally something that would want to do but is convenient if you are debugging the I/O buffer logic and do not want to get overloaded with other un-related debug output. + + NOTE that this selection is not avaiable if DEBUG features are not enabled (CONFIG_DEBUG_FEATURES) with IOBs are being used to syslog buffering logic (CONFIG_SYSLOG_BUFFER). +
+ +

4.12.2 Throttling

+ + +An allocation throttle was added. I/O buffer allocation logic supports a throttle value originally for read-ahead buffering to prevent the read-ahead logic from consuming all available I/O buffers and blocking the write buffering logic. This throttle logic is only needed for networking only if both write buffering and read-ahead buffering are used. Of use of I/O buffering might have other motivations for throttling. + +

4.12.3 Public Types

+ +

+ This structure epresents one I/O buffer. A packet is contained by one or more I/O buffers in a chain. The io_pktlen is only valid for the I/O buffer at the head of the chain. +

+ +
+struct iob_s
+{
+  /* Singly-link list support */
+
+  FAR struct iob_s *io_flink;
+
+  /* Payload */
+
+#if CONFIG_IOB_BUFSIZE < 256
+  uint8_t  io_len;      /* Length of the data in the entry */
+  uint8_t  io_offset;   /* Data begins at this offset */
+#else
+  uint16_t io_len;      /* Length of the data in the entry */
+  uint16_t io_offset;   /* Data begins at this offset */
+#endif
+  uint16_t io_pktlen;   /* Total length of the packet */
+
+  uint8_t  io_data[CONFIG_IOB_BUFSIZE];
+};
+
+ +

+ This container structure supports queuing of I/O buffer chains. This structure is intended only for internal use by the IOB module. +

+ +
+#if CONFIG_IOB_NCHAINS > 0
+struct iob_qentry_s
+{
+  /* Singly-link list support */
+
+  FAR struct iob_qentry_s *qe_flink;
+
+  /* Payload -- Head of the I/O buffer chain */
+
+  FAR struct iob_s *qe_head;
+};
+#endif /* CONFIG_IOB_NCHAINS > 0 */
+
+ +

+ The I/O buffer queue head structure. +

+ +
+#if CONFIG_IOB_NCHAINS > 0
+struct iob_queue_s
+{
+  /* Head of the I/O buffer chain list */
+
+  FAR struct iob_qentry_s *qh_head;
+  FAR struct iob_qentry_s *qh_tail;
+};
+#endif /* CONFIG_IOB_NCHAINS > 0 */
+
+ +

4.12.4 Public Function Prototypes

+ + + +

4.12.4.1 iob_initialize()

+

Function Prototype: +

+#include <nuttx/mm/iob.h>
+void iob_initialize(void);
+
+ +

Description. + Set up the I/O buffers for normal operations. +

+ +

4.12.4.2 iob_alloc()

+

Function Prototype: +

+#include <nuttx/mm/iob.h>
+FAR struct iob_s *iob_alloc(bool throttled);
+
+ +

Description. + Allocate an I/O buffer by taking the buffer at the head of the free list. +

+ +

4.12.4.3 iob_tryalloc()

+

Function Prototype: +

+#include <nuttx/mm/iob.h>
+FAR struct iob_s *iob_tryalloc(bool throttled);
+
+ +

Description. + Try to allocate an I/O buffer by taking the buffer at the head of the free list without waiting for a buffer to become free. +

+ +

4.12.4.4 iob_free()

+

Function Prototype: +

+#include <nuttx/mm/iob.h>
+FAR struct iob_s *iob_free(FAR struct iob_s *iob);
+
+ +

Description. + Free the I/O buffer at the head of a buffer chain returning it to the free list. The link to the next I/O buffer in the chain is return. +

+ +

4.12.4.5 iob_free_chain()

+

Function Prototype: +

+#include <nuttx/mm/iob.h>
+void iob_free_chain(FAR struct iob_s *iob);
+
+ +

Description. + Free an entire buffer chain, starting at the beginning of the I/O buffer chain +

+ +

4.12.4.6 iob_add_queue()

+

Function Prototype: +

+#include <nuttx/mm/iob.h>
+#if CONFIG_IOB_NCHAINS > 0
+int iob_add_queue(FAR struct iob_s *iob, FAR struct iob_queue_s *iobq);
+#endif /* CONFIG_IOB_NCHAINS > 0 */
+
+ +

Description. + Add one I/O buffer chain to the end of a queue. May fail due to lack of resources. +

+ +

4.12.4.7 iob_tryadd_queue()

+

Function Prototype: +

+#include <nuttx/mm/iob.h>
+#if CONFIG_IOB_NCHAINS > 0
+int iob_tryadd_queue(FAR struct iob_s *iob, FAR struct iob_queue_s *iobq);
+#endif /* CONFIG_IOB_NCHAINS > 0 */
+
+ +

Description. + Add one I/O buffer chain to the end of a queue without waiting for resources to become free. +

+ +

4.12.4.8 iob_remove_queue()

+

Function Prototype: +

+#include <nuttx/mm/iob.h>
+#if CONFIG_IOB_NCHAINS > 0
+FAR struct iob_s *iob_remove_queue(FAR struct iob_queue_s *iobq);
+#endif /* CONFIG_IOB_NCHAINS > 0 */
+
+ +

Description. + 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. +

+ +

4.12.4.9 iob_peek_queue()

+

Function Prototype: +

+#include <nuttx/mm/iob.h>
+#if CONFIG_IOB_NCHAINS > 0
+FAR struct iob_s *iob_peek_queue(FAR struct iob_queue_s *iobq);
+#endif
+
+ +

Description. + Return a reference to the I/O buffer chain at the head of a queue. This is similar to iob_remove_queue except that the I/O buffer chain is in place at the head of the queue. The I/O buffer chain may safely be modified by the caller but must be removed from the queue before it can be freed. +

+ +

Returned Value. + Returns a reference to the I/O buffer chain at the head of the queue. +

+ +

4.12.4.10 iob_free_queue()

+

Function Prototype: +

+#include <nuttx/mm/iob.h>
+#if CONFIG_IOB_NCHAINS > 0
+void iob_free_queue(FAR struct iob_queue_s *qhead);
+#endif /* CONFIG_IOB_NCHAINS > 0 */
+
+ +

Description. + Free an entire queue of I/O buffer chains. +

+ +

4.12.4.11 iob_copyin()

+

Function Prototype: +

+#include <nuttx/mm/iob.h>
+int iob_copyin(FAR struct iob_s *iob, FAR const uint8_t *src,
+               unsigned int len, unsigned int offset, bool throttled);
+
+ +

Description. + Copy data len bytes from a user buffer into the I/O buffer chain, starting at offset, extending the chain as necessary. +

+ +

4.12.4.12 iob_trycopyin()

+

Function Prototype: +

+#include <nuttx/mm/iob.h>
+int iob_trycopyin(FAR struct iob_s *iob, FAR const uint8_t *src,
+                  unsigned int len, unsigned int offset, bool throttled);
+
+ +

Description. + Copy data len bytes from a user buffer into the I/O buffer chain, starting at offset, extending the chain as necessary BUT without waiting if buffers are not available. +

+ +

4.12.4.13 iob_copyout()

+

Function Prototype: +

+#include <nuttx/mm/iob.h>
+int iob_copyout(FAR uint8_t *dest, FAR const struct iob_s *iob,
+                unsigned int len, unsigned int offset);
+
+ +

Description. + Copy data len bytes of data into the user buffer starting at offset in the I/O buffer, returning that actual number of bytes copied out. +

+ +

4.12.4.14 iob_clone()

+

Function Prototype: +

+#include <nuttx/mm/iob.h>
+int iob_clone(FAR struct iob_s *iob1, FAR struct iob_s *iob2, bool throttled);
+
+ +

Description. + Duplicate (and pack) the data in iob1 in iob2. iob2 must be empty. +

+ +

4.12.4.15 iob_concat()

+

Function Prototype: +

+#include <nuttx/mm/iob.h>
+void iob_concat(FAR struct iob_s *iob1, FAR struct iob_s *iob2);
+
+ +

Description. + Concatenate iob_s chain iob2 to iob1. +

+ +

4.12.4.16 iob_trimhead()

+

Function Prototype: +

+#include <nuttx/mm/iob.h>
+FAR struct iob_s *iob_trimhead(FAR struct iob_s *iob, unsigned int trimlen);
+
+ +

Description. + Remove bytes from the beginning of an I/O chain. Emptied I/O buffers are freed and, hence, the beginning of the chain may change. +

+ +

4.12.4.17 iob_trimhead_queue()

+

Function Prototype: +

+#include <nuttx/mm/iob.h>
+#if CONFIG_IOB_NCHAINS > 0
+FAR struct iob_s *iob_trimhead_queue(FAR struct iob_queue_s *qhead,
+                                     unsigned int trimlen);
+#endif
+
+ +

Description. + Remove bytes from the beginning of an I/O chain at the head of the queue. Emptied I/O buffers are freed and, hence, the head of the queue may change. +

+

+ This function is just a wrapper around iob_trimhead() that assures that the iob at the head of queue is modified with the trimming operations. +

+ +

Returned Value. + The new iob at the head of the queue is returned. +

+ +

4.12.4.18 iob_trimtail()

+

Function Prototype: +

+#include <nuttx/mm/iob.h>
+FAR struct iob_s *iob_trimtail(FAR struct iob_s *iob, unsigned int trimlen);
+
+ +

Description. + Remove bytes from the end of an I/O chain. Emptied I/O buffers are freed NULL will be returned in the special case where the entry I/O buffer chain is freed. +

+ +

4.12.4.19 iob_pack()

+

Function Prototype: +

+#include <nuttx/mm/iob.h>
+FAR struct iob_s *iob_pack(FAR struct iob_s *iob);
+
+ +

Description. + Pack all data in the I/O buffer chain so that the data offset is zero and all but the final buffer in the chain are filled. Any emptied buffers at the end of the chain are freed. +

+ +

4.12.4.20 iob_contig()

+

Function Prototype: +

+#include <nuttx/mm/iob.h>
+int iob_contig(FAR struct iob_s *iob, unsigned int len);
+
+ +

Description. + Ensure that there is len bytes of contiguous space at the beginning of the I/O buffer chain starting at iob. +

+ +

4.12.4.21 iob_dump()

+

Function Prototype: +

+#include <nuttx/mm/iob.h>
+#ifdef CONFIG_DEBUG_FEATURES
+void iob_dump(FAR const char *msg, FAR struct iob_s *iob, unsigned int len,
+              unsigned int offset);
+#endif
+
+ +

Description. + Dump the contents of a I/O buffer chain +

+
diff --git a/mm/iob/Kconfig b/mm/iob/Kconfig index 0790961a794..b64f90e3ce8 100644 --- a/mm/iob/Kconfig +++ b/mm/iob/Kconfig @@ -51,7 +51,6 @@ 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 @@ -70,7 +69,7 @@ config IOB_DEBUG if you are debugging the I/O buffer logic and do not want to get overloaded with other un-related debug output. - NOTE that this selection is not avaiable with IOBs are being used + NOTE that this selection is not available if IOBs are being used to syslog buffering logic (CONFIG_SYSLOG_BUFFER=y)! endif # MM_IOB