mbuf: add Rx timestamp flag and helpers

There is already a dynamic field for timestamp,
used only for Tx scheduling with the dedicated Tx offload flag.
The same field can be used for Rx timestamp filled by drivers.

A new dynamic flag is defined for Rx usage.
A new function wraps the registration of both field and Rx flag.
The type rte_mbuf_timestamp_t is defined for the API users.

After migrating all Rx timestamp usages, it will be possible
to remove the deprecated timestamp field.

Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
Acked-by: David Marchand <david.marchand@redhat.com>
Acked-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
Acked-by: Olivier Matz <olivier.matz@6wind.com>
This commit is contained in:
Thomas Monjalon 2020-10-28 14:20:44 +01:00
parent 52bf2010c9
commit 9db924cc21
3 changed files with 72 additions and 5 deletions

View File

@ -13,6 +13,7 @@
#include <rte_errno.h> #include <rte_errno.h>
#include <rte_malloc.h> #include <rte_malloc.h>
#include <rte_string_fns.h> #include <rte_string_fns.h>
#include <rte_bitops.h>
#include <rte_mbuf.h> #include <rte_mbuf.h>
#include <rte_mbuf_dyn.h> #include <rte_mbuf_dyn.h>
@ -569,3 +570,45 @@ void rte_mbuf_dyn_dump(FILE *out)
rte_mcfg_tailq_write_unlock(); rte_mcfg_tailq_write_unlock();
} }
static int
rte_mbuf_dyn_timestamp_register(int *field_offset, uint64_t *flag,
const char *direction, const char *flag_name)
{
static const struct rte_mbuf_dynfield field_desc = {
.name = RTE_MBUF_DYNFIELD_TIMESTAMP_NAME,
.size = sizeof(rte_mbuf_timestamp_t),
.align = __alignof__(rte_mbuf_timestamp_t),
};
struct rte_mbuf_dynflag flag_desc = {};
int offset;
offset = rte_mbuf_dynfield_register(&field_desc);
if (offset < 0) {
RTE_LOG(ERR, MBUF,
"Failed to register mbuf field for timestamp\n");
return -1;
}
if (field_offset != NULL)
*field_offset = offset;
strlcpy(flag_desc.name, flag_name, sizeof(flag_desc.name));
offset = rte_mbuf_dynflag_register(&flag_desc);
if (offset < 0) {
RTE_LOG(ERR, MBUF,
"Failed to register mbuf flag for %s timestamp\n",
direction);
return -1;
}
if (flag != NULL)
*flag = RTE_BIT64(offset);
return 0;
}
int
rte_mbuf_dyn_rx_timestamp_register(int *field_offset, uint64_t *rx_flag)
{
return rte_mbuf_dyn_timestamp_register(field_offset, rx_flag,
"Rx", RTE_MBUF_DYNFLAG_RX_TIMESTAMP_NAME);
}

View File

@ -258,13 +258,36 @@ void rte_mbuf_dyn_dump(FILE *out);
* timestamp. The dynamic Tx timestamp flag tells whether the field contains * timestamp. The dynamic Tx timestamp flag tells whether the field contains
* actual timestamp value for the packets being sent, this value can be * actual timestamp value for the packets being sent, this value can be
* used by PMD to schedule packet sending. * used by PMD to schedule packet sending.
*
* After PKT_RX_TIMESTAMP flag and fixed timestamp field deprecation
* and obsoleting, the dedicated Rx timestamp flag is supposed to be
* introduced and the shared dynamic timestamp field will be used
* to handle the timestamps on receiving datapath as well.
*/ */
#define RTE_MBUF_DYNFIELD_TIMESTAMP_NAME "rte_dynfield_timestamp" #define RTE_MBUF_DYNFIELD_TIMESTAMP_NAME "rte_dynfield_timestamp"
typedef uint64_t rte_mbuf_timestamp_t;
/**
* Indicate that the timestamp field in the mbuf was filled by the driver.
*/
#define RTE_MBUF_DYNFLAG_RX_TIMESTAMP_NAME "rte_dynflag_rx_timestamp"
/**
* @warning
* @b EXPERIMENTAL: this API may change without prior notice.
*
* Register dynamic mbuf field and flag for Rx timestamp.
*
* @param field_offset
* Pointer to the offset of the registered mbuf field, can be NULL.
* The same field is shared for Rx and Tx timestamp.
* @param rx_flag
* Pointer to the mask of the registered offload flag, can be NULL.
* @return
* 0 on success, -1 otherwise.
* Possible values for rte_errno:
* - EEXIST: already registered with different parameters.
* - EPERM: called from a secondary process.
* - ENOENT: no more field or flag available.
* - ENOMEM: allocation failure.
*/
__rte_experimental
int rte_mbuf_dyn_rx_timestamp_register(int *field_offset, uint64_t *rx_flag);
/** /**
* When PMD sees the RTE_MBUF_DYNFLAG_TX_TIMESTAMP_NAME flag set on the * When PMD sees the RTE_MBUF_DYNFLAG_TX_TIMESTAMP_NAME flag set on the

View File

@ -42,6 +42,7 @@ EXPERIMENTAL {
rte_mbuf_dynflag_register; rte_mbuf_dynflag_register;
rte_mbuf_dynflag_register_bitnum; rte_mbuf_dynflag_register_bitnum;
rte_mbuf_dyn_dump; rte_mbuf_dyn_dump;
rte_mbuf_dyn_rx_timestamp_register;
rte_pktmbuf_copy; rte_pktmbuf_copy;
rte_pktmbuf_free_bulk; rte_pktmbuf_free_bulk;
rte_pktmbuf_pool_create_extbuf; rte_pktmbuf_pool_create_extbuf;