From patchwork Wed Jul 15 12:16:48 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pankaj Gupta X-Patchwork-Id: 495810 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 44F711402AE for ; Wed, 15 Jul 2015 22:18:41 +1000 (AEST) Received: from localhost ([::1]:35708 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZFLe3-000687-3R for incoming@patchwork.ozlabs.org; Wed, 15 Jul 2015 08:18:39 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53763) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZFLcf-00048g-R2 for qemu-devel@nongnu.org; Wed, 15 Jul 2015 08:17:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZFLce-0003KG-10 for qemu-devel@nongnu.org; Wed, 15 Jul 2015 08:17:13 -0400 Received: from mx1.redhat.com ([209.132.183.28]:50679) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZFLcd-0003K8-Rs for qemu-devel@nongnu.org; Wed, 15 Jul 2015 08:17:11 -0400 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (Postfix) with ESMTPS id 91F8E2C731F for ; Wed, 15 Jul 2015 12:17:11 +0000 (UTC) Received: from dhcp223-82.pnq.redhat.com (dhcp223-74.pnq.redhat.com [10.65.223.74]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t6FCH0P1025663; Wed, 15 Jul 2015 08:17:09 -0400 From: Pankaj Gupta To: qemu-devel@nongnu.org Date: Wed, 15 Jul 2015 17:46:48 +0530 Message-Id: <1436962608-9961-3-git-send-email-pagupta@redhat.com> In-Reply-To: <1436962608-9961-1-git-send-email-pagupta@redhat.com> References: <1436962608-9961-1-git-send-email-pagupta@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: amit.shah@redhat.com, Pankaj Gupta , mst@redhat.com Subject: [Qemu-devel] [PATCH 2/2 v3] virtio-rng: Serve pending request if any after timer bumps up quota. X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org We are arming timer when we get first request from guest. Even if guest pulls all the data we will be serving guest only when timer bumps up new quota. When timer expires we check if we have a pending request from guest, we serve it and re-arm the timer else we don't do any thing. Signed-off-by: Pankaj Gupta --- hw/virtio/virtio-rng.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/hw/virtio/virtio-rng.c b/hw/virtio/virtio-rng.c index ae04352..3d9a002 100644 --- a/hw/virtio/virtio-rng.c +++ b/hw/virtio/virtio-rng.c @@ -142,9 +142,13 @@ static int virtio_rng_load(QEMUFile *f, void *opaque, int version_id) static void check_rate_limit(void *opaque) { VirtIORNG *vrng = opaque; + size_t size; vrng->quota_remaining = vrng->conf.max_bytes; - virtio_rng_process(vrng); + size = get_request_size(vrng->vq, 0); + if (size > 0) { + virtio_rng_process(vrng); + } vrng->activate_timer = true; }