8000 wiznet: lwip: Implement zero-copy for socket buffers. by greezybacon · Pull Request #17447 · micropython/micropython · GitHub
[go: up one dir, main page]

Skip to content

wiznet: lwip: Implement zero-copy for socket buffers. #17447

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

greezybacon
Copy link
Contributor

Summary

This is closer to a zero-copy mechanism for the Wiznet chip and LwIP stack. Instead of using a static Ethernet frame buffer, it copies from the device directly into LwIP pbufs and visa versa.

Additionally, it avoids an issue for WIZnet devices:

  1. In the wiznet5k_poll method, if the chip indicates there is data available to receive and it is received but no buffer space is available in LwIP, then the packet will be fetched from the device and discarded. Instead, now it will remain on the device until sufficient memory is available in the MCU.

Furthermore, it optimizes and simplifies the usage of the WIZnet device based on the particular usage that the MACRAW mode will be used on exactly one socket on the device. It frees 1514 bytes of a static Ethernet frame buffer over the baseline.

Testing

I've tested this pretty extensively on the RP2040 and WIZnet W5100S. Based on interest, I'm happy to test it further on other devices.

Trade-offs and Alternatives

As written, it removes support for the W5200 and W5300 chips- although there is no reference board or firmware in the project for these devices.

However, insourcing a simplified driver could make for a simpler platform to add support for the W6100.

If Ethernet tracing is enabled, when traces are written to the console, if the LwIP pbuf is fragmented, only the first fragment is traced. This is to prevent the need for a copy of the buffer.

This avoids an issue for WIZnet devices:

  1. In the `wiznet5k_poll` method, if the chip indicates there is data
     available to receive and it is received but no buffer space is
     available in LwIP, then the packet will be fetched from the device
     and discarded. Instead, now it will remain on the device until
     sufficient memory is available in the MCU.

Additionally, it optimizes and simplifies the usage of the WIZnet device
based on the assumption that the MACRAW mode will be used on exactly one
socket on the device. It also sends and receives socket buffers directly
between the device and LwIP PBUFs without a copy. It frees 1514 bytes of
a static Ethernet frame buffer over the baseline.

Signed-off-by: Jared Hancock <jared.hancock@centeredsolutions.com>
Copy link
codecov bot commented Jun 6, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.54%. Comparing base (f498a16) to head (ace33cb).
Report is 232 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #17447      +/-   ##
==========================================
- Coverage   98.54%   98.54%   -0.01%     
==========================================
  Files         169      169              
  Lines       21890    21943      +53     
==========================================
+ Hits        21571    21623      +52     
- Misses        319      320       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
github-actions bot commented Jun 6, 2025

Code size report:

   bare-arm:    +0 +0.000% 
minimal x86:    +0 +0.000% 
   unix x64:    +0 +0.000% standard
      stm32:    +0 +0.000% PYBV10
     mimxrt:    +0 +0.000% TEENSY40
        rp2:    +0 +0.000% RPI_PICO_W
       samd:    +0 +0.000% ADAFRUIT_ITSYBITSY_M4_EXPRESS
  qemu rv32:    +0 +0.000% VIRT_RV32

@dpgeorge dpgeorge added extmod Relates to extmod/ directory in source drivers labels Jun 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
drivers extmod Relates to extmod/ directory in source
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0