From 3c30d1118e2e28cad795f342c984acb5e89431d7 Mon Sep 17 00:00:00 2001 From: Jarno Rajahalme Date: Tue, 26 Aug 2014 15:11:39 -0700 Subject: lib/flow.h: Improve struct miniflow comment and definition. Miniflows can nowadays be dynamically allocated to different inline sizes, as done by lib/classifier.c, but this had not been documented at the struct miniflow definition. Also, MINI_N_INLINE had a different value for 32-bit and 64-bit builds due to a historical reason. Now we use 8 for both. Finally, use change the storage type of 'values_inline' to uint8_t, as uint64_t looks kind of wide for a boolean, even though we intend the bit be carved out from the uint64_t where 'map' resides. Suggested-by: Ben Pfaff Signed-off-by: Jarno Rajahalme --- lib/flow.h | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'lib/flow.h') diff --git a/lib/flow.h b/lib/flow.h index 3b8d24d8f..2891d60a9 100644 --- a/lib/flow.h +++ b/lib/flow.h @@ -346,7 +346,10 @@ bool flow_equal_except(const struct flow *a, const struct flow *b, /* Compressed flow. */ -#define MINI_N_INLINE (sizeof(void *) == 4 ? 7 : 8) +/* Number of 32-bit words present in struct miniflow. */ +#define MINI_N_INLINE 8 + +/* Maximum number of 32-bit words supported. */ BUILD_ASSERT_DECL(FLOW_U32S <= 63); /* A sparse representation of a "struct flow". @@ -367,6 +370,11 @@ BUILD_ASSERT_DECL(FLOW_U32S <= 63); * the first element of the values array, the next 1-bit is in the next array * element, and so on. * + * MINI_N_INLINE is the default number of inline words. When a miniflow is + * dynamically allocated the actual amount of inline storage may be different. + * In that case 'inline_values' contains storage at least for the number + * of words indicated by 'map' (one uint32_t for each 1-bit in the map). + * * Elements in values array are allowed to be zero. This is useful for "struct * minimatch", for which ensuring that the miniflow and minimask members have * same 'map' allows optimization. This allowance applies only to a miniflow @@ -375,12 +383,14 @@ BUILD_ASSERT_DECL(FLOW_U32S <= 63); */ struct miniflow { uint64_t map:63; - uint64_t values_inline:1; + uint8_t values_inline:1; union { uint32_t *offline_values; - uint32_t inline_values[MINI_N_INLINE]; + uint32_t inline_values[MINI_N_INLINE]; /* Minimum inline size. */ }; }; +BUILD_ASSERT_DECL(sizeof(struct miniflow) + == sizeof(uint64_t) + MINI_N_INLINE * sizeof(uint32_t)); #define MINIFLOW_VALUES_SIZE(COUNT) ((COUNT) * sizeof(uint32_t)) -- cgit v1.2.1