2
0
mirror of https://github.com/openvswitch/ovs synced 2025-08-31 14:25:26 +00:00

flow: Take advantage of zero-padding in struct flow and flow_wildcards.

Since we know these bytes are always 0 in both structures, we can use
faster functions that only work with full words.

Signed-off-by: Ben Pfaff <blp@nicira.com>
This commit is contained in:
Ben Pfaff
2012-06-18 15:12:57 -07:00
parent 51c14ddd8d
commit 16c6d0c384
2 changed files with 8 additions and 18 deletions

View File

@@ -77,6 +77,10 @@ struct flow {
uint8_t nw_frag; /* FLOW_FRAG_* flags. */
uint8_t zeros[2]; /* Must be zero. */
};
BUILD_ASSERT_DECL(sizeof(struct flow) % 8 == 0);
/* Remember to update FLOW_WC_SEQ when changing 'struct flow'. */
BUILD_ASSERT_DECL(sizeof(struct flow) == 152 && FLOW_WC_SEQ == 17);
/* Represents the metadata fields of struct flow. */
struct flow_metadata {
@@ -86,17 +90,6 @@ struct flow_metadata {
uint16_t in_port; /* OpenFlow port or zero. */
};
/* Assert that there are FLOW_SIG_SIZE bytes of significant data in "struct
* flow", followed by FLOW_PAD_SIZE bytes of padding. */
#define FLOW_SIG_SIZE (118 + FLOW_N_REGS * 4)
#define FLOW_PAD_SIZE 2
BUILD_ASSERT_DECL(offsetof(struct flow, nw_frag) == FLOW_SIG_SIZE - 1);
BUILD_ASSERT_DECL(sizeof(((struct flow *)0)->nw_frag) == 1);
BUILD_ASSERT_DECL(sizeof(struct flow) == FLOW_SIG_SIZE + FLOW_PAD_SIZE);
/* Remember to update FLOW_WC_SEQ when changing 'struct flow'. */
BUILD_ASSERT_DECL(FLOW_SIG_SIZE == 150 && FLOW_WC_SEQ == 17);
void flow_extract(struct ofpbuf *, uint32_t priority, ovs_be64 tun_id,
uint16_t in_port, struct flow *);
void flow_zero_wildcards(struct flow *, const struct flow_wildcards *);
@@ -118,7 +111,7 @@ void flow_compose(struct ofpbuf *, const struct flow *);
static inline int
flow_compare_3way(const struct flow *a, const struct flow *b)
{
return memcmp(a, b, FLOW_SIG_SIZE);
return memcmp(a, b, sizeof *a);
}
static inline bool
@@ -130,7 +123,7 @@ flow_equal(const struct flow *a, const struct flow *b)
static inline size_t
flow_hash(const struct flow *flow, uint32_t basis)
{
return hash_bytes(flow, FLOW_SIG_SIZE, basis);
return hash_words((const uint32_t *) flow, sizeof *flow / 4, basis);
}
/* Information on wildcards for a flow, as a supplement to "struct flow". */
@@ -160,6 +153,7 @@ struct flow_wildcards {
uint8_t nw_ttl_mask; /* 1-bit in each significant nw_ttl bit. */
uint8_t zeros[6]; /* Padding field set to zero. */
};
BUILD_ASSERT_DECL(sizeof(struct flow_wildcards) % 8 == 0);
/* Remember to update FLOW_WC_SEQ when updating struct flow_wildcards. */
BUILD_ASSERT_DECL(sizeof(struct flow_wildcards) == 152 && FLOW_WC_SEQ == 17);