ofproto: Shrink struct rule_actions slightly.
authorBen Pfaff <blp@nicira.com>
Wed, 28 May 2014 18:55:53 +0000 (11:55 -0700)
committerBen Pfaff <blp@nicira.com>
Thu, 12 Jun 2014 21:43:40 +0000 (14:43 -0700)
Nothing actually used 'provider_meter_id', but some code did want to know
whether there was a meter, so we can save a little space by using a bool
instead.  An upcoming commit will add a second bool member.  This change
allows that bool to be added without using extra space.

Signed-off-by: Ben Pfaff <blp@nicira.com>
Acked-by: Ethan Jackson <ethan@nicira.com>
ofproto/ofproto-provider.h
ofproto/ofproto.c

index 8da2822..9c6b960 100644 (file)
@@ -398,18 +398,23 @@ static inline bool rule_is_hidden(const struct rule *);
  * A struct rule_actions may be accessed without a risk of being
  * freed by code that holds a read-lock or write-lock on 'rule->mutex' (where
  * 'rule' is the rule for which 'rule->actions == actions') or during the RCU
- * active period. */
+ * active period.
+ *
+ * All members are immutable: they do not change during the struct's
+ * lifetime. */
 struct rule_actions {
-    /* These members are immutable: they do not change during the struct's
-     * lifetime.  */
+    /* Flags.
+     *
+     * 'has_meter' is true if 'ofpacts' contains an OFPACT_METER action. */
+    bool has_meter;
+
+    /* Actions. */
     uint32_t ofpacts_len;         /* Size of 'ofpacts', in bytes. */
-    uint32_t provider_meter_id;   /* Datapath meter_id, or UINT32_MAX. */
     struct ofpact ofpacts[];      /* Sequence of "struct ofpacts". */
 };
 BUILD_ASSERT_DECL(offsetof(struct rule_actions, ofpacts) % OFPACT_ALIGNTO == 0);
 
-const struct rule_actions *rule_actions_create(const struct ofproto *,
-                                               const struct ofpact *, size_t);
+const struct rule_actions *rule_actions_create(const struct ofpact *, size_t);
 void rule_actions_destroy(const struct rule_actions *);
 
 /* A set of rules to which an OpenFlow operation applies. */
index bad0e29..9bee50a 100644 (file)
@@ -2494,16 +2494,13 @@ static uint32_t get_provider_meter_id(const struct ofproto *,
 /* Creates and returns a new 'struct rule_actions', whose actions are a copy
  * of from the 'ofpacts_len' bytes of 'ofpacts'. */
 const struct rule_actions *
-rule_actions_create(const struct ofproto *ofproto,
-                    const struct ofpact *ofpacts, size_t ofpacts_len)
+rule_actions_create(const struct ofpact *ofpacts, size_t ofpacts_len)
 {
     struct rule_actions *actions;
 
     actions = xmalloc(sizeof *actions + ofpacts_len);
     actions->ofpacts_len = ofpacts_len;
-    actions->provider_meter_id
-        = get_provider_meter_id(ofproto,
-                                ofpacts_get_meter(ofpacts, ofpacts_len));
+    actions->has_meter = ofpacts_get_meter(ofpacts, ofpacts_len) != 0;
     memcpy(actions->ofpacts, ofpacts, ofpacts_len);
 
     return actions;
@@ -3869,7 +3866,7 @@ add_flow(struct ofproto *ofproto, struct ofputil_flow_mod *fm,
 
     *CONST_CAST(uint8_t *, &rule->table_id) = table - ofproto->tables;
     rule->flags = fm->flags & OFPUTIL_FF_STATE;
-    actions = rule_actions_create(ofproto, fm->ofpacts, fm->ofpacts_len);
+    actions = rule_actions_create(fm->ofpacts, fm->ofpacts_len);
     ovsrcu_set(&rule->actions, actions);
     list_init(&rule->meter_list_node);
     rule->eviction_group = NULL;
@@ -3890,7 +3887,7 @@ add_flow(struct ofproto *ofproto, struct ofputil_flow_mod *fm,
     }
     cookies_insert(ofproto, rule);
     eviction_group_add_rule(rule);
-    if (actions->provider_meter_id != UINT32_MAX) {
+    if (actions->has_meter) {
         meter_insert_rule(rule);
     }
 
@@ -4005,8 +4002,7 @@ modify_flows__(struct ofproto *ofproto, struct ofputil_flow_mod *fm,
         }
 
         if (change_actions) {
-            ovsrcu_set(&rule->actions, rule_actions_create(ofproto,
-                                                           fm->ofpacts,
+            ovsrcu_set(&rule->actions, rule_actions_create(fm->ofpacts,
                                                            fm->ofpacts_len));
             rule_actions_destroy(actions);
         }