diff mbox

[ovs-dev,3/5] dpif-netdev: Add CD statistics

Message ID 1497395376-69228-4-git-send-email-yipeng1.wang@intel.com
State Deferred
Delegated to: Darrell Ball
Headers show

Commit Message

Wang, Yipeng1 June 13, 2017, 11:09 p.m. UTC
From: Yipeng Wang <yipeng1.wang@intel.com>

This patch adds CD hit and miss statistics to dp_stat_type. PMD stats will
show the total CD hit and miss counts. This patch depends on the first patch.

Signed-off-by: Yipeng Wang <yipeng1.wang at intel.com>
Signed-off-by: Charlie Tai <charlie.tai at intel.com>
Co-authored-by: Charlie Tai <charlie.tai at intel.com>
Signed-off-by: Sameh Gobriel <sameh.gobriel at intel.com>
Co-authored-by: Sameh Gobriel <sameh.gobriel at intel.com>
Signed-off-by: Ren Wang <ren.wang at intel.com>
Co-authored-by: Ren Wang <ren.wang at intel.com>
Signed-off-by: Antonio Fischetti <antonio.fischetti at intel.com>
Co-authored-by: Antonio Fischetti <antonio.fischetti at intel.com>
---
 lib/dpif-netdev.c | 36 ++++++++++++++++++++++++++----------
 1 file changed, 26 insertions(+), 10 deletions(-)
diff mbox

Patch

diff --git a/lib/dpif-netdev.c b/lib/dpif-netdev.c
index 23b3e42..691fbad 100644
--- a/lib/dpif-netdev.c
+++ b/lib/dpif-netdev.c
@@ -263,7 +263,7 @@  static void dpcls_remove(struct dpcls *, struct dpcls_rule *);
 static bool dpcls_lookup(struct dpcls *cls,
                          const struct netdev_flow_key keys[],
                          struct dpcls_rule **rules, size_t cnt,
-                         int *num_lookups_p);
+                         int *num_lookups_p, int *cd_hit);
 static inline struct dpcls_subtable *
 dpcls_find_subtable(struct dpcls *cls, const struct netdev_flow_key *mask);
 
@@ -387,6 +387,8 @@  enum dp_stat_type {
     DP_STAT_LOST,               /* Packets not passed up to the client. */
     DP_STAT_LOOKUP_HIT,         /* Number of subtable lookups for flow table
                                    hits */
+    DP_STAT_CD_HIT,             /* Packets that hit CD. */
+    DP_STAT_CD_MISS,            /* Packets that miss CD. */
     DP_N_STATS
 };
 
@@ -848,7 +850,8 @@  pmd_info_show_stats(struct ds *reply,
             stats[i] = 0;
         }
 
