X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=datapath%2Ftable.c;h=79b9bc1bd2c8f7b8793aa2b5f6b8cbd7b8295a72;hb=31ac1e590b9bb2a2ce7c70cd7c8fd2db0fb8e481;hp=8a10532400af4de4d68a2b6c3b5261481ff30f54;hpb=c6fadeb1f0488997b44e85a00a8887756232156d;p=openvswitch diff --git a/datapath/table.c b/datapath/table.c index 8a105324..79b9bc1b 100644 --- a/datapath/table.c +++ b/datapath/table.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009, 2010 Nicira Networks. + * Copyright (c) 2009, 2010, 2011 Nicira Networks. * Distributed under the terms of the GNU GPL version 2. * * Significant portions of this file may be copied from parts of the Linux @@ -40,17 +40,18 @@ static struct tbl_bucket *bucket_alloc(int n_objs) return kmalloc(bucket_size(n_objs), GFP_KERNEL); } -static void free_buckets(struct tbl_bucket ***l1, unsigned int n_buckets, +static void free_buckets(struct tbl_bucket __rcu ***l1, + unsigned int n_buckets, void (*free_obj)(struct tbl_node *)) { unsigned int i; - for (i = 0; i < n_buckets >> TBL_L1_BITS; i++) { - struct tbl_bucket **l2 = l1[i]; + for (i = 0; i < n_buckets >> TBL_L1_SHIFT; i++) { + struct tbl_bucket __rcu **l2 = l1[i]; unsigned int j; - for (j = 0; j < TBL_L1_SIZE; j++) { - struct tbl_bucket *bucket = l2[j]; + for (j = 0; j < TBL_L2_SIZE; j++) { + struct tbl_bucket *bucket = (struct tbl_bucket __force *)l2[j]; if (!bucket) continue; @@ -66,19 +67,19 @@ static void free_buckets(struct tbl_bucket ***l1, unsigned int n_buckets, kfree(l1); } -static struct tbl_bucket ***alloc_buckets(unsigned int n_buckets) +static struct tbl_bucket __rcu ***alloc_buckets(unsigned int n_buckets) { - struct tbl_bucket ***l1; + struct tbl_bucket __rcu ***l1; unsigned int i; - l1 = kmalloc((n_buckets >> TBL_L1_BITS) * sizeof(struct tbl_bucket **), + l1 = kmalloc((n_buckets >> TBL_L1_SHIFT) * sizeof(struct tbl_bucket **), GFP_KERNEL); if (!l1) return NULL; - for (i = 0; i < n_buckets >> TBL_L1_BITS; i++) { - l1[i] = (struct tbl_bucket **)get_zeroed_page(GFP_KERNEL); + for (i = 0; i < n_buckets >> TBL_L1_SHIFT; i++) { + l1[i] = (struct tbl_bucket __rcu **)get_zeroed_page(GFP_KERNEL); if (!l1[i]) { - free_buckets(l1, i << TBL_L1_BITS, NULL); + free_buckets(l1, i << TBL_L1_SHIFT, NULL); return NULL; } } @@ -97,7 +98,7 @@ struct tbl *tbl_create(unsigned int n_buckets) { struct tbl *table; - table = kzalloc(sizeof *table, GFP_KERNEL); + table = kzalloc(sizeof(*table), GFP_KERNEL); if (!table) goto err; @@ -225,16 +226,23 @@ struct tbl_node *tbl_lookup(struct tbl *table, void *target, u32 hash, int tbl_foreach(struct tbl *table, int (*callback)(struct tbl_node *, void *aux), void *aux) { - unsigned int i, j, k; - for (i = 0; i < table->n_buckets >> TBL_L1_BITS; i++) { - struct tbl_bucket __rcu **l2 = table->buckets[i]; - for (j = 0; j < TBL_L1_SIZE; j++) { - struct tbl_bucket *bucket = rcu_dereference(l2[j]); + unsigned int n_l1 = table->n_buckets >> TBL_L1_SHIFT; + unsigned int l1_idx; + + for (l1_idx = 0; l1_idx < n_l1; l1_idx++) { + struct tbl_bucket __rcu **l2 = table->buckets[l1_idx]; + unsigned int l2_idx; + + for (l2_idx = 0; l2_idx < TBL_L2_SIZE; l2_idx++) { + struct tbl_bucket *bucket; + unsigned int i; + + bucket = rcu_dereference(l2[l2_idx]); if (!bucket) continue; - for (k = 0; k < bucket->n_objs; k++) { - int error = (*callback)(bucket->objs[k], aux); + for (i = 0; i < bucket->n_objs; i++) { + int error = (*callback)(bucket->objs[i], aux); if (error) return error; }