The non-pmd structure (the dp_netdev_pmd_thread with core_id ==
NON_PMD_CORE_ID) should have the same lifecycle as the dp_netdev
structure, for two reasons:

* Destroying and recreating it is useless
* Some thread (i.e. a monitor thread) calling dpif_netdev_execute()
  expects the structure to be there.

Since the non-pmd structure is never destroyed this commit introduces
the garbage collection of the non pmd exact match cache from the main
thread.

Signed-off-by: Daniele Di Proietto <diproiet...@vmware.com>
---
 lib/dpif-netdev.c | 29 ++++++++++++-----------------
 1 file changed, 12 insertions(+), 17 deletions(-)

diff --git a/lib/dpif-netdev.c b/lib/dpif-netdev.c
index 6b61db4..3b781f5 100644
--- a/lib/dpif-netdev.c
+++ b/lib/dpif-netdev.c
@@ -428,7 +428,6 @@ static void dp_netdev_configure_pmd(struct 
dp_netdev_pmd_thread *pmd,
                                     struct dp_netdev *dp, int index,
                                     int core_id, int numa_id);
 static void dp_netdev_destroy_pmd(struct dp_netdev_pmd_thread *pmd);
-static void dp_netdev_set_nonpmd(struct dp_netdev *dp);
 static struct dp_netdev_pmd_thread *dp_netdev_get_pmd(struct dp_netdev *dp,
                                                       int core_id);
 static struct dp_netdev_pmd_thread *
@@ -437,6 +436,7 @@ static void dp_netdev_destroy_all_pmds(struct dp_netdev 
*dp);
 static void dp_netdev_del_pmds_on_numa(struct dp_netdev *dp, int numa_id);
 static void dp_netdev_set_pmds_on_numa(struct dp_netdev *dp, int numa_id);
 static void dp_netdev_reset_pmd_threads(struct dp_netdev *dp);
+static void dp_netdev_del_pmd(struct dp_netdev_pmd_thread *pmd);
 static bool dp_netdev_pmd_try_ref(struct dp_netdev_pmd_thread *pmd);
 static void dp_netdev_pmd_unref(struct dp_netdev_pmd_thread *pmd);
 static void dp_netdev_pmd_flow_flush(struct dp_netdev_pmd_thread *pmd);
@@ -596,6 +596,7 @@ create_dp_netdev(const char *name, const struct dpif_class 
*class,
                  struct dp_netdev **dpp)
     OVS_REQUIRES(dp_netdev_mutex)
 {
+    struct dp_netdev_pmd_thread *non_pmd;
     struct dp_netdev *dp;
     int error;
 
@@ -623,7 +624,9 @@ create_dp_netdev(const char *name, const struct dpif_class 
*class,
 
     /* Reserves the core NON_PMD_CORE_ID for all non-pmd threads. */
     ovs_numa_try_pin_core_specific(NON_PMD_CORE_ID);
-    dp_netdev_set_nonpmd(dp);
+    non_pmd = xzalloc(sizeof *non_pmd);
+    dp_netdev_configure_pmd(non_pmd, dp, 0, NON_PMD_CORE_ID,
+                            OVS_NUMA_UNSPEC);
     dp->n_dpdk_rxqs = NR_QUEUE;
 
     ovs_mutex_lock(&dp->port_mutex);
@@ -687,6 +690,7 @@ dp_netdev_free(struct dp_netdev *dp)
     shash_find_and_delete(&dp_netdevs, dp->name);
 
     dp_netdev_destroy_all_pmds(dp);
+    dp_netdev_del_pmd(dp_netdev_get_pmd(dp, NON_PMD_CORE_ID));
     cmap_destroy(&dp->poll_threads);
     ovs_mutex_destroy(&dp->non_pmd_mutex);
     ovsthread_key_delete(dp->per_pmd_key);
@@ -2170,8 +2174,6 @@ dpif_netdev_pmd_set(struct dpif *dpif, unsigned int 
n_rxqs, const char *cmask)
         free(dp->pmd_cmask);
         dp->pmd_cmask = cmask ? xstrdup(cmask) : NULL;
 
-        /* Restores the non-pmd. */
-        dp_netdev_set_nonpmd(dp);
         /* Restores all pmd threads. */
         dp_netdev_reset_pmd_threads(dp);
     }
@@ -2264,6 +2266,7 @@ dpif_netdev_run(struct dpif *dpif)
             }
         }
     }
+    emc_cache_slow_sweep(&non_pmd->flow_cache);
     ovs_mutex_unlock(&dp->non_pmd_mutex);
     dp_netdev_pmd_unref(non_pmd);
 
@@ -2469,17 +2472,6 @@ dp_netdev_get_pmd(struct dp_netdev *dp, int core_id)
     return dp_netdev_pmd_try_ref(pmd) ? pmd : NULL;
 }
 
-/* Sets the 'struct dp_netdev_pmd_thread' for non-pmd threads. */
-static void
-dp_netdev_set_nonpmd(struct dp_netdev *dp)
-{
-    struct dp_netdev_pmd_thread *non_pmd;
-
-    non_pmd = xzalloc(sizeof *non_pmd);
-    dp_netdev_configure_pmd(non_pmd, dp, 0, NON_PMD_CORE_ID,
-                            OVS_NUMA_UNSPEC);
-}
-
 /* Caller must have valid pointer to 'pmd'. */
 static bool
 dp_netdev_pmd_try_ref(struct dp_netdev_pmd_thread *pmd)
@@ -2574,14 +2566,17 @@ dp_netdev_del_pmd(struct dp_netdev_pmd_thread *pmd)
     dp_netdev_pmd_unref(pmd);
 }
 
-/* Destroys all pmd threads. */
+/* Destroys all pmd threads. The non-pmd structure has to be
+ * destroyed manually, since it has a different life cycle */
 static void
 dp_netdev_destroy_all_pmds(struct dp_netdev *dp)
 {
     struct dp_netdev_pmd_thread *pmd;
 
     CMAP_FOR_EACH (pmd, node, &dp->poll_threads) {
-        dp_netdev_del_pmd(pmd);
+        if (pmd->core_id != NON_PMD_CORE_ID) {
+            dp_netdev_del_pmd(pmd);
+        }
     }
 }
 
-- 
2.1.4

_______________________________________________
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev

Reply via email to