Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp1967046imm; Wed, 16 May 2018 06:00:08 -0700 (PDT) X-Google-Smtp-Source: AB8JxZo9LeNU+D9/im4m/239G9OhUDh+XBSygvoG1PPtKBmlCB34fp3XxAg/jwaUynyJ/40dXt1P X-Received: by 2002:a17:902:822:: with SMTP id 31-v6mr891106plk.172.1526475608388; Wed, 16 May 2018 06:00:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526475608; cv=none; d=google.com; s=arc-20160816; b=iVyJlIqieJlm+AtgaeOQwlX3WUn9bh/eEzXlLEDMN1tpCC0W29jgJO9t+EXFUst5hr RtiajO7zCjNmftArXrlLjtSgTrRUOw/U6JT3NB8JM+wv7zpmJb7uGEhGAaayM+bt7PfH 1SqR9OED6pWYK4XFLSRdi0xo3qTwzlSWUzFwJah5m0CUsQ+rxA6afH3Rfv7MeN8MPdSS M200iLWIzLZkLoQbWcvm4em4c4tr+gv4v2tETVStZOd/bT1OvPgL/quczyOVPW5TU7V0 ROl1yhcpF8etpgp0dj4ttoyluR7U0dhwKUNlpEVCcA/0i4EHIGWIt4VrwhOMyNHKTWSa V3kQ== 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=nKlZRS/xvXn8tOOdyo9OOfVT3M4D4tDmvDETN4qM99Y=; b=WTCQ55J3B7aswN8lMMagXSwRjj1ck/XG4eBWccU0CsamZAT/w0c7C9bM4hKzb6Rdis M0FDZy6x3LomSvRKie/bNaDNSRAzJBxLvomtcL+Nrd4qw6+BAETp9BCy4+IsmXMKYRAk B3StL8FF/iEml9V97vh5eohM5F0oDtTuQ3fs0PRc2NXZmr4tYlyx7q5KrSOL11A3360R wVipNCERFPBW/aunjNcp+9T4Z8zhMeYRBMfOi6FlPRK7ZAjVHAeghbyTb+XUAm2/Pnhd gGOPTe7S2VQeWsf+aXC/TB+H2Z6/eZMCI3GXi4iRFCsllcPx49+Tbxp1BVC14QDOHQ1G PP6A== 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 r4-v6si2013137pgt.613.2018.05.16.05.59.54; Wed, 16 May 2018 06:00:08 -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 S1752894AbeEPM6E (ORCPT + 99 others); Wed, 16 May 2018 08:58:04 -0400 Received: from mga07.intel.com ([134.134.136.100]:30347 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752414AbeEPM6A (ORCPT ); Wed, 16 May 2018 08:58:00 -0400 X-Amp-Result: UNSCANNABLE X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 16 May 2018 05:58:00 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.49,390,1520924400"; d="scan'208";a="224698142" Received: from debian.sh.intel.com (HELO debian) ([10.67.104.203]) by orsmga005.jf.intel.com with ESMTP; 16 May 2018 05:57:58 -0700 Date: Wed, 16 May 2018 20:58:25 +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 v4 4/5] virtio_ring: add event idx support in packed ring Message-ID: <20180516125825.GA4171@debian> References: <20180516083737.26504-1-tiwei.bie@intel.com> <20180516083737.26504-5-tiwei.bie@intel.com> <64f5085b-4b62-d545-36e0-0951c11b29a8@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <64f5085b-4b62-d545-36e0-0951c11b29a8@redhat.com> 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 Wed, May 16, 2018 at 08:17:21PM +0800, Jason Wang wrote: > On 2018年05月16日 16:37, Tiwei Bie wrote: [...] > > @@ -1160,15 +1186,27 @@ static void virtqueue_disable_cb_packed(struct virtqueue *_vq) > > static unsigned virtqueue_enable_cb_prepare_packed(struct virtqueue *_vq) > > { > > struct vring_virtqueue *vq = to_vvq(_vq); > > + u16 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. */ > > + > > + wrap_counter = vq->wrap_counter; > > + if (vq->last_used_idx > vq->next_avail_idx) > > Should this be ">=" consider rx refill may try to completely fill the ring? It seems that there are two cases that last_used_idx equals to next_avail_idx. The first one is that the ring is empty. And the second one is that the ring is full. Although in the first case, most probably, the driver won't enable the interrupt. Maybe I really should track the used_wrap_counter instead of calculating it each time I need it.. I'll give it a try.. > > > + wrap_counter ^= 1; > > + > > + vq->vring_packed.driver->off_wrap = cpu_to_virtio16(_vq->vdev, > > + vq->last_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); > > } > > @@ -1194,15 +1232,40 @@ 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 */ > > + 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; > > + > > + wrap_counter = vq->wrap_counter; > > + if (vq->last_used_idx > vq->next_avail_idx) > > + wrap_counter ^= 1; > > + > > + used_idx = vq->last_used_idx + bufs; > > + if (used_idx >= vq->vring_packed.num) { > > + used_idx -= vq->vring_packed.num; > > + wrap_counter ^= 1; > > + } > > Looks correct but maybe it's better to add some comments for such logic. Make sense. > > > + > > + 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); > > } > > @@ -1869,8 +1932,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 > > Maybe it's time to remove this #if 0. Will do it. Thanks for the review! Best regards, Tiwei Bie