Skip to content

Commit 9d2f627

Browse files
chaudrondavem330
authored andcommitted
net: openvswitch: add masks cache hit counter
Add a counter that counts the number of masks cache hits, and export it through the megaflow netlink statistics. Reviewed-by: Paolo Abeni <[email protected]> Reviewed-by: Tonghao Zhang <[email protected]> Signed-off-by: Eelco Chaudron <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent d652692 commit 9d2f627

File tree

5 files changed

+24
-8
lines changed

5 files changed

+24
-8
lines changed

include/uapi/linux/openvswitch.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@ struct ovs_dp_megaflow_stats {
102102
__u64 n_mask_hit; /* Number of masks used for flow lookups. */
103103
__u32 n_masks; /* Number of masks for the datapath. */
104104
__u32 pad0; /* Pad for future expension. */
105+
__u64 n_cache_hit; /* Number of cache matches for flow lookups. */
105106
__u64 pad1; /* Pad for future expension. */
106-
__u64 pad2; /* Pad for future expension. */
107107
};
108108

109109
struct ovs_vport_stats {

net/openvswitch/datapath.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,13 +225,14 @@ void ovs_dp_process_packet(struct sk_buff *skb, struct sw_flow_key *key)
225225
struct dp_stats_percpu *stats;
226226
u64 *stats_counter;
227227
u32 n_mask_hit;
228+
u32 n_cache_hit;
228229
int error;
229230

230231
stats = this_cpu_ptr(dp->stats_percpu);
231232

232233
/* Look up flow. */
233234
flow = ovs_flow_tbl_lookup_stats(&dp->table, key, skb_get_hash(skb),
234-
&n_mask_hit);
235+
&n_mask_hit, &n_cache_hit);
235236
if (unlikely(!flow)) {
236237
struct dp_upcall_info upcall;
237238

@@ -262,6 +263,7 @@ void ovs_dp_process_packet(struct sk_buff *skb, struct sw_flow_key *key)
262263
u64_stats_update_begin(&stats->syncp);
263264
(*stats_counter)++;
264265
stats->n_mask_hit += n_mask_hit;
266+
stats->n_cache_hit += n_cache_hit;
265267
u64_stats_update_end(&stats->syncp);
266268
}
267269

@@ -699,6 +701,7 @@ static void get_dp_stats(const struct datapath *dp, struct ovs_dp_stats *stats,
699701
stats->n_missed += local_stats.n_missed;
700702
stats->n_lost += local_stats.n_lost;
701703
mega_stats->n_mask_hit += local_stats.n_mask_hit;
704+
mega_stats->n_cache_hit += local_stats.n_cache_hit;
702705
}
703706
}
704707

net/openvswitch/datapath.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,15 @@
3838
* @n_mask_hit: Number of masks looked up for flow match.
3939
* @n_mask_hit / (@n_hit + @n_missed) will be the average masks looked
4040
* up per packet.
41+
* @n_cache_hit: The number of received packets that had their mask found using
42+
* the mask cache.
4143
*/
4244
struct dp_stats_percpu {
4345
u64 n_hit;
4446
u64 n_missed;
4547
u64 n_lost;
4648
u64 n_mask_hit;
49+
u64 n_cache_hit;
4750
struct u64_stats_sync syncp;
4851
};
4952

