From patchwork Fri Jun 4 02:34:57 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rusty Russell X-Patchwork-Id: 54533 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 6F7DFB7D4C for ; Fri, 4 Jun 2010 12:35:48 +1000 (EST) Received: from localhost ([127.0.0.1]:42337 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OKMl7-0006w5-Bk for incoming@patchwork.ozlabs.org; Thu, 03 Jun 2010 22:35:45 -0400 Received: from [140.186.70.92] (port=48108 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OKMkX-0006vx-1L for qemu-devel@nongnu.org; Thu, 03 Jun 2010 22:35:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OKMkS-0007RF-14 for qemu-devel@nongnu.org; Thu, 03 Jun 2010 22:35:08 -0400 Received: from ozlabs.org ([203.10.76.45]:52279) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OKMkR-0007QY-Lu for qemu-devel@nongnu.org; Thu, 03 Jun 2010 22:35:03 -0400 Received: from vivaldi.localnet (ppp121-45-40-179.lns20.adl2.internode.on.net [121.45.40.179]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPSA id 160F5B7D20; Fri, 4 Jun 2010 12:34:59 +1000 (EST) From: Rusty Russell To: "Michael S. Tsirkin" Date: Fri, 4 Jun 2010 12:04:57 +0930 User-Agent: KMail/1.13.2 (Linux/2.6.32-22-generic; KDE/4.4.2; i686; ; ) References: <10a74b58c908bad64ff890c881e2b2de88687f0e.1275403477.git.mst@redhat.com> In-Reply-To: <10a74b58c908bad64ff890c881e2b2de88687f0e.1275403477.git.mst@redhat.com> MIME-Version: 1.0 Message-Id: <201006041204.57973.rusty@rustcorp.com.au> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) Cc: qemu-devel@nongnu.org, Andrew Morton , linux-kernel@vger.kernel.org, kvm@vger.kernel.org, virtualization@lists.linux-foundation.org Subject: [Qemu-devel] Re: [PATCHv3 1/2] virtio: support layout with avail ring before idx X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org On Wed, 2 Jun 2010 12:17:12 am Michael S. Tsirkin wrote: > This adds an (unused) option to put available ring before control (avail > index, flags), and adds padding between index and flags. This avoids > cache line sharing between control and ring, and also makes it possible > to extend avail control without incurring extra cache misses. > > Signed-off-by: Michael S. Tsirkin No no no no. 254? You're trying to Morton me![1] How's this (untested): Cheers, Rusty. [1] Andrew Morton has this technique where he posts a solution so ugly it forces others to fix it properly. Ego-roping, basically. diff --git a/include/linux/virtio_ring.h b/include/linux/virtio_ring.h --- a/include/linux/virtio_ring.h +++ b/include/linux/virtio_ring.h @@ -74,8 +74,8 @@ struct vring { /* The standard layout for the ring is a continuous chunk of memory which looks * like this. We assume num is a power of 2. * - * struct vring - * { + * struct vring { + * *** The driver writes to this part. * // The actual descriptors (16 bytes each) * struct vring_desc desc[num]; * @@ -84,9 +84,11 @@ struct vring { * __u16 avail_idx; * __u16 available[num]; * - * // Padding to the next align boundary. + * // Padding so used_flags is on the next align boundary. * char pad[]; + * __u16 last_used; // On a cacheline of its own. * + * *** The device writes to this part. * // A ring of used descriptor heads with free-running index. * __u16 used_flags; * __u16 used_idx; @@ -110,6 +112,12 @@ static inline unsigned vring_size(unsign + sizeof(__u16) * 2 + sizeof(struct vring_used_elem) * num; } +/* Last used index sits at the very end of the driver part of the struct */ +static inline __u16 *vring_last_used_idx(const struct vring *vr) +{ + return (__u16 *)vr->used - 1; +} + #ifdef __KERNEL__ #include struct virtio_device;