You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by pk...@apache.org on 2022/02/17 20:27:48 UTC

[incubator-nuttx] branch master updated (8828a43 -> 1911ae2)

This is an automated email from the ASF dual-hosted git repository.

pkarashchenko pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git.


    from 8828a43  Default macro to compile one Rust file
     new a92d5f6  net/ioballoc: add support of alloc with timeout net_iobtimedalloc()
     new 1911ae2  net/tcp: add interface tcp_wrbuffer_timedalloc()

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 include/nuttx/net/net.h | 34 +++++++++++++++++++++--
 net/tcp/tcp.h           | 26 +++++++++++++++--
 net/tcp/tcp_wrbuffer.c  | 74 +++++++++++++++++++++++--------------------------
 net/utils/net_lock.c    | 45 ++++++++++++++++++++++++++----
 4 files changed, 130 insertions(+), 49 deletions(-)

[incubator-nuttx] 02/02: net/tcp: add interface tcp_wrbuffer_timedalloc()

Posted by pk...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

pkarashchenko pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git

commit 1911ae219255ab34a7b19c299b378838116e7de1
Author: chao.an <an...@xiaomi.com>
AuthorDate: Thu Feb 17 12:58:00 2022 +0800

    net/tcp: add interface tcp_wrbuffer_timedalloc()
    
    add new interface to support alloc wrbuffer with timeout
    
    Signed-off-by: chao.an <an...@xiaomi.com>
---
 net/tcp/tcp.h          | 26 ++++++++++++++++--
 net/tcp/tcp_wrbuffer.c | 74 ++++++++++++++++++++++++--------------------------
 2 files changed, 59 insertions(+), 41 deletions(-)

diff --git a/net/tcp/tcp.h b/net/tcp/tcp.h
index 87dab15..030a52b 100644
--- a/net/tcp/tcp.h
+++ b/net/tcp/tcp.h
@@ -1548,6 +1548,30 @@ int psock_tcp_cansend(FAR struct tcp_conn_s *conn);
 void tcp_wrbuffer_initialize(void);
 #endif /* CONFIG_NET_TCP_WRITE_BUFFERS */
 
+#ifdef CONFIG_NET_TCP_WRITE_BUFFERS
+
+struct tcp_wrbuffer_s;
+
+/****************************************************************************
+ * Name: tcp_wrbuffer_timedalloc
+ *
+ * Description:
+ *   Allocate a TCP write buffer by taking a pre-allocated buffer from
+ *   the free list.  This function is called from TCP logic when a buffer
+ *   of TCP data is about to sent
+ *   This function is wrapped version of tcp_wrbuffer_alloc(),
+ *   this wait will be terminated when the specified timeout expires.
+ *
+ * Input Parameters:
+ *   timeout   - The relative time to wait until a timeout is declared.
+ *
+ * Assumptions:
+ *   Called from user logic with the network locked.
+ *
+ ****************************************************************************/
+
+FAR struct tcp_wrbuffer_s *tcp_wrbuffer_timedalloc(unsigned int timeout);
+
 /****************************************************************************
  * Name: tcp_wrbuffer_alloc
  *
@@ -1564,8 +1588,6 @@ void tcp_wrbuffer_initialize(void);
  *
  ****************************************************************************/
 
-#ifdef CONFIG_NET_TCP_WRITE_BUFFERS
-struct tcp_wrbuffer_s;
 FAR struct tcp_wrbuffer_s *tcp_wrbuffer_alloc(void);
 
 /****************************************************************************
diff --git a/net/tcp/tcp_wrbuffer.c b/net/tcp/tcp_wrbuffer.c
index a93a2bc..7fb1bec 100644
--- a/net/tcp/tcp_wrbuffer.c
+++ b/net/tcp/tcp_wrbuffer.c
@@ -106,24 +106,27 @@ void tcp_wrbuffer_initialize(void)
 }
 
 /****************************************************************************
- * Name: tcp_wrbuffer_alloc
+ * Name: tcp_wrbuffer_timedalloc
  *
  * Description:
  *   Allocate a TCP write buffer by taking a pre-allocated buffer from
  *   the free list.  This function is called from TCP logic when a buffer
  *   of TCP data is about to sent
+ *   This function is wrapped version of tcp_wrbuffer_alloc(),
+ *   this wait will be terminated when the specified timeout expires.
  *
  * Input Parameters:
- *   None
+ *   timeout   - The relative time to wait until a timeout is declared.
  *
  * Assumptions:
  *   Called from user logic with the network locked.
  *
  ****************************************************************************/
 
