[ovs-dev] [PATCH 2/5] mac-learning: Add per mac learning instance counters

Eelco Chaudron echaudro at redhat.com
Mon Jun 25 10:57:40 UTC 2018


This patch adds counters per mac_learning instance.
The following counters are added:

total_learned: Total number of learned MAC entries
total_expired: Total number of expired MAC entries
total_evicted: Total number of evicted MAC entries, i.e. entries moved
               out due to the table being full.
total_moved  : Total number of port moved MAC entries, i.e. entries
               where the MAC address moved to a different port.

Signed-off-by: Eelco Chaudron <echaudro at redhat.com>
---
 lib/mac-learning.c |   17 +++++++++++++++++
 lib/mac-learning.h |    6 ++++++
 2 files changed, 23 insertions(+)

diff --git a/lib/mac-learning.c b/lib/mac-learning.c
index 8b7981dbb..c13a5fac8 100644
--- a/lib/mac-learning.c
+++ b/lib/mac-learning.c
@@ -153,6 +153,7 @@ evict_mac_entry_fairly(struct mac_learning *ml)
     e = CONTAINER_OF(ovs_list_front(&mlport->port_lrus),
                      struct mac_entry, port_lru_node);
     COVERAGE_INC(mac_learning_evicted);
+    ml->total_evicted++;
     mac_learning_expire(ml, e);
 }
 
@@ -180,6 +181,18 @@ normalize_idle_time(unsigned int idle_time)
             : idle_time);
 }
 
+/* Clear all the mac_learning statistics */
+static void
+mac_learning_clear_statistics(struct mac_learning *ml)
+{
+    if (ml != NULL) {
+        ml->total_learned = 0;
+        ml->total_expired = 0;
+        ml->total_evicted = 0;
+        ml->total_moved = 0;
+    }
+}
+
 /* Creates and returns a new MAC learning table with an initial MAC aging
  * timeout of 'idle_time' seconds and an initial maximum of MAC_DEFAULT_MAX
  * entries. */
@@ -200,6 +213,7 @@ mac_learning_create(unsigned int idle_time)
     heap_init(&ml->ports_by_usage);
     ovs_refcount_init(&ml->ref_cnt);
     ovs_rwlock_init(&ml->rwlock);
+    mac_learning_clear_statistics(ml);
     return ml;
 }
 
@@ -323,6 +337,7 @@ mac_learning_insert(struct mac_learning *ml,
         e->grat_arp_lock = TIME_MIN;
         e->mlport = NULL;
         COVERAGE_INC(mac_learning_learned);
+        ml->total_learned++;
     } else {
         ovs_list_remove(&e->lru_node);
     }
@@ -426,6 +441,7 @@ update_learning_table__(struct mac_learning *ml, struct eth_addr src,
     if (mac_entry_get_port(ml, mac) != in_port) {
         if (mac_entry_get_port(ml, mac) != NULL) {
             COVERAGE_INC(mac_learning_moved);
+            ml->total_moved++;
         }
         mac_entry_set_port(ml, mac, in_port);
         return true;
@@ -524,6 +540,7 @@ mac_learning_run(struct mac_learning *ml)
            && (hmap_count(&ml->table) > ml->max_entries
                || time_now() >= e->expires)) {
         COVERAGE_INC(mac_learning_expired);
+        ml->total_expired++;
         mac_learning_expire(ml, e);
     }
 
diff --git a/lib/mac-learning.h b/lib/mac-learning.h
index ee14185d9..29c4bc448 100644
--- a/lib/mac-learning.h
+++ b/lib/mac-learning.h
@@ -160,6 +160,12 @@ struct mac_learning {
     struct ovs_rwlock rwlock;
     bool need_revalidate;
 
+    /* Statistics */
+    uint64_t total_learned;
+    uint64_t total_expired;
+    uint64_t total_evicted;
+    uint64_t total_moved;
+
     /* Fairness.
      *
      * Both of these data structures include the same "struct



More information about the dev mailing list