Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp1512606imm; Tue, 15 May 2018 22:01:43 -0700 (PDT) X-Google-Smtp-Source: AB8JxZokRZ5ceVm4SwWK24lzIdza9pl8uqSBnUsORJ7/Y26JjfBWGKD+4CFVxT5EiYOXqXAWbYUx X-Received: by 2002:a17:902:2d24:: with SMTP id o33-v6mr17599364plb.14.1526446903547; Tue, 15 May 2018 22:01:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526446903; cv=none; d=google.com; s=arc-20160816; b=qiSGU8OU2CLfOx9qgd6STbP9h28wsphH7txkfjJCJSel8WMsdKVsGdGhNpB8br1dif i0MHDqCqxSV7IoNQP+iscU4kc2Xdcsz/xUS8nGfOOc5l2+/TfdT3XMBt7mJ0Z/lDFELd LCPhoke8F20HilU1TkOK3+IfU7rdFK3b6Lsbh4LhFzvKq9ziwE+1Qt+wLVG7CivOF/Th qPsQMguQ5goDBEpgeF0OkveC+7Dg10a3pMRe5OWvi25aLjOyOvKkKB7iReYM6qI/+pW2 4d9XxX+DDnxCLJGSBQMHzVMFmxSni+2vF4TG54mRbS2I5QaDToSnZXh3wqGjfaZFH5yL 6Fjg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:arc-authentication-results; bh=MGkoXoYL2LicwfJ6OWBk0K/23UljRvHk0VBWIFhcBAs=; b=jv8uCB4VSdFmjnl+Tz8yAzrleWUM5Sjs7ykEchDHZa0MJOssGALMVKyiBK4dgaQY/n Ozd9YX0AySs4S19t5Qcwqo/NQY0zllYvpEb36qBN0kx9sNt5O1wMh0iRR4y/me0nfBKO aMza93aSB4lKH5vhIwGzs0YrABjZVRicDYy4/P8m1vyAhLov7gtbcKoPrwDu3g00n5QZ g6kl5sg9W8DAQFkGOSynvZtLGWb4KDM3wZoDzVJU+yaiokqzyyVsKWh3ErJRzIEwRUld 5HRzFhG1QLPErvDcCeN8O+mAdHYW8aPW7JtVCAsByvdg+di3JTbFR8BxaF/qQUx3HdO+ p4TQ== 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=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z62-v6si1364961pgd.172.2018.05.15.22.01.28; Tue, 15 May 2018 22:01:43 -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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751595AbeEPFBR (ORCPT + 99 others); Wed, 16 May 2018 01:01:17 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:40824 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1750992AbeEPFBQ (ORCPT ); Wed, 16 May 2018 01:01:16 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8EA07400E9BA; Wed, 16 May 2018 05:01:15 +0000 (UTC) Received: from [10.72.12.133] (ovpn-12-133.pek2.redhat.com [10.72.12.133]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DF594AFD62; Wed, 16 May 2018 05:01:07 +0000 (UTC) Subject: Re: [RFC v3 4/5] virtio_ring: add event idx support in packed ring To: Tiwei Bie , mst@redhat.com, virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org Cc: wexu@redhat.com, jfreimann@redhat.com References: <20180425051550.24342-1-tiwei.bie@intel.com> <20180425051550.24342-5-tiwei.bie@intel.com> From: Jason Wang Message-ID: <915efeaa-4e47-9004-a722-54b0c40ebcbb@redhat.com> Date: Wed, 16 May 2018 13:01:04 +0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 In-Reply-To: <20180425051550.24342-5-tiwei.bie@intel.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Wed, 16 May 2018 05:01:15 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Wed, 16 May 2018 05:01:15 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'jasowang@redhat.com' RCPT:'' Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2018年04月25日 13:15, Tiwei Bie wrote: > This commit introduces the event idx support in packed > ring. This feature is temporarily disabled, because the > implementation in this patch may not work as expected, > and some further discussions on the implementation are > needed, e.g. do we have to check the wrap counter when > checking whether a kick is needed? > > Signed-off-by: Tiwei Bie > --- > drivers/virtio/virtio_ring.c | 53 ++++++++++++++++++++++++++++++++++++++++---- > 1 file changed, 49 insertions(+), 4 deletions(-) > > diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c > index 0181e93897be..b1039c2985b9 100644 > --- a/drivers/virtio/virtio_ring.c > +++ b/drivers/virtio/virtio_ring.c > @@ -986,7 +986,7 @@ static inline int virtqueue_add_packed(struct virtqueue *_vq, > static bool virtqueue_kick_prepare_packed(struct virtqueue *_vq) > { > struct vring_virtqueue *vq = to_vvq(_vq); > - u16 flags; > + u16 new, old, off_wrap, flags; > bool needs_kick; > u32 snapshot; > > @@ -995,7 +995,12 @@ static bool virtqueue_kick_prepare_packed(struct virtqueue *_vq) > * suppressions. */ > virtio_mb(vq->weak_barriers); > > + old = vq->next_avail_idx - vq->num_added; > + new = vq->next_avail_idx; > + vq->num_added = 0; > + > snapshot = *(u32 *)vq->vring_packed.device; > + off_wrap = virtio16_to_cpu(_vq->vdev, snapshot & 0xffff); > flags = cpu_to_virtio16(_vq->vdev, snapshot >> 16) & 0x3; > > #ifdef DEBUG > @@ -1006,7 +1011,10 @@ static bool virtqueue_kick_prepare_packed(struct virtqueue *_vq) > vq->last_add_time_valid = false; > #endif > > - needs_kick = (flags != VRING_EVENT_F_DISABLE); > + if (flags == VRING_EVENT_F_DESC) > + needs_kick = vring_need_event(off_wrap & ~(1<<15), new, old); > + else > + needs_kick = (flags != VRING_EVENT_F_DISABLE); > END_USE(vq); > return needs_kick; > } > @@ -1116,6 +1124,15 @@ static void *virtqueue_get_buf_ctx_packed(struct virtqueue *_vq, > if (vq->last_used_idx >= vq->vring_packed.num) > vq->last_used_idx -= vq->vring_packed.num; > > + /* If we expect an interrupt for the next entry, tell host > + * by writing event index and flush out the write before > + * the read in the next get_buf call. */ > + if (vq->event_flags_shadow == VRING_EVENT_F_DESC) > + virtio_store_mb(vq->weak_barriers, > + &vq->vring_packed.driver->off_wrap, > + cpu_to_virtio16(_vq->vdev, vq->last_used_idx | > + (vq->wrap_counter << 15))); > + > #ifdef DEBUG > vq->last_add_time_valid = false; > #endif > @@ -1143,10 +1160,17 @@ static unsigned virtqueue_enable_cb_prepare_packed(struct virtqueue *_vq) > > /* We optimistically turn back on interrupts, then check if there was > * more to do. */ > + /* Depending on the VIRTIO_RING_F_USED_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. */ > + > + vq->vring_packed.driver->off_wrap = cpu_to_virtio16(_vq->vdev, > + vq->last_used_idx | (vq->wrap_counter << 15)); Using vq->wrap_counter seems not correct, what we need is the warp counter for the last_used_idx not next_avail_idx. And I think there's even no need to bother with event idx here, how about just set VRING_EVENT_F_ENABLE? > > if (vq->event_flags_shadow == VRING_EVENT_F_DISABLE) { > virtio_wmb(vq->weak_barriers); > - vq->event_flags_shadow = VRING_EVENT_F_ENABLE; > + 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); > } > @@ -1172,15 +1196,34 @@ static bool virtqueue_poll_packed(struct virtqueue *_vq, unsigned last_used_idx) > 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_USED_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. */ > + > + /* TODO: tune this threshold */ > + bufs = (u16)(vq->next_avail_idx - vq->last_used_idx) * 3 / 4; bufs could be more than vq->num here, is this intended? > + > + used_idx = vq->last_used_idx + bufs; > + wrap_counter = vq->wrap_counter; > + > + if (used_idx >= vq->vring_packed.num) { > + used_idx -= vq->vring_packed.num; > + wrap_counter ^= 1; When used_idx is greater or equal vq->num, there's no need to flip warp_counter bit since it should match next_avail_idx. And we need also care about the case when next_avail wraps but used_idx not. so we probaly need: else if (vq->next_avail_idx < used_idx) {     wrap_counter ^= 1; } I think maybe it's time to add some sample codes in the spec to avoid duplicating the efforts(bugs). Thanks > + } > + > + 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) { > virtio_wmb(vq->weak_barriers); > - vq->event_flags_shadow = VRING_EVENT_F_ENABLE; > + 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); > } > @@ -1822,8 +1865,10 @@ void vring_transport_features(struct virtio_device *vdev) > switch (i) { > case VIRTIO_RING_F_INDIRECT_DESC: > break; > +#if 0 > case VIRTIO_RING_F_EVENT_IDX: > break; > +#endif > case VIRTIO_F_VERSION_1: > break; > case VIRTIO_F_IOMMU_PLATFORM: