Skip to content

Commit 23dabf8

Browse files
Jarno Rajahalmejessegross
authored andcommitted
openvswitch: Remove 5-tuple optimization.
The 5-tuple optimization becomes unnecessary with a later per-NUMA node stats patch. Remove it first to make the changes easier to grasp. Signed-off-by: Jarno Rajahalme <jrajahalme@nicira.com> Signed-off-by: Jesse Gross <jesse@nicira.com>
1 parent 8c63ff0 commit 23dabf8

7 files changed

Lines changed: 32 additions & 113 deletions

File tree

‎net/openvswitch/datapath.c‎

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ static int ovs_packet_cmd_execute(struct sk_buff *skb, struct genl_info *info)
524524
packet->protocol = htons(ETH_P_802_2);
525525

526526
/* Build an sw_flow for sending this packet. */
527-
flow = ovs_flow_alloc(false);
527+
flow = ovs_flow_alloc();
528528
err = PTR_ERR(flow);
529529
if (IS_ERR(flow))
530530
goto err_kfree_skb;
@@ -782,7 +782,6 @@ static int ovs_flow_cmd_new_or_set(struct sk_buff *skb, struct genl_info *info)
782782
struct datapath *dp;
783783
struct sw_flow_actions *acts = NULL;
784784
struct sw_flow_match match;
785-
bool exact_5tuple;
786785
int error;
787786

788787
/* Extract key. */
@@ -791,7 +790,7 @@ static int ovs_flow_cmd_new_or_set(struct sk_buff *skb, struct genl_info *info)
791790
goto error;
792791

793792
ovs_match_init(&match, &key, &mask);
794-
error = ovs_nla_get_match(&match, &exact_5tuple,
793+
error = ovs_nla_get_match(&match,
795794
a[OVS_FLOW_ATTR_KEY], a[OVS_FLOW_ATTR_MASK]);
796795
if (error)
797796
goto error;
@@ -830,7 +829,7 @@ static int ovs_flow_cmd_new_or_set(struct sk_buff *skb, struct genl_info *info)
830829
goto err_unlock_ovs;
831830

832831
/* Allocate flow. */
833-
flow = ovs_flow_alloc(!exact_5tuple);
832+
flow = ovs_flow_alloc();
834833
if (IS_ERR(flow)) {
835834
error = PTR_ERR(flow);
836835
goto err_unlock_ovs;
@@ -914,7 +913,7 @@ static int ovs_flow_cmd_get(struct sk_buff *skb, struct genl_info *info)
914913
}
915914

916915
ovs_match_init(&match, &key, NULL);
917-
err = ovs_nla_get_match(&match, NULL, a[OVS_FLOW_ATTR_KEY], NULL);
916+
err = ovs_nla_get_match(&match, a[OVS_FLOW_ATTR_KEY], NULL);
918917
if (err)
919918
return err;
920919

@@ -968,7 +967,7 @@ static int ovs_flow_cmd_del(struct sk_buff *skb, struct genl_info *info)
968967
}
969968

970969
ovs_match_init(&match, &key, NULL);
971-
err = ovs_nla_get_match(&match, NULL, a[OVS_FLOW_ATTR_KEY], NULL);
970+
err = ovs_nla_get_match(&match, a[OVS_FLOW_ATTR_KEY], NULL);
972971
if (err)
973972
goto unlock;
974973

‎net/openvswitch/flow.c‎

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,7 @@ void ovs_flow_stats_update(struct sw_flow *flow, struct sk_buff *skb)
6666
struct flow_stats *stats;
6767
__be16 tcp_flags = 0;
6868

69-
if (!flow->stats.is_percpu)
70-
stats = flow->stats.stat;
71-
else
72-
stats = this_cpu_ptr(flow->stats.cpu_stats);
69+
stats = this_cpu_ptr(flow->stats);
7370

