2
0
mirror of https://github.com/openvswitch/ovs synced 2025-09-01 06:45:17 +00:00

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>
This commit is contained in:
Jarno Rajahalme
2016-08-31 08:43:48 -07:00
parent 47bf118665
commit dfe191d5fa
5 changed files with 114 additions and 54 deletions

View File

@@ -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. */