From 6b40d9f715fc03d089ae847313356dad5314a792 Mon Sep 17 00:00:00 2001 From: Mesut Ali Ergin Date: Fri, 1 Apr 2016 12:05:10 -0700 Subject: [PATCH] Enable BURST_MODE for l2fwd JIRA: VSPERF-267 This change adds optional burst mode to l2fwd module that makes use of skb->xmit_more API available in Linux Kernel > 3.18 in order to batch transmission of packets out of the NIC, increasing forwarding performance significantly. By default burst mode is disabled. If a value greater than 1 is provided, burst mode is enabled to send that many packets at once. Typical values would be burst=8 or burst=16. Change-Id: I8ef5f86cf73d4cb5a8e4c618a86111ebf411dca8 Signed-off-by: Mesut Ali Ergin Signed-off-by: Mallesh Koujalagi --- src/l2fwd/l2fwd.c | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/src/l2fwd/l2fwd.c b/src/l2fwd/l2fwd.c index 338b6f50..3d45680c 100644 --- a/src/l2fwd/l2fwd.c +++ b/src/l2fwd/l2fwd.c @@ -40,6 +40,7 @@ #include #include #include +#include #include #include @@ -67,6 +68,14 @@ static bool terminate = false; module_param(terminate, bool, 0); MODULE_PARM_DESC(terminate, "Free skb instead of forwarding"); +#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,18,0) +#define BURST_MODE +static short burst = 1; +module_param(burst, short, 0); +MODULE_PARM_DESC(burst, "Send burst-many packets to output device at once (default is 1)"); + +short burst_count; +#endif static struct net_device *dev1, *dev2; int count; @@ -171,7 +180,32 @@ static rx_handler_result_t netdev_frame_hook(struct sk_buff **pskb) skb->dev = dev; skb_push(skb, ETH_HLEN); +#ifdef BURST_MODE + if (burst > 1) + { + struct netdev_queue *txq = netdev_get_tx_queue(dev, 0); + skb_set_queue_mapping(skb, 0); + + if (!netif_xmit_frozen_or_stopped(txq)) + { + const struct net_device_ops *ops = dev->netdev_ops; + int status = NETDEV_TX_OK; + skb->xmit_more = --burst_count > 0 ? 1 : 0; + status = ops->ndo_start_xmit(skb, dev); + if (status == NETDEV_TX_OK) + txq_trans_update(txq); + if (!burst_count) + burst_count = burst; + } + + } + else + { + dev_queue_xmit(skb); + } +#else dev_queue_xmit(skb); +#endif } return retval; @@ -187,7 +221,9 @@ static int __init l2fwd_init_module(void) char name_fmt_str[IFNAMSIZ+1]; char t_name[IFNAMSIZ+1]; - +#ifdef BURST_MODE + burst_count = burst; +#endif sprintf(name_fmt_str,"%%%ds",IFNAMSIZ); dnat_fmt = (char *)kmalloc(strlen(name_fmt_str)+strlen(dnat_fmt_suffix)+1,GFP_KERNEL); -- 2.16.6