[1/1] virtio-balloon: export all balloon statistics
diff mbox

Message ID 1464682467-31040-1-git-send-email-den@openvz.org
State New
Headers show

Commit Message

Denis V. Lunev May 31, 2016, 8:14 a.m. UTC
From: Igor Redko <redkoi@virtuozzo.com>

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 <redkoi@virtuozzo.com>
Signed-off-by: Denis V. Lunev <den@openvz.org>
CC: Michael S. Tsirkin <mst@redhat.com>
---
 configure                          | 12 ++++++++++++
 hw/virtio/virtio-balloon.c         | 31 +++++++++++++++++++++++++------
 include/hw/virtio/virtio-balloon.h |  3 ++-
 3 files changed, 39 insertions(+), 7 deletions(-)

Comments

Denis V. Lunev June 7, 2016, 10:34 a.m. UTC | #1
On 05/31/2016 11:14 AM, Denis V. Lunev wrote:
> From: Igor Redko <redkoi@virtuozzo.com>
>
> 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 <redkoi@virtuozzo.com>
> Signed-off-by: Denis V. Lunev <den@openvz.org>
> CC: Michael S. Tsirkin <mst@redhat.com>
> ---
>   configure                          | 12 ++++++++++++
>   hw/virtio/virtio-balloon.c         | 31 +++++++++++++++++++++++++------
>   include/hw/virtio/virtio-balloon.h |  3 ++-
>   3 files changed, 39 insertions(+), 7 deletions(-)
>
> diff --git a/configure b/configure
> index b5aab72..3c3fc9a 100755
> --- a/configure
> +++ b/configure
> @@ -320,6 +320,7 @@ vhdx=""
>   numa=""
>   tcmalloc="no"
>   jemalloc="no"
> +unknown_balloon_stats="no"
>   
>   # parse CC options first
>   for opt do
> @@ -1147,6 +1148,10 @@ for opt do
>     ;;
>     --enable-jemalloc) jemalloc="yes"
>     ;;
> +  --enable-unknown-balloon-stats) unknown_balloon_stats="yes"
> +  ;;
> +  --disable-unknown-balloon-stats) unknown_balloon_stats="no"
> +  ;;
>     *)
>         echo "ERROR: unknown option $opt"
>         echo "Try '$0 --help' for more information"
> @@ -1369,6 +1374,8 @@ disabled with --disable-FEATURE, default is enabled if available:
>     numa            libnuma support
>     tcmalloc        tcmalloc support
>     jemalloc        jemalloc support
> +  unknown-balloon-stats  report unknown balloon statistics counters
> +  ;;
>   
>   NOTE: The object files are built at the place where configure is launched
>   EOF
> @@ -4884,6 +4891,7 @@ echo "NUMA host support $numa"
>   echo "tcmalloc support  $tcmalloc"
>   echo "jemalloc support  $jemalloc"
>   echo "avx2 optimization $avx2_opt"
> +echo "unknown balloon stat counters support  $unknown_balloon_stats"
>   
>   if test "$sdl_too_old" = "yes"; then
>   echo "-> Your SDL version is too old - please upgrade to have SDL support"
> @@ -5461,6 +5469,10 @@ if test "$rdma" = "yes" ; then
>     echo "CONFIG_RDMA=y" >> $config_host_mak
>   fi
>   
> +if test "$unknown_balloon_stats" = "yes" ; then
> +  echo "CONFIG_UNKNOWN_BALLOON_STATS=y" >> $config_host_mak
> +fi
> +
>   # Hold two types of flag:
>   #   CONFIG_THREAD_SETNAME_BYTHREAD  - we've got a way of setting the name on
>   #                                     a thread we have a handle to
> diff --git a/hw/virtio/virtio-balloon.c b/hw/virtio/virtio-balloon.c
> index 8c15e09..840101f 100644
> --- a/hw/virtio/virtio-balloon.c
> +++ b/hw/virtio/virtio-balloon.c
> @@ -68,8 +68,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)
> @@ -135,8 +134,17 @@ 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; 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 {
> +#if defined(CONFIG_UNKNOWN_BALLOON_STATS)
> +            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);
> +#endif
> +        }
>           if (err) {
>               goto out_nested;
>           }
> @@ -285,10 +293,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;
ping
Michael S. Tsirkin June 7, 2016, 12:30 p.m. UTC | #2
On Tue, Jun 07, 2016 at 01:34:26PM +0300, Denis V. Lunev wrote:
> On 05/31/2016 11:14 AM, Denis V. Lunev wrote:
> > From: Igor Redko <redkoi@virtuozzo.com>
> > 
> > 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.

Looks like a nice hack for your experiements, but I see relatively
little point in putting this upstream.  I might reconsider if I hear
from other developers who independently find this useful.

Patch
diff mbox

diff --git a/configure b/configure
index b5aab72..3c3fc9a 100755
--- a/configure
+++ b/configure
@@ -320,6 +320,7 @@  vhdx=""
 numa=""
 tcmalloc="no"
 jemalloc="no"
+unknown_balloon_stats="no"
 
 # parse CC options first
 for opt do
@@ -1147,6 +1148,10 @@  for opt do
   ;;
   --enable-jemalloc) jemalloc="yes"
   ;;
+  --enable-unknown-balloon-stats) unknown_balloon_stats="yes"
+  ;;
+  --disable-unknown-balloon-stats) unknown_balloon_stats="no"
+  ;;
   *)
       echo "ERROR: unknown option $opt"
       echo "Try '$0 --help' for more information"
@@ -1369,6 +1374,8 @@  disabled with --disable-FEATURE, default is enabled if available:
   numa            libnuma support
   tcmalloc        tcmalloc support
   jemalloc        jemalloc support
+  unknown-balloon-stats  report unknown balloon statistics counters
+  ;;
 
 NOTE: The object files are built at the place where configure is launched
 EOF
@@ -4884,6 +4891,7 @@  echo "NUMA host support $numa"
 echo "tcmalloc support  $tcmalloc"
 echo "jemalloc support  $jemalloc"
 echo "avx2 optimization $avx2_opt"
+echo "unknown balloon stat counters support  $unknown_balloon_stats"
 
 if test "$sdl_too_old" = "yes"; then
 echo "-> Your SDL version is too old - please upgrade to have SDL support"
@@ -5461,6 +5469,10 @@  if test "$rdma" = "yes" ; then
   echo "CONFIG_RDMA=y" >> $config_host_mak
 fi
 
+if test "$unknown_balloon_stats" = "yes" ; then
+  echo "CONFIG_UNKNOWN_BALLOON_STATS=y" >> $config_host_mak
+fi
+
 # Hold two types of flag:
 #   CONFIG_THREAD_SETNAME_BYTHREAD  - we've got a way of setting the name on
 #                                     a thread we have a handle to
diff --git a/hw/virtio/virtio-balloon.c b/hw/virtio/virtio-balloon.c
index 8c15e09..840101f 100644
--- a/hw/virtio/virtio-balloon.c
+++ b/hw/virtio/virtio-balloon.c
@@ -68,8 +68,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)
@@ -135,8 +134,17 @@  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; 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 {
+#if defined(CONFIG_UNKNOWN_BALLOON_STATS)
+            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);
+#endif
+        }
         if (err) {
             goto out_nested;
         }
@@ -285,10 +293,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;