From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752533AbcERIYD (ORCPT ); Wed, 18 May 2016 04:24:03 -0400 Received: from mx1.redhat.com ([209.132.183.28]:47638 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751583AbcERIYA (ORCPT ); Wed, 18 May 2016 04:24:00 -0400 Date: Wed, 18 May 2016 11:23:56 +0300 From: "Michael S. Tsirkin" To: Jesper Dangaard Brouer Cc: Jason Wang , Eric Dumazet , davem@davemloft.net, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Steven Rostedt Subject: Re: [PATCH net-next] tuntap: introduce tx skb ring Message-ID: <20160518112225-mutt-send-email-mst@redhat.com> References: <1463361421-4397-1-git-send-email-jasowang@redhat.com> <1463370998.18194.74.camel@edumazet-glaptop3.roam.corp.google.com> <57397C14.1080701@redhat.com> <20160518101359.37f5343b@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20160518101359.37f5343b@redhat.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Wed, 18 May 2016 08:23:59 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, May 18, 2016 at 10:13:59AM +0200, Jesper Dangaard Brouer wrote: > On Mon, 16 May 2016 15:51:48 +0800 > Jason Wang wrote: > > > On 2016年05月16日 11:56, Eric Dumazet wrote: > > > On Mon, 2016-05-16 at 09:17 +0800, Jason Wang wrote: > > >> We used to queue tx packets in sk_receive_queue, this is less > > >> efficient since it requires spinlocks to synchronize between producer > > >> and consumer. > > > ... > > > > > >> struct tun_struct *detached; > > >> + /* reader lock */ > > >> + spinlock_t rlock; > > >> + unsigned long tail; > > >> + struct tun_desc tx_descs[TUN_RING_SIZE]; > > >> + /* writer lock */ > > >> + spinlock_t wlock; > > >> + unsigned long head; > > >> }; > > >> > > > Ok, we had these kind of ideas floating around for many other cases, > > > like qdisc, UDP or af_packet sockets... > > > > > > I believe we should have a common set of helpers, not hidden in > > > drivers/net/tun.c but in net/core/skb_ring.c or something, with more > > > flexibility (like the number of slots) > > > > > > > Yes, this sounds good. > > I agree. It is sad to see everybody is implementing the same thing, > open coding an array/circular based ring buffer. This kind of code is > hard to maintain and get right with barriers etc. We can achieve the > same performance with a generic implementation, by inlining the help > function calls. > > I implemented an array based Lock-Free/cmpxchg based queue, that you > could be inspired by, see: > https://github.com/netoptimizer/prototype-kernel/blob/master/kernel/include/linux/alf_queue.h > > The main idea behind my implementation is bulking, to amortize the > locked cmpxchg operation. You might not need it now, but I expect we > need it in the future. > > You cannot use my alf_queue directly as your "struct tun_desc" is > larger than one-pointer (which the alf_queue works with). But it > should be possible to extend to handle larger "objects". > > > Maybe Steven Rostedt have an even better ring queue implementation > already avail in the kernel? BTW at least for tun, index based isn't really needed. A simple array seems to be more readable, faster and use less memory. I have implemented this and it seems to work OK, will post shortly. > -- > Best regards, > Jesper Dangaard Brouer > MSc.CS, Principal Kernel Engineer at Red Hat > Author of http://www.iptv-analyzer.org > LinkedIn: http://www.linkedin.com/in/brouer