History

net: openvswitch: Add support to count upcall packets

Add support to count upall packets, when kmod of openvswitch upcall to count the number of packets for upcall succeed and failed, which is a better way to see how many packets upcalled on every interfaces.

wangchuanlei committed 3 years ago

Commit 1933ea31 parent e47877c4 files · +121 −0Browse files

Unified · Split

4 files
  1. include/uapi/linux/openvswitch.h +14 −0
  2. net/openvswitch/datapath.c +41 −0
  3. net/openvswitch/vport.c +50 −0
  4. net/openvswitch/vport.h +16 −0
include/uapi/linux/openvswitch.h+14−0
@@ -277,11 +277,25 @@ enum ovs_vport_attr { · 276 unmodified lines
277 OVS_VPORT_ATTR_PAD,277 OVS_VPORT_ATTR_PAD,
278 OVS_VPORT_ATTR_IFINDEX,278 OVS_VPORT_ATTR_IFINDEX,
279 OVS_VPORT_ATTR_NETNSID,279 OVS_VPORT_ATTR_NETNSID,
280 OVS_VPORT_ATTR_UPCALL_STATS,
280 __OVS_VPORT_ATTR_MAX281 __OVS_VPORT_ATTR_MAX
281};282};
282 283
283#define OVS_VPORT_ATTR_MAX (__OVS_VPORT_ATTR_MAX - 1)284#define OVS_VPORT_ATTR_MAX (__OVS_VPORT_ATTR_MAX - 1)
284 285
286/**
287 * enum ovs_vport_upcall_attr - attributes for %OVS_VPORT_UPCALL* commands
288 * @OVS_VPORT_UPCALL_SUCCESS: 64-bit upcall success packets.
289 * @OVS_VPORT_UPCALL_FAIL: 64-bit upcall fail packets.
290 */
291enum ovs_vport_upcall_attr {
292 OVS_VPORT_UPCALL_ATTR_SUCCESS,
293 OVS_VPORT_UPCALL_ATTR_FAIL,
294 __OVS_VPORT_UPCALL_ATTR_MAX
295};
296
297#define OVS_VPORT_UPCALL_ATTR_MAX (__OVS_VPORT_UPCALL_ATTR_MAX - 1)
298
285enum {299enum {
286 OVS_VXLAN_EXT_UNSPEC,300 OVS_VXLAN_EXT_UNSPEC,
287 OVS_VXLAN_EXT_GBP, /* Flag or __u32 */301 OVS_VXLAN_EXT_GBP, /* Flag or __u32 */
net/openvswitch/datapath.c+41−0
@@ -209,6 +209,26 @@ static struct vport *new_vport(const struct vport_parms *parms) · 208 unmodified lines
209 return vport;209 return vport;
210}210}
211 211
212static void ovs_vport_update_upcall_stats(struct sk_buff *skb,
213 const struct dp_upcall_info *upcall_info,
214 bool upcall_result)
215{
216 struct vport *p = OVS_CB(skb)->input_vport;
217 struct vport_upcall_stats_percpu *stats;
218
219 if (upcall_info->cmd != OVS_PACKET_CMD_MISS &&
220 upcall_info->cmd != OVS_PACKET_CMD_ACTION)
221 return;
222
223 stats = this_cpu_ptr(p->upcall_stats);
224 u64_stats_update_begin(&stats->syncp);
225 if (upcall_result)
226 u64_stats_inc(&stats->n_success);
227 else
228 u64_stats_inc(&stats->n_fail);
229 u64_stats_update_end(&stats->syncp);
230}
231
212void ovs_dp_detach_port(struct vport *p)232void ovs_dp_detach_port(struct vport *p)
213{233{
214 ASSERT_OVSL();234 ASSERT_OVSL();
@@ -216,6 +236,9 @@ void ovs_dp_detach_port(struct vport *p) · 1 unmodified line
216 /* First drop references to device. */236 /* First drop references to device. */
217 hlist_del_rcu(&p->dp_hash_node);237 hlist_del_rcu(&p->dp_hash_node);
218 238
239 /* Free percpu memory */
240 free_percpu(p->upcall_stats);
241
219 /* Then destroy it. */242 /* Then destroy it. */
220 ovs_vport_del(p);243 ovs_vport_del(p);
221}244}
@@ -305,6 +328,8 @@ int ovs_dp_upcall(struct datapath *dp, struct sk_buff *skb, · 83 unmodified lines
305 err = queue_userspace_packet(dp, skb, key, upcall_info, cutlen);328 err = queue_userspace_packet(dp, skb, key, upcall_info, cutlen);
306 else329 else
307 err = queue_gso_packets(dp, skb, key, upcall_info, cutlen);330 err = queue_gso_packets(dp, skb, key, upcall_info, cutlen);
331
332 ovs_vport_update_upcall_stats(skb, upcall_info, !err);
308 if (err)333 if (err)
309 goto err;334 goto err;
310 335
@@ -1826,6 +1851,12 @@ static int ovs_dp_cmd_new(struct sk_buff *skb, struct genl_info *info) · 1515 unmodified lines
1826 goto err_destroy_portids;1851 goto err_destroy_portids;
1827 }1852 }
1828 1853
1854 vport->upcall_stats = netdev_alloc_pcpu_stats(struct vport_upcall_stats_percpu);
1855 if (!vport->upcall_stats) {
1856 err = -ENOMEM;
1857 goto err_destroy_portids;
1858 }
1859
1829 err = ovs_dp_cmd_fill_info(dp, reply, info->snd_portid,1860 err = ovs_dp_cmd_fill_info(dp, reply, info->snd_portid,
1830 info->snd_seq, 0, OVS_DP_CMD_NEW);1861 info->snd_seq, 0, OVS_DP_CMD_NEW);
1831 BUG_ON(err < 0);1862 BUG_ON(err < 0);
@@ -2098,6 +2129,9 @@ static int ovs_vport_cmd_fill_info(struct vport *vport, struct sk_buff *skb, · 266 unmodified lines
2098 OVS_VPORT_ATTR_PAD))2129 OVS_VPORT_ATTR_PAD))
2099 goto nla_put_failure;2130 goto nla_put_failure;
2100 2131
2132 if (ovs_vport_get_upcall_stats(vport, skb))
2133 goto nla_put_failure;
2134
2101 if (ovs_vport_get_upcall_portids(vport, skb))2135 if (ovs_vport_get_upcall_portids(vport, skb))
2102 goto nla_put_failure;2136 goto nla_put_failure;
2103 2137
@@ -2279,6 +2313,12 @@ restart: · 175 unmodified lines
2279 goto exit_unlock_free;2313 goto exit_unlock_free;
2280 }2314 }
2281 2315
2316 vport->upcall_stats = netdev_alloc_pcpu_stats(struct vport_upcall_stats_percpu);
2317 if (!vport->upcall_stats) {
2318 err = -ENOMEM;
2319 goto exit_unlock_free;
2320 }
2321
2282 err = ovs_vport_cmd_fill_info(vport, reply, genl_info_net(info),2322 err = ovs_vport_cmd_fill_info(vport, reply, genl_info_net(info),
2283 info->snd_portid, info->snd_seq, 0,2323 info->snd_portid, info->snd_seq, 0,
2284 OVS_VPORT_CMD_NEW, GFP_KERNEL);2324 OVS_VPORT_CMD_NEW, GFP_KERNEL);
@@ -2508,6 +2548,7 @@ static const struct nla_policy vport_policy[OVS_VPORT_ATTR_MAX + 1] = { · 223 unmodified lines
2508 [OVS_VPORT_ATTR_OPTIONS] = { .type = NLA_NESTED },2548 [OVS_VPORT_ATTR_OPTIONS] = { .type = NLA_NESTED },
2509 [OVS_VPORT_ATTR_IFINDEX] = { .type = NLA_U32 },2549 [OVS_VPORT_ATTR_IFINDEX] = { .type = NLA_U32 },
2510 [OVS_VPORT_ATTR_NETNSID] = { .type = NLA_S32 },2550 [OVS_VPORT_ATTR_NETNSID] = { .type = NLA_S32 },
2551 [OVS_VPORT_ATTR_UPCALL_STATS] = { .type = NLA_NESTED },
2511};2552};
2512 2553
2513static const struct genl_small_ops dp_vport_genl_ops[] = {2554static const struct genl_small_ops dp_vport_genl_ops[] = {
net/openvswitch/vport.c+50−0
@@ -284,6 +284,56 @@ void ovs_vport_get_stats(struct vport *vport, struct ovs_vport_stats *stats) · 283 unmodified lines
284 stats->tx_packets = dev_stats->tx_packets;284 stats->tx_packets = dev_stats->tx_packets;
285}285}
286 286
287/**
288 * ovs_vport_get_upcall_stats - retrieve upcall stats
289 *
290 * @vport: vport from which to retrieve the stats.
291 * @skb: sk_buff where upcall stats should be appended.
292 *
293 * Retrieves upcall stats for the given device.
294 *
295 * Must be called with ovs_mutex or rcu_read_lock.
296 */
297int ovs_vport_get_upcall_stats(struct vport *vport, struct sk_buff *skb)
298{
299 struct nlattr *nla;
300 int i;
301
302 __u64 tx_success = 0;
303 __u64 tx_fail = 0;
304
305 for_each_possible_cpu(i) {
306 const struct vport_upcall_stats_percpu *stats;
307 unsigned int start;
308
309 stats = per_cpu_ptr(vport->upcall_stats, i);
310 do {
311 start = u64_stats_fetch_begin(&stats->syncp);
312 tx_success += u64_stats_read(&stats->n_success);
313 tx_fail += u64_stats_read(&stats->n_fail);
314 } while (u64_stats_fetch_retry(&stats->syncp, start));
315 }
316
317 nla = nla_nest_start_noflag(skb, OVS_VPORT_ATTR_UPCALL_STATS);
318 if (!nla)
319 return -EMSGSIZE;
320
321 if (nla_put_u64_64bit(skb, OVS_VPORT_UPCALL_ATTR_SUCCESS, tx_success,
322 OVS_VPORT_ATTR_PAD)) {
323 nla_nest_cancel(skb, nla);
324 return -EMSGSIZE;
325 }
326
327 if (nla_put_u64_64bit(skb, OVS_VPORT_UPCALL_ATTR_FAIL, tx_fail,
328 OVS_VPORT_ATTR_PAD)) {
329 nla_nest_cancel(skb, nla);
330 return -EMSGSIZE;
331 }
332 nla_nest_end(skb, nla);
333
334 return 0;
335}
336
287/**337/**
288 * ovs_vport_get_options - retrieve device options338 * ovs_vport_get_options - retrieve device options
289 *339 *
net/openvswitch/vport.h+16−0
@@ -32,6 +32,8 @@ struct vport *ovs_vport_locate(const struct net *net, const char *name); · 31 unmodified lines
32 32
33void ovs_vport_get_stats(struct vport *, struct ovs_vport_stats *);33void ovs_vport_get_stats(struct vport *, struct ovs_vport_stats *);
34 34
35int ovs_vport_get_upcall_stats(struct vport *vport, struct sk_buff *skb);
36
35int ovs_vport_set_options(struct vport *, struct nlattr *options);37int ovs_vport_set_options(struct vport *, struct nlattr *options);
36int ovs_vport_get_options(const struct vport *, struct sk_buff *);38int ovs_vport_get_options(const struct vport *, struct sk_buff *);
37 39
@@ -65,6 +67,7 @@ struct vport_portids { · 27 unmodified lines
65 * @hash_node: Element in @dev_table hash table in vport.c.67 * @hash_node: Element in @dev_table hash table in vport.c.
66 * @dp_hash_node: Element in @datapath->ports hash table in datapath.c.68 * @dp_hash_node: Element in @datapath->ports hash table in datapath.c.
67 * @ops: Class structure.69 * @ops: Class structure.
70 * @upcall_stats: Upcall stats of every ports.
68 * @detach_list: list used for detaching vport in net-exit call.71 * @detach_list: list used for detaching vport in net-exit call.
69 * @rcu: RCU callback head for deferred destruction.72 * @rcu: RCU callback head for deferred destruction.
70 */73 */
@@ -78,6 +81,7 @@ struct vport { · 7 unmodified lines
78 struct hlist_node hash_node;81 struct hlist_node hash_node;
79 struct hlist_node dp_hash_node;82 struct hlist_node dp_hash_node;
80 const struct vport_ops *ops;83 const struct vport_ops *ops;
84 struct vport_upcall_stats_percpu __percpu *upcall_stats;
81 85
82 struct list_head detach_list;86 struct list_head detach_list;
83 struct rcu_head rcu;87 struct rcu_head rcu;
@@ -137,6 +141,18 @@ struct vport_ops { · 53 unmodified lines
137 struct list_head list;141 struct list_head list;
138};142};
139 143
144/**
145 * struct vport_upcall_stats_percpu - per-cpu packet upcall statistics for
146 * a given vport.
147 * @n_success: Number of packets that upcall to userspace succeed.
148 * @n_fail: Number of packets that upcall to userspace failed.
149 */
150struct vport_upcall_stats_percpu {
151 struct u64_stats_sync syncp;
152 u64_stats_t n_success;
153 u64_stats_t n_fail;
154};
155
140struct vport *ovs_vport_alloc(int priv_size, const struct vport_ops *,156struct vport *ovs_vport_alloc(int priv_size, const struct vport_ops *,
141 const struct vport_parms *);157 const struct vport_parms *);
142void ovs_vport_free(struct vport *);158void ovs_vport_free(struct vport *);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t