From: Ben Pfaff Date: Fri, 20 Jul 2012 21:46:15 +0000 (-0700) Subject: classifier: Optimize iteration with a catch-all target rule. X-Git-Tag: sliver-openvswitch-1.8.90-0~15^2~25 X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=3ca1de08b4d0374e4b9389d98351b2b0192c8189;p=sliver-openvswitch.git classifier: Optimize iteration with a catch-all target rule. When cls_cursor_init() is given a NULL target, it can skip an expensive step comparing the rule against the target for every table and every rule in the classifier. collect_rule_loose() and other callers could take advantage of this optimization, except that they actually pass in a rule that matches everything instead of a NULL rule (e.g. for "ovs-ofctl dump-flows " without specifying a matching rule). This optimizes that case. Signed-off-by: Ben Pfaff --- diff --git a/lib/classifier.c b/lib/classifier.c index f6f7a64d4..81b05fdb5 100644 --- a/lib/classifier.c +++ b/lib/classifier.c @@ -111,6 +111,13 @@ cls_rule_format(const struct cls_rule *rule, struct ds *s) { match_format(&rule->match, s, rule->priority); } + +/* Returns true if 'rule' matches every packet, false otherwise. */ +bool +cls_rule_is_catchall(const struct cls_rule *rule) +{ + return flow_wildcards_is_catchall(&rule->match.wc); +} /* Initializes 'cls' as a classifier that initially contains no classification * rules. */ @@ -399,7 +406,7 @@ cls_cursor_init(struct cls_cursor *cursor, const struct classifier *cls, const struct cls_rule *target) { cursor->cls = cls; - cursor->target = target; + cursor->target = target && !cls_rule_is_catchall(target) ? target : NULL; } /* Returns the first matching cls_rule in 'cursor''s iteration, or a null diff --git a/lib/classifier.h b/lib/classifier.h index 341c34413..ebb1bbada 100644 --- a/lib/classifier.h +++ b/lib/classifier.h @@ -78,6 +78,8 @@ uint32_t cls_rule_hash(const struct cls_rule *, uint32_t basis); void cls_rule_format(const struct cls_rule *, struct ds *); +bool cls_rule_is_catchall(const struct cls_rule *); + bool cls_rule_is_loose_match(const struct cls_rule *rule, const struct match *criteria);