> On Sep 18, 2019, at 6:54 PM, Olivier Matz <olivier.m...@6wind.com> wrote:
> 
> Many features require to store data inside the mbuf. As the room in mbuf
> structure is limited, it is not possible to have a field for each
> feature. Also, changing fields in the mbuf structure can break the API
> or ABI.
> 
> This commit addresses these issues, by enabling the dynamic registration
> of fields or flags:
> 
> - a dynamic field is a named area in the rte_mbuf structure, with a
>  given size (>= 1 byte) and alignment constraint.
> - a dynamic flag is a named bit in the rte_mbuf structure.
> 
> The typical use case is a PMD that registers space for an offload
> feature, when the application requests to enable this feature.  As
> the space in mbuf is limited, the space should only be reserved if it
> is going to be used (i.e when the application explicitly asks for it).
> 
> The registration can be done at any moment, but it is not possible
> to unregister fields or flags for now.
> 
> Signed-off-by: Olivier Matz <olivier.m...@6wind.com>
> Acked-by: Thomas Monjalon <tho...@monjalon.net>
> —
> 

The idea of registration for space in the mbuf I am not a big fan. I did like 
Konstantin’s suggestion of having the compiler help with optimizing the code, 
but with a slight difference. Maybe I misunderstand, but now with this design 
you have to pass the offsets to different parts of the application or place in 
global memory or have each section request the offsets. It seems great if the 
application is one big application or an appliance model application having 
control of the whole design not so good for service chains like designs where 
different parts of the whole application is design by different teams.

Konstantin’s suggest if I understand it was to use structures to allow the 
compiler to optimize the access to the mbuf and I like that idea, but with one 
change we add a field in the mbuf to define the mbuf structure type.

Say 0 is the standard rte_mbuf type then type 1 could be the IPSec offset type 
mbuf, type 2 could be something else, … The type 0 looks just like the mbuf we 
have today with maybe the optional fields set to reserved or some type of 
filler variables to reserve the holes in the structure. Then type 1 is the 
IPSec mbuf and in the reserved sections of the mbuf contain the IPSec related 
data with the standard mbuf fields still matching the type 0 version.

This allows the mbuf to be used by the developer and the compiler now knows 
exactly where the fields are located in the structure and does not have to deal 
with any of the macros and offsets and registration suggested here. Just cast 
the mbuf pointer into the new type mbuf structure. We just have to make sure 
the code that needs to use a given mbuf type has access to the structure 
definitions.

If the mbufs it going to be translated from one type mbuf to another mbuf type, 
we just have to define that type and then cast the mbuf pointer to that 
structure. When an mbuf is received from IPSec PMD then the application needs 
to forward that mbuf to the next stage it can reset the type to 0 or to another 
type filling in the reserved fields to be used by the next stage in the 
pipeline.

The mbuf now contains the type and every point in the application can look at 
the type to determine how that mbuf is defined. I am sure there are some holes 
here, but I think it is a better solution then using all of these macros, 
offset values and registration APIs.


Regards,
Keith

Reply via email to