xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Andres Lagar-Cavilla <andres@lagarcavilla.org>
To: xen-devel@lists.xensource.com
Cc: ian.campbell@citrix.com, andres@gridcentric.ca, tim@xen.org,
	keir.xen@gmail.com, JBeulich@suse.com, ian.jackson@citrix.com,
	adin@gridcentric.ca
Subject: [PATCH 12 of 13] Memshrtool: tool to test and exercise the sharing subsystem
Date: Wed, 25 Jan 2012 22:32:36 -0500	[thread overview]
Message-ID: <88856b776fcfc5b3d0ce.1327548756@xdev.gridcentric.ca> (raw)
In-Reply-To: <patchbomb.1327548744@xdev.gridcentric.ca>

 tools/tests/mem-sharing/Makefile     |   26 +++++
 tools/tests/mem-sharing/memshrtool.c |  165 +++++++++++++++++++++++++++++++++++
 2 files changed, 191 insertions(+), 0 deletions(-)


This is demo code meant to showcase how to perform sharing
operations. It is useful for testing. We submit it so others in
the list can have unlimited sharing fun, but not necessarily
expecting it be added to the tree.

Signed-off-by: Adin Scannell <adin@scannell.ca>
Signed-off-by: Andres Lagar-Cavilla <andres@lagarcavilla.org>

