Skip to content

Commit

Permalink
meta-flow: Simplify handling of a variable number of registers.
Browse files Browse the repository at this point in the history
At the time that Open vSwitch implemented registers, there was a high cost
to adding additional fields, so I wrote the code so that the number of
registers could be reduced at compile time.  Now, fields are cheaper
(though not free) and in the meantime I have never heard of anyone reducing
the number of registers.  Since I intend to add more code that would
require awkward "#if"s like this, I think that this is a good time to
simplify it by requiring FLOW_N_REGS to be fixed.  This commit does that.

Signed-off-by: Ben Pfaff <[email protected]>
Acked-by: Jarno Rajahalme <[email protected]>
  • Loading branch information
blp committed Jul 26, 2014
1 parent 02386a4 commit 771c99c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 61 deletions.
21 changes: 3 additions & 18 deletions lib/meta-flow.c
Original file line number Diff line number Diff line change
Expand Up @@ -223,32 +223,17 @@ const struct mf_field mf_fields[MFF_N_IDS] = {
OFPUTIL_P_NXM_OXM_ANY, \
-1, \
}
#if FLOW_N_REGS > 0
#if FLOW_N_REGS == 8
REGISTER(0),
#endif
#if FLOW_N_REGS > 1
REGISTER(1),
#endif
#if FLOW_N_REGS > 2
REGISTER(2),
#endif
#if FLOW_N_REGS > 3
REGISTER(3),
#endif
#if FLOW_N_REGS > 4
REGISTER(4),
#endif
#if FLOW_N_REGS > 5
REGISTER(5),
#endif
#if FLOW_N_REGS > 6
REGISTER(6),
#endif
#if FLOW_N_REGS > 7
REGISTER(7),
#endif
#if FLOW_N_REGS > 8
#error
#else
#error "Need to update mf_fields[] to match FLOW_N_REGS"
#endif

/* ## -- ## */
Expand Down
50 changes: 7 additions & 43 deletions lib/meta-flow.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2011, 2012, 2013 Nicira, Inc.
* Copyright (c) 2011, 2012, 2013, 2014 Nicira, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -47,29 +47,17 @@ enum OVS_PACKED_ENUM mf_field_id {
MFF_SKB_PRIORITY, /* be32 */
MFF_PKT_MARK, /* be32 */

#if FLOW_N_REGS > 0
#if FLOW_N_REGS == 8
MFF_REG0, /* be32 */
#endif
#if FLOW_N_REGS > 1
MFF_REG1, /* be32 */
#endif
#if FLOW_N_REGS > 2
MFF_REG2, /* be32 */
#endif
#if FLOW_N_REGS > 3
MFF_REG3, /* be32 */
#endif
#if FLOW_N_REGS > 4
MFF_REG4, /* be32 */
#endif
#if FLOW_N_REGS > 5
MFF_REG5, /* be32 */
#endif
#if FLOW_N_REGS > 6
MFF_REG6, /* be32 */
#endif
#if FLOW_N_REGS > 7
MFF_REG7, /* be32 */
#else
#error "Need to update MFF_REG* to match FLOW_N_REGS"
#endif

/* L2. */
Expand Down Expand Up @@ -148,36 +136,12 @@ enum OVS_PACKED_ENUM mf_field_id {

/* Use this macro as CASE_MFF_REGS: in a switch statement to choose all of the
* MFF_REGx cases. */
#if FLOW_N_REGS == 1
# define CASE_MFF_REGS \
case MFF_REG0
#elif FLOW_N_REGS == 2
# define CASE_MFF_REGS \
case MFF_REG0: case MFF_REG1
#elif FLOW_N_REGS == 3
# define CASE_MFF_REGS \
case MFF_REG0: case MFF_REG1: case MFF_REG2
#elif FLOW_N_REGS == 4
# define CASE_MFF_REGS \
case MFF_REG0: case MFF_REG1: case MFF_REG2: case MFF_REG3
#elif FLOW_N_REGS == 5
# define CASE_MFF_REGS \
case MFF_REG0: case MFF_REG1: case MFF_REG2: case MFF_REG3: \
case MFF_REG4
#elif FLOW_N_REGS == 6
# define CASE_MFF_REGS \
case MFF_REG0: case MFF_REG1: case MFF_REG2: case MFF_REG3: \
case MFF_REG4: case MFF_REG5
#elif FLOW_N_REGS == 7
# define CASE_MFF_REGS \
case MFF_REG0: case MFF_REG1: case MFF_REG2: case MFF_REG3: \
case MFF_REG4: case MFF_REG5: case MFF_REG6
#elif FLOW_N_REGS == 8
# define CASE_MFF_REGS \
#if FLOW_N_REGS == 8
#define CASE_MFF_REGS \
case MFF_REG0: case MFF_REG1: case MFF_REG2: case MFF_REG3: \
case MFF_REG4: case MFF_REG5: case MFF_REG6: case MFF_REG7
#else
# error
#error "Need to update CASE_MFF_REGS to match FLOW_N_REGS"
#endif

/* Prerequisites for matching a field.
Expand Down

0 comments on commit 771c99c

Please sign in to comment.