Reserve the use of size_t for sizes of objects in bytes. Suggested-by: Joe Stringer <joestrin...@nicira.com> Signed-off-by: Jarno Rajahalme <jrajaha...@nicira.com> --- lib/classifier-private.h | 10 +++++----- lib/classifier.c | 45 +++++++++++++++++++++++---------------------- lib/classifier.h | 6 +++--- lib/flow.c | 31 ++++++++++++++++--------------- lib/flow.h | 30 ++++++++++++++++-------------- 5 files changed, 63 insertions(+), 59 deletions(-)
diff --git a/lib/classifier-private.h b/lib/classifier-private.h index 4c5ad80..3b7ea3a 100644 --- a/lib/classifier-private.h +++ b/lib/classifier-private.h @@ -287,7 +287,7 @@ flow_hash_in_minimask(const struct flow *flow, const struct minimask *mask, const uint64_t *flow_u64 = (const uint64_t *)flow; const uint64_t *p = mask_values; uint32_t hash; - size_t idx; + unsigned int idx; hash = basis; MAP_FOR_EACH_INDEX(idx, mask->masks.tnl_map) { @@ -341,7 +341,7 @@ flow_hash_in_minimask_range(const struct flow *flow, struct miniflow map; const uint64_t *p; uint32_t hash = *basis; - size_t idx; + unsigned int idx; offset = miniflow_get_map_in_range(&mask->masks, start, end, &map); p = mask_values + offset; @@ -375,7 +375,7 @@ flow_wildcards_fold_minimask_range(struct flow_wildcards *wc, const uint64_t *p = miniflow_get_values(&mask->masks); uint64_t *dst_u64 = (uint64_t *)&wc->masks; struct miniflow map; - size_t idx; + unsigned int idx; p += miniflow_get_map_in_range(&mask->masks, start, end, &map); MAP_FOR_EACH_INDEX(idx, map.tnl_map) { @@ -392,10 +392,10 @@ static inline uint32_t minimask_hash(const struct minimask *mask, uint32_t basis) { const uint64_t *p = miniflow_get_values(&mask->masks); - size_t n_values = miniflow_n_values(&mask->masks); + unsigned int n_values = miniflow_n_values(&mask->masks); uint32_t hash = basis; - for (size_t i = 0; i < n_values; i++) { + for (unsigned int i = 0; i < n_values; i++) { hash = hash_add64(hash, *p++); } hash = hash_add64(hash, mask->masks.tnl_map); diff --git a/lib/classifier.c b/lib/classifier.c index 6484a34..8b59cff 100644 --- a/lib/classifier.c +++ b/lib/classifier.c @@ -57,8 +57,8 @@ BUILD_ASSERT_DECL(TP_PORTS_OFS32 == offsetof(struct flow, tp_dst) / 4); BUILD_ASSERT_DECL(TP_PORTS_OFS32 % 2 == 0); #define TP_PORTS_OFS64 (TP_PORTS_OFS32 / 2) -static size_t -cls_conjunction_set_size(size_t n) +static unsigned int +cls_conjunction_set_size(unsigned int n) { return (sizeof(struct cls_conjunction_set) + n * sizeof(struct cls_conjunction)); @@ -66,11 +66,11 @@ cls_conjunction_set_size(size_t n) static struct cls_conjunction_set * cls_conjunction_set_alloc(struct cls_match *match, - const struct cls_conjunction conj[], size_t n) + const struct cls_conjunction conj[], unsigned int n) { if (n) { - size_t min_n_clauses = conj[0].n_clauses; - for (size_t i = 1; i < n; i++) { + unsigned int min_n_clauses = conj[0].n_clauses; + for (unsigned int i = 1; i < n; i++) { min_n_clauses = MIN(min_n_clauses, conj[i].n_clauses); } @@ -88,9 +88,9 @@ cls_conjunction_set_alloc(struct cls_match *match, static struct cls_match * cls_match_alloc(const struct cls_rule *rule, cls_version_t version, - const struct cls_conjunction conj[], size_t n) + const struct cls_conjunction conj[], unsigned int n) { - size_t count = miniflow_n_values(rule->match.flow); + unsigned int count = miniflow_n_values(rule->match.flow); struct cls_match *cls_match = xmalloc(sizeof *cls_match + MINIFLOW_VALUES_SIZE(count)); @@ -242,7 +242,7 @@ cls_rule_destroy(struct cls_rule *rule) void cls_rule_set_conjunctions(struct cls_rule *cr, - const struct cls_conjunction *conj, size_t n) + const struct cls_conjunction *conj, unsigned int n) { struct cls_match *match = cr->cls_match; struct cls_conjunction_set *old @@ -573,14 +573,14 @@ subtable_replace_head_rule(struct classifier *cls OVS_UNUSED, const struct cls_rule * classifier_replace(struct classifier *cls, const struct cls_rule *rule, cls_version_t version, - const struct cls_conjunction *conjs, size_t n_conjs) + const struct cls_conjunction *conjs, unsigned int n_conjs) { struct cls_match *new; struct cls_subtable *subtable; uint32_t ihash[CLS_MAX_INDICES]; uint8_t prev_be64ofs = 0; struct cls_match *head; - size_t n_rules = 0; + unsigned int n_rules = 0; uint32_t basis; uint32_t hash; int i; @@ -759,7 +759,7 @@ classifier_replace(struct classifier *cls, const struct cls_rule *rule, void classifier_insert(struct classifier *cls, const struct cls_rule *rule, cls_version_t version, const struct cls_conjunction conj[], - size_t n_conj) + unsigned int n_conj) { const struct cls_rule *displaced_rule = classifier_replace(cls, rule, version, conj, n_conj); @@ -784,7 +784,7 @@ classifier_remove(struct classifier *cls, const struct cls_rule *cls_rule) int i; uint32_t basis = 0, hash, ihash[CLS_MAX_INDICES]; uint8_t prev_be64ofs = 0; - size_t n_rules; + unsigned int n_rules; rule = cls_rule->cls_match; if (!rule) { @@ -951,8 +951,8 @@ find_conjunctive_match__(struct hmap *matches, uint64_t id, uint32_t hash) static bool find_conjunctive_match(const struct cls_conjunction_set *set, unsigned int max_n_clauses, struct hmap *matches, - struct conjunctive_match *cm_stubs, size_t n_cm_stubs, - uint32_t *idp) + struct conjunctive_match *cm_stubs, + unsigned int n_cm_stubs, uint32_t *idp) { const struct cls_conjunction *c; @@ -971,7 +971,7 @@ find_conjunctive_match(const struct cls_conjunction_set *set, hash = hash_int(c->id, 0); cm = find_conjunctive_match__(matches, c->id, hash); if (!cm) { - size_t n = hmap_count(matches); + unsigned int n = hmap_count(matches); cm = n < n_cm_stubs ? &cm_stubs[n] : xmalloc(sizeof *cm); hmap_insert(matches, &cm->hmap_node, hash); @@ -989,7 +989,8 @@ find_conjunctive_match(const struct cls_conjunction_set *set, static void free_conjunctive_matches(struct hmap *matches, - struct conjunctive_match *cm_stubs, size_t n_cm_stubs) + struct conjunctive_match *cm_stubs, + unsigned int n_cm_stubs) { if (hmap_count(matches) > n_cm_stubs) { struct conjunctive_match *cm, *next; @@ -1030,7 +1031,7 @@ classifier_lookup__(const struct classifier *cls, cls_version_t version, * we refer to these as "soft matches". */ struct cls_conjunction_set *soft_stub[64]; struct cls_conjunction_set **soft = soft_stub; - size_t n_soft = 0, allocated_soft = ARRAY_SIZE(soft_stub); + unsigned int n_soft = 0, allocated_soft = ARRAY_SIZE(soft_stub); int soft_pri = INT_MIN; /* n_soft ? MAX(soft[*]->priority) : INT_MIN. */ /* Synchronize for cls->n_tries and subtable->trie_plen. They can change @@ -1535,7 +1536,7 @@ insert_subtable(struct classifier *cls, const struct minimask *mask) int i, index = 0; struct flow_wildcards old, new; uint8_t prev; - size_t count = miniflow_n_values(&mask->masks); + unsigned int count = miniflow_n_values(&mask->masks); subtable = xzalloc(sizeof *subtable + MINIFLOW_VALUES_SIZE(count)); cmap_init(&subtable->rules); @@ -1699,7 +1700,7 @@ miniflow_and_mask_matches_flow(const struct miniflow *flow, const uint64_t *flowp = miniflow_get_values(flow); const uint64_t *maskp = miniflow_get_values(&mask->masks); const uint64_t *target_u64 = (const uint64_t *)target; - size_t idx; + unsigned int idx; MAP_FOR_EACH_INDEX(idx, mask->masks.tnl_map) { if ((*flowp++ ^ target_u64[idx]) & *maskp++) { @@ -1755,7 +1756,7 @@ miniflow_and_mask_matches_flow_wc(const struct miniflow *flow, const uint64_t *target_u64 = (const uint64_t *)target; uint64_t *wc_u64 = (uint64_t *)&wc->masks; uint64_t diff; - size_t idx; + unsigned int idx; MAP_FOR_EACH_INDEX(idx, mask->masks.tnl_map) { uint64_t msk = *maskp++; @@ -2213,9 +2214,9 @@ minimask_get_prefix_len(const struct minimask *minimask, static const ovs_be32 * minimatch_get_prefix(const struct minimatch *match, const struct mf_field *mf) { - size_t u64_ofs = mf->flow_be32ofs / 2; + unsigned int idx = mf->flow_be32ofs / 2; - return (OVS_FORCE const ovs_be32 *)miniflow_get__(match->flow, u64_ofs) + return (OVS_FORCE const ovs_be32 *)miniflow_get__(match->flow, idx) + (mf->flow_be32ofs & 1); } diff --git a/lib/classifier.h b/lib/classifier.h index 889dc1e..fd2af72 100644 --- a/lib/classifier.h +++ b/lib/classifier.h @@ -369,7 +369,7 @@ void cls_rule_move(struct cls_rule *dst, struct cls_rule *src); void cls_rule_destroy(struct cls_rule *); void cls_rule_set_conjunctions(struct cls_rule *, - const struct cls_conjunction *, size_t n); + const struct cls_conjunction *, unsigned int n); bool cls_rule_equal(const struct cls_rule *, const struct cls_rule *); void cls_rule_format(const struct cls_rule *, struct ds *); @@ -391,12 +391,12 @@ bool classifier_set_prefix_fields(struct classifier *, unsigned int n_trie_fields); void classifier_insert(struct classifier *, const struct cls_rule *, cls_version_t, const struct cls_conjunction *, - size_t n_conjunctions); + unsigned int n_conjunctions); const struct cls_rule *classifier_replace(struct classifier *, const struct cls_rule *, cls_version_t, const struct cls_conjunction *, - size_t n_conjunctions); + unsigned int n_conjunctions); const struct cls_rule *classifier_remove(struct classifier *, const struct cls_rule *); static inline void classifier_defer(struct classifier *); diff --git a/lib/flow.c b/lib/flow.c index 1b7a3d5..14488d2 100644 --- a/lib/flow.c +++ b/lib/flow.c @@ -791,7 +791,7 @@ flow_zero_wildcards(struct flow *flow, const struct flow_wildcards *wildcards) { uint64_t *flow_u64 = (uint64_t *) flow; const uint64_t *wc_u64 = (const uint64_t *) &wildcards->masks; - size_t i; + unsigned int i; for (i = 0; i < FLOW_U64S; i++) { flow_u64[i] &= wc_u64[i]; @@ -1356,7 +1356,7 @@ bool flow_wildcards_is_catchall(const struct flow_wildcards *wc) { const uint64_t *wc_u64 = (const uint64_t *) &wc->masks; - size_t i; + unsigned int i; for (i = 0; i < FLOW_U64S; i++) { if (wc_u64[i]) { @@ -1377,7 +1377,7 @@ flow_wildcards_and(struct flow_wildcards *dst, uint64_t *dst_u64 = (uint64_t *) &dst->masks; const uint64_t *src1_u64 = (const uint64_t *) &src1->masks; const uint64_t *src2_u64 = (const uint64_t *) &src2->masks; - size_t i; + unsigned int i; for (i = 0; i < FLOW_U64S; i++) { dst_u64[i] = src1_u64[i] & src2_u64[i]; @@ -1395,7 +1395,7 @@ flow_wildcards_or(struct flow_wildcards *dst, uint64_t *dst_u64 = (uint64_t *) &dst->masks; const uint64_t *src1_u64 = (const uint64_t *) &src1->masks; const uint64_t *src2_u64 = (const uint64_t *) &src2->masks; - size_t i; + unsigned int i; for (i = 0; i < FLOW_U64S; i++) { dst_u64[i] = src1_u64[i] | src2_u64[i]; @@ -1426,7 +1426,7 @@ flow_wildcards_has_extra(const struct flow_wildcards *a, { const uint64_t *a_u64 = (const uint64_t *) &a->masks; const uint64_t *b_u64 = (const uint64_t *) &b->masks; - size_t i; + unsigned int i; for (i = 0; i < FLOW_U64S; i++) { if ((a_u64[i] & b_u64[i]) != b_u64[i]) { @@ -1445,7 +1445,7 @@ flow_equal_except(const struct flow *a, const struct flow *b, const uint64_t *a_u64 = (const uint64_t *) a; const uint64_t *b_u64 = (const uint64_t *) b; const uint64_t *wc_u64 = (const uint64_t *) &wc->masks; - size_t i; + unsigned int i; for (i = 0; i < FLOW_U64S; i++) { if ((a_u64[i] ^ b_u64[i]) & wc_u64[i]) { @@ -1772,7 +1772,7 @@ flow_hash_in_wildcards(const struct flow *flow, const uint64_t *wc_u64 = (const uint64_t *) &wc->masks; const uint64_t *flow_u64 = (const uint64_t *) flow; uint32_t hash; - size_t i; + unsigned int i; hash = basis; for (i = 0; i < FLOW_U64S; i++) { @@ -2252,7 +2252,7 @@ miniflow_init(struct miniflow *dst, const struct flow *src) { const uint64_t *src_u64 = (const uint64_t *) src; uint64_t *dst_u64 = miniflow_values(dst); - size_t idx; + unsigned int idx; MAPS_FOR_EACH_INDEX(idx, *dst) { *dst_u64++ = src_u64[idx]; @@ -2286,9 +2286,10 @@ miniflow_map_init(struct miniflow *flow, const struct flow *src) * map of each from 'src'. * Returns the size of the miniflow data. */ size_t -miniflow_alloc(struct miniflow *dsts[], size_t n, const struct miniflow *src) +miniflow_alloc(struct miniflow *dsts[], unsigned int n, + const struct miniflow *src) { - size_t n_values = miniflow_n_values(src); + unsigned int n_values = miniflow_n_values(src); size_t data_size = MINIFLOW_VALUES_SIZE(n_values); struct miniflow *dst = xmalloc(n * (sizeof *src + data_size)); unsigned int i; @@ -2323,7 +2324,7 @@ miniflow_create(const struct flow *src) * 'dst' to have inline space for 'n_values' data in 'src'. */ void miniflow_clone(struct miniflow *dst, const struct miniflow *src, - size_t n_values) + unsigned int n_values) { *dst = *src; /* Copy maps. */ memcpy(miniflow_values(dst), miniflow_get_values(src), @@ -2380,7 +2381,7 @@ miniflow_equal_in_minimask(const struct miniflow *a, const struct miniflow *b, const struct minimask *mask) { const uint64_t *p = miniflow_get_values(&mask->masks); - size_t idx; + unsigned int idx; MAPS_FOR_EACH_INDEX(idx, mask->masks) { if ((miniflow_get(a, idx) ^ miniflow_get(b, idx)) & *p++) { @@ -2399,7 +2400,7 @@ miniflow_equal_flow_in_minimask(const struct miniflow *a, const struct flow *b, { const uint64_t *b_u64 = (const uint64_t *) b; const uint64_t *p = miniflow_get_values(&mask->masks); - size_t idx; + unsigned int idx; MAPS_FOR_EACH_INDEX(idx, mask->masks) { if ((miniflow_get(a, idx) ^ b_u64[idx]) & *p++) { @@ -2441,7 +2442,7 @@ minimask_combine(struct minimask *dst_, const struct miniflow *b = &b_->masks; const uint64_t *ap = miniflow_get_values(a); const uint64_t *bp = miniflow_get_values(b); - size_t idx; + unsigned int idx; dst->tnl_map = 0; MAP_FOR_EACH_INDEX(idx, a->tnl_map & b->tnl_map) { @@ -2495,7 +2496,7 @@ minimask_has_extra(const struct minimask *a, const struct minimask *b) { const uint64_t *ap = miniflow_get_values(&a->masks); const uint64_t *bp = miniflow_get_values(&b->masks); - size_t idx; + unsigned int idx; MAP_FOR_EACH_INDEX(idx, b->masks.tnl_map) { uint64_t b_u64 = *bp++; diff --git a/lib/flow.h b/lib/flow.h index 5bc9267..df2f0a7 100644 --- a/lib/flow.h +++ b/lib/flow.h @@ -218,7 +218,7 @@ void flow_format(struct ds *, const struct flow *); void flow_print(FILE *, const struct flow *); static inline int flow_compare_3way(const struct flow *, const struct flow *); static inline bool flow_equal(const struct flow *, const struct flow *); -static inline size_t flow_hash(const struct flow *, uint32_t basis); +static inline uint32_t flow_hash(const struct flow *, uint32_t basis); void flow_set_dl_vlan(struct flow *, ovs_be16 vid); void flow_set_vlan_vid(struct flow *, ovs_be16 vid); @@ -265,7 +265,7 @@ flow_equal(const struct flow *a, const struct flow *b) return !flow_compare_3way(a, b); } -static inline size_t +static inline uint32_t flow_hash(const struct flow *flow, uint32_t basis) { return hash_words64((const uint64_t *)flow, @@ -441,26 +441,27 @@ struct pkt_metadata; void miniflow_extract(struct dp_packet *packet, struct miniflow *dst); void miniflow_map_init(struct miniflow *, const struct flow *); void flow_wc_map(const struct flow *, struct miniflow *); -size_t miniflow_alloc(struct miniflow *dsts[], size_t n, +size_t miniflow_alloc(struct miniflow *dsts[], unsigned int n, const struct miniflow *src); void miniflow_init(struct miniflow *, const struct flow *); void miniflow_clone(struct miniflow *, const struct miniflow *, - size_t n_values); + unsigned int n_values); struct miniflow * miniflow_create(const struct flow *); void miniflow_expand(const struct miniflow *, struct flow *); -static inline uint64_t flow_u64_value(const struct flow *flow, size_t index) +static inline uint64_t flow_u64_value(const struct flow *flow, + unsigned int index) { return ((uint64_t *)flow)[index]; } -static inline uint64_t *flow_u64_lvalue(struct flow *flow, size_t index) +static inline uint64_t *flow_u64_lvalue(struct flow *flow, unsigned int index) { return &((uint64_t *)flow)[index]; } -static inline size_t +static inline unsigned int miniflow_n_values(const struct miniflow *flow) { return count_1bits(flow->tnl_map) + count_1bits(flow->pkt_map); @@ -582,21 +583,22 @@ mf_get_next_in_map(struct mf_for_each_in_map_aux *aux, /* This can be used when it is known that 'u64_idx' is set in 'map'. */ static inline const uint64_t * -miniflow_values_get__(const uint64_t *values, uint64_t map, size_t u64_idx) +miniflow_values_get__(const uint64_t *values, uint64_t map, + unsigned int idx) { - return values + count_1bits(map & ((UINT64_C(1) << u64_idx) - 1)); + return values + count_1bits(map & ((UINT64_C(1) << idx) - 1)); } /* This can be used when it is known that 'u64_idx' is set in * the map of 'mf'. */ static inline const uint64_t * -miniflow_get__(const struct miniflow *mf, size_t u64_idx) +miniflow_get__(const struct miniflow *mf, unsigned int idx) { - return OVS_LIKELY(u64_idx >= FLOW_TNL_U64S) + return OVS_LIKELY(idx >= FLOW_TNL_U64S) ? miniflow_values_get__(miniflow_get_values(mf) + count_1bits(mf->tnl_map), - mf->pkt_map, u64_idx - FLOW_TNL_U64S) - : miniflow_values_get__(miniflow_get_values(mf), mf->tnl_map, u64_idx); + mf->pkt_map, idx - FLOW_TNL_U64S) + : miniflow_values_get__(miniflow_get_values(mf), mf->tnl_map, idx); } #define MINIFLOW_IN_MAP(MF, U64_IDX) \ @@ -780,7 +782,7 @@ flow_union_with_miniflow(struct flow *dst, const struct miniflow *src) { uint64_t *dst_u64 = (uint64_t *) dst; const uint64_t *p = miniflow_get_values(src); - size_t idx; + unsigned int idx; MAP_FOR_EACH_INDEX(idx, src->tnl_map) { dst_u64[idx] |= *p++; -- 2.1.4 _______________________________________________ dev mailing list dev@openvswitch.org http://openvswitch.org/mailman/listinfo/dev