From 4c7562c5a43863a820702e160678aad625a28f62 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Wed, 28 May 2014 11:55:53 -0700 Subject: [PATCH] ofproto: Shrink struct rule_actions slightly. 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 Acked-by: Ethan Jackson --- ofproto/ofproto-provider.h | 17 +++++++++++------ ofproto/ofproto.c | 14 +++++--------- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/ofproto/ofproto-provider.h b/ofproto/ofproto-provider.h index 8da282285..9c6b960d9 100644 --- a/ofproto/ofproto-provider.h +++ b/ofproto/ofproto-provider.h @@ -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. */ diff --git a/ofproto/ofproto.c b/ofproto/ofproto.c index bad0e29e9..9bee50a68 100644 --- a/ofproto/ofproto.c +++ b/ofproto/ofproto.c @@ -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); } -- 2.20.1