Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp576922imm; Fri, 8 Jun 2018 01:33:04 -0700 (PDT) X-Google-Smtp-Source: ADUXVKK646TOP9lhC6r8ElnYO1Qb55VybwfrIrar4IOuPRmOjLvRWKHSiPg1x8izNrPksywRoUGg X-Received: by 2002:a62:458a:: with SMTP id n10-v6mr5045788pfi.215.1528446784734; Fri, 08 Jun 2018 01:33:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528446784; cv=none; d=google.com; s=arc-20160816; b=t7RwC3g0RfnU34grZ2kYv1b4PJJklcpvObd1hCZ/9Ul52cCne4u/meMhRTSr73Ix51 yVBPolPTwuPbXZCLFUEQ30NqIZ8YKWss21C8fw7ncSbBK5bRv8DVjB6B5MZ4PUmcUxAf j21RkQZuji21AqnDsG3kZWyDkskL++snKWOGVSJbFYs6Xlc+K2yzHIB+598UN0+sCLIa MdBBRvF/mf8Pnt1zQwKzK07FspEoMsi8BNzgVTShwewfTowhuzhlD0FAjued0kU3RKY3 mopRaeooFw7sfaIOVpF1ia5G1y94FI+0QAHI1JUbWmhfN1y+St1Lmc5Wwl9bn7uUYkZE DFcQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date :arc-authentication-results; bh=ImnBpu1Y9h8ocrMrIkv0rDBP/uPALLdfdYIE2EvcaK4=; b=pnUMMnd7N6e6KA69P3TqVzZGWY3+RhN6Jezbl9L3cM/eBPJjPOE+Sj3Wqync4lF45Z HwZi9YsBLJtQ1N4/rtEv80+mD+CAQbOxvoktYnRtO8xKKapacJ9piofdDBgg6Onr29gJ 8LUm1b92kIojSnQEWn/VISj9G+swOyECucu2fTa0sQ3bbmkUgY2nv20KQ+HTZb2PN75j i/xMzb6bilj2iPLp0zS0lj4T2vsw5AY7DiTtDB6y8KlUhhgYD0v9+aTrR9wbBxf7qpg3 NXfj+aat6iG8291WvJ3OIWBuDzzP6u3s2A47X9RqHNNZ8DSUiC6OpynuIvHrn6nX15Y0 xmRw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b39-v6si6173449plb.306.2018.06.08.01.32.50; Fri, 08 Jun 2018 01:33:04 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753026AbeFHIcI (ORCPT + 99 others); Fri, 8 Jun 2018 04:32:08 -0400 Received: from mga06.intel.com ([134.134.136.31]:57721 "EHLO mga06.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752886AbeFHIcC (ORCPT ); Fri, 8 Jun 2018 04:32:02 -0400 X-Amp-Result: UNSCANNABLE X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 08 Jun 2018 01:32:01 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.49,490,1520924400"; d="scan'208";a="47753071" Received: from debian.sh.intel.com (HELO debian) ([10.67.104.203]) by orsmga008.jf.intel.com with ESMTP; 08 Jun 2018 01:32:00 -0700 Date: Fri, 8 Jun 2018 16:32:13 +0800 From: Tiwei Bie To: Jason Wang Cc: mst@redhat.com, virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, wexu@redhat.com, jfreimann@redhat.com Subject: Re: [RFC v6 4/5] virtio_ring: add event idx support in packed ring Message-ID: <20180608083213.GA8512@debian> References: <20180605074046.20709-1-tiwei.bie@intel.com> <20180605074046.20709-5-tiwei.bie@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.9.5 (2018-04-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jun 07, 2018 at 05:50:32PM +0800, Jason Wang wrote: > On 2018年06月05日 15:40, Tiwei Bie wrote: > > static bool virtqueue_enable_cb_delayed_packed(struct virtqueue *_vq) > > { > > struct vring_virtqueue *vq = to_vvq(_vq); > > + u16 bufs, used_idx, wrap_counter; > > START_USE(vq); > > /* We optimistically turn back on interrupts, then check if there was > > * more to do. */ > > + /* Depending on the VIRTIO_RING_F_EVENT_IDX feature, we need to > > + * either clear the flags bit or point the event index at the next > > + * entry. Always update the event index to keep code simple. */ > > + > > Maybe for packed ring, it's time to treat event index separately to avoid a > virtio_wmb() for event idx is off. Okay. I'll do it. > > > + /* TODO: tune this threshold */ > > + if (vq->next_avail_idx < vq->last_used_idx) > > + bufs = (vq->vring_packed.num + vq->next_avail_idx - > > + vq->last_used_idx) * 3 / 4; > > + else > > + bufs = (vq->next_avail_idx - vq->last_used_idx) * 3 / 4; > > vq->next_avail-idx could be equal to vq->last_usd_idx when the ring is full. > Though virito-net is the only user now and it can guarantee this won't > happen. But consider this is a core API, we should make sure it can work for > any cases. > > It looks to me that bufs is just vq->vring_packed.num - vq->num_free? I'll try it! Thanks for the suggestion! :) > > > + > > + wrap_counter = vq->used_wrap_counter; > > + > > + used_idx = vq->last_used_idx + bufs; > > + if (used_idx >= vq->vring_packed.num) { > > + used_idx -= vq->vring_packed.num; > > + wrap_counter ^= 1; > > + } > > + > > + vq->vring_packed.driver->off_wrap = cpu_to_virtio16(_vq->vdev, > > + used_idx | (wrap_counter << 15)); > > if (vq->event_flags_shadow == VRING_EVENT_F_DISABLE) { > > - vq->event_flags_shadow = VRING_EVENT_F_ENABLE; > > + /* We need to update event offset and event wrap > > + * counter first before updating event flags. */ > > + virtio_wmb(vq->weak_barriers); > > + vq->event_flags_shadow = vq->event ? VRING_EVENT_F_DESC : > > + VRING_EVENT_F_ENABLE; > > vq->vring_packed.driver->flags = cpu_to_virtio16(_vq->vdev, > > vq->event_flags_shadow); > > - /* We need to enable interrupts first before re-checking > > - * for more used buffers. */ > > - virtio_mb(vq->weak_barriers); > > } > > + /* We need to update event suppression structure first > > + * before re-checking for more used buffers. */ > > + virtio_mb(vq->weak_barriers); > > + > > if (more_used_packed(vq)) { > > END_USE(vq); > > return false; > > I think what we need to to make sure the descriptor used_idx is used? > Otherwise we may stop and restart qdisc too frequently? Good catch! Yeah. It's not the best choice to check the descriptor at last_used_idx. I'll try to fix this! Best regards, Tiwei Bie > > Thanks > > > -- >