lwip-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [lwip-devel] Zero Copy support


From: Dirk Ziegelmeier
Subject: Re: [lwip-devel] Zero Copy support
Date: Tue, 20 Sep 2016 09:07:07 +0200

Here is an example of custom PBUF usage for zero-copy RX. In most cases, you need this because you need to know when the buffer is freed by lwIP - using a PBUF_REF you do not a "free" callback.

typedef struct my_custom_pbuf
{
   struct pbuf_custom p;
   void* dma_descriptor;
} my_custom_pbuf_t;

void my_pbuf_free_custom(void* p)
{
  my_custom_pbuf_t* my_puf = (my_custom_pbuf_t*)p;
  free_rx_dma_descriptor(my_pbuf->dma_descriptor);
  my_pbuf_pool_put(my_pbuf);
}

void eth_rx_irq()
{
  dma_descriptor* dma_desc = get_RX_DMA_descriptor_from_ethernet();
  my_custom_pbuf_t* my_pbuf = my_pbuf_pool_get();

  my_pbuf->p.custom_free_function = my_pbuf_free_custom;
  my_pbuf->dma_descriptor = dma_desc;

  struct pbuf* p = pbuf_alloced_custom(PBUF_RAW,
    dma_desc->rx_length,
    PBUF_REF,
    &my_pbuf.p,
    dma_desc->rx_data,
    dma_desc->max_buffer_size);

  netif->input(p, netif);
}

Dirk

On Mon, Sep 19, 2016 at 4:41 PM, Joel Cunningham <address@hidden> wrote:
Here's some information on the state of zero-copy:

RX has been implemented in git head (2.0.0 pending release) and can be implemented using PBUF_REF instead of PBUF_POOL.  The winpcap netif in lwip-contrib has an example of how to use PBUF_REF and a custom pbuf in the RX pathway.  Note the winpcap example isn't actually zero-copy from the pcap API because that doesn't allow handing off memory allocations, but you can see how the PBUF_REF/custom pbuf works

TX for TCP from the core to the driver is not fully implemented for asynchronous drivers.  There's an open task tracking the remaining work: https://savannah.nongnu.org/task/?7896.  The main piece missing is that when the pbuf is passed to the driver, we end up making a second reference to the pbuf because TCP continues to hold a reference for retransmission.  Synchronization for access and modification across multiple contexts (TCP retransmision and driver) is not currently implemented, thus leaving a case where both could modify the memory at the same time.  Other stacks (Linux for example) make a copy of the pbuf upon the case of modification when the reference count is > 1

Joel

On Sep 17, 2016, at 04:21 AM, Dimax <address@hidden> wrote:

Hi,
We have started to work on implementation of Zero Copy in our ETH driver based on lwip-1.4.1. But now it looks like 2.0.0 release is on it's way, so we are thinking to migrate with new development to 0.2.0.

My questions are: 
- What critical changes were made between 1.4.1 and 2.0.0 in what is related to pbufs allocation/deallocation
- Are there any guidelines or thought about Zero Copy implementation in 2.0.0  

Our initial effort was to find a place(s) to catch pbufs alloc/free and overlay it with our functionality that will be synced with DMA buffers creation processing and release.
I can see LWIP_SUPPORT_CUSTOM_PBUF introduced in 2.0.0. Where can we get mode details about this feature?

Thanks

_______________________________________________
lwip-devel mailing list
address@hidden
https://lists.nongnu.org/mailman/listinfo/lwip-devel

_______________________________________________
lwip-devel mailing list
address@hidden
https://lists.nongnu.org/mailman/listinfo/lwip-devel



reply via email to

[Prev in Thread] Current Thread [Next in Thread]