Skip to contentSkip to conversation

nios2: nios2-generic: do not allocate rx buf in net.c

PATCH New Thomas Chou 2 participants 5 messages Nov 5, 2015 – Nov 6, 2015

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 nios2: nios2-generic: do not allocate rx buf in net.c

Do not allocate rx buf in net.c, because altera_tse allocates its own rx buf in driver. This can save 6KB memory.

---
 include/configs/nios2-generic.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
include/configs/nios2-generic.h +2 -1
index 4569de8..856c836 100644
@@ -33,8 +33,9 @@
 #define CONFIG_SYS_MAX_FLASH_SECT	512
 
 /*
- * MII/PHY
+ * NET options
  */
+#define CONFIG_SYS_RX_ETH_BUFFER	0
 #define CONFIG_CMD_MII
 #define CONFIG_PHY_GIGE
 #define CONFIG_SYS_FAULT_ECHO_LINK_DOWN
Signature · 1 line
2.5.0
#1 lore raw

PATCH 1/1 nios2: nios2-generic: do not allocate rx buf in net.c

Quoted 4 lines · Thomas Chou

Do not allocate rx buf in net.c, because altera_tse allocates its own rx buf in driver. This can save 6KB memory.

Shouldn't we instead fix the altera driver to use the pre-allocated buffer ?

Best regards,
Marek Vasut

#2 lore raw

PATCH 1/1 nios2: nios2-generic: do not allocate rx buf in net.c

Hi Marek,

Quoted 8 lines · Marek Vasut
Quoted 4 lines · Thomas Chou

Do not allocate rx buf in net.c, because altera_tse allocates its own rx buf in driver. This can save 6KB memory.

Shouldn't we instead fix the altera driver to use the pre-allocated buffer ?

It should not. The drivers and devices are dynamically binding in driver model. The buffers used by devices should be allocated per device. Eg, there may be multiple ethernet devices and they should not use the same pre-allocated rx bufs.

Best regards,
Thomas

#3 lore raw

PATCH 1/1 nios2: nios2-generic: do not allocate rx buf in net.c

Quoted 1 line · Thomas Chou

Hi Marek,

Hi!

Quoted 7 lines · Marek Vasut
Quoted 6 lines · Thomas Chou
Quoted 4 lines

Do not allocate rx buf in net.c, because altera_tse allocates its own rx buf in driver. This can save 6KB memory.

Quoted 7 lines
Quoted 2 lines

Shouldn't we instead fix the altera driver to use the pre-allocated buffer ?

It should not. The drivers and devices are dynamically binding in driver model. The buffers used by devices should be allocated per device. Eg, there may be multiple ethernet devices and they should not use the same pre-allocated rx bufs.

Oh ok, I see your point now. But then, this allocation of buffers in the ethernet drivers becomes a boilerplate code, right ? So maybe there should be some mechanism in the network stack to allocate the buffers for the drivers to prevent duplication of code.

What do you think?

Best regards,
Marek Vasut

#4 lore raw

PATCH 1/1 nios2: nios2-generic: do not allocate rx buf in net.c

Hi Marek,

Quoted 20 lines · Marek Vasut
Quoted 1 line · Thomas Chou

Hi Marek,

Hi!

Quoted 7 lines · Marek Vasut
Quoted 6 lines · Thomas Chou
Quoted 4 lines

Do not allocate rx buf in net.c, because altera_tse allocates its own rx buf in driver. This can save 6KB memory.

Quoted 7 lines
Quoted 2 lines

Shouldn't we instead fix the altera driver to use the pre-allocated buffer ?

It should not. The drivers and devices are dynamically binding in driver model. The buffers used by devices should be allocated per device. Eg, there may be multiple ethernet devices and they should not use the same pre-allocated rx bufs.

Quoted 4 lines

Oh ok, I see your point now. But then, this allocation of buffers in the ethernet drivers becomes a boilerplate code, right ? So maybe there should be some mechanism in the network stack to allocate the buffers for the drivers to prevent duplication of code.

The pre-alloacted tx_buf is still in use by net/ . But most ethernet drivers allocate their own rx_buf (perhaps as ring buffer). Most of them use memalign(PKTSIZE_ALIGN), which is the same as malloc_cache_aligned(PKTSIZE_ALIGN). Each driver may have different requirement of size/number of the rx buf.

The driver passes the rx buf to net/ . And the net/ return the rx buf with free_pkt() to the driver after use.

I think this scheme works fine. There not much duplication of code for rx_buf allocation, which might be only a malloc_cache_aligned().

Best regards,
Thomas