diff -r 4cefca5789b1 -r 88856b776fcf tools/tests/mem-sharing/Makefile
--- /dev/null
+++ b/tools/tests/mem-sharing/Makefile
@@ -0,0 +1,26 @@
+XEN_ROOT=$(CURDIR)/../../..
+include $(XEN_ROOT)/tools/Rules.mk
+
+CFLAGS += -Werror
+
+CFLAGS += $(CFLAGS_libxenctrl)
+CFLAGS += $(CFLAGS_xeninclude)
+
+TARGETS-y := 
+TARGETS-$(CONFIG_X86) += memshrtool
+TARGETS := $(TARGETS-y)
+
+.PHONY: all
+all: build
+
+.PHONY: build
+build: $(TARGETS)
+
+.PHONY: clean
+clean:
+	$(RM) *.o $(TARGETS) *~ $(DEPS)
+
+memshrtool: memshrtool.o
+	$(CC) -o $@ $< $(LDFLAGS) $(LDLIBS_libxenctrl)
+
+-include $(DEPS)
diff -r 4cefca5789b1 -r 88856b776fcf tools/tests/mem-sharing/memshrtool.c
--- /dev/null
+++ b/tools/tests/mem-sharing/memshrtool.c
@@ -0,0 +1,165 @@
+/*
+ * memshrtool.c
+ *
+ * Copyright 2011 GridCentric Inc. (Adin Scannell, Andres Lagar-Cavilla)
+ */
+
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <string.h>
+#include <sys/mman.h>
+
+#include "xenctrl.h"
+
+static int usage(const char* prog)
+{
+    printf("usage: %s <command> [args...]\n", prog);
+    printf("where <command> may be:\n");
+    printf("  info                    - Display total sharing info.\n");
+    printf("  enable                  - Enable sharing on a domain.\n");
+    printf("  disable                 - Disable sharing on a domain.\n");
+    printf("  nominate <domid> <gfn>  - Nominate a page for sharing.\n");
+    printf("  share <domid> <gfn> <handle> <source> <source-gfn> <source-handle>\n");
+    printf("                          - Share two pages.\n");
+    printf("  unshare <domid> <gfn>   - Unshare a page by grabbing a writable map.\n");
+    printf("  add-to-physmap <domid> <gfn> <source> <source-gfn> <source-handle>\n");
+    printf("                          - Populate a page in a domain with a shared page.\n");
+    printf("  debug-gfn <domid> <gfn> - Debug a particular domain and gfn.\n");
+    return 1;
+}
+
+#define R(f) do { \
+    int rc = f; \
+    if ( rc < 0 ) { \
+        printf("error executing %s: %s\n", #f, \
+                ((errno * -1) == XEN_DOMCTL_MEM_SHARING_C_HANDLE_INVALID) ? \
+                "problem with client handle" :\
+                ((errno * -1) == XEN_DOMCTL_MEM_SHARING_S_HANDLE_INVALID) ? \
+                "problem with source handle" : strerror(errno)); \
+        return rc; \
+    } \
+} while(0)
+
+int main(int argc, const char** argv)
+{
+    const char* cmd = NULL;
+    xc_interface *xch = xc_interface_open(0, 0, 0);
+
+    if( argc < 2 )
+        return usage(argv[0]);
+
+    cmd = argv[1];
+
+    if( !strcasecmp(cmd, "info") )
+    {
+        if( argc != 2 )
+            return usage(argv[0]);
+
+        printf("used = %ld\n", xc_sharing_used_frames(xch));
+        printf("freed = %ld\n", xc_sharing_freed_pages(xch));
+    }
+    else if( !strcasecmp(cmd, "enable") )
+    {
+        domid_t domid;
+
+        if( argc != 3 )
+            return usage(argv[0]);
+
+        domid = strtol(argv[2], NULL, 0);
+        R(xc_memshr_control(xch, domid, 1));
+    }
+    else if( !strcasecmp(cmd, "disable") )
+    {
+        domid_t domid;
+
+        if( argc != 3 )
+            return usage(argv[0]);
+
+        domid = strtol(argv[2], NULL, 0);
+        R(xc_memshr_control(xch, domid, 0));
+    }
+    else if( !strcasecmp(cmd, "nominate") )
+    {
+        domid_t domid;
+        unsigned long gfn;
+        uint64_t handle;
+
+        if( argc != 4 )
+            return usage(argv[0]);
+
+        domid = strtol(argv[2], NULL, 0);
+        gfn = strtol(argv[3], NULL, 0);
+        R(xc_memshr_nominate_gfn(xch, domid, gfn, &handle));
+        printf("handle = 0x%08llx\n", (unsigned long long) handle);
+    }
+    else if( !strcasecmp(cmd, "share") )
+    {
+        domid_t domid;
+        unsigned long gfn;
+        uint64_t handle;
+        domid_t source_domid;
+        unsigned long source_gfn;
+        uint64_t source_handle;
+
+        if( argc != 8 )
+            return usage(argv[0]);
+
+        domid = strtol(argv[2], NULL, 0);
+        gfn = strtol(argv[3], NULL, 0);
+        handle = strtol(argv[4], NULL, 0);
+        source_domid = strtol(argv[5], NULL, 0);
+        source_gfn = strtol(argv[6], NULL, 0);
+        source_handle = strtol(argv[7], NULL, 0);
+        R(xc_memshr_share_gfns(xch, source_domid, source_gfn, source_handle, domid, gfn, handle));
+    }
+    else if( !strcasecmp(cmd, "unshare") )
+    {
+        domid_t domid;
+        unsigned long gfn;
+        void *map;
+
+        if( argc != 4 )
+            return usage(argv[0]);
+
+        domid = strtol(argv[2], NULL, 0);
+        gfn = strtol(argv[3], NULL, 0);
+        map = xc_map_foreign_range(xch, domid, 4096, PROT_WRITE, gfn);
+        if( map )
+            munmap(map, 4096);
+        R((int)!map);
+    }
+    else if( !strcasecmp(cmd, "add-to-physmap") )
+    {
+        domid_t domid;
+        unsigned long gfn;
+        domid_t source_domid;
+        unsigned long source_gfn;
+        uint64_t source_handle;
+
+        if( argc != 7 )
+            return usage(argv[0]);
+
+        domid = strtol(argv[2], NULL, 0);
+        gfn = strtol(argv[3], NULL, 0);
+        source_domid = strtol(argv[4], NULL, 0);
+        source_gfn = strtol(argv[5], NULL, 0);
+        source_handle = strtol(argv[6], NULL, 0);
+        R(xc_memshr_add_to_physmap(xch, source_domid, source_gfn, source_handle, domid, gfn));
+    }
+    else if( !strcasecmp(cmd, "debug-gfn") )
+    {
+        domid_t domid;
+        unsigned long gfn;
+
+        if( argc != 4 )
+            return usage(argv[0]);
+
+        domid = strtol(argv[2], NULL, 0);
+        gfn = strtol(argv[3], NULL, 0);
+        R(xc_memshr_debug_gfn(xch, domid, gfn));
+    }
+
+    return 0;
+}

  parent reply	other threads:[~2012-01-26  3:32 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-01-26  3:32 [PATCH 00 of 13] Sharing overhaul V4 Andres Lagar-Cavilla
2012-01-26  3:32 ` [PATCH 01 of 13] x86/mm: Eliminate hash table in sharing code as index of shared mfns Andres Lagar-Cavilla
2012-01-26  3:32 ` [PATCH 02 of 13] x86/mm: Update mem sharing interface to (re)allow sharing of grants Andres Lagar-Cavilla
2012-01-26  3:32 ` [PATCH 03 of 13] x86/mm: Add per-page locking for memory sharing, when audits are disabled Andres Lagar-Cavilla
2012-01-26  3:32 ` [PATCH 04 of 13] x86/mm: Enforce lock ordering for sharing page locks Andres Lagar-Cavilla
2012-01-26  3:32 ` [PATCH 05 of 13] x86/mm: Check how many mfns are shared, in addition to how many are saved Andres Lagar-Cavilla
2012-01-26  3:32 ` [PATCH 06 of 13] x86/mm: New domctl: add a shared page to the physmap Andres Lagar-Cavilla
2012-01-26  3:32 ` [PATCH 07 of 13] Add the ability to poll stats about shared memory via the console Andres Lagar-Cavilla
2012-01-26  3:32 ` [PATCH 08 of 13] x86/mm: use RCU in mem sharing audit list, eliminate global lock completely Andres Lagar-Cavilla
2012-01-26  3:32 ` [PATCH 09 of 13] Update memshr API and tools Andres Lagar-Cavilla
2012-01-26  3:32 ` [PATCH 10 of 13] Tools: Expose to libxc the total number of shared frames and space saved Andres Lagar-Cavilla
2012-01-26  3:32 ` [PATCH 11 of 13] Tools: Add a sharing command to xl for information about shared pages Andres Lagar-Cavilla
2012-01-26  3:32 ` Andres Lagar-Cavilla [this message]
2012-01-27 18:21   ` [PATCH 12 of 13] Memshrtool: tool to test and exercise the sharing subsystem Ian Jackson
2012-01-27 18:27     ` Andres Lagar-Cavilla
2012-01-26  3:32 ` [PATCH 13 of 13] x86/mm: Sharing overhaul style improvements Andres Lagar-Cavilla
2012-01-26 12:54 ` [PATCH 00 of 13] Sharing overhaul V4 Tim Deegan
2012-01-26 13:08   ` Andres Lagar-Cavilla
2012-01-26 13:16   ` Olaf Hering

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=88856b776fcfc5b3d0ce.1327548756@xdev.gridcentric.ca \
    --to=andres@lagarcavilla.org \
    --cc=JBeulich@suse.com \
    --cc=adin@gridcentric.ca \
    --cc=andres@gridcentric.ca \
    --cc=ian.campbell@citrix.com \
    --cc=ian.jackson@citrix.com \
    --cc=keir.xen@gmail.com \
    --cc=tim@xen.org \
    --cc=xen-devel@lists.xensource.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).