meta-flow: Avoid unnecessary large memset.
authorJarno Rajahalme <jrajahalme@nicira.com>
Wed, 26 Aug 2015 22:45:46 +0000 (15:45 -0700)
committerJarno Rajahalme <jrajahalme@nicira.com>
Wed, 26 Aug 2015 22:45:46 +0000 (15:45 -0700)
mf_mask_field_and_prereqs() used to memset a static variable again and
again.  Now that mf_value is larger (due to tun_metadata field), this
is more expensive.  Avoid this by using static initialization.

mf_mask_field_and_prereqs() is used only for set field and reg move,
which never deal with the tun_metadata field as a whole.

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

index 528c109..af8ed49 100644 (file)
@@ -390,13 +390,13 @@ mf_are_prereqs_ok(const struct mf_field *mf, const struct flow *flow)
 
 /* Set field and it's prerequisities in the mask.
  * This is only ever called for writeable 'mf's, but we do not make the
- * distinction here. */
+ * distinction here. 
+ * The widest field this is ever called for an IPv6 address (16 bytes). */
 void
 mf_mask_field_and_prereqs(const struct mf_field *mf, struct flow *mask)
 {
-    static union mf_value exact_match_mask;
+    static union mf_value exact_match_mask = { .ipv6 = IN6ADDR_EXACT_INIT };
 
-    memset(&exact_match_mask, 0xff, sizeof exact_match_mask);
     mf_set_flow_value(mf, &exact_match_mask, mask);
 
     switch (mf->prereqs) {