Some stats in pmd-perf-show don't check for divide by zero
which results in not a number (-nan).

This is a normal case for some of the stats when there are
no Rx queues assigned to the PMD thread core.

It is not obvious what -nan is to a user so add a check for
divide by zero and set stat to 0 if present.

Before patch:
pmd thread numa_id 1 core_id 9:

  Iterations:                    0  (-nan us/it)
  - Used TSC cycles:             0  (  0.0 % of total cycles)
  - idle iterations:             0  ( -nan % of used cycles)
  - busy iterations:             0  ( -nan % of used cycles)

After patch:
pmd thread numa_id 1 core_id 9:

  Iterations:                    0  (0.00 us/it)
  - Used TSC cycles:             0  (  0.0 % of total cycles)
  - idle iterations:             0  (  0.0 % of used cycles)
  - busy iterations:             0  (  0.0 % of used cycles)

Signed-off-by: Kevin Traynor <ktray...@redhat.com>
---
 lib/dpif-netdev-perf.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/lib/dpif-netdev-perf.c b/lib/dpif-netdev-perf.c
index 1a7bab04c..a552948ac 100644
--- a/lib/dpif-netdev-perf.c
+++ b/lib/dpif-netdev-perf.c
@@ -242,10 +242,12 @@ pmd_perf_format_overall_stats(struct ds *str, struct 
pmd_perf_stats *s,
             "  Sleep time (us):    %12.0f  (%3.0f us/iteration avg.)\n",
             tot_iter,
-            (tot_cycles + tot_sleep_cycles) * us_per_cycle / tot_iter,
+            tot_iter
+                ? (tot_cycles + tot_sleep_cycles) * us_per_cycle / tot_iter
+                : 0,
             tot_cycles, 100.0 * (tot_cycles / duration) / tsc_hz,
             idle_iter,
-            100.0 * stats[PMD_CYCLES_ITER_IDLE] / tot_cycles,
+            tot_cycles ? 100.0 * stats[PMD_CYCLES_ITER_IDLE] / tot_cycles : 0,
             busy_iter,
-            100.0 * stats[PMD_CYCLES_ITER_BUSY] / tot_cycles,
+            tot_cycles ? 100.0 * stats[PMD_CYCLES_ITER_BUSY] / tot_cycles : 0,
             sleep_iter, tot_iter ? 100.0 * sleep_iter / tot_iter : 0,
             tot_sleep_cycles * us_per_cycle,
-- 
2.39.1

_______________________________________________
dev mailing list
d...@openvswitch.org
https://mail.openvswitch.org/mailman/listinfo/ovs-dev

Reply via email to