You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by "zhhyu7 (via GitHub)" <gi...@apache.org> on 2024/04/24 09:36:24 UTC
[PR] mm/iob: Support alloc IOB via malloc [nuttx]
zhhyu7 opened a new pull request, #12224:
URL: https://github.com/apache/nuttx/pull/12224
## Summary
Support the network interface card driver to receive zero copies of packets and send and receive giant frame packets, allowing drivers to initialize the DMA buffer to the iob structure, and we can apply for IOB with large memory.
## Impact
## Testing
sim:local
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] mm/iob: Support alloc IOB via malloc [nuttx]
Posted by "zhhyu7 (via GitHub)" <gi...@apache.org>.
zhhyu7 commented on code in PR #12224:
URL: https://github.com/apache/nuttx/pull/12224#discussion_r1579404102
##########
mm/iob/iob_free.c:
##########
@@ -112,6 +115,15 @@ FAR struct iob_s *iob_free(FAR struct iob_s *iob)
next, next->io_pktlen, next->io_len);
}
+#ifdef CONFIG_IOB_ALLOC
+ if (iob->io_free != NULL)
+ {
+ iob->io_free(iob->io_data);
+ kmm_free(iob);
Review Comment:
@anchao we need to free iob header when driver call iob_alloc_with_data with custom free callback.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] mm/iob: Support alloc IOB via malloc [nuttx]
Posted by "zhhyu7 (via GitHub)" <gi...@apache.org>.
zhhyu7 commented on code in PR #12224:
URL: https://github.com/apache/nuttx/pull/12224#discussion_r1579404102
##########
mm/iob/iob_free.c:
##########
@@ -112,6 +115,15 @@ FAR struct iob_s *iob_free(FAR struct iob_s *iob)
next, next->io_pktlen, next->io_len);
}
+#ifdef CONFIG_IOB_ALLOC
+ if (iob->io_free != NULL)
+ {
+ iob->io_free(iob->io_data);
+ kmm_free(iob);
Review Comment:
@anchao we need to free iob head when driver call iob_alloc_with_data with custom free callback.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] mm/iob: Support alloc IOB via malloc [nuttx]
Posted by "anchao (via GitHub)" <gi...@apache.org>.
anchao commented on code in PR #12224:
URL: https://github.com/apache/nuttx/pull/12224#discussion_r1578763584
##########
mm/iob/iob_alloc.c:
##########
@@ -329,3 +349,89 @@ FAR struct iob_s *iob_tryalloc(bool throttled)
spin_unlock_irqrestore(&g_iob_lock, flags);
return NULL;
}
+
+#ifdef CONFIG_IOB_ALLOC
+
+/****************************************************************************
+ * Name: iob_alloc_dynamic
+ *
+ * Description:
+ * Allocate an I/O buffer and playload from heap
+ *
+ * Input Parameters:
+ * size - The size of the io_data that is allocated.
+ *
+ * +---------+
+ * | IOB |
+ * | io_data |--+
+ * | buffer |<-+
+ * +---------+
+ *
+ ****************************************************************************/
+
+FAR struct iob_s *iob_alloc_dynamic(uint16_t size)
+{
+ FAR struct iob_s *iob;
+ size_t alignsize;
+
+ alignsize = ROUNDUP(sizeof(struct iob_s), CONFIG_IOB_ALIGNMENT) + size;
+
+ iob = kmm_memalign(CONFIG_IOB_ALIGNMENT, alignsize);
+ if (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_bufsize = size; /* Total length of the iob buffer */
+ iob->io_pktlen = 0; /* Total length of the packet */
+ iob->io_free = iob_free_dummy; /* Customer free callback */
+ iob->io_data = (FAR uint8_t *)ROUNDUP((uintptr_t)(iob + 1),
+ CONFIG_IOB_ALIGNMENT);
+ }
+
+ return iob;
+}
+
+/****************************************************************************
+ * Name: iob_alloc_with_data
+ *
+ * Description:
+ * Allocate an I/O buffer from heap and attach the external payload
+ *
+ * Input Parameters:
+ * data - Make io_data point to a specific address, the caller is
+ * responsible for the memory management. The caller should
+ * ensure that the memory is not freed before the iob is freed.
+ *
+ * +---------+ +-->+--------+
+ * | IOB | | | data |
+ * | io_data |--+ +--------+
+ * +---------+
+ *
+ * size - The size of the data parameter
+ * free_cb - Notify the caller when the iob is freed. The caller can
+ * perform additional operations on the data before it is freed.
+ * The free_cb is called when the iob is freed.
+ *
+ ****************************************************************************/
+
+FAR struct iob_s *iob_alloc_with_data(FAR void *data, uint16_t size,
+ iob_free_t free_cb)
Review Comment:
free_cb should not be NULL
##########
include/nuttx/mm/iob.h:
##########
@@ -88,10 +88,18 @@
# define IOB_QEMPTY(q) ((q)->qh_head == NULL)
#endif
+#ifdef CONFIG_IOB_ALLOC
+# define IOB_BUFSIZE(p) ((p)->io_bufsize)
+#else
+# define IOB_BUFSIZE(p) CONFIG_IOB_BUFSIZE
+#endif
+
/****************************************************************************
* Public Types
****************************************************************************/
+typedef CODE void (*iob_free_t)(FAR void *data);
Review Comment:
```suggestion
typedef CODE void (*iob_free_cb_t)(FAR struct iob_s *iob);
```
##########
mm/iob/iob_free.c:
##########
@@ -112,6 +115,15 @@ FAR struct iob_s *iob_free(FAR struct iob_s *iob)
next, next->io_pktlen, next->io_len);
}
+#ifdef CONFIG_IOB_ALLOC
+ if (iob->io_free != NULL)
+ {
+ iob->io_free(iob->io_data);
+ kmm_free(iob);
Review Comment:
```suggestion
iob->io_free(iob);
```
##########
mm/iob/iob_alloc.c:
##########
@@ -197,6 +200,23 @@ static FAR struct iob_s *iob_allocwait(bool throttled, unsigned int timeout)
return iob;
}
+#ifdef CONFIG_IOB_ALLOC
+/****************************************************************************
+ * Name: iob_free_dummy
+ *
+ * Description:
+ * Dummy free callback function, do nothing.
+ *
+ * Input Parameters:
+ * data -
+ *
+ ****************************************************************************/
+
+static void iob_free_dummy(FAR void *data)
+{
+}
Review Comment:
```suggestion
static void iob_free_dynamic(FAR struct iob_s *iob)
{
kmm_free(iob);
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] mm/iob: Support alloc IOB via malloc [nuttx]
Posted by "zhhyu7 (via GitHub)" <gi...@apache.org>.
zhhyu7 commented on code in PR #12224:
URL: https://github.com/apache/nuttx/pull/12224#discussion_r1579433651
##########
mm/iob/iob_alloc.c:
##########
@@ -329,3 +349,89 @@ FAR struct iob_s *iob_tryalloc(bool throttled)
spin_unlock_irqrestore(&g_iob_lock, flags);
return NULL;
}
+
+#ifdef CONFIG_IOB_ALLOC
+
+/****************************************************************************
+ * Name: iob_alloc_dynamic
+ *
+ * Description:
+ * Allocate an I/O buffer and playload from heap
+ *
+ * Input Parameters:
+ * size - The size of the io_data that is allocated.
+ *
+ * +---------+
+ * | IOB |
+ * | io_data |--+
+ * | buffer |<-+
+ * +---------+
+ *
+ ****************************************************************************/
+
+FAR struct iob_s *iob_alloc_dynamic(uint16_t size)
+{
+ FAR struct iob_s *iob;
+ size_t alignsize;
+
+ alignsize = ROUNDUP(sizeof(struct iob_s), CONFIG_IOB_ALIGNMENT) + size;
+
+ iob = kmm_memalign(CONFIG_IOB_ALIGNMENT, alignsize);
+ if (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_bufsize = size; /* Total length of the iob buffer */
+ iob->io_pktlen = 0; /* Total length of the packet */
+ iob->io_free = iob_free_dummy; /* Customer free callback */
+ iob->io_data = (FAR uint8_t *)ROUNDUP((uintptr_t)(iob + 1),
+ CONFIG_IOB_ALIGNMENT);
+ }
+
+ return iob;
+}
+
+/****************************************************************************
+ * Name: iob_alloc_with_data
+ *
+ * Description:
+ * Allocate an I/O buffer from heap and attach the external payload
+ *
+ * Input Parameters:
+ * data - Make io_data point to a specific address, the caller is
+ * responsible for the memory management. The caller should
+ * ensure that the memory is not freed before the iob is freed.
+ *
+ * +---------+ +-->+--------+
+ * | IOB | | | data |
+ * | io_data |--+ +--------+
+ * +---------+
+ *
+ * size - The size of the data parameter
+ * free_cb - Notify the caller when the iob is freed. The caller can
+ * perform additional operations on the data before it is freed.
+ * The free_cb is called when the iob is freed.
+ *
+ ****************************************************************************/
+
+FAR struct iob_s *iob_alloc_with_data(FAR void *data, uint16_t size,
+ iob_free_t free_cb)
Review Comment:
done
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] mm/iob: Support alloc IOB via malloc [nuttx]
Posted by "zhhyu7 (via GitHub)" <gi...@apache.org>.
zhhyu7 commented on code in PR #12224:
URL: https://github.com/apache/nuttx/pull/12224#discussion_r1579433081
##########
include/nuttx/mm/iob.h:
##########
@@ -88,10 +88,18 @@
# define IOB_QEMPTY(q) ((q)->qh_head == NULL)
#endif
+#ifdef CONFIG_IOB_ALLOC
+# define IOB_BUFSIZE(p) ((p)->io_bufsize)
+#else
+# define IOB_BUFSIZE(p) CONFIG_IOB_BUFSIZE
+#endif
+
/****************************************************************************
* Public Types
****************************************************************************/
+typedef CODE void (*iob_free_t)(FAR void *data);
Review Comment:
done
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] mm/iob: Support alloc IOB via malloc [nuttx]
Posted by "xiaoxiang781216 (via GitHub)" <gi...@apache.org>.
xiaoxiang781216 merged PR #12224:
URL: https://github.com/apache/nuttx/pull/12224
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org