Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752608AbdI0IYd (ORCPT ); Wed, 27 Sep 2017 04:24:33 -0400 Received: from mx1.redhat.com ([209.132.183.28]:39102 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752373AbdI0IYO (ORCPT ); Wed, 27 Sep 2017 04:24:14 -0400 DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com CE540C0546D2 Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=jasowang@redhat.com From: Jason Wang To: netdev@vger.kernel.org, linux-kernel@vger.kernel.org Cc: mst@redhat.com, Jason Wang Subject: [PATCH net-next 3/3] tun: introduce cpu id based steering policy Date: Wed, 27 Sep 2017 16:23:57 +0800 Message-Id: <1506500637-13881-4-git-send-email-jasowang@redhat.com> In-Reply-To: <1506500637-13881-1-git-send-email-jasowang@redhat.com> References: <1506500637-13881-1-git-send-email-jasowang@redhat.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Wed, 27 Sep 2017 08:24:13 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3323 Lines: 107 This patch introduces a simple queue selection policy which just choose txq based on processor id. This maybe useful for connectless workload or #queues is equal to #cpus. Redirect UDP packets generated by MoonGen between two virtio-net ports through xdp_redirect show 37.4% (from 0.8Mpps to 1.1Mpps) improvement compared to automatic steering policy since the overhead of flow caches/hasing was totally eliminated. Signed-off-by: Jason Wang --- drivers/net/tun.c | 33 ++++++++++++++++++++++++++++++++- include/uapi/linux/if_tun.h | 1 + 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/drivers/net/tun.c b/drivers/net/tun.c index 1106521..03b4506 100644 --- a/drivers/net/tun.c +++ b/drivers/net/tun.c @@ -190,6 +190,20 @@ struct tun_steering_ops { u32 data); }; +void tun_steering_xmit_nop(struct tun_struct *tun, struct sk_buff *skb) +{ +} + +u32 tun_steering_pre_rx_nop(struct tun_struct *tun, struct sk_buff *skb) +{ + return 0; +} + +void tun_steering_post_rx_nop(struct tun_struct *tun, struct tun_file *tfile, + u32 data) +{ +} + struct tun_flow_entry { struct hlist_node hash_link; struct rcu_head rcu; @@ -571,6 +585,11 @@ static u16 tun_automq_select_queue(struct tun_struct *tun, struct sk_buff *skb) return txq; } +static u16 tun_cpu_select_queue(struct tun_struct *tun, struct sk_buff *skb) +{ + return smp_processor_id() % tun->numqueues; +} + static u16 tun_select_queue(struct net_device *dev, struct sk_buff *skb, void *accel_priv, select_queue_fallback_t fallback) { @@ -2152,6 +2171,13 @@ static struct tun_steering_ops tun_automq_ops = { .post_rx = tun_automq_post_rx, }; +static struct tun_steering_ops tun_cpu_ops = { + .select_queue = tun_cpu_select_queue, + .xmit = tun_steering_xmit_nop, + .pre_rx = tun_steering_pre_rx_nop, + .post_rx = tun_steering_post_rx_nop, +}; + static int tun_flags(struct tun_struct *tun) { return tun->flags & (TUN_FEATURES | IFF_PERSIST | IFF_TUN | IFF_TAP); @@ -2775,6 +2801,9 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd, case TUN_STEERING_AUTOMQ: tun->steering_ops = &tun_automq_ops; break; + case TUN_STEERING_CPU: + tun->steering_ops = &tun_cpu_ops; + break; default: ret = -EFAULT; } @@ -2784,6 +2813,8 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd, ret = 0; if (tun->steering_ops == &tun_automq_ops) steering = TUN_STEERING_AUTOMQ; + else if (tun->steering_ops == &tun_cpu_ops) + steering = TUN_STEERING_CPU; else BUG(); if (copy_to_user(argp, &steering, sizeof(steering))) @@ -2792,7 +2823,7 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd, case TUNGETSTEERINGFEATURES: ret = 0; - steering = TUN_STEERING_AUTOMQ; + steering = TUN_STEERING_AUTOMQ | TUN_STEERING_CPU; if (copy_to_user(argp, &steering, sizeof(steering))) ret = -EFAULT; break; diff --git a/include/uapi/linux/if_tun.h b/include/uapi/linux/if_tun.h index 109760e..5f71d29 100644 --- a/include/uapi/linux/if_tun.h +++ b/include/uapi/linux/if_tun.h @@ -112,5 +112,6 @@ struct tun_filter { }; #define TUN_STEERING_AUTOMQ 0x01 /* Automatic flow steering */ +#define TUN_STEERING_CPU 0x02 /* Processor id based flow steering */ #endif /* _UAPI__IF_TUN_H */ -- 2.7.4