From patchwork Sat Feb 20 07:54:42 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Denis V. Lunev" X-Patchwork-Id: 8365941 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id E61C49F38B for ; Sat, 20 Feb 2016 07:55:14 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 3E03F20513 for ; Sat, 20 Feb 2016 07:55:14 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 6DC2420511 for ; Sat, 20 Feb 2016 07:55:13 +0000 (UTC) Received: from localhost ([::1]:58977 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aX2Nk-0008BQ-Tg for patchwork-qemu-devel@patchwork.kernel.org; Sat, 20 Feb 2016 02:55:12 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53899) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aX2Na-00088h-F7 for qemu-devel@nongnu.org; Sat, 20 Feb 2016 02:55:03 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aX2NY-0003iK-2q for qemu-devel@nongnu.org; Sat, 20 Feb 2016 02:55:02 -0500 Received: from mailhub.sw.ru ([195.214.232.25]:20255 helo=relay.sw.ru) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aX2NX-0003hE-Jj for qemu-devel@nongnu.org; Sat, 20 Feb 2016 02:54:59 -0500 Received: from irbis.sw.ru ([10.30.2.139]) by relay.sw.ru (8.13.4/8.13.4) with ESMTP id u1K7sh8O029634; Sat, 20 Feb 2016 10:54:47 +0300 (MSK) From: "Denis V. Lunev" To: Date: Sat, 20 Feb 2016 10:54:42 +0300 Message-Id: <1455954883-28858-2-git-send-email-den@openvz.org> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1455954883-28858-1-git-send-email-den@openvz.org> References: <1455954883-28858-1-git-send-email-den@openvz.org> X-detected-operating-system: by eggs.gnu.org: OpenBSD 3.x X-Received-From: 195.214.232.25 Cc: Igor Redko , "Michael S. Tsirkin" , qemu-devel@nongnu.org, "Denis V. Lunev" Subject: [Qemu-devel] [PATCH 1/2] virtio-balloon: export all balloon statistics 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Igor Redko We are making experiments with different autoballooning strategies based on the guest behavior. Thus we need to experiment with different guest statistics. For now every counter change requires QEMU recompilation and dances with Libvirt. This patch introduces transport for unrecognized counters in virtio-balloon. This transport can be used for measuring benefits from using new balloon counters, before submitting any patches. Current alternative is 'guest-exec' transport which isn't made for such delicate matters and can influence test results. Originally all counters with tag >= VIRTIO_BALLOON_S_NR were ignored. Instead of this we keep first (VIRTIO_BALLOON_S_NR + 32) counters from the queue and pass unrecognized ones with the following names: 'x-stat-XXXX', where XXXX is a tag number in hex. Defined counters are reported with their regular names. Signed-off-by: Igor Redko Signed-off-by: Denis V. Lunev CC: Michael S. Tsirkin --- hw/virtio/virtio-balloon.c | 30 ++++++++++++++++++++++++------ include/hw/virtio/virtio-balloon.h | 3 ++- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/hw/virtio/virtio-balloon.c b/hw/virtio/virtio-balloon.c index a382f43..cc551a3 100644 --- a/hw/virtio/virtio-balloon.c +++ b/hw/virtio/virtio-balloon.c @@ -66,8 +66,7 @@ static const char *balloon_stat_names[] = { */ static inline void reset_stats(VirtIOBalloon *dev) { - int i; - for (i = 0; i < VIRTIO_BALLOON_S_NR; dev->stats[i++] = -1); + dev->stats_cnt = 0; } static bool balloon_stats_supported(const VirtIOBalloon *s) @@ -133,12 +132,20 @@ static void balloon_stats_get_all(Object *obj, Visitor *v, const char *name, if (err) { goto out_end; } - for (i = 0; i < VIRTIO_BALLOON_S_NR; i++) { - visit_type_uint64(v, balloon_stat_names[i], &s->stats[i], &err); + for (i = 0; !err && i < s->stats_cnt; i++) { + if (s->stats[i].tag < VIRTIO_BALLOON_S_NR) { + visit_type_uint64(v, balloon_stat_names[s->stats[i].tag], + &s->stats[i].val, &err); + } else { + gchar *str = g_strdup_printf("x-stat-%04x", s->stats[i].tag); + visit_type_uint64(v, str, &s->stats[i].val, &err); + g_free(str); + } if (err) { break; } } + error_propagate(errp, err); err = NULL; visit_end_struct(v, &err); @@ -273,10 +280,21 @@ static void virtio_balloon_receive_stats(VirtIODevice *vdev, VirtQueue *vq) == sizeof(stat)) { uint16_t tag = virtio_tswap16(vdev, stat.tag); uint64_t val = virtio_tswap64(vdev, stat.val); + int i; offset += sizeof(stat); - if (tag < VIRTIO_BALLOON_S_NR) - s->stats[tag] = val; + for (i = 0; i < s->stats_cnt; i++) { + if (s->stats[i].tag == tag) { + break; + } + } + if (i < ARRAY_SIZE(s->stats)) { + s->stats[i].tag = tag; + s->stats[i].val = val; + if (s->stats_cnt <= i) { + s->stats_cnt = i + 1; + } + } } s->stats_vq_offset = offset; diff --git a/include/hw/virtio/virtio-balloon.h b/include/hw/virtio/virtio-balloon.h index 35f62ac..5c8730e 100644 --- a/include/hw/virtio/virtio-balloon.h +++ b/include/hw/virtio/virtio-balloon.h @@ -36,7 +36,8 @@ typedef struct VirtIOBalloon { VirtQueue *ivq, *dvq, *svq; uint32_t num_pages; uint32_t actual; - uint64_t stats[VIRTIO_BALLOON_S_NR]; + VirtIOBalloonStatModern stats[VIRTIO_BALLOON_S_NR + 32]; + uint16_t stats_cnt; VirtQueueElement *stats_vq_elem; size_t stats_vq_offset; QEMUTimer *stats_timer;