On Mon, Jan 15, 2018 at 11:12:03AM +0100, Christian Schwamborn wrote:
> Is there a easy way to get/monitor the used 'grants' frames? As I understand
> it, the xen-diag tool you mentioned doesn't compile in xen 4.8?

I just gave it another try and after modifying xen-diag.c
a bit to work with 4.8 here is what I get:

  # ./xen-diag gnttab_query_size 0
  domid=0: nr_frames=4, max_nr_frames=256
  # ./xen-diag gnttab_query_size 1
  domid=1: nr_frames=11, max_nr_frames=256
  
  # ./xen-diag  gnttab_query_size 0
  domid=0: nr_frames=4, max_nr_frames=256
  # ./xen-diag  gnttab_query_size 1
  domid=1: nr_frames=11, max_nr_frames=256
  # ./xen-diag  gnttab_query_size 5
  domid=5: nr_frames=11, max_nr_frames=256

so currently at 11, not high at all.

Attaching a patch for stretch xen package if you want to check
your hosts.

-- 
Valentin
--- a/tools/misc/Makefile
+++ b/tools/misc/Makefile
@@ -31,6 +31,7 @@
 INSTALL_SBIN                   += xenpm
 INSTALL_SBIN                   += xenwatchdogd
 INSTALL_SBIN                   += xen-livepatch
+INSTALL_SBIN                   += xen-diag
 INSTALL_SBIN += $(INSTALL_SBIN-y)
 
 # Everything to be installed in a private bin/
@@ -98,6 +99,9 @@
 xen-livepatch: xen-livepatch.o
 	$(CC) $(LDFLAGS) -o $@ $< $(LDLIBS_libxenctrl) $(APPEND_LDFLAGS)
 
+xen-diag: xen-diag.o
+	$(CC) $(LDFLAGS) -o $@ $< $(LDLIBS_libxenctrl) $(APPEND_LDFLAGS)
+
 xen-lowmemd: xen-lowmemd.o
 	$(CC) $(LDFLAGS) -o $@ $< $(LDLIBS_libxenevtchn) $(LDLIBS_libxenctrl) $(LDLIBS_libxenstore) $(APPEND_LDFLAGS)
 
--- /dev/null
+++ b/tools/misc/xen-diag.c
@@ -0,0 +1,129 @@
+/*
+ * Copyright (c) 2017 Oracle and/or its affiliates. All rights reserved.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <err.h>
+#include <errno.h>
+#include <unistd.h>
+#include <string.h>
+#include <xenctrl.h>
+
+#include <xen/errno.h>
+#include <xen-tools/libs.h>
+
+static xc_interface *xch;
+
+#define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0]))
+
+void show_help(void)
+{
+    fprintf(stderr,
+            "xen-diag: xen diagnostic utility\n"
+            "Usage: xen-diag command [args]\n"
+            "Commands:\n"
+            "  help                       display this help\n"
+            "  gnttab_query_size <domid>  dump the current and max grant frames for <domid>\n");
+}
+
+/* wrapper function */
+static int help_func(int argc, char *argv[])
+{
+    show_help();
+    return 0;
+}
+
+static int gnttab_query_size_func(int argc, char *argv[])
+{
+    int domid, rc = 1;
+    struct gnttab_query_size query;
+
+    if ( argc != 1 )
+    {
+        show_help();
+        return rc;
+    }
+
+    domid = strtol(argv[0], NULL, 10);
+    query.dom = domid;
+    rc = xc_gnttab_op(xch, GNTTABOP_query_size, &query, sizeof(query), 1);
+
+    if ( rc == 0 && (query.status == GNTST_okay) )
+        printf("domid=%d: nr_frames=%d, max_nr_frames=%d\n",
+               query.dom, query.nr_frames, query.max_nr_frames);
+
+    return rc == 0 && (query.status == GNTST_okay) ? 0 : 1;
+}
+
+struct {
+    const char *name;
+    int (*function)(int argc, char *argv[]);
+} main_options[] = {
+    { "help", help_func },
+    { "gnttab_query_size", gnttab_query_size_func},
+};
+
+int main(int argc, char *argv[])
+{
+    int ret, i;
+
+    /*
+     * Set stdout to be unbuffered to avoid having to fflush when
+     * printing without a newline.
+     */
+    setvbuf(stdout, NULL, _IONBF, 0);
+
+    if ( argc <= 1 )
+    {
+        show_help();
+        return 0;
+    }
+
+    for ( i = 0; i < ARRAY_SIZE(main_options); i++ )
+        if ( !strncmp(main_options[i].name, argv[1], strlen(argv[1])) )
+            break;
+
+    if ( i == ARRAY_SIZE(main_options) )
+    {
+        show_help();
+        return 0;
+    }
+    else
+    {
+        xch = xc_interface_open(0, 0, 0);
+        if ( !xch )
+        {
+            fprintf(stderr, "failed to get the handler\n");
+            return 0;
+        }
+
+        ret = main_options[i].function(argc - 2, argv + 2);
+
+        xc_interface_close(xch);
+    }
+
+    /*
+     * Exitcode 0 for success.
+     * Exitcode 1 for an error.
+     * Exitcode 2 if the operation should be retried for any reason (e.g. a
+     * timeout or because another operation was in progress).
+     */
+
+#define EXIT_TIMEOUT (EXIT_FAILURE + 1)
+
+    BUILD_BUG_ON(EXIT_SUCCESS != 0);
+    BUILD_BUG_ON(EXIT_FAILURE != 1);
+    BUILD_BUG_ON(EXIT_TIMEOUT != 2);
+
+    switch ( ret )
+    {
+    case 0:
+        return EXIT_SUCCESS;
+    case EAGAIN:
+    case EBUSY:
+        return EXIT_TIMEOUT;
+    default:
+        return EXIT_FAILURE;
+    }
+}

Reply via email to