diff options
author | Jarno Rajahalme <jarno@ovn.org> | 2016-08-31 08:43:48 -0700 |
---|---|---|
committer | Jarno Rajahalme <jarno@ovn.org> | 2016-08-31 08:43:48 -0700 |
commit | dfe191d5faa60d34a64e3bd1040fd6fa02b4889c (patch) | |
tree | cbed0e4dc2384d2a97ab211d540e61b1370cfda0 /include/openvswitch/ofp-actions.h | |
parent | 47bf118665a3d0f3c153d1fe80e9af02ac9a4e9c (diff) | |
download | openvswitch-dfe191d5faa60d34a64e3bd1040fd6fa02b4889c.tar.gz |
ofp-actions: Waste less memory in learn actions.
Make the immediate data member 'src_imm' of a learn spec allocated at
the end of the action for just the right size. This, together with
some structure packing saves on average of ~128 bytes for each learn
spec in each learn action. Typical learn actions have about 4 specs
each, so this amounts to saving about 0.5kb for each learn action.
Signed-off-by: Jarno Rajahalme <jarno@ovn.org>
Acked-by: Ben Pfaff <blp@ovn.org>
Diffstat (limited to 'include/openvswitch/ofp-actions.h')
-rw-r--r-- | include/openvswitch/ofp-actions.h | 42 |
1 files changed, 28 insertions, 14 deletions
diff --git a/include/openvswitch/ofp-actions.h b/include/openvswitch/ofp-actions.h index 310ec335b..b30b270e7 100644 --- a/include/openvswitch/ofp-actions.h +++ b/include/openvswitch/ofp-actions.h @@ -651,19 +651,6 @@ struct ofpact_resubmit { uint8_t table_id; }; -/* Part of struct ofpact_learn, below. */ -struct ofpact_learn_spec { - int n_bits; /* Number of bits in source and dest. */ - - int src_type; /* One of NX_LEARN_SRC_*. */ - struct mf_subfield src; /* NX_LEARN_SRC_FIELD only. */ - union mf_subvalue src_imm; /* NX_LEARN_SRC_IMMEDIATE only. */ - - int dst_type; /* One of NX_LEARN_DST_*. */ - struct mf_subfield dst; /* NX_LEARN_DST_MATCH, NX_LEARN_DST_LOAD only. */ -}; - - /* Bits for 'flags' in struct nx_action_learn. * * If NX_LEARN_F_SEND_FLOW_REM is set, then the learned flows will have their @@ -708,6 +695,33 @@ enum nx_learn_flags { #define NX_LEARN_DST_RESERVED (3 << 11) /* Not yet defined. */ #define NX_LEARN_DST_MASK (3 << 11) +/* Part of struct ofpact_learn, below. */ +struct ofpact_learn_spec { + struct mf_subfield src; /* NX_LEARN_SRC_FIELD only. */ + struct mf_subfield dst; /* NX_LEARN_DST_MATCH, NX_LEARN_DST_LOAD only. */ + uint16_t src_type; /* One of NX_LEARN_SRC_*. */ + uint16_t dst_type; /* One of NX_LEARN_DST_*. */ + uint8_t n_bits; /* Number of bits in source and dest. */ + uint64_t src_imm[]; /* OFPACT_ALIGNTO (uint64_t) aligned. */ +}; +BUILD_ASSERT_DECL(offsetof(struct ofpact_learn_spec, src_imm) + % OFPACT_ALIGNTO == 0); +BUILD_ASSERT_DECL(offsetof(struct ofpact_learn_spec, src_imm) + == sizeof(struct ofpact_learn_spec)); + +static inline const struct ofpact_learn_spec * +ofpact_learn_spec_next(const struct ofpact_learn_spec *spec) +{ + if (spec->src_type == NX_LEARN_SRC_IMMEDIATE) { + unsigned int n_uint64s + = OFPACT_ALIGN(DIV_ROUND_UP(spec->n_bits, 8)) / sizeof (uint64_t); + return (const struct ofpact_learn_spec *) + ((const uint64_t *)(spec + 1) + n_uint64s); + } else { + return spec + 1; + } +} + /* OFPACT_LEARN. * * Used for NXAST_LEARN. */ @@ -718,8 +732,8 @@ struct ofpact_learn { uint16_t hard_timeout; /* Max time before discarding (seconds). */ uint16_t priority; /* Priority level of flow entry. */ uint8_t table_id; /* Table to insert flow entry. */ - ovs_be64 cookie; /* Cookie for new flow. */ enum nx_learn_flags flags; /* NX_LEARN_F_*. */ + ovs_be64 cookie; /* Cookie for new flow. */ uint16_t fin_idle_timeout; /* Idle timeout after FIN, if nonzero. */ uint16_t fin_hard_timeout; /* Hard timeout after FIN, if nonzero. */ |