-FAR struct tcp_wrbuffer_s *tcp_wrbuffer_alloc(void)
+FAR struct tcp_wrbuffer_s *tcp_wrbuffer_timedalloc(unsigned int timeout)
 {
   FAR struct tcp_wrbuffer_s *wrb;
+  int ret;
 
   /* We need to allocate two things:  (1) A write buffer structure and (2)
    * at least one I/O buffer to start the chain.
@@ -133,7 +136,11 @@ FAR struct tcp_wrbuffer_s *tcp_wrbuffer_alloc(void)
    * buffer
    */
 
-  net_lockedwait_uninterruptible(&g_wrbuffer.sem);
+  ret = net_timedwait_uninterruptible(&g_wrbuffer.sem, timeout);
+  if (ret != OK)
+    {
+      return NULL;
+    }
 
   /* Now, we are guaranteed to have a write buffer structure reserved
    * for us in the free list.
@@ -145,7 +152,8 @@ FAR struct tcp_wrbuffer_s *tcp_wrbuffer_alloc(void)
 
   /* Now get the first I/O buffer for the write buffer structure */
 
-  wrb->wb_iob = net_ioballoc(true, IOBUSER_NET_TCP_WRITEBUFFER);
+  wrb->wb_iob = net_iobtimedalloc(true, timeout,
+                                  IOBUSER_NET_TCP_WRITEBUFFER);
 
   /* Did we get an IOB?  We should always get one except under some really
    * weird error conditions.
@@ -162,6 +170,27 @@ FAR struct tcp_wrbuffer_s *tcp_wrbuffer_alloc(void)
 }
 
 /****************************************************************************
+ * Name: tcp_wrbuffer_alloc
+ *
+ * Description:
+ *   Allocate a TCP write buffer by taking a pre-allocated buffer from
+ *   the free list.  This function is called from TCP logic when a buffer
+ *   of TCP data is about to sent
+ *
+ * Input Parameters:
+ *   None
+ *
+ * Assumptions:
+ *   Called from user logic with the network locked.
+ *
+ ****************************************************************************/
+
+FAR struct tcp_wrbuffer_s *tcp_wrbuffer_alloc(void)
+{
+  return tcp_wrbuffer_timedalloc(UINT_MAX);
+}
+
+/****************************************************************************
  * Name: tcp_wrbuffer_tryalloc
  *
  * Description:
@@ -181,40 +210,7 @@ FAR struct tcp_wrbuffer_s *tcp_wrbuffer_alloc(void)
 
 FAR struct tcp_wrbuffer_s *tcp_wrbuffer_tryalloc(void)
 {
-  FAR struct tcp_wrbuffer_s *wrb;
-
-  /* We need to allocate two things:  (1) A write buffer structure and (2)
-   * at least one I/O buffer to start the chain.
-   *
-   * Allocate the write buffer structure first then the IOBG.  In order to
-   * avoid deadlocks, we will need to free the IOB first, then the write
-   * buffer
-   */
-
-  if (nxsem_trywait(&g_wrbuffer.sem) != OK)
-    {
-      return NULL;
-    }
-
-  /* Now, we are guaranteed to have a write buffer structure reserved
-   * for us in the free list.
-   */
-
-  wrb = (FAR struct tcp_wrbuffer_s *)sq_remfirst(&g_wrbuffer.freebuffers);
-  DEBUGASSERT(wrb);
-  memset(wrb, 0, sizeof(struct tcp_wrbuffer_s));
-
-  /* Now get the first I/O buffer for the write buffer structure */
-
-  wrb->wb_iob = iob_tryalloc(false, IOBUSER_NET_TCP_WRITEBUFFER);
-  if (!wrb->wb_iob)
-    {
-      nerr("ERROR: Failed to allocate I/O buffer\n");
-      tcp_wrbuffer_release(wrb);
-      return NULL;
-    }
-
-  return wrb;
+  return tcp_wrbuffer_timedalloc(0);
 }
 
 /****************************************************************************

[incubator-nuttx] 01/02: net/ioballoc: add support of alloc with timeout net_iobtimedalloc()

Posted by pk...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

pkarashchenko pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git

commit a92d5f622e322230e71435431a23fc6f132b4b69
Author: chao.an <an...@xiaomi.com>
AuthorDate: Thu Feb 17 12:42:35 2022 +0800

    net/ioballoc: add support of alloc with timeout net_iobtimedalloc()
    
    Signed-off-by: chao.an <an...@xiaomi.com>
---
 include/nuttx/net/net.h | 34 ++++++++++++++++++++++++++++++++--
 net/utils/net_lock.c    | 45 +++++++++++++++++++++++++++++++++++++++------
 2 files changed, 71 insertions(+), 8 deletions(-)

diff --git a/include/nuttx/net/net.h b/include/nuttx/net/net.h
index 0543dc0..8bdd503 100644
--- a/include/nuttx/net/net.h
+++ b/include/nuttx/net/net.h
@@ -460,6 +460,36 @@ int net_timedwait_uninterruptible(sem_t *sem, unsigned int timeout);
 
 int net_lockedwait_uninterruptible(sem_t *sem);
 
+#ifdef CONFIG_MM_IOB
+
+/****************************************************************************
+ * Name: net_iobtimedalloc
+ *
+ * Description:
+ *   Allocate an IOB.  If no IOBs are available, then atomically wait for
+ *   for the IOB while temporarily releasing the lock on the network.
+ *   This function is wrapped version of net_ioballoc(), this wait will
+ *   be terminated when the specified timeout expires.
+ *
+ *   Caution should be utilized.  Because the network lock is relinquished
+ *   during the wait, there could be changes in the network state that occur
+ *   before the lock is recovered.  Your design should account for this
+ *   possibility.
+ *
+ * Input Parameters:
+ *   throttled  - An indication of the IOB allocation is "throttled"
+ *   timeout    - The relative time to wait until a timeout is declared.
+ *   consumerid - id representing who is consuming the IOB
+ *
+ * Returned Value:
+ *   A pointer to the newly allocated IOB is returned on success.  NULL is
+ *   returned on any allocation failure.
+ *
+ ****************************************************************************/
+
+FAR struct iob_s *net_iobtimedalloc(bool throttled, unsigned int timeout,
+                                    enum iob_user_e consumerid);
+
 /****************************************************************************
  * Name: net_ioballoc
  *
@@ -473,7 +503,8 @@ int net_lockedwait_uninterruptible(sem_t *sem);
  *   possibility.
  *
  * Input Parameters:
- *   throttled - An indication of the IOB allocation is "throttled"
+ *   throttled  - An indication of the IOB allocation is "throttled"
+ *   consumerid - id representing who is consuming the IOB
  *
  * Returned Value:
  *   A pointer to the newly allocated IOB is returned on success.  NULL is
@@ -481,7 +512,6 @@ int net_lockedwait_uninterruptible(sem_t *sem);
  *
  ****************************************************************************/
 
