[ovs-dev] [PATCH 07/17] dpif-netdev: Use a boolean instead of pmd->port_seq.

Daniele Di Proietto diproiettod at vmware.com
Wed Nov 16 00:46:02 UTC 2016


There's no need for a sequence number, since the main thread has to wait
for the pmd thread, so there's no chance that an update will be
undetected.

A seq object will be introduced for another purpose in the next commit,
and changing this to boolean makes the code more readable.

Signed-off-by: Daniele Di Proietto <diproiettod at vmware.com>
---
 lib/dpif-netdev.c | 19 +++++++------------
 1 file changed, 7 insertions(+), 12 deletions(-)

diff --git a/lib/dpif-netdev.c b/lib/dpif-netdev.c
index 81366b2..23546b9 100644
--- a/lib/dpif-netdev.c
+++ b/lib/dpif-netdev.c
@@ -485,7 +485,7 @@ struct dp_netdev_pmd_thread {
     unsigned long long last_cycles;
 
     struct latch exit_latch;        /* For terminating the pmd thread. */
-    atomic_uint change_seq;         /* For reloading pmd ports. */
+    atomic_bool reload;             /* Do we need to reload ports? */
     pthread_t thread;
     unsigned core_id;               /* CPU core id of this pmd thread. */
     int numa_id;                    /* numa node id of this pmd thread. */
@@ -527,8 +527,6 @@ struct dp_netdev_pmd_thread {
     uint64_t cycles_zero[PMD_N_CYCLES];
 };
 
-#define PMD_INITIAL_SEQ 1
-
 /* Interface to netdev-based datapath. */
 struct dpif_netdev {
     struct dpif dpif;
@@ -1202,8 +1200,6 @@ dpif_netdev_get_stats(const struct dpif *dpif, struct dpif_dp_stats *stats)
 static void
 dp_netdev_reload_pmd__(struct dp_netdev_pmd_thread *pmd)
 {
-    int old_seq;
-
     if (pmd->core_id == NON_PMD_CORE_ID) {
         ovs_mutex_lock(&pmd->dp->non_pmd_mutex);
         ovs_mutex_lock(&pmd->port_mutex);
@@ -1214,7 +1210,7 @@ dp_netdev_reload_pmd__(struct dp_netdev_pmd_thread *pmd)
     }
 
     ovs_mutex_lock(&pmd->cond_mutex);
-    atomic_add_relaxed(&pmd->change_seq, 1, &old_seq);
+    atomic_store_relaxed(&pmd->reload, true);
     ovs_mutex_cond_wait(&pmd->cond, &pmd->cond_mutex);
     ovs_mutex_unlock(&pmd->cond_mutex);
 }
@@ -3131,7 +3127,6 @@ pmd_thread_main(void *f_)
     struct dp_netdev_pmd_thread *pmd = f_;
     unsigned int lc = 0;
     struct rxq_poll *poll_list;
-    unsigned int port_seq = PMD_INITIAL_SEQ;
     bool exiting;
     int poll_cnt;
     int i;
@@ -3159,7 +3154,7 @@ reload:
         }
 
         if (lc++ > 1024) {
-            unsigned int seq;
+            bool reload;
 
             lc = 0;
 
@@ -3169,9 +3164,8 @@ reload:
                 emc_cache_slow_sweep(&pmd->flow_cache);
             }
 
-            atomic_read_relaxed(&pmd->change_seq, &seq);
-            if (seq != port_seq) {
-                port_seq = seq;
+            atomic_read_relaxed(&pmd->reload, &reload);
+            if (reload) {
                 break;
             }
         }
@@ -3228,6 +3222,7 @@ static void
 dp_netdev_pmd_reload_done(struct dp_netdev_pmd_thread *pmd)
 {
     ovs_mutex_lock(&pmd->cond_mutex);
+    atomic_store_relaxed(&pmd->reload, false);
     xpthread_cond_signal(&pmd->cond);
     ovs_mutex_unlock(&pmd->cond_mutex);
 }
@@ -3322,7 +3317,7 @@ dp_netdev_configure_pmd(struct dp_netdev_pmd_thread *pmd, struct dp_netdev *dp,
 
     ovs_refcount_init(&pmd->ref_cnt);
     latch_init(&pmd->exit_latch);
-    atomic_init(&pmd->change_seq, PMD_INITIAL_SEQ);
+    atomic_init(&pmd->reload, false);
     xpthread_cond_init(&pmd->cond, NULL);
     ovs_mutex_init(&pmd->cond_mutex);
     ovs_mutex_init(&pmd->flow_mutex);
-- 
2.10.2



More information about the dev mailing list