7471
if ((flow->key.eth.type == htons(ETH_P_IP) ||
7572
flow->key.eth.type == htons(ETH_P_IPV6)) &&
@@ -110,16 +107,14 @@ void ovs_flow_stats_get(struct sw_flow *flow, struct ovs_flow_stats *ovs_stats,
110107
memset(ovs_stats, 0, sizeof(*ovs_stats));
111108

112109
local_bh_disable();
113-
if (!flow->stats.is_percpu) {
114-
stats_read(flow->stats.stat, ovs_stats, used, tcp_flags);
115-
} else {
116-
for_each_possible_cpu(cpu) {
117-
struct flow_stats *stats;
118-
119-
stats = per_cpu_ptr(flow->stats.cpu_stats, cpu);
120-
stats_read(stats, ovs_stats, used, tcp_flags);
121-
}
110+
111+
for_each_possible_cpu(cpu) {
112+
struct flow_stats *stats;
113+
114+
stats = per_cpu_ptr(flow->stats.cpu_stats, cpu);
115+
stats_read(stats, ovs_stats, used, tcp_flags);
122116
}
117+
123118
local_bh_enable();
124119
}
125120

@@ -138,13 +133,10 @@ void ovs_flow_stats_clear(struct sw_flow *flow)
138133
int cpu;
139134

140135
local_bh_disable();
141-
if (!flow->stats.is_percpu) {
142-
stats_reset(flow->stats.stat);
143-
} else {
144-
for_each_possible_cpu(cpu) {
145-
stats_reset(per_cpu_ptr(flow->stats.cpu_stats, cpu));
146-
}
147-
}
136+
137+
for_each_possible_cpu(cpu)
138+
stats_reset(per_cpu_ptr(flow->stats, cpu));
139+
148140
local_bh_enable();
149141
}
150142

‎net/openvswitch/flow.h‎

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -155,14 +155,6 @@ struct flow_stats {
155155
__be16 tcp_flags; /* Union of seen TCP flags. */
156156
};
157157

158-
struct sw_flow_stats {
159-
bool is_percpu;
160-
union {
161-
struct flow_stats *stat;
162-
struct flow_stats __percpu *cpu_stats;
163-
};
164-
};
165-
166158
struct sw_flow {
167159
struct rcu_head rcu;
168160
struct hlist_node hash_node[2];
@@ -172,7 +164,7 @@ struct sw_flow {
172164
struct sw_flow_key unmasked_key;
173165
struct sw_flow_mask *mask;
174166
struct sw_flow_actions __rcu *sf_acts;
175-
struct sw_flow_stats stats;
167+
struct flow_stats __percpu *stats;
176168
};
177169

178170
struct arp_eth_header {

‎net/openvswitch/flow_netlink.c‎

Lines changed: 4 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -268,20 +268,6 @@ static bool is_all_zero(const u8 *fp, size_t size)
268268
return true;
269269
}
270270

271-
static bool is_all_set(const u8 *fp, size_t size)
272-
{
273-
int i;
274-
275-
if (!fp)
276-
return false;
277-
278-
for (i = 0; i < size; i++)
279-
if (fp[i] != 0xff)
280-
return false;
281-
282-
return true;
283-
}
284-
285271
static int __parse_flow_nlattrs(const struct nlattr *attr,
286272
const struct nlattr *a[],
287273
u64 *attrsp, bool nz)
@@ -503,9 +489,8 @@ static int metadata_from_nlattrs(struct sw_flow_match *match, u64 *attrs,
503489
return 0;
504490
}
505491

506-
static int ovs_key_from_nlattrs(struct sw_flow_match *match, bool *exact_5tuple,
507-
u64 attrs, const struct nlattr **a,
508-
bool is_mask)
492+
static int ovs_key_from_nlattrs(struct sw_flow_match *match, u64 attrs,
493+
const struct nlattr **a, bool is_mask)
509494
{
510495
int err;
511496
u64 orig_attrs = attrs;
@@ -562,11 +547,6 @@ static int ovs_key_from_nlattrs(struct sw_flow_match *match, bool *exact_5tuple
562547
SW_FLOW_KEY_PUT(match, eth.type, htons(ETH_P_802_2), is_mask);
563548
}
564549

565-
if (is_mask && exact_5tuple) {
566-
if (match->mask->key.eth.type != htons(0xffff))
567-
*exact_5tuple = false;
568-
}
569-
570550
if (attrs & (1 << OVS_KEY_ATTR_IPV4)) {
571551
const struct ovs_key_ipv4 *ipv4_key;
572552

@@ -589,13 +569,6 @@ static int ovs_key_from_nlattrs(struct sw_flow_match *match, bool *exact_5tuple
589569
SW_FLOW_KEY_PUT(match, ipv4.addr.dst,
590570
ipv4_key->ipv4_dst, is_mask);
591571
attrs &= ~(1 << OVS_KEY_ATTR_IPV4);
592-
593-
if (is_mask && exact_5tuple && *exact_5tuple) {
594-
if (ipv4_key->ipv4_proto != 0xff ||
595-
ipv4_key->ipv4_src != htonl(0xffffffff) ||
596-
ipv4_key->ipv4_dst != htonl(0xffffffff))
597-
*exact_5tuple = false;
598-
}
599572
}
600573

601574
if (attrs & (1 << OVS_KEY_ATTR_IPV6)) {
@@ -627,15 +600,6 @@ static int ovs_key_from_nlattrs(struct sw_flow_match *match, bool *exact_5tuple
627600
is_mask);
628601

629602
attrs &= ~(1 << OVS_KEY_ATTR_IPV6);
630-
631-
if (is_mask && exact_5tuple && *exact_5tuple) {
632-
if (ipv6_key->ipv6_proto != 0xff ||
633-
!is_all_set((const u8 *)ipv6_key->ipv6_src,
634-
sizeof(match->key->ipv6.addr.src)) ||
635-
!is_all_set((const u8 *)ipv6_key->ipv6_dst,
636-
sizeof(match->key->ipv6.addr.dst)))
637-
*exact_5tuple = false;
638-
}
639603
}
640604

641605
if (attrs & (1 << OVS_KEY_ATTR_ARP)) {
@@ -678,11 +642,6 @@ static int ovs_key_from_nlattrs(struct sw_flow_match *match, bool *exact_5tuple
678642
tcp_key->tcp_dst, is_mask);
679643
}
680644
attrs &= ~(1 << OVS_KEY_ATTR_TCP);
681-
682-
if (is_mask && exact_5tuple && *exact_5tuple &&
683-
(tcp_key->tcp_src != htons(0xffff) ||
684-
tcp_key->tcp_dst != htons(0xffff)))
685-
*exact_5tuple = false;
686645
}
687646

688647
if (attrs & (1 << OVS_KEY_ATTR_TCP_FLAGS)) {
@@ -714,11 +673,6 @@ static int ovs_key_from_nlattrs(struct sw_flow_match *match, bool *exact_5tuple
714673
udp_key->udp_dst, is_mask);
715674
}
716675
attrs &= ~(1 << OVS_KEY_ATTR_UDP);
717-
718-
if (is_mask && exact_5tuple && *exact_5tuple &&
719-
(udp_key->udp_src != htons(0xffff) ||
720-
udp_key->udp_dst != htons(0xffff)))
721-
*exact_5tuple = false;
722676
}
723677

724678
if (attrs & (1 << OVS_KEY_ATTR_SCTP)) {
@@ -804,7 +758,6 @@ static void sw_flow_mask_set(struct sw_flow_mask *mask,
804758
* attribute specifies the mask field of the wildcarded flow.
805759
*/
806760
int ovs_nla_get_match(struct sw_flow_match *match,
807-
bool *exact_5tuple,
808761
const struct nlattr *key,
809762
const struct nlattr *mask)
810763
{
@@ -852,13 +805,10 @@ int ovs_nla_get_match(struct sw_flow_match *match,
852805
}
853806
}
854807

855-
err = ovs_key_from_nlattrs(match, NULL, key_attrs, a, false);
808+
err = ovs_key_from_nlattrs(match, key_attrs, a, false);
856809
if (err)
857810
return err;
858811

859-
if (exact_5tuple)
860-
*exact_5tuple = true;
861-
862812
if (mask) {
863813
err = parse_flow_mask_nlattrs(mask, a, &mask_attrs);
864814
if (err)
@@ -896,7 +846,7 @@ int ovs_nla_get_match(struct sw_flow_match *match,
896846
}
897847
}
898848

899-
err = ovs_key_from_nlattrs(match, exact_5tuple, mask_attrs, a, true);
849+
err = ovs_key_from_nlattrs(match, mask_attrs, a, true);
900850
if (err)
901851
return err;
902852
} else {

‎net/openvswitch/flow_netlink.h‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ int ovs_nla_put_flow(const struct sw_flow_key *,
4545
int ovs_nla_get_flow_metadata(struct sw_flow *flow,
4646
const struct nlattr *attr);
4747
int ovs_nla_get_match(struct sw_flow_match *match,
48-
bool *exact_5tuple,
4948
const struct nlattr *,
5049
const struct nlattr *);
5150

‎net/openvswitch/flow_table.c‎

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ void ovs_flow_mask_key(struct sw_flow_key *dst, const struct sw_flow_key *src,
7272
*d++ = *s++ & *m++;
7373
}
7474

75-
struct sw_flow *ovs_flow_alloc(bool percpu_stats)
75+
struct sw_flow *ovs_flow_alloc(void)
7676
{
7777
struct sw_flow *flow;
7878
int cpu;
@@ -84,25 +84,15 @@ struct sw_flow *ovs_flow_alloc(bool percpu_stats)
8484
flow->sf_acts = NULL;
8585
flow->mask = NULL;
8686

87-
flow->stats.is_percpu = percpu_stats;
87+
flow->stats = alloc_percpu(struct flow_stats);
88+
if (!flow->stats)
89+
goto err;
8890

89-
if (!percpu_stats) {
90-
flow->stats.stat = kzalloc(sizeof(*flow->stats.stat), GFP_KERNEL);
91-
if (!flow->stats.stat)
92-
goto err;
91+
for_each_possible_cpu(cpu) {
92+
struct flow_stats *cpu_stats;
9393

94-
spin_lock_init(&flow->stats.stat->lock);
95-
} else {
96-
flow->stats.cpu_stats = alloc_percpu(struct flow_stats);
97-
if (!flow->stats.cpu_stats)
98-
goto err;
99-
100-
for_each_possible_cpu(cpu) {
101-
struct flow_stats *cpu_stats;
102-
103-
cpu_stats = per_cpu_ptr(flow->stats.cpu_stats, cpu);
104-
spin_lock_init(&cpu_stats->lock);
105-
}
94+
cpu_stats = per_cpu_ptr(flow->stats, cpu);
95+
spin_lock_init(&cpu_stats->lock);
10696
}
10797
return flow;
10898
err:
@@ -141,10 +131,7 @@ static struct flex_array *alloc_buckets(unsigned int n_buckets)
141131
static void flow_free(struct sw_flow *flow)
142132
{
143133
kfree((struct sf_flow_acts __force *)flow->sf_acts);
144-
if (flow->stats.is_percpu)
145-
free_percpu(flow->stats.cpu_stats);
146-
else
147-
kfree(flow->stats.stat);
134+
free_percpu(flow->stats);
148135
kmem_cache_free(flow_cache, flow);
149136
}
150137

‎net/openvswitch/flow_table.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ struct flow_table {
5555
int ovs_flow_init(void);
5656
void ovs_flow_exit(void);
5757

58-
struct sw_flow *ovs_flow_alloc(bool percpu_stats);
58+
struct sw_flow *ovs_flow_alloc(void);
5959
void ovs_flow_free(struct sw_flow *, bool deferred);
6060

6161
int ovs_flow_tbl_init(struct flow_table *);

0 commit comments

Comments
 (0)