-        if (i != DP_STAT_LOST) {
+        if (i != DP_STAT_LOST && i != DP_STAT_LOOKUP_HIT
+                && i != DP_STAT_CD_MISS && i != DP_STAT_CD_HIT) {
             /* Lost packets are already included in DP_STAT_MISS */
             total_packets += stats[i];
         }
@@ -885,6 +888,10 @@  pmd_info_show_stats(struct ds *reply,
                   : 0,
                   stats[DP_STAT_MISS], stats[DP_STAT_LOST]);
 
+    ds_put_format(reply,
+                  "\tCD hits:%llu\n\tCD miss:%llu\n",
+                  stats[DP_STAT_CD_HIT], stats[DP_STAT_CD_MISS]);
+
     if (total_cycles == 0) {
         return;
     }
@@ -2486,7 +2493,7 @@  find_index_in_sub_ptrs(struct dpcls *cls,
 static struct dp_netdev_flow *
 dp_netdev_pmd_lookup_flow(struct dp_netdev_pmd_thread *pmd,
                           const struct netdev_flow_key *key,
-                          int *lookup_num_p)
+                          int *lookup_num_p, int *cd_hit)
 {
     struct dpcls *cls;
     struct dpcls_rule *rule;
@@ -2495,7 +2502,7 @@  dp_netdev_pmd_lookup_flow(struct dp_netdev_pmd_thread *pmd,
 
     cls = dp_netdev_pmd_lookup_dpcls(pmd, in_port);
     if (OVS_LIKELY(cls)) {
-        dpcls_lookup(cls, key, &rule, 1, lookup_num_p);
+        dpcls_lookup(cls, key, &rule, 1, lookup_num_p, cd_hit);
         netdev_flow = dp_netdev_flow_cast(rule);
     }
     return netdev_flow;
@@ -2848,7 +2855,7 @@  flow_put_on_pmd(struct dp_netdev_pmd_thread *pmd,
     }
 
     ovs_mutex_lock(&pmd->flow_mutex);
-    netdev_flow = dp_netdev_pmd_lookup_flow(pmd, key, NULL);
+    netdev_flow = dp_netdev_pmd_lookup_flow(pmd, key, NULL, NULL);
     if (!netdev_flow) {
         if (put->flags & DPIF_FP_CREATE) {
             if (cmap_count(&pmd->flow_table) < MAX_FLOWS) {
@@ -5048,7 +5055,7 @@  handle_packet_upcall(struct dp_netdev_pmd_thread *pmd,
          * to be locking everyone out of making flow installs.  If we
          * move to a per-core classifier, it would be reasonable. */
         ovs_mutex_lock(&pmd->flow_mutex);
-        netdev_flow = dp_netdev_pmd_lookup_flow(pmd, key, NULL);
+        netdev_flow = dp_netdev_pmd_lookup_flow(pmd, key, NULL, NULL);
         if (OVS_LIKELY(!netdev_flow)) {
             netdev_flow = dp_netdev_flow_add(pmd, key, &match, &ufid,
                                              add_actions->data,
@@ -5080,6 +5087,7 @@  fast_path_processing(struct dp_netdev_pmd_thread *pmd,
     struct dp_netdev *dp = pmd->dp;
     int miss_cnt = 0, lost_cnt = 0;
     int lookup_cnt = 0, add_lookup_cnt;
+    int cd_hit = 0, add_cd_hit;
     bool any_miss;
     size_t i;
 
@@ -5090,7 +5098,7 @@  fast_path_processing(struct dp_netdev_pmd_thread *pmd,
     /* Get the classifier for the in_port */
     cls = dp_netdev_pmd_lookup_dpcls(pmd, in_port);
     if (OVS_LIKELY(cls)) {
-        any_miss = !dpcls_lookup(cls, keys, rules, cnt, &lookup_cnt);
+        any_miss = !dpcls_lookup(cls, keys, rules, cnt, &lookup_cnt, &cd_hit);
     } else {
         any_miss = true;
         memset(rules, 0, sizeof(rules));
@@ -5113,9 +5121,10 @@  fast_path_processing(struct dp_netdev_pmd_thread *pmd,
              * a rule covering this flow.  In this case, it's a lot cheaper
              * to catch it here than execute a miss. */
             netdev_flow = dp_netdev_pmd_lookup_flow(pmd, &keys[i],
-                                                    &add_lookup_cnt);
+                                                &add_lookup_cnt, &add_cd_hit);
             if (netdev_flow) {
                 lookup_cnt += add_lookup_cnt;
+                cd_hit += add_cd_hit;
                 rules[i] = &netdev_flow->cr;
                 continue;
             }
@@ -5156,6 +5165,9 @@  fast_path_processing(struct dp_netdev_pmd_thread *pmd,
     dp_netdev_count_packet(pmd, DP_STAT_LOOKUP_HIT, lookup_cnt);
     dp_netdev_count_packet(pmd, DP_STAT_MISS, miss_cnt);
     dp_netdev_count_packet(pmd, DP_STAT_LOST, lost_cnt);
+    dp_netdev_count_packet(pmd, DP_STAT_CD_HIT, cd_hit);
+    dp_netdev_count_packet(pmd, DP_STAT_CD_MISS, cnt-cd_hit);
+
 }
 
 /* Packets enter the datapath from a port (or from recirculation) here.
@@ -6124,7 +6136,7 @@  dpcls_rule_matches_key(const struct dpcls_rule *rule,
 static bool
 dpcls_lookup(struct dpcls *cls, const struct netdev_flow_key keys[],
              struct dpcls_rule **rules, const size_t cnt,
-             int *num_lookups_p)
+             int *num_lookups_p, int *cd_hit)
 {
     /* The received 'cnt' miniflows are the search-keys that will be processed
      * to find a matching entry into the available subtables.
@@ -6151,8 +6163,8 @@  dpcls_lookup(struct dpcls *cls, const struct netdev_flow_key keys[],
      * The cuckoo distributor lookup pass begin first before go to megaflow
      * cache.  CD hit will return a subtable index to the subtable to lookup.
      */
-
     int i;
+    int cd_match = 0;
     int data[MAP_BITS];
 
     cd_lookup_bulk_pipe(cls, keys, cnt, &found_map, data);
@@ -6168,6 +6180,7 @@  dpcls_lookup(struct dpcls *cls, const struct netdev_flow_key keys[],
                 if (OVS_LIKELY(dpcls_rule_matches_key(rule, &keys[i]))) {
                     rules[i] = rule;
                     lookups_match += 1;
+                    cd_match += 1;
                     goto scnext;
                 }
             }
@@ -6196,6 +6209,9 @@  dpcls_lookup(struct dpcls *cls, const struct netdev_flow_key keys[],
         if (num_lookups_p) {
             *num_lookups_p = lookups_match;
         }
+        if (cd_hit) {
+            *cd_hit = cd_match;
+        }
 
         return true;              /* All found in CD. */
     }