ofproto/ofproto: Use relaxed atomics.
authorJarno Rajahalme <jrajahalme@nicira.com>
Fri, 29 Aug 2014 17:34:53 +0000 (10:34 -0700)
committerJarno Rajahalme <jrajahalme@nicira.com>
Fri, 29 Aug 2014 17:34:53 +0000 (10:34 -0700)
Neither 'miss_config', 'n_missed', nor 'n_matched' is used to
synchronize the state of any other variable, so we can use relaxed
atomic operations on them.

Signed-off-by: Jarno Rajahalme <jrajahalme@nicira.com>
Acked-by: Ben Pfaff <blp@nicira.com>
ofproto/ofproto-dpif.c
ofproto/ofproto.c

index 4449767..a635ca6 100644 (file)
@@ -1511,9 +1511,10 @@ query_tables(struct ofproto *ofproto,
         for (i = 0; i < ofproto->n_tables; i++) {
             unsigned long missed, matched;
 
-            atomic_read(&ofproto->tables[i].n_matched, &matched);
+            atomic_read_relaxed(&ofproto->tables[i].n_matched, &matched);
+            atomic_read_relaxed(&ofproto->tables[i].n_missed, &missed);
+
             stats[i].matched_count = matched;
-            atomic_read(&ofproto->tables[i].n_missed, &missed);
             stats[i].lookup_count = matched + missed;
         }
     }
@@ -3445,9 +3446,10 @@ rule_dpif_lookup_from_table(struct ofproto_dpif *ofproto,
                                           take_ref);
         if (stats) {
             struct oftable *tbl = &ofproto->up.tables[next_id];
-            atomic_ulong *stat = *rule ? &tbl->n_matched : &tbl->n_missed;
             unsigned long orig;
-            atomic_add(stat, stats->n_packets, &orig);
+
+            atomic_add_relaxed(*rule ? &tbl->n_matched : &tbl->n_missed,
+                               stats->n_packets, &orig);
         }
         if (*rule) {
             return RULE_DPIF_LOOKUP_VERDICT_MATCH;
index 4db6fec..3e80b87 100644 (file)
@@ -2812,7 +2812,7 @@ query_tables(struct ofproto *ofproto,
         sprintf(f->name, "table%d", i);
         f->metadata_match = OVS_BE64_MAX;
         f->metadata_write = OVS_BE64_MAX;
-        atomic_read(&ofproto->tables[i].miss_config, &f->miss_config);
+        atomic_read_relaxed(&ofproto->tables[i].miss_config, &f->miss_config);
         f->max_entries = 1000000;
 
         bitmap_set_multiple(f->nonmiss.next, i + 1,
@@ -5817,7 +5817,8 @@ enum ofputil_table_miss
 ofproto_table_get_miss_config(const struct ofproto *ofproto, uint8_t table_id)
 {
     enum ofputil_table_miss value;
-    atomic_read(&ofproto->tables[table_id].miss_config, &value);
+
+    atomic_read_relaxed(&ofproto->tables[table_id].miss_config, &value);
     return value;
 }
 
@@ -5830,11 +5831,12 @@ table_mod(struct ofproto *ofproto, const struct ofputil_table_mod *tm)
         if (tm->table_id == OFPTT_ALL) {
             int i;
             for (i = 0; i < ofproto->n_tables; i++) {
-                atomic_store(&ofproto->tables[i].miss_config, tm->miss_config);
+                atomic_store_relaxed(&ofproto->tables[i].miss_config,
+                                     tm->miss_config);
             }
         } else {
-            atomic_store(&ofproto->tables[tm->table_id].miss_config,
-                         tm->miss_config);
+            atomic_store_relaxed(&ofproto->tables[tm->table_id].miss_config,
+                                 tm->miss_config);
         }
     }
     return 0;