net/openvswitch/flow_table.c

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -667,6 +667,7 @@ static struct sw_flow *flow_lookup(struct flow_table *tbl,
667667
struct mask_array *ma,
668668
const struct sw_flow_key *key,
669669
u32 *n_mask_hit,
670+
u32 *n_cache_hit,
670671
u32 *index)
671672
{
672673
u64 *usage_counters = this_cpu_ptr(ma->masks_usage_cntr);
@@ -682,6 +683,7 @@ static struct sw_flow *flow_lookup(struct flow_table *tbl,
682683
u64_stats_update_begin(&ma->syncp);
683684
usage_counters[*index]++;
684685
u64_stats_update_end(&ma->syncp);
686+
(*n_cache_hit)++;
685687
return flow;
686688
}
687689
}
@@ -719,7 +721,8 @@ static struct sw_flow *flow_lookup(struct flow_table *tbl,
719721
struct sw_flow *ovs_flow_tbl_lookup_stats(struct flow_table *tbl,
720722
const struct sw_flow_key *key,
721723
u32 skb_hash,
722-
u32 *n_mask_hit)
724+
u32 *n_mask_hit,
725+
u32 *n_cache_hit)
723726
{
724727
struct mask_array *ma = rcu_dereference(tbl->mask_array);
725728
struct table_instance *ti = rcu_dereference(tbl->ti);
@@ -729,10 +732,13 @@ struct sw_flow *ovs_flow_tbl_lookup_stats(struct flow_table *tbl,
729732
int seg;
730733

731734
*n_mask_hit = 0;
735+
*n_cache_hit = 0;
732736
if (unlikely(!skb_hash)) {
733737
u32 mask_index = 0;
738+
u32 cache = 0;
734739

735-
return flow_lookup(tbl, ti, ma, key, n_mask_hit, &mask_index);
740+
return flow_lookup(tbl, ti, ma, key, n_mask_hit, &cache,
741+
&mask_index);
736742
}
737743

738744
/* Pre and post recirulation flows usually have the same skb_hash
@@ -753,7 +759,7 @@ struct sw_flow *ovs_flow_tbl_lookup_stats(struct flow_table *tbl,
753759
e = &entries[index];
754760
if (e->skb_hash == skb_hash) {
755761
flow = flow_lookup(tbl, ti, ma, key, n_mask_hit,
756-
&e->mask_index);
762+
n_cache_hit, &e->mask_index);
757763
if (!flow)
758764
e->skb_hash = 0;
759765
return flow;
@@ -766,10 +772,12 @@ struct sw_flow *ovs_flow_tbl_lookup_stats(struct flow_table *tbl,
766772
}
767773

768774
/* Cache miss, do full lookup. */
769-
flow = flow_lookup(tbl, ti, ma, key, n_mask_hit, &ce->mask_index);
775+
flow = flow_lookup(tbl, ti, ma, key, n_mask_hit, n_cache_hit,
776+
&ce->mask_index);
770777
if (flow)
771778
ce->skb_hash = skb_hash;
772779

780+
*n_cache_hit = 0;
773781
return flow;
774782
}
775783

@@ -779,9 +787,10 @@ struct sw_flow *ovs_flow_tbl_lookup(struct flow_table *tbl,
779787
struct table_instance *ti = rcu_dereference_ovsl(tbl->ti);
780788
struct mask_array *ma = rcu_dereference_ovsl(tbl->mask_array);
781789
u32 __always_unused n_mask_hit;
790+
u32 __always_unused n_cache_hit;
782791
u32 index = 0;
783792

784-
return flow_lookup(tbl, ti, ma, key, &n_mask_hit, &index);
793+
return flow_lookup(tbl, ti, ma, key, &n_mask_hit, &n_cache_hit, &index);
785794
}
786795

787796
struct sw_flow *ovs_flow_tbl_lookup_exact(struct flow_table *tbl,

net/openvswitch/flow_table.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ struct sw_flow *ovs_flow_tbl_dump_next(struct table_instance *table,
8282
struct sw_flow *ovs_flow_tbl_lookup_stats(struct flow_table *,
8383
const struct sw_flow_key *,
8484
u32 skb_hash,
85-
u32 *n_mask_hit);
85+
u32 *n_mask_hit,
86+
u32 *n_cache_hit);
8687
struct sw_flow *ovs_flow_tbl_lookup(struct flow_table *,
8788
const struct sw_flow_key *);
8889
struct sw_flow *ovs_flow_tbl_lookup_exact(struct flow_table *tbl,

0 commit comments

Comments
 (0)