patchlwIP - A Lightweight TCP/IP stack - Patches: patch #7658, Make pbuf_free() send PBUF_POOL...

 
 

You are not allowed to post comments on this tracker with your current authentication level.

patch #7658: Make pbuf_free() send PBUF_POOL pbufs to Ethernet driver directly.

Submitter:  Timmy Brolin <brolin>
Submitted:  Wed 02 Nov 2011 08:18:55 PM UTC
   
 
Category:  pbufs Priority:  5 - Normal
Status:  Done Privacy:  Public
Assigned to:  goldsimon Open/Closed:  Closed
Planned Release:  None

Fri 13 Feb 2015 08:56:38 PM UTC, comment #4: 

Done in a different way:
- LWIP_SUPPORT_CUSTOM_PBUF can be overridden if needed
- LWIP_HOOK_MEMP_AVAILABLE informs you of an empty pool getting an element back. This has a little more overhead than passing the pbuf to the driver directly but has the bonus of being more versatile.

If you really care for the overhead, use custom pbufs (it works, I have an IPv4 platform using them - custom PBUF_REF pbufs are used for RX)

Simon Goldschmidt <goldsimon>
Group administrator
Wed 04 Jul 2012 10:50:32 AM UTC, comment #3: 

Just found task #11472 which this patch is "sort-of" related to.

The issue of supporting "fixed location RX" buffers can easily be achieved by using the lwIP support for MEMP_SEPARATE_POOLS to allow the specific driver to provide the location for the actual memp_memory_PBUF_POOL_base[] vector... and in-conjunction with a free hook as provided by this patch allows drivers to control RX buffers from fixed locations.

Admittedly at the moment it is for the complete PBUF_POOL space (and not specifically RX-only buffers). If a completely stand-alone RX space is required for a target then ideally the CUSTOM PBUF support could be improved (exported) to allow drivers to easily implement a separate RX "custom" PBUF pool. i.e. allow LWIP_SUPPORT_CUSTOM_PBUF to be a lwipopts.h->opt.h option (and not just in pbuf.h), with suitable exported API support so that drivers can use the CUSTOM support for fixed location, DMA-ring-buffer, etc. So this patch would not strictly be needed, especially if the LWIP_SUPPORT_CUSTOM_PBUF support allowed for "buffer re-use" (as this patch does).

James Smith <rallysmith>
Fri 01 Jun 2012 09:48:07 AM UTC, comment #2: 

I noticed this patch request, and that it has not been acted on for a while, and since we need (use) similar functionality I thought it prudent to add to this existing patch in the hope of reviving it, instead of creating a new (competing) patch.

Similarly for our driver support we need a hook to allow PBUF_POOL entries to be returned to the driver in a timely fashion, and ideally avoiding unnecessary free/alloc operations.

Attached is a suggested patch (against the head of the git tree) implementing the support slightly differently to that originally suggested last year by Timothy in his original comment.

Basically I used a more generic (in my opinion) manifest name of PBUF_POOL_FREE_HOOK (instead of DMA_RING_REPLENISH) and the polarity of the "return" code is changed to 0 means re-used, and 1 means pbuf_free() can continue to release the allocation (that way around made it easier/simpler ensuring that the pbuf_free() "count" is maintained with minimum overhead).

A new routine pbuf_pool_reinit() is provided to allow the callback (if defined) to reset the PBUF state. Some assumptions are covered by asserts.



(file #25968)

James Smith <rallysmith>
Sat 17 Dec 2011 09:22:38 PM UTC, comment #1: 

I like the idea, however we'd need a function that the netif driver can call to set the pbuf to "newly allocated" state - we wouldn't want that code to be spread accross netif drivers.

Simon Goldschmidt <goldsimon>
Group administrator
Wed 02 Nov 2011 08:18:55 PM UTC, original submission:  

I have tested this method on my hardware and it works nicely.
This is my suggestion for how it can be implemented in LwIP:

In pbuf.c, function pbuf_free(), change this:

   /* is this a pbuf from the pool? */
   if (type == PBUF_POOL) {
     memp_free(MEMP_PBUF_POOL, p);

To this:

   if (type == PBUF_POOL) {
     if( !DMA_RING_REPLENISH( p ) ) {
       memp_free(MEMP_PBUF_POOL, p);
     }

In opt.h, add this:

#ifndef DMA_RING_REPLENISH
#define DMA_RING_REPLENISH( p ) 0
#endif

In lwipopts.h, the feature can be enabled by a define like this:

#define DMA_RING_REPLENISH( p ) MAC_ReplenishRx( p )


The way it works is that whenever a PBUF_POOL is deallocated, it is first offered to the Ethernet driver via the function DMA_RING_REPLENISH(). If the Ethernet driver wants the pbuf, it returns true. If however the Ethernet driver does not want the pbuf at this time (DMA ring is already full), then it returns false, and the pbuf is is freed normally using memp_free().

By offering the pbuf to the Ethernet driver directly, the entire memp_free(), context switch, pbuf_alloc() sequence is bypassed, saving CPU cycles. It can also simplify the Ethernet driver.

The pbuf might be in a somewhat random shape when it is offered to the Ethernet driver, so the DMA_RING_REPLENISH() function is responsible for restoring the pbuf struct content to default "newly allocated" state, including incrementing "ref" to "1".

Timmy Brolin <brolin>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attached Files
file #25968:  pbuf_7658.patch added by rallysmith (7KiB - application/octet-stream - Allow PBUF_POOL entries to be reused via a callback )

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by rallysmith (Updated the item)
  • -email is unavailable- added by goldsimon (Posted a comment)
  • -email is unavailable- added by brolin (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

     

    Follow 5 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2015-02-13 goldsimon StatusNone Done
        Assigned toNone goldsimon
        Open/ClosedOpen Closed
    2013-01-15 goldsimon CategoryNone pbufs
    2012-06-01 rallysmith Attached File- Added pbuf_7658.patch, #25968

    Back to the top

    Powered by Savane 3.12.
    Corresponding source code