Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  • Public:
    • IBuf: Single buffer in a linked chain
    • IBufChain: Linked chain of IBufs
    • IBufQueue; Queue container for IBufChains
    • Buf (IBuf in shared pointer)
    • IBufChain: Linked chain of IBufs
    • BufChain (IBufChain in shared pointer)
    • IBufQueue; Queue container for IBufChains
    • BufQueue (IBufQueue in shared pointer)
  • Private:
    • CBufImpl: Implementation of IBuf with ability to be a CFreeListNode
    • BufImpl (CBufImpl in shared pointer)
    • CBufChainImpl: Implementation of IBufChain with ability to be a CFreeListNodeBufImpl (CBufImpl in shared pointer)
    • BufChainImpl (CBufChainImpl in shared pointer)
    • CBufQueue: implementation of IBufQueue
    • IBufSync:
    • BufSync: (IBufSync in shared pointer)
    • CBufQueueBase (typedef of queue: 

      typedef queue< IBufChain *, boost::lockfree::fixed_sized< true > > CBufQueueBase;)

    • CEventBufSync

    • CBufQueue

Buf

IBuf class methods implemented in CBufImpl :

  • Buf getBuf(size_t capa, bool clip = false): Get a new buffer from free list or create new. Reduced to allowed size if size exceeds max available buffer when clip = true.
  • numBufsAlloced(): Buffers created from heap.
  • numBufsFree(): Total on free list.
  • numBufsInUse(): Number of buffers currently used

IBuf virtual methods implemented in CBufImpl:

  • size_t getCapacity(): Get max capacity of buffer as created
  • uint8_t * getPayload(): Get pointer to start of payload within the buffer
  • size_t getSize(): Get size of usable payload within the buffer
  • size_t getAvail(): Get amount of room left (capacity - end of payload)
  • size_t getHeadRoom(): Get available data before start of payload (not sure why this would be needed?)
  • void setSize(size_t s): Set size of payload in the buffer
  • void setPayload(uint8_t *p): Set start of payload within the buffer to *p
  • bool adjPayload(ssize_t delta): Shift the payload pointer by a specified amount, return false if shift exceeds payload
  • Buf getNext(): Get next entry in chain
  • Buf getPrev(): Get previous entry in chain
  • BufChain getChain(): Get pointer to head of chain
  • void after(Buf buf): Insert this buffer after buf
  • void before(Buf buf): Insert this buffer before buf
  • void unlink(): Remove this buffer from the chain
  • void split(): Split the list at this entry. This buffer becomes the head of a new list, can not be on a chain

CBufImpl private variables:

  • weak_ptr<CBufChainImpl> chain_: Weak pointer to chain containing this buffer
  • BufImpl next_: Next entry (strong pointer)
  • weak_ptr<CBufImpl>: Previous entry (weak pointer)
  • unsigned short beg_, end_, capa_: Beginning of payload, end of payload and capacity
  • uint8_t data_[]: Array of bytes containing data

...

  • void addToChain(BufChainImpl c); Add this buffer, and the rest of the list, to an empty chain
  • void reinit(): Reset the payload pointers (beg = end = HEADROOM)
  • BufImpl getNextImpl(): Get next entry
  • BufImpl getPrevImpl(): Get prev entry
  • BufChainImpl getChainImpl(): Get chain pointer
  • unlinkCheap(CBufChainImpl::key k): 

BufChain

IBufChain class methods implemented in CBufChainImpl :

  • void take_ownership(BufChain p_owner): Set smart pointer inside the class to keep it from being destroyed
  • BufChain yield_ownership() Take ownership back and unlink internal smart pointer
  • BufChain create(): create a buffer chain.

IBufChain virtual methods implemented in CBufChainImpl:

  • Buf getHead(): get head of chain
  • Buf getTail(): get tail of chain
  • unsigned getLen(): get number of elements 
  • unsigned getSize(): get total number of payload bytes in chain
  • Buf createAtHead(size_t size, bool clip=false): create a new buffer at the heat
  • Buf createAtTail(size_t size, bool clip=false): create a new buffer at the tail
  • void addAtHead(Buf b): add a buffer to the head
  • void addAtTail(Buf b): add a buffer to the tail
  • uint64_t extract(void *buf, uint65_t off, unit64_t size): extract data to passed buffer
  • uint65_t insert(void *buf, uint64_t off, uint64_t size): insert data from passed buffer

CBufChainImpl private variables:

  • BufChainImpl strong_self_: pointer to self used to maintain valid pointer
  • BufImpl head_: head of chain
  • BufImpl tail_: tail of chain
  • unsigned len_t: length of chain
  • size_t size_: total size in bytes

...

  • BufChain pop(const CTimeout *abs_timeout): Pop an entry from the queue with timeout
  • BufChain tryPop(): try to pop without timeout?
  • bool push(BufChain b, const CTimeout *abs_timeout): add an entry to the queue with timeout
  • bool tryPush(BufChain b): add an entry without timeout?
  • CTimeout getAbsTimeoutPop(const CTimeout *rel_timeout): ?????
  • CTimeout getAbsTimeoutPush(const CTimeout *rel_timeout): ????
  • IEventSource getReadEventSource(): ????
  • IEventSource getWriteEventSource(): ????
  • bool isFull(): queue is full
  • bool isEmpty() queue is full
  • void shutdown(): ????
  • void startup(): ????

CBufQueue private attributes



Questions:

Till,

I am going through the CPSW code and have some questions and comments, starting with the CPSW buffer implementation. BTW I like the approach to the buffer chains which minimizes the number of copies to the copy from the UDP receive and the copy to user space. 

1. It appears you base the buffer size constants and container variables around the assumption that we will limit each buffer element size to 64K. I am not sure if that is a safe assumption once we add support for interfaces that are not TCP/IP or UDP. With PGP or axi-stream we can have much larger buffers. Also you seem to hardcode some ethernet based constants in the .h file and I am not sure that is the best place for a generic implementation. (more notes on size later)

2. In adjPayload you have this line:

if ( delta > beg || delta > old_size )
return false;

Why do you care if the shift size is greater than the beginning payload offset? Should this be an unsigned compare to check for left shifts beyond the beginning of the buffer?

...