From: Ben Pfaff Date: Mon, 21 Jul 2008 20:51:02 +0000 (-0700) Subject: Don't use atomic_t for tracking table flow counts. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7d73c8bac528e3c997dcd070cf87c4383f809c4c;p=openvswitch Don't use atomic_t for tracking table flow counts. Changes to n_flows is already fully serialized by dp_mutex. --- diff --git a/datapath/hwtable_dummy/hwtable_dummy.c b/datapath/hwtable_dummy/hwtable_dummy.c index 6f7ed8c1..4c6e5372 100644 --- a/datapath/hwtable_dummy/hwtable_dummy.c +++ b/datapath/hwtable_dummy/hwtable_dummy.c @@ -63,7 +63,7 @@ struct sw_table_dummy { struct sw_table swt; unsigned int max_flows; - atomic_t n_flows; + unsigned int n_flows; struct list_head flows; struct list_head iter_flows; unsigned long int next_serial; @@ -151,8 +151,7 @@ static int table_dummy_delete(struct sw_table *swt, && (!strict || (flow->priority == priority))) count += do_delete(swt, flow); } - if (count) - atomic_sub(count, &td->n_flows); + td->n_flows -= count; return count; } @@ -201,8 +200,7 @@ static int table_dummy_timeout(struct datapath *dp, struct sw_table *swt) spin_unlock_bh(&pending_free_lock); mutex_unlock(&dp_mutex); - if (del_count) - atomic_sub(del_count, &td->n_flows); + td->n_flows -= del_count; return del_count; } @@ -256,7 +254,7 @@ static void table_dummy_stats(struct sw_table *swt, { struct sw_table_dummy *td = (struct sw_table_dummy *) swt; stats->name = "dummy"; - stats->n_flows = atomic_read(&td->n_flows); + stats->n_flows = td->n_flows; stats->max_flows = td->max_flows; } @@ -280,7 +278,7 @@ static struct sw_table *table_dummy_create(void) swt->stats = table_dummy_stats; td->max_flows = DUMMY_MAX_FLOW; - atomic_set(&td->n_flows, 0); + td->n_flows = 0; INIT_LIST_HEAD(&td->flows); INIT_LIST_HEAD(&td->iter_flows); td->next_serial = 0; diff --git a/datapath/table-hash.c b/datapath/table-hash.c index b7475e3b..202114b6 100644 --- a/datapath/table-hash.c +++ b/datapath/table-hash.c @@ -22,7 +22,7 @@ static void kmem_free(void *, size_t); struct sw_table_hash { struct sw_table swt; struct crc32 crc32; - atomic_t n_flows; + unsigned int n_flows; unsigned int bucket_mask; /* Number of buckets minus 1. */ struct sw_flow **buckets; }; @@ -53,7 +53,7 @@ static int table_hash_insert(struct sw_table *swt, struct sw_flow *flow) bucket = find_bucket(swt, &flow->key); if (*bucket == NULL) { - atomic_inc(&th->n_flows); + th->n_flows++; rcu_assign_pointer(*bucket, flow); retval = 1; } else { @@ -106,8 +106,7 @@ static int table_hash_delete(struct sw_table *swt, count += do_delete(bucket, flow); } } - if (count) - atomic_sub(count, &th->n_flows); + th->n_flows -= count; return count; } @@ -127,10 +126,9 @@ static int table_hash_timeout(struct datapath *dp, struct sw_table *swt) dp_send_flow_expired(dp, flow); } } + th->n_flows -= count; mutex_unlock(&dp_mutex); - if (count) - atomic_sub(count, &th->n_flows); return count; } @@ -189,7 +187,7 @@ static void table_hash_stats(struct sw_table *swt, { struct sw_table_hash *th = (struct sw_table_hash *) swt; stats->name = "hash"; - stats->n_flows = atomic_read(&th->n_flows); + stats->n_flows = th->n_flows; stats->max_flows = th->bucket_mask + 1; } @@ -222,7 +220,7 @@ struct sw_table *table_hash_create(unsigned int polynomial, swt->stats = table_hash_stats; crc32_init(&th->crc32, polynomial); - atomic_set(&th->n_flows, 0); + th->n_flows = 0; return swt; } diff --git a/datapath/table-linear.c b/datapath/table-linear.c index e4092996..e1274bf3 100644 --- a/datapath/table-linear.c +++ b/datapath/table-linear.c @@ -16,7 +16,7 @@ struct sw_table_linear { struct sw_table swt; unsigned int max_flows; - atomic_t n_flows; + unsigned int n_flows; struct list_head flows; struct list_head iter_flows; unsigned long int next_serial; @@ -61,10 +61,10 @@ static int table_linear_insert(struct sw_table *swt, struct sw_flow *flow) } /* Make sure there's room in the table. */ - if (atomic_read(&tl->n_flows) >= tl->max_flows) { + if (tl->n_flows >= tl->max_flows) { return 0; } - atomic_inc(&tl->n_flows); + tl->n_flows++; /* Insert the entry immediately in front of where we're pointing. */ flow->serial = tl->next_serial++; @@ -96,8 +96,7 @@ static int table_linear_delete(struct sw_table *swt, && (!strict || (flow->priority == priority))) count += do_delete(swt, flow); } - if (count) - atomic_sub(count, &tl->n_flows); + tl->n_flows -= count; return count; } @@ -115,10 +114,8 @@ static int table_linear_timeout(struct datapath *dp, struct sw_table *swt) dp_send_flow_expired(dp, flow); } } + tl->n_flows -= count; mutex_unlock(&dp_mutex); - - if (count) - atomic_sub(count, &tl->n_flows); return count; } @@ -163,7 +160,7 @@ static void table_linear_stats(struct sw_table *swt, { struct sw_table_linear *tl = (struct sw_table_linear *) swt; stats->name = "linear"; - stats->n_flows = atomic_read(&tl->n_flows); + stats->n_flows = tl->n_flows; stats->max_flows = tl->max_flows; } @@ -187,7 +184,7 @@ struct sw_table *table_linear_create(unsigned int max_flows) swt->stats = table_linear_stats; tl->max_flows = max_flows; - atomic_set(&tl->n_flows, 0); + tl->n_flows = 0; INIT_LIST_HEAD(&tl->flows); INIT_LIST_HEAD(&tl->iter_flows); tl->next_serial = 0;