[12/15] app/testpmd: switch timestamp to dynamic mbuf field
Checks
Commit Message
The mbuf timestamp is moved to a dynamic field
in order to allow removal of the deprecated static field.
The related mbuf flag is also replaced.
Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
---
app/test-pmd/util.c | 39 +++++++++++++++++++++++++++++++++++++--
1 file changed, 37 insertions(+), 2 deletions(-)
Comments
On 10/29/20 12:27 PM, Thomas Monjalon wrote:
> The mbuf timestamp is moved to a dynamic field
> in order to allow removal of the deprecated static field.
> The related mbuf flag is also replaced.
>
> Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
> ---
> app/test-pmd/util.c | 39 +++++++++++++++++++++++++++++++++++++--
> 1 file changed, 37 insertions(+), 2 deletions(-)
>
> diff --git a/app/test-pmd/util.c b/app/test-pmd/util.c
> index 781a813759..eebb5166ad 100644
> --- a/app/test-pmd/util.c
> +++ b/app/test-pmd/util.c
> @@ -5,6 +5,7 @@
>
> #include <stdio.h>
>
> +#include <rte_bitops.h>
> #include <rte_net.h>
> #include <rte_mbuf.h>
> #include <rte_ether.h>
> @@ -22,6 +23,40 @@ print_ether_addr(const char *what, const struct rte_ether_addr *eth_addr)
> printf("%s%s", what, buf);
> }
>
> +static inline bool
> +is_timestamp_enabled(const struct rte_mbuf *mbuf)
> +{
> + static uint64_t timestamp_rx_dynflag;
> +
> + int timestamp_rx_dynflag_offset;
> +
> + if (timestamp_rx_dynflag == 0) {
> + timestamp_rx_dynflag_offset = rte_mbuf_dynflag_lookup(
> + RTE_MBUF_DYNFLAG_RX_TIMESTAMP_NAME, NULL);
If the flag is not registered, it will try to lookup on every
call. I'm not sure that it is good.
> + if (timestamp_rx_dynflag_offset < 0)
> + return false;
> + timestamp_rx_dynflag = RTE_BIT64(timestamp_rx_dynflag_offset);
> + }
> +
> + return (mbuf->ol_flags & timestamp_rx_dynflag) != 0;
> +}
> +
> +static inline rte_mbuf_timestamp_t
> +get_timestamp(const struct rte_mbuf *mbuf)
> +{
> + static int timestamp_dynfield_offset = -1;
> +
> + if (timestamp_dynfield_offset < 0) {
> + timestamp_dynfield_offset = rte_mbuf_dynfield_lookup(
> + RTE_MBUF_DYNFIELD_TIMESTAMP_NAME, NULL);
same here
> + if (timestamp_dynfield_offset < 0)
> + return 0;
> + }
> +
> + return *RTE_MBUF_DYNFIELD(mbuf,
> + timestamp_dynfield_offset, rte_mbuf_timestamp_t *);
> +}
> +
> static inline void
> dump_pkt_burst(uint16_t port_id, uint16_t queue, struct rte_mbuf *pkts[],
> uint16_t nb_pkts, int is_rx)
> @@ -107,8 +142,8 @@ dump_pkt_burst(uint16_t port_id, uint16_t queue, struct rte_mbuf *pkts[],
> printf("hash=0x%x ID=0x%x ",
> mb->hash.fdir.hash, mb->hash.fdir.id);
> }
> - if (ol_flags & PKT_RX_TIMESTAMP)
> - printf(" - timestamp %"PRIu64" ", mb->timestamp);
> + if (is_timestamp_enabled(mb))
> + printf(" - timestamp %"PRIu64" ", get_timestamp(mb));
> if (ol_flags & PKT_RX_QINQ)
> printf(" - QinQ VLAN tci=0x%x, VLAN tci outer=0x%x",
> mb->vlan_tci, mb->vlan_tci_outer);
>
29/10/2020 11:20, Andrew Rybchenko:
> On 10/29/20 12:27 PM, Thomas Monjalon wrote:
> > The mbuf timestamp is moved to a dynamic field
> > in order to allow removal of the deprecated static field.
> > The related mbuf flag is also replaced.
> >
> > Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
> > ---
> > --- a/app/test-pmd/util.c
> > +++ b/app/test-pmd/util.c
> > +static inline bool
> > +is_timestamp_enabled(const struct rte_mbuf *mbuf)
> > +{
> > + static uint64_t timestamp_rx_dynflag;
> > +
> > + int timestamp_rx_dynflag_offset;
> > +
> > + if (timestamp_rx_dynflag == 0) {
> > + timestamp_rx_dynflag_offset = rte_mbuf_dynflag_lookup(
> > + RTE_MBUF_DYNFLAG_RX_TIMESTAMP_NAME, NULL);
>
> If the flag is not registered, it will try to lookup on every
> call. I'm not sure that it is good.
I don't see the problem.
It is a dump in a test application.
The idea is to have a fresh dump whatever was updated recently.
On 10/29/20 1:43 PM, Thomas Monjalon wrote:
> 29/10/2020 11:20, Andrew Rybchenko:
>> On 10/29/20 12:27 PM, Thomas Monjalon wrote:
>>> The mbuf timestamp is moved to a dynamic field
>>> in order to allow removal of the deprecated static field.
>>> The related mbuf flag is also replaced.
>>>
>>> Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
>>> ---
>>> --- a/app/test-pmd/util.c
>>> +++ b/app/test-pmd/util.c
>>> +static inline bool
>>> +is_timestamp_enabled(const struct rte_mbuf *mbuf)
>>> +{
>>> + static uint64_t timestamp_rx_dynflag;
>>> +
>>> + int timestamp_rx_dynflag_offset;
>>> +
>>> + if (timestamp_rx_dynflag == 0) {
>>> + timestamp_rx_dynflag_offset = rte_mbuf_dynflag_lookup(
>>> + RTE_MBUF_DYNFLAG_RX_TIMESTAMP_NAME, NULL);
>>
>> If the flag is not registered, it will try to lookup on every
>> call. I'm not sure that it is good.
>
> I don't see the problem.
> It is a dump in a test application.
> The idea is to have a fresh dump whatever was updated recently.
OK, makes sense.
@@ -5,6 +5,7 @@
#include <stdio.h>
+#include <rte_bitops.h>
#include <rte_net.h>
#include <rte_mbuf.h>
#include <rte_ether.h>
@@ -22,6 +23,40 @@ print_ether_addr(const char *what, const struct rte_ether_addr *eth_addr)
printf("%s%s", what, buf);
}
+static inline bool
+is_timestamp_enabled(const struct rte_mbuf *mbuf)
+{
+ static uint64_t timestamp_rx_dynflag;
+
+ int timestamp_rx_dynflag_offset;
+
+ if (timestamp_rx_dynflag == 0) {
+ timestamp_rx_dynflag_offset = rte_mbuf_dynflag_lookup(
+ RTE_MBUF_DYNFLAG_RX_TIMESTAMP_NAME, NULL);
+ if (timestamp_rx_dynflag_offset < 0)
+ return false;
+ timestamp_rx_dynflag = RTE_BIT64(timestamp_rx_dynflag_offset);
+ }
+
+ return (mbuf->ol_flags & timestamp_rx_dynflag) != 0;
+}
+
+static inline rte_mbuf_timestamp_t
+get_timestamp(const struct rte_mbuf *mbuf)
+{
+ static int timestamp_dynfield_offset = -1;
+
+ if (timestamp_dynfield_offset < 0) {
+ timestamp_dynfield_offset = rte_mbuf_dynfield_lookup(
+ RTE_MBUF_DYNFIELD_TIMESTAMP_NAME, NULL);
+ if (timestamp_dynfield_offset < 0)
+ return 0;
+ }
+
+ return *RTE_MBUF_DYNFIELD(mbuf,
+ timestamp_dynfield_offset, rte_mbuf_timestamp_t *);
+}
+
static inline void
dump_pkt_burst(uint16_t port_id, uint16_t queue, struct rte_mbuf *pkts[],
uint16_t nb_pkts, int is_rx)
@@ -107,8 +142,8 @@ dump_pkt_burst(uint16_t port_id, uint16_t queue, struct rte_mbuf *pkts[],
printf("hash=0x%x ID=0x%x ",
mb->hash.fdir.hash, mb->hash.fdir.id);
}
- if (ol_flags & PKT_RX_TIMESTAMP)
- printf(" - timestamp %"PRIu64" ", mb->timestamp);
+ if (is_timestamp_enabled(mb))
+ printf(" - timestamp %"PRIu64" ", get_timestamp(mb));
if (ol_flags & PKT_RX_QINQ)
printf(" - QinQ VLAN tci=0x%x, VLAN tci outer=0x%x",
mb->vlan_tci, mb->vlan_tci_outer);