From patchwork Wed Oct 28 15:39:00 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 56308 Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id n9SFfStr010343 for ; Wed, 28 Oct 2009 15:41:28 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754434AbZJ1PlV (ORCPT ); Wed, 28 Oct 2009 11:41:21 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1754437AbZJ1PlV (ORCPT ); Wed, 28 Oct 2009 11:41:21 -0400 Received: from mx1.redhat.com ([209.132.183.28]:32259 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754388AbZJ1PlU (ORCPT ); Wed, 28 Oct 2009 11:41:20 -0400 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id n9SFfNIg017957; Wed, 28 Oct 2009 11:41:23 -0400 Received: from redhat.com (vpn-6-118.tlv.redhat.com [10.35.6.118]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with SMTP id n9SFfIQq029889; Wed, 28 Oct 2009 11:41:19 -0400 Date: Wed, 28 Oct 2009 17:39:00 +0200 From: "Michael S. Tsirkin" To: Shirley Ma Cc: Sridhar Samudrala , Shirley Ma , David Stevens , kvm@vger.kernel.org, sri@linux.vnet.ibm.com, mashirle@linux.vnet.ibm.com Subject: Re: vhost-net patches Message-ID: <20091028153859.GA28926@redhat.com> References: <20091023110438.GA20229@redhat.com> <1256310168.4443.2.camel@localhost.localdomain> <1256310765.4443.4.camel@localhost.localdomain> <1256315020.4443.12.camel@localhost.localdomain> <20091026200513.GA26623@redhat.com> <1256592889.10142.8.camel@localhost.localdomain> <20091027064302.GB26914@redhat.com> <1256654819.4753.6.camel@localhost.localdomain> <20091027152753.GA4622@redhat.com> <1256661378.6745.2.camel@localhost.localdomain> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <1256661378.6745.2.camel@localhost.localdomain> User-Agent: Mutt/1.5.19 (2009-01-05) X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org diff --git a/drivers/vhost/net.c b/drivers/vhost/net.c index a140dad..e830b30 100644 --- a/drivers/vhost/net.c +++ b/drivers/vhost/net.c @@ -106,22 +106,41 @@ static void handle_tx(struct vhost_net *net) .msg_flags = MSG_DONTWAIT, }; size_t len, total_len = 0; - int err; + int err, wmem; size_t hdr_size; struct socket *sock = rcu_dereference(vq->private_data); - if (!sock || !sock_writeable(sock->sk)) + if (!sock) + return; + + wmem = atomic_read(&sock->sk->sk_wmem_alloc); + if (wmem >= sock->sk->sk_sndbuf) return; use_mm(net->dev.mm); mutex_lock(&vq->mutex); - tx_poll_stop(net); + vhost_no_notify(vq); + + if (wmem >= sock->sk->sk_sndbuf * 3 / 4) { + //tx_poll_start(net); + } else { + //tx_poll_stop(net); + } hdr_size = vq->hdr_size; for (;;) { head = vhost_get_vq_desc(&net->dev, vq, vq->iov, &out, &in); /* Nothing new? Wait for eventfd to tell us they refilled. */ - if (head == vq->num) + if (head == vq->num) { + wmem = atomic_read(&sock->sk->sk_wmem_alloc); + if (wmem >= sock->sk->sk_sndbuf * 3 / 4) { + set_bit(SOCK_ASYNC_NOSPACE, &sock->flags); + break; + } + if (vhost_notify(vq)) { + continue; + } break; + } if (in) { vq_err(vq, "Unexpected descriptor format for TX: " "out %d, int %d\n", out, in); diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c index 30708c6..67bfc08 100644 --- a/drivers/vhost/vhost.c +++ b/drivers/vhost/vhost.c @@ -775,7 +775,7 @@ void vhost_no_notify(struct vhost_virtqueue *vq) int vhost_init(void) { - vhost_workqueue = create_workqueue("vhost"); + vhost_workqueue = create_singlethread_workqueue("vhost"); if (!vhost_workqueue) return -ENOMEM; return 0;