Skip to contentSkip to conversation

latencystats: fix timestamp marking and latency calculation

PATCH Superseded Reshma Pattan 4 participants 9 messages Sep 21, 2018 – Oct 25, 2018

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 latencystats: fix timestamp marking and latency calculation

Latency calculation logic is not correct for the case where packets gets dropped before TX. As for the dropped packets, the timestamp is not cleared, and such packets still gets counted for latency calculation in next runs, that will result in inaccurate latency measurement.

So fix this issue as below,

Before setting timestamp in mbuf, check mbuf don't have any prior valid time stamp flag set and after marking the timestamp, set mbuf flags to indicate timestamp is valid.

Before calculating timestamp check mbuf flags are set to indicate timestamp is valid.

With the above logic it is guaranteed that correct timestamps have been used.

Fixes 5cd3cac9ed ("latency: added new library for latency stats")
---
 lib/librte_latencystats/rte_latencystats.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
lib/librte_latencystats/rte_latencystats.c +6 -2
index 1fdec68e3..8870226bb 100644
@@ -125,8 +125,11 @@ add_time_stamps(uint16_t pid __rte_unused,
 	for (i = 0; i < nb_pkts; i++) {
 		diff_tsc = now - prev_tsc;
 		timer_tsc += diff_tsc;
-		if (timer_tsc >= samp_intvl) {
+
+		if ((pkts[i]->ol_flags & PKT_RX_TIMESTAMP) == 0
+			&& (timer_tsc >= samp_intvl)) {
 			pkts[i]->timestamp = now;
+			pkts[i]->ol_flags |= PKT_RX_TIMESTAMP;
 			timer_tsc = 0;
 		}
 		prev_tsc = now;
@@ -156,7 +159,8 @@ calc_latency(uint16_t pid __rte_unused,
 
 	now = rte_rdtsc();
 	for (i = 0; i < nb_pkts; i++) {
-		if (pkts[i]->timestamp)
+		if ((pkts[i]->ol_flags & PKT_RX_TIMESTAMP) &&
+				pkts[i]->timestamp)
 			latency[cnt++] = now - pkts[i]->timestamp;
 	}
 
Signature · 1 line
2.14.4
#1 lore raw

Hi Reshma,

Quoted 6 lines

-----Original Message-----
From: [email protected] [mailto:[email protected]]
Sent: Friday, September 21, 2018 11:02 PM
To: [email protected]; [email protected]; [email protected]
Cc: Reshma Pattan <[email protected]>
Subject: [PATCH] latencystats: fix timestamp marking and latency

calculation

Quoted 4 lines

Latency calculation logic is not correct for the case where packets gets dropped before TX. As for the dropped packets, the timestamp is not cleared, and such packets still gets counted for latency calculation in

next

Quoted 9 lines

runs, that will result in inaccurate latency measurement.

So fix this issue as below,

Before setting timestamp in mbuf, check mbuf don't have any prior valid time stamp flag set and after marking the timestamp, set mbuf flags to indicate timestamp is valid.

Before calculating timestamp check mbuf flags are set to indicate

timestamp

Quoted 2 lines

is valid.

This solution as suggested by Konstantin is great. Not only does it solve the problem but also now the usage of mbuf->timestamp is not exclusive to latencystats anymore. The application can make use of timestamp at the same as latencystats simply by toggling PKT_RX_TIMESTAMP. I think we should update the doc to include this information.

Quoted 30 lines

With the above logic it is guaranteed that correct timestamps have been used.

Fixes 5cd3cac9ed ("latency: added new library for latency stats")
---
 lib/librte_latencystats/rte_latencystats.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
lib/librte_latencystats/rte_latencystats.c +4 -1
index 1fdec68e3..8870226bb 100644
@@ -125,8 +125,11 @@ add_time_stamps(uint16_t pid __rte_unused,
 	for (i = 0; i < nb_pkts; i++) {
 		diff_tsc = now - prev_tsc;
 		timer_tsc += diff_tsc;
-		if (timer_tsc >= samp_intvl) {
+
+		if ((pkts[i]->ol_flags & PKT_RX_TIMESTAMP) == 0
+			&& (timer_tsc >= samp_intvl)) {
 			pkts[i]->timestamp = now;
+			pkts[i]->ol_flags |= PKT_RX_TIMESTAMP;
 			timer_tsc = 0;
 		}
 		prev_tsc = now;

lib/librte_latencystats/rte_latencystats.c calc_latency(uint16_t pid __rte_unused, · line 163

Quoted 6 lines
lib/librte_latencystats/rte_latencystats.c +2 -1
@@ -156,7 +159,8 @@ calc_latency(uint16_t pid __rte_unused,
 
 	now = rte_rdtsc();
 	for (i = 0; i < nb_pkts; i++) {
-		if (pkts[i]->timestamp)
+		if ((pkts[i]->ol_flags & PKT_RX_TIMESTAMP) &&
+				pkts[i]->timestamp)

Just a nit, but I think we don't have to check for pkts[i]->timestamp here.

Quoted 5 lines
lib/librte_latencystats/rte_latencystats.c +0 -1
 			latency[cnt++] = now - pkts[i]->timestamp;
 	}
 
--

2.14.4

Best regards,
BL

#2 lore raw

Hi,

Quoted 34 lines

-----Original Message-----
From: [email protected] [mailto:[email protected]]
Sent: Saturday, September 22, 2018 3:58 AM
To: Pattan, Reshma <[email protected]>; Ananyev, Konstantin <[email protected]>; [email protected]
Subject: RE: [PATCH] latencystats: fix timestamp marking and latency calculation

Hi Reshma,

Quoted 4 lines

-----Original Message-----
From: [email protected] [mailto:[email protected]]
Sent: Friday, September 21, 2018 11:02 PM
To: [email protected]; [email protected];

[email protected]

Quoted 2 lines

Cc: Reshma Pattan <[email protected]>
Subject: [PATCH] latencystats: fix timestamp marking and latency

calculation

Quoted 5 lines

Latency calculation logic is not correct for the case where packets gets dropped before TX. As for the dropped packets, the timestamp is not cleared, and such packets still gets counted for latency calculation in

next

Quoted 9 lines

runs, that will result in inaccurate latency measurement.

So fix this issue as below,

Before setting timestamp in mbuf, check mbuf don't have any prior valid time stamp flag set and after marking the timestamp, set mbuf flags to indicate timestamp is valid.

Before calculating timestamp check mbuf flags are set to indicate

timestamp

Quoted 9 lines
Quoted 2 lines

is valid.

This solution as suggested by Konstantin is great. Not only does it solve the problem but also now the usage of mbuf->timestamp is not exclusive to latencystats anymore. The application can make use of timestamp at the same as latencystats simply by toggling PKT_RX_TIMESTAMP. I think we should update the doc to include this information.

Do you mean latency stats document? Or Mbuf doc.

Thanks,
Reshma

#3 lore raw

Hi Reshma,

I mean in the latencystats document. A few lines about what is taken away by the library (the mbuf timestamp when PKT_RX_TIMESTAMP is set) would be very helpful.

Best regards,
BL

----- Original Message -----
From: "reshma pattan" <[email protected]>
To: [email protected]
Cc: "Konstantin Ananyev" <[email protected]>, [email protected]
Sent: Monday, September 24, 2018 8:07:18 PM
Subject: RE: [PATCH] latencystats: fix timestamp marking and latency calculation

Hi,

Quoted 34 lines

-----Original Message-----
From: [email protected] [mailto:[email protected]]
Sent: Saturday, September 22, 2018 3:58 AM
To: Pattan, Reshma <[email protected]>; Ananyev, Konstantin <[email protected]>; [email protected]
Subject: RE: [PATCH] latencystats: fix timestamp marking and latency calculation

Hi Reshma,

Quoted 4 lines

-----Original Message-----
From: [email protected] [mailto:[email protected]]
Sent: Friday, September 21, 2018 11:02 PM
To: [email protected]; [email protected];

[email protected]

Quoted 2 lines

Cc: Reshma Pattan <[email protected]>
Subject: [PATCH] latencystats: fix timestamp marking and latency

calculation

Quoted 5 lines

Latency calculation logic is not correct for the case where packets gets dropped before TX. As for the dropped packets, the timestamp is not cleared, and such packets still gets counted for latency calculation in

next

Quoted 9 lines

runs, that will result in inaccurate latency measurement.

So fix this issue as below,

Before setting timestamp in mbuf, check mbuf don't have any prior valid time stamp flag set and after marking the timestamp, set mbuf flags to indicate timestamp is valid.

Before calculating timestamp check mbuf flags are set to indicate

timestamp

Quoted 9 lines
Quoted 2 lines

is valid.

This solution as suggested by Konstantin is great. Not only does it solve the problem but also now the usage of mbuf->timestamp is not exclusive to latencystats anymore. The application can make use of timestamp at the same as latencystats simply by toggling PKT_RX_TIMESTAMP. I think we should update the doc to include this information.

Do you mean latency stats document? Or Mbuf doc.

Thanks,
Reshma

Tested-by on v1 1/1
#4 lore raw
In reply to Reshma Pattan
Quoted 6 lines

-----Original Message-----
From: [email protected] [mailto:[email protected]]
Sent: Friday, September 21, 2018 11:02 PM
To: [email protected]; [email protected]; [email protected]
Cc: Reshma Pattan <[email protected]>
Subject: [PATCH] latencystats: fix timestamp marking and latency

calculation

Quoted 4 lines

Latency calculation logic is not correct for the case where packets gets dropped before TX. As for the dropped packets, the timestamp is not cleared, and such packets still gets counted for latency calculation in

next

Quoted 9 lines

runs, that will result in inaccurate latency measurement.

So fix this issue as below,

Before setting timestamp in mbuf, check mbuf don't have any prior valid time stamp flag set and after marking the timestamp, set mbuf flags to indicate timestamp is valid.

Before calculating timestamp check mbuf flags are set to indicate

timestamp

Quoted 9 lines

is valid.

With the above logic it is guaranteed that correct timestamps have been used.

Fixes 5cd3cac9ed ("latency: added new library for latency stats")
#5 lore raw

PATCH v2 1/1 latencystats: fix timestamp marking and latency calculation

In reply to Reshma Pattan

Latency calculation logic is not correct for the case where packets gets dropped before TX. As for the dropped packets, the timestamp is not cleared, and such packets still gets counted for latency calculation in next runs, that will result in inaccurate latency measurement.

So fix this issue as below,

Before setting timestamp in mbuf, check mbuf don't have any prior valid time stamp flag set and after marking the timestamp, set mbuf flags to indicate timestamp is valid.

Before calculating timestamp check mbuf flags are set to indicate timestamp is valid.

With the above logic it is guaranteed that correct timestamps have been used.

Fixes 5cd3cac9ed ("latency: added new library for latency stats")

---
v2: remove check for mbuf->timestamp

---
 lib/librte_latencystats/rte_latencystats.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
lib/librte_latencystats/rte_latencystats.c +5 -2
index 1fdec68e3..0f702b722 100644
@@ -125,8 +125,11 @@ add_time_stamps(uint16_t pid __rte_unused,
 	for (i = 0; i < nb_pkts; i++) {
 		diff_tsc = now - prev_tsc;
 		timer_tsc += diff_tsc;
-		if (timer_tsc >= samp_intvl) {
+
+		if ((pkts[i]->ol_flags & PKT_RX_TIMESTAMP) == 0
+			&& (timer_tsc >= samp_intvl)) {
 			pkts[i]->timestamp = now;
+			pkts[i]->ol_flags |= PKT_RX_TIMESTAMP;
 			timer_tsc = 0;
 		}
 		prev_tsc = now;
@@ -156,7 +159,7 @@ calc_latency(uint16_t pid __rte_unused,
 
 	now = rte_rdtsc();
 	for (i = 0; i < nb_pkts; i++) {
-		if (pkts[i]->timestamp)
+		if (pkts[i]->ol_flags & PKT_RX_TIMESTAMP)
 			latency[cnt++] = now - pkts[i]->timestamp;
 	}
 
Signature · 1 line
2.14.4
Acked-by on v2 1/1
#6 lore raw

Hi Reshma,

Quoted 38 lines

Latency calculation logic is not correct for the case where packets gets dropped before TX. As for the dropped packets, the timestamp is not cleared, and such packets still gets counted for latency calculation in next runs, that will result in inaccurate latency measurement.

So fix this issue as below,

Before setting timestamp in mbuf, check mbuf don't have any prior valid time stamp flag set and after marking the timestamp, set mbuf flags to indicate timestamp is valid.

Before calculating timestamp check mbuf flags are set to indicate timestamp is valid.

With the above logic it is guaranteed that correct timestamps have been used.

Fixes 5cd3cac9ed ("latency: added new library for latency stats")

---
v2: remove check for mbuf->timestamp

---
 lib/librte_latencystats/rte_latencystats.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
lib/librte_latencystats/rte_latencystats.c +0 -0
index 1fdec68e3..0f702b722 100644

lib/librte_latencystats/rte_latencystats.c add_time_stamps(uint16_t pid __rte_unused, · line 130

Quoted 7 lines
lib/librte_latencystats/rte_latencystats.c +3 -1
@@ -125,8 +125,11 @@ add_time_stamps(uint16_t pid __rte_unused,
 	for (i = 0; i < nb_pkts; i++) {
 		diff_tsc = now - prev_tsc;
 		timer_tsc += diff_tsc;
-		if (timer_tsc >= samp_intvl) {
+
+		if ((pkts[i]->ol_flags & PKT_RX_TIMESTAMP) == 0
+			&& (timer_tsc >= samp_intvl)) {

As a nit - I think you need extra tab here, to follow dpdk codying style. Apart from that:

Quoted 16 lines
lib/librte_latencystats/rte_latencystats.c +2 -2
 			pkts[i]->timestamp = now;
+			pkts[i]->ol_flags |= PKT_RX_TIMESTAMP;
 			timer_tsc = 0;
 		}
 		prev_tsc = now;
@@ -156,7 +159,7 @@ calc_latency(uint16_t pid __rte_unused,
 
 	now = rte_rdtsc();
 	for (i = 0; i < nb_pkts; i++) {
-		if (pkts[i]->timestamp)
+		if (pkts[i]->ol_flags & PKT_RX_TIMESTAMP)
 			latency[cnt++] = now - pkts[i]->timestamp;
 	}
 
--

2.14.4

#7 lore raw

PATCH v3 1/1 latencystats: fix timestamp marking and latency calculation

In reply to Reshma Pattan

Latency calculation logic is not correct for the case where packets gets dropped before TX. As for the dropped packets, the timestamp is not cleared, and such packets still gets counted for latency calculation in next runs, that will result in inaccurate latency measurement.

So fix this issue as below,

Before setting timestamp in mbuf, check mbuf don't have any prior valid time stamp flag set and after marking the timestamp, set mbuf flags to indicate timestamp is valid.

Before calculating timestamp check mbuf flags are set to indicate timestamp is valid.

With the above logic it is guaranteed that correct timestamps have been used.

Fixes 5cd3cac9ed ("latency: added new library for latency stats")

---
v3: style related fix
v2: remove check for mbuf->timestamp

---
 lib/librte_latencystats/rte_latencystats.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
lib/librte_latencystats/rte_latencystats.c +5 -2
index 1fdec68e3..5715549e4 100644
@@ -125,8 +125,11 @@ add_time_stamps(uint16_t pid __rte_unused,
 	for (i = 0; i < nb_pkts; i++) {
 		diff_tsc = now - prev_tsc;
 		timer_tsc += diff_tsc;
-		if (timer_tsc >= samp_intvl) {
+
+		if ((pkts[i]->ol_flags & PKT_RX_TIMESTAMP) == 0
+				&& (timer_tsc >= samp_intvl)) {
 			pkts[i]->timestamp = now;
+			pkts[i]->ol_flags |= PKT_RX_TIMESTAMP;
 			timer_tsc = 0;
 		}
 		prev_tsc = now;
@@ -156,7 +159,7 @@ calc_latency(uint16_t pid __rte_unused,
 
 	now = rte_rdtsc();
 	for (i = 0; i < nb_pkts; i++) {
-		if (pkts[i]->timestamp)
+		if (pkts[i]->ol_flags & PKT_RX_TIMESTAMP)
 			latency[cnt++] = now - pkts[i]->timestamp;
 	}
 
Signature · 1 line
2.17.1
#8 lore raw

25/09/2018 16:51, Reshma Pattan:

Quoted 28 lines

Latency calculation logic is not correct for the case where packets gets dropped before TX. As for the dropped packets, the timestamp is not cleared, and such packets still gets counted for latency calculation in next runs, that will result in inaccurate latency measurement.

So fix this issue as below,

Before setting timestamp in mbuf, check mbuf don't have any prior valid time stamp flag set and after marking the timestamp, set mbuf flags to indicate timestamp is valid.

Before calculating timestamp check mbuf flags are set to indicate timestamp is valid.

With the above logic it is guaranteed that correct timestamps have been used.

Fixes 5cd3cac9ed ("latency: added new library for latency stats")
Quoted 4 lines

---
v3: style related fix
v2: remove check for mbuf->timestamp
---

Applied, thanks