unsigned int max_priority;
};
-struct cls_subtable_cache {
- struct cls_subtable_entry *subtables;
+struct cls_subtables {
+ size_t count; /* One past last valid array element. */
size_t alloc_size; /* Number of allocated elements. */
- size_t size; /* One past last valid array element. */
+ struct cls_subtable_entry *array;
};
enum {
};
struct cls_classifier {
- int n_rules; /* Total number of rules. */
+ int n_rules; /* Total number of rules. */
uint8_t n_flow_segments;
uint8_t flow_segments[CLS_MAX_INDICES]; /* Flow segment boundaries to use
* for staged lookup. */
- struct hmap subtables; /* Contains "struct cls_subtable"s. */
- struct cls_subtable_cache subtables_priority;
- struct hmap partitions; /* Contains "struct cls_partition"s. */
+ struct hmap subtables_map; /* Contains "struct cls_subtable"s. */
+ struct cls_subtables subtables;
+ struct hmap partitions; /* Contains "struct cls_partition"s. */
struct cls_trie tries[CLS_MAX_TRIES]; /* Prefix tries. */
unsigned int n_tries;
};
/* A set of rules that all have the same fields wildcarded. */
struct cls_subtable {
- struct hmap_node hmap_node; /* Within struct cls_classifier 'subtables'
+ struct hmap_node hmap_node; /* Within struct cls_classifier 'subtables_map'
* hmap. */
struct hmap rules; /* Contains "struct cls_rule"s. */
int n_rules; /* Number of rules, including duplicates. */
uint8_t be32ofs, unsigned int nbits);
static void
-cls_subtable_cache_init(struct cls_subtable_cache *array)
+cls_subtables_init(struct cls_subtables *subtables)
{
- memset(array, 0, sizeof *array);
+ memset(subtables, 0, sizeof *subtables);
}
static void
-cls_subtable_cache_destroy(struct cls_subtable_cache *array)
+cls_subtables_destroy(struct cls_subtables *subtables)
{
- free(array->subtables);
- memset(array, 0, sizeof *array);
+ free(subtables->array);
+ memset(subtables, 0, sizeof *subtables);
}
-/* Array insertion. */
+/* Subtables insertion. */
static void
-cls_subtable_cache_push_back(struct cls_subtable_cache *array,
- struct cls_subtable_entry a)
+cls_subtables_push_back(struct cls_subtables *subtables,
+ struct cls_subtable_entry a)
{
- if (array->size == array->alloc_size) {
- array->subtables = x2nrealloc(array->subtables, &array->alloc_size,
+ if (subtables->count == subtables->alloc_size) {
+ subtables->array = x2nrealloc(subtables->array, &subtables->alloc_size,
sizeof a);
}
- array->subtables[array->size++] = a;
+ subtables->array[subtables->count++] = a;
}
/* Move subtable entry at 'from' to 'to', shifting the elements in between
* (including the one at 'to') accordingly. */
static inline void
-cls_subtable_cache_move(struct cls_subtable_entry *to,
- struct cls_subtable_entry *from)
+cls_subtables_move(struct cls_subtable_entry *to,
+ struct cls_subtable_entry *from)
{
if (to != from) {
struct cls_subtable_entry temp = *from;
}
}
-/* Array removal. */
+/* Subtables removal. */
static inline void
-cls_subtable_cache_remove(struct cls_subtable_cache *array,
- struct cls_subtable_entry *elem)
+cls_subtables_remove(struct cls_subtables *subtables,
+ struct cls_subtable_entry *elem)
{
- ssize_t size = (&array->subtables[array->size]
+ ssize_t size = (&subtables->array[subtables->count]
- (elem + 1)) * sizeof *elem;
if (size > 0) {
memmove(elem, elem + 1, size);
}
- array->size--;
+ subtables->count--;
}
-#define CLS_SUBTABLE_CACHE_FOR_EACH(SUBTABLE, ITER, ARRAY) \
- for (ITER = (ARRAY)->subtables; \
- ITER < &(ARRAY)->subtables[(ARRAY)->size] \
- && OVS_LIKELY(SUBTABLE = ITER->subtable); \
- ++ITER)
-#define CLS_SUBTABLE_CACHE_FOR_EACH_CONTINUE(SUBTABLE, ITER, ARRAY) \
- for (++ITER; \
- ITER < &(ARRAY)->subtables[(ARRAY)->size] \
- && OVS_LIKELY(SUBTABLE = ITER->subtable); \
- ++ITER)
-#define CLS_SUBTABLE_CACHE_FOR_EACH_REVERSE(SUBTABLE, ITER, ARRAY) \
- for (ITER = &(ARRAY)->subtables[(ARRAY)->size]; \
- ITER > (ARRAY)->subtables \
- && OVS_LIKELY(SUBTABLE = (--ITER)->subtable);)
+#define CLS_SUBTABLES_FOR_EACH(SUBTABLE, ITER, SUBTABLES) \
+ for ((ITER) = (SUBTABLES)->array; \
+ (ITER) < &(SUBTABLES)->array[(SUBTABLES)->count] \
+ && OVS_LIKELY((SUBTABLE) = (ITER)->subtable); \
+ ++(ITER))
+#define CLS_SUBTABLES_FOR_EACH_CONTINUE(SUBTABLE, ITER, SUBTABLES) \
+ for (++(ITER); \
+ (ITER) < &(SUBTABLES)->array[(SUBTABLES)->count] \
+ && OVS_LIKELY((SUBTABLE) = (ITER)->subtable); \
+ ++(ITER))
+#define CLS_SUBTABLES_FOR_EACH_REVERSE(SUBTABLE, ITER, SUBTABLES) \
+ for ((ITER) = &(SUBTABLES)->array[(SUBTABLES)->count]; \
+ (ITER) > (SUBTABLES)->array \
+ && OVS_LIKELY((SUBTABLE) = (--(ITER))->subtable);)
static void
-cls_subtable_cache_verify(struct cls_subtable_cache *array)
+cls_subtables_verify(struct cls_subtables *subtables)
{
struct cls_subtable *table;
struct cls_subtable_entry *iter;
unsigned int priority = 0;
- CLS_SUBTABLE_CACHE_FOR_EACH_REVERSE (table, iter, array) {
+ CLS_SUBTABLES_FOR_EACH_REVERSE (table, iter, subtables) {
if (iter->max_priority != table->max_priority) {
VLOG_WARN("Subtable %p has mismatching priority in cache (%u != %u)",
table, iter->max_priority, table->max_priority);
}
static void
-cls_subtable_cache_reset(struct cls_classifier *cls)
+cls_subtables_reset(struct cls_classifier *cls)
{
- struct cls_subtable_cache old = cls->subtables_priority;
+ struct cls_subtables old = cls->subtables;
struct cls_subtable *subtable;
VLOG_WARN("Resetting subtable cache.");
- cls_subtable_cache_verify(&cls->subtables_priority);
+ cls_subtables_verify(&cls->subtables);
- cls_subtable_cache_init(&cls->subtables_priority);
+ cls_subtables_init(&cls->subtables);
- HMAP_FOR_EACH (subtable, hmap_node, &cls->subtables) {
+ HMAP_FOR_EACH (subtable, hmap_node, &cls->subtables_map) {
struct cls_match *head;
struct cls_subtable_entry elem;
struct cls_subtable *table;
/* Locate the subtable from the old cache. */
found = false;
- CLS_SUBTABLE_CACHE_FOR_EACH (table, iter, &old) {
+ CLS_SUBTABLES_FOR_EACH (table, iter, &old) {
if (table == subtable) {
if (iter->max_priority != new_max) {
VLOG_WARN("Subtable %p has wrong max priority (%u != %u) "
elem.subtable = subtable;
elem.tag = subtable->tag;
elem.max_priority = subtable->max_priority;
- cls_subtable_cache_push_back(&cls->subtables_priority, elem);
+ cls_subtables_push_back(&cls->subtables, elem);
/* Possibly move 'subtable' earlier in the priority array. If
* we break out of the loop, then the subtable (at 'from')
* element. If the loop terminates normally, then 'iter' will
* be at the first array element and we'll move the subtable
* to the front of the array. */
- CLS_SUBTABLE_CACHE_FOR_EACH_REVERSE (table, iter,
- &cls->subtables_priority) {
+ CLS_SUBTABLES_FOR_EACH_REVERSE (table, iter, &cls->subtables) {
if (table == subtable) {
from = iter; /* Locate the subtable as we go. */
} else if (table->max_priority >= new_max) {
}
/* Move subtable at 'from' to 'iter'. */
- cls_subtable_cache_move(iter, from);
+ cls_subtables_move(iter, from);
}
/* Verify that the old and the new have the same size. */
- if (old.size != cls->subtables_priority.size) {
+ if (old.count != cls->subtables.count) {
VLOG_WARN("subtables cache sizes differ: old (%"PRIuSIZE
") != new (%"PRIuSIZE").",
- old.size, cls->subtables_priority.size);
+ old.count, cls->subtables.count);
}
- cls_subtable_cache_destroy(&old);
+ cls_subtables_destroy(&old);
- cls_subtable_cache_verify(&cls->subtables_priority);
+ cls_subtables_verify(&cls->subtables);
}
\f
cls_->cls = cls;
cls->n_rules = 0;
- hmap_init(&cls->subtables);
- cls_subtable_cache_init(&cls->subtables_priority);
+ hmap_init(&cls->subtables_map);
+ cls_subtables_init(&cls->subtables);
hmap_init(&cls->partitions);
cls->n_flow_segments = 0;
if (flow_segments) {
}
HMAP_FOR_EACH_SAFE (subtable, next_subtable, hmap_node,
- &cls->subtables) {
+ &cls->subtables_map) {
destroy_subtable(cls, subtable);
}
- hmap_destroy(&cls->subtables);
+ hmap_destroy(&cls->subtables_map);
HMAP_FOR_EACH_SAFE (partition, next_partition, hmap_node,
&cls->partitions) {
}
hmap_destroy(&cls->partitions);
- cls_subtable_cache_destroy(&cls->subtables_priority);
+ cls_subtables_destroy(&cls->subtables);
free(cls);
}
}
trie->field = field;
/* Add existing rules to the trie. */
- CLS_SUBTABLE_CACHE_FOR_EACH (subtable, iter, &cls->subtables_priority) {
+ CLS_SUBTABLES_FOR_EACH (subtable, iter, &cls->subtables) {
unsigned int plen;
plen = field ? minimask_get_prefix_len(&subtable->mask, field) : 0;
struct cls_match *best;
struct trie_ctx trie_ctx[CLS_MAX_TRIES];
int i;
- struct cls_subtable_entry *subtables = cls->subtables_priority.subtables;
- int n_subtables = cls->subtables_priority.size;
+ struct cls_subtable_entry *subtables = cls->subtables.array;
+ int n_subtables = cls->subtables.count;
int64_t best_priority = -1;
/* Prefetch the subtables array. */
/* Prefetch the first subtables. */
if (n_subtables > 1) {
- lookahead_subtable(subtables);
- lookahead_subtable(subtables + 1);
+ lookahead_subtable(subtables);
+ lookahead_subtable(subtables + 1);
}
best = NULL;
struct cls_subtable *subtable;
struct cls_subtable_entry *iter;
- CLS_SUBTABLE_CACHE_FOR_EACH (subtable, iter, &cls->subtables_priority) {
+ CLS_SUBTABLES_FOR_EACH (subtable, iter, &cls->subtables) {
struct cls_match *rule;
rule = find_match_miniflow(subtable, flow,
struct cls_subtable_entry *iter;
/* Iterate subtables in the descending max priority order. */
- CLS_SUBTABLE_CACHE_FOR_EACH (subtable, iter, &cls->subtables_priority) {
+ CLS_SUBTABLES_FOR_EACH (subtable, iter, &cls->subtables) {
uint32_t storage[FLOW_U32S];
struct minimask mask;
struct cls_match *head;
{
struct cls_subtable *subtable;
- HMAP_FOR_EACH (subtable, hmap_node, &cursor->cls->subtables) {
+ HMAP_FOR_EACH (subtable, hmap_node, &cursor->cls->subtables_map) {
struct cls_match *rule = search_subtable(subtable, cursor->target);
if (rule) {
cursor->subtable = subtable;
}
subtable = cursor->subtable;
- HMAP_FOR_EACH_CONTINUE (subtable, hmap_node, &cursor->cls->subtables) {
+ HMAP_FOR_EACH_CONTINUE (subtable, hmap_node, &cursor->cls->subtables_map) {
rule = search_subtable(subtable, cursor->target);
if (rule) {
cursor->subtable = subtable;
struct cls_subtable *subtable;
HMAP_FOR_EACH_IN_BUCKET (subtable, hmap_node, minimask_hash(mask, 0),
- &cls->subtables) {
+ &cls->subtables_map) {
if (minimask_equal(mask, &subtable->mask)) {
return subtable;
}
subtable->ports_mask_len
= 32 - ctz32(ntohl(MINIFLOW_GET_BE32(&mask->masks, tp_src)));
- hmap_insert(&cls->subtables, &subtable->hmap_node, hash);
+ hmap_insert(&cls->subtables_map, &subtable->hmap_node, hash);
elem.subtable = subtable;
elem.tag = subtable->tag;
elem.max_priority = subtable->max_priority;
- cls_subtable_cache_push_back(&cls->subtables_priority, elem);
+ cls_subtables_push_back(&cls->subtables, elem);
return subtable;
}
struct cls_subtable *table = NULL;
struct cls_subtable_entry *iter;
- CLS_SUBTABLE_CACHE_FOR_EACH (table, iter, &cls->subtables_priority) {
+ CLS_SUBTABLES_FOR_EACH (table, iter, &cls->subtables) {
if (table == subtable) {
- cls_subtable_cache_remove(&cls->subtables_priority, iter);
+ cls_subtables_remove(&cls->subtables, iter);
break;
}
}
hindex_destroy(&subtable->indices[i]);
}
minimask_destroy(&subtable->mask);
- hmap_remove(&cls->subtables, &subtable->hmap_node);
+ hmap_remove(&cls->subtables_map, &subtable->hmap_node);
hmap_destroy(&subtable->rules);
free(subtable);
}
*
* - Update 'subtable->max_priority' and 'subtable->max_count' if necessary.
*
- * - Update 'subtable''s position in 'cls->subtables_priority' if necessary.
+ * - Update 'subtable''s position in 'cls->subtables' if necessary.
*
* This function should only be called after adding a new rule, not after
* replacing a rule by an identical one or modifying a rule in-place. */
* element. If the loop terminates normally, then 'iter' will
* be at the first array element and we'll move the subtable
* to the front of the array. */
- CLS_SUBTABLE_CACHE_FOR_EACH_REVERSE (table, iter,
- &cls->subtables_priority) {
+ CLS_SUBTABLES_FOR_EACH_REVERSE (table, iter, &cls->subtables) {
if (table == subtable) {
from = iter; /* Locate the subtable as we go. */
iter->max_priority = new_priority;
} else if (table->max_priority >= new_priority) {
if (from == NULL) {
/* Corrupted cache? */
- cls_subtable_cache_reset(cls);
+ cls_subtables_reset(cls);
VLOG_ABORT("update_subtables_after_insertion(): Subtable priority list corrupted.");
OVS_NOT_REACHED();
}
}
/* Move subtable at 'from' to 'iter'. */
- cls_subtable_cache_move(iter, from);
+ cls_subtables_move(iter, from);
}
}
*
* - Update 'subtable->max_priority' and 'subtable->max_count' if necessary.
*
- * - Update 'subtable''s position in 'cls->subtables_priority' if necessary.
+ * - Update 'subtable''s position in 'cls->subtables' if necessary.
*
* This function should only be called after removing a rule, not after
* replacing a rule by an identical one or modifying a rule in-place. */
* at which the subtable should be moved (either at a subtable
* with an equal or lower priority, or just past the array),
* so it is decremented once. */
- CLS_SUBTABLE_CACHE_FOR_EACH (table, iter, &cls->subtables_priority) {
+ CLS_SUBTABLES_FOR_EACH (table, iter, &cls->subtables) {
if (table == subtable) {
from = iter; /* Locate the subtable as we go. */
iter->max_priority = subtable->max_priority;
} else if (table->max_priority <= subtable->max_priority) {
if (from == NULL) {
/* Corrupted cache? */
- cls_subtable_cache_reset(cls);
+ cls_subtables_reset(cls);
VLOG_ABORT("update_subtables_after_removal(): Subtable priority list corrupted.");
OVS_NOT_REACHED();
}
iter--;
/* Move subtable at 'from' to 'iter'. */
- cls_subtable_cache_move(iter, from);
+ cls_subtables_move(iter, from);
}
}