Skip to content
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

add external pktmbuf metadata API #97

Conversation

KeithWiles
Copy link
Contributor

The metadata was contained in the headroom of the pktmbuf and it is
limited in size to max headroom size normally 128 bytes.
The headroom size is also used for adding protocol headers and if the
room is consumed by the metadata then headers can not be added.

Created a new API pktmbuf_pool_cfg_create() to be able to create a
external metadata buffer array indexed by the pktmbuf_t.metadata_idx
value. The new metadata array of buffers must be a multiple of a
cacheline (64 bytes) and the number of buffers will match the number of
pktmbuf_t buffers in the mempool.

If the new API pktmbuf_pool_cfg_create() is not used the metadata buffer
will be part of the headroom in the pktmbuf buffer.

Signed-off-by: Keith Wiles keith.wiles@intel.com

@KeithWiles
Copy link
Contributor Author

KeithWiles commented Jun 24, 2022

Let's hold off on this merge until after the CNET TCP #91 , as it may change that code a bit.

@KeithWiles KeithWiles force-pushed the pktmbuf_external_metadata branch 2 times, most recently from 0df682c to 976ccc5 Compare June 24, 2022 21:19
The metadata was contained in the headroom of the pktmbuf and it is
limited in size to max headroom size normally 128 bytes.
The headroom size is also used for adding protcol headers and if the
room is consumed by the metadata then headers can not be added.

Created a new API pktmbuf_pool_cfg_create() to be able to create a
external metadata buffer array indexed by the pktmbuf_t.metadata_idx
value. The new metadata array of buffers must be a multiple of a
cacheline (64 bytes) and the number of buffers will match the number of
pktmbuf_t buffers in the mempool.

If the new API pktmbuf_pool_cfg_create() is not used the metadata buffer
will be part of the headroom in the pktmbuf buffer.

Signed-off-by: Keith Wiles <keith.wiles@intel.com>
lib/core/pktmbuf/pktmbuf.h Show resolved Hide resolved
* @return
* -1 if pktmbuf pointer is NULL or size of metadata buffer or headroom size if internal.
*/
static inline uint32_t
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should you returned a int32_t if you plan on returning -1? YOu could create a define PKTMBUF_INV_MD_SZ (u32)-1 and return that instead if you want ot keep it a uint

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use int32_t

pktmbuf_pool_cfg(pktmbuf_pool_cfg_t *c, void *addr, uint32_t bufcnt, uint32_t bufsz,
uint32_t cache_sz, void *metadata, uint32_t metadata_bufsz, mbuf_ops_t *ops)
{
if (c) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a little challenging to immediately follow the nested if statements with all the returns. Would you consider checking all the values for null/zero at the top? I think you can avoid some of hte nested if statements. I think the following more clearly conveys the constraints.

if (!c || !addr || !bufcnt || !bufsz)
  return -1;

if ((!metadata && metadata_bufsz) || (metadata && !metadata_bufsz))
  return -1;

if (metadata && ((metadata_bufsz % CNE_CACHE_LINE_SIZE) != 0))
  return -1;

c->addr = addr;
c->bufcnt = bufcnt;
c->bufsz = bufsz;
c->cache_sz = cache_sz;
c->ops = ops;
c->metadata = metadata;
c->metadata_bufsz = metadata_bufsz;

return 0;

Also, this doesn't really need to be a static inline function. Would you consider putting this in pktmbuf.c?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your suggestion is much easy to read and understand. I just tried to make it too hard :-(


CNE_MAX_SET(cache_sz, MEMPOOL_CACHE_MAX_SIZE);
if (c->bufcnt == 0 || c->bufsz == 0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This contradicts the code that occurs a few lines down which allows these to be set to 0 to indicate a default could be used. I'd prefer not to change those semantics.

CNE_DEFAULT_SET(c->bufcnt, 0, DEFAULT_MBUF_COUNT);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

restored to previous.

* @param addr
* Address of the pktmbuf buffers, must not be NULL
* @param bufcnt
* Number of buffers in the pktmbuf pool, must not be zero
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pktmbuf_pool_create() function (prior to this change) let users pass a value of 0 for bufcnt and/or bufsz to indicate a default value should be chosen. Do you think we should keep that? I like it, since its less to configure...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed the text to allow them to zero and I do not see if the code needs to change now after the above change.

@KeithWiles
Copy link
Contributor Author

I could not get the conflicts to be resolved in a clean way, so I will close this PR and open a new one based on the current main branch.

@KeithWiles KeithWiles closed this Jun 29, 2022
@KeithWiles KeithWiles deleted the pktmbuf_external_metadata branch July 21, 2022 18:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants