summaryrefslogtreecommitdiffstats
path: root/net/openvswitch/datapath.c
diff options
context:
space:
mode:
authorThomas Graf <tgraf@suug.ch>2013-12-13 09:22:21 -0500
committerJesse Gross <jesse@nicira.com>2014-01-06 18:53:17 -0500
commitbda56f143c9dc38ae7926ba21ebeb35359a6c051 (patch)
treeb3deb68ee339b9857796a51a4a68deba0188fede /net/openvswitch/datapath.c
parent8055a89cfa533f70bea5970727a50e220bb7d18e (diff)
openvswitch: Use skb_zerocopy() for upcall
Use of skb_zerocopy() can avoid the expensive call to memcpy() when copying the packet data into the Netlink skb. Completes checksum through skb_checksum_help() if not already done in GSO segmentation. Zerocopy is only performed if user space supported unaligned Netlink messages. memory mapped netlink i/o is preferred over zerocopy if it is set up. Cost of upcall is significantly reduced from: + 7.48% vhost-8471 [k] memcpy + 5.57% ovs-vswitchd [k] memcpy + 2.81% vhost-8471 [k] csum_partial_copy_generic to: + 5.72% ovs-vswitchd [k] memcpy + 3.32% vhost-5153 [k] memcpy + 0.68% vhost-5153 [k] skb_zerocopy (megaflows disabled) Signed-off-by: Thomas Graf <tgraf@suug.ch> Signed-off-by: Jesse Gross <jesse@nicira.com>
Diffstat (limited to 'net/openvswitch/datapath.c')
-rw-r--r--net/openvswitch/datapath.c37
1 files changed, 29 insertions, 8 deletions
diff --git a/net/openvswitch/datapath.c b/net/openvswitch/datapath.c
index 235acaeaedc7..85578342d566 100644
--- a/net/openvswitch/datapath.c
+++ b/net/openvswitch/datapath.c
@@ -371,11 +371,11 @@ static size_t key_attr_size(void)
371 + nla_total_size(28); /* OVS_KEY_ATTR_ND */ 371 + nla_total_size(28); /* OVS_KEY_ATTR_ND */
372} 372}
373 373
374static size_t upcall_msg_size(const struct sk_buff *skb, 374static size_t upcall_msg_size(const struct nlattr *userdata,
375 const struct nlattr *userdata) 375 unsigned int hdrlen)
376{ 376{
377 size_t size = NLMSG_ALIGN(sizeof(struct ovs_header)) 377 size_t size = NLMSG_ALIGN(sizeof(struct ovs_header))
378 + nla_total_size(skb->len) /* OVS_PACKET_ATTR_PACKET */ 378 + nla_total_size(hdrlen) /* OVS_PACKET_ATTR_PACKET */
379 + nla_total_size(key_attr_size()); /* OVS_PACKET_ATTR_KEY */ 379 + nla_total_size(key_attr_size()); /* OVS_PACKET_ATTR_KEY */
380 380
381 /* OVS_PACKET_ATTR_USERDATA */ 381 /* OVS_PACKET_ATTR_USERDATA */
@@ -397,6 +397,7 @@ static int queue_userspace_packet(struct datapath *dp, struct sk_buff *skb,
397 .snd_portid = upcall_info->portid, 397 .snd_portid = upcall_info->portid,
398 }; 398 };
399 size_t len; 399 size_t len;
400 unsigned int hlen;
400 int err, dp_ifindex; 401 int err, dp_ifindex;
401 402
402 dp_ifindex = get_dpifindex(dp); 403 dp_ifindex = get_dpifindex(dp);
@@ -421,7 +422,21 @@ static int queue_userspace_packet(struct datapath *dp, struct sk_buff *skb,
421 goto out; 422 goto out;
422 } 423 }
423 424
424 len = upcall_msg_size(skb, upcall_info->userdata); 425 /* Complete checksum if needed */
426 if (skb->ip_summed == CHECKSUM_PARTIAL &&
427 (err = skb_checksum_help(skb)))
428 goto out;
429
430 /* Older versions of OVS user space enforce alignment of the last
431 * Netlink attribute to NLA_ALIGNTO which would require extensive
432 * padding logic. Only perform zerocopy if padding is not required.
433 */
434 if (dp->user_features & OVS_DP_F_UNALIGNED)
435 hlen = skb_zerocopy_headlen(skb);
436 else
437 hlen = skb->len;
438
439 len = upcall_msg_size(upcall_info->userdata, hlen);
425 user_skb = genlmsg_new_unicast(len, &info, GFP_ATOMIC); 440 user_skb = genlmsg_new_unicast(len, &info, GFP_ATOMIC);
426 if (!user_skb) { 441 if (!user_skb) {
427 err = -ENOMEM; 442 err = -ENOMEM;
@@ -441,13 +456,19 @@ static int queue_userspace_packet(struct datapath *dp, struct sk_buff *skb,
441 nla_len(upcall_info->userdata), 456 nla_len(upcall_info->userdata),
442 nla_data(upcall_info->userdata)); 457 nla_data(upcall_info->userdata));
443 458
444 nla = __nla_reserve(user_skb, OVS_PACKET_ATTR_PACKET, skb->len); 459 /* Only reserve room for attribute header, packet data is added
460 * in skb_zerocopy() */
461 if (!(nla = nla_reserve(user_skb, OVS_PACKET_ATTR_PACKET, 0))) {
462 err = -ENOBUFS;
463 goto out;
464 }
465 nla->nla_len = nla_attr_size(skb->len);
445 466
446 skb_copy_and_csum_dev(skb, nla_data(nla)); 467 skb_zerocopy(user_skb, skb, skb->len, hlen);
447 468
448 genlmsg_end(user_skb, upcall); 469 ((struct nlmsghdr *) user_skb->data)->nlmsg_len = user_skb->len;
449 err = genlmsg_unicast(ovs_dp_get_net(dp), user_skb, upcall_info->portid);
450 470
471 err = genlmsg_unicast(ovs_dp_get_net(dp), user_skb, upcall_info->portid);
451out: 472out:
452 kfree_skb(nskb); 473 kfree_skb(nskb);
453 return err; 474 return err;