-#ifdef CONFIG_MM_IOB
 FAR struct iob_s *net_ioballoc(bool throttled, enum iob_user_e consumerid);
 #endif
 
diff --git a/net/utils/net_lock.c b/net/utils/net_lock.c
index 94b3385..91666c5 100644
--- a/net/utils/net_lock.c
+++ b/net/utils/net_lock.c
@@ -451,12 +451,16 @@ int net_lockedwait_uninterruptible(sem_t *sem)
   return net_timedwait_uninterruptible(sem, UINT_MAX);
 }
 
+#ifdef CONFIG_MM_IOB
+
 /****************************************************************************
- * Name: net_ioballoc
+ * Name: net_timedalloc
  *
  * Description:
  *   Allocate an IOB.  If no IOBs are available, then atomically wait for
  *   for the IOB while temporarily releasing the lock on the network.
+ *   This function is wrapped version of nxsem_timedwait(), this wait will
+ *   be terminated when the specified timeout expires.
  *
  *   Caution should be utilized.  Because the network lock is relinquished
  *   during the wait, there could be changes in the network state that occur
@@ -464,7 +468,9 @@ int net_lockedwait_uninterruptible(sem_t *sem)
  *   possibility.
  *
  * Input Parameters:
- *   throttled - An indication of the IOB allocation is "throttled"
+ *   throttled  - An indication of the IOB allocation is "throttled"
+ *   timeout    - The relative time to wait until a timeout is declared.
+ *   consumerid - id representing who is consuming the IOB
  *
  * Returned Value:
  *   A pointer to the newly allocated IOB is returned on success.  NULL is
@@ -472,13 +478,13 @@ int net_lockedwait_uninterruptible(sem_t *sem)
  *
  ****************************************************************************/
 
-#ifdef CONFIG_MM_IOB
-FAR struct iob_s *net_ioballoc(bool throttled, enum iob_user_e consumerid)
+FAR struct iob_s *net_iobtimedalloc(bool throttled, unsigned int timeout,
+                                    enum iob_user_e consumerid)
 {
   FAR struct iob_s *iob;
 
   iob = iob_tryalloc(throttled, consumerid);
-  if (iob == NULL)
+  if (iob == NULL && timeout != 0)
     {
       unsigned int count;
       int blresult;
@@ -488,7 +494,7 @@ FAR struct iob_s *net_ioballoc(bool throttled, enum iob_user_e consumerid)
        */
 
       blresult = net_breaklock(&count);
-      iob      = iob_alloc(throttled, consumerid);
+      iob      = iob_timedalloc(throttled, timeout, consumerid);
       if (blresult >= 0)
         {
           net_restorelock(count);
@@ -497,4 +503,31 @@ FAR struct iob_s *net_ioballoc(bool throttled, enum iob_user_e consumerid)
 
   return iob;
 }
+
+/****************************************************************************
+ * Name: net_ioballoc
+ *
+ * Description:
+ *   Allocate an IOB.  If no IOBs are available, then atomically wait for
+ *   for the IOB while temporarily releasing the lock on the network.
+ *
+ *   Caution should be utilized.  Because the network lock is relinquished
+ *   during the wait, there could be changes in the network state that occur
+ *   before the lock is recovered.  Your design should account for this
+ *   possibility.
+ *
+ * Input Parameters:
+ *   throttled  - An indication of the IOB allocation is "throttled"
+ *   consumerid - id representing who is consuming the IOB
+ *
+ * Returned Value:
+ *   A pointer to the newly allocated IOB is returned on success.  NULL is
+ *   returned on any allocation failure.
+ *
+ ****************************************************************************/
+
+FAR struct iob_s *net_ioballoc(bool throttled, enum iob_user_e consumerid)
+{
+  return net_iobtimedalloc(throttled, UINT_MAX, consumerid);
+}
 #endif