[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [xen staging] tools: Move memshrtool from tests/ to misc/
commit 67848a25515353ccc67d4931bb4311e10dad0d13 Author: Andrew Cooper <andrew.cooper3@xxxxxxxxxx> AuthorDate: Tue Jan 12 18:37:53 2021 +0000 Commit: Andrew Cooper <andrew.cooper3@xxxxxxxxxx> CommitDate: Wed Jan 13 19:30:50 2021 +0000 tools: Move memshrtool from tests/ to misc/ memshrtool is a tool for a human to use, rather than a test. Move it into misc/ as a more appropriate location to live. Also rename it to xen-memshare Signed-off-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx> Acked-by: Ian Jackson <ian.jackson@xxxxxxxxxxxxx> --- .gitignore | 1 - tools/misc/.gitignore | 1 + tools/misc/Makefile | 4 + tools/misc/xen-memshare.c | 207 +++++++++++++++++++++++++++++++++++ tools/tests/Makefile | 1 - tools/tests/mem-sharing/Makefile | 31 ------ tools/tests/mem-sharing/memshrtool.c | 207 ----------------------------------- 7 files changed, 212 insertions(+), 240 deletions(-) diff --git a/.gitignore b/.gitignore index 630bdf5b99..35957cc21f 100644 --- a/.gitignore +++ b/.gitignore @@ -273,7 +273,6 @@ tools/tests/x86_emulator/test_x86_emulator tools/tests/x86_emulator/x86_emulate tools/tests/x86_emulator/xop*.[ch] tools/tests/xenstore/xs-test -tools/tests/mem-sharing/memshrtool tools/tests/mce-test/tools/xen-mceinj tools/tests/vpci/list.h tools/tests/vpci/vpci.[hc] diff --git a/tools/misc/.gitignore b/tools/misc/.gitignore index e332ed4ec7..b2c3b21f57 100644 --- a/tools/misc/.gitignore +++ b/tools/misc/.gitignore @@ -1,2 +1,3 @@ xen-access +xen-memshare xen-ucode diff --git a/tools/misc/Makefile b/tools/misc/Makefile index 612b7002e5..912c5d4f0e 100644 --- a/tools/misc/Makefile +++ b/tools/misc/Makefile @@ -22,6 +22,7 @@ INSTALL_SBIN-$(CONFIG_MIGRATE) += xen-hptool INSTALL_SBIN-$(CONFIG_X86) += xen-hvmcrash INSTALL_SBIN-$(CONFIG_X86) += xen-hvmctx INSTALL_SBIN-$(CONFIG_X86) += xen-lowmemd +INSTALL_SBIN-$(CONFIG_X86) += xen-memshare INSTALL_SBIN-$(CONFIG_X86) += xen-mfndump INSTALL_SBIN-$(CONFIG_X86) += xen-ucode INSTALL_SBIN += xencov @@ -86,6 +87,9 @@ xen-hvmctx: xen-hvmctx.o xen-hvmcrash: xen-hvmcrash.o $(CC) $(LDFLAGS) -o $@ $< $(LDLIBS_libxenctrl) $(APPEND_LDFLAGS) +xen-memshare: xen-memshare.o + $(CC) $(LDFLAGS) -o $@ $< $(LDLIBS_libxenctrl) $(APPEND_LDFLAGS) + xenperf: xenperf.o $(CC) $(LDFLAGS) -o $@ $< $(LDLIBS_libxenctrl) $(APPEND_LDFLAGS) diff --git a/tools/misc/xen-memshare.c b/tools/misc/xen-memshare.c new file mode 100644 index 0000000000..8e5e22b9e9 --- /dev/null +++ b/tools/misc/xen-memshare.c @@ -0,0 +1,207 @@ +/* + * 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> + +#define XC_WANT_COMPAT_MAP_FOREIGN_API +#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(" range <source-domid> <destination-domid> <first-gfn> <last-gfn>\n"); + printf(" - Share pages between domains in a range.\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"); + printf(" audit - Audit the sharing subsytem in Xen.\n"); + return 1; +} + +#define R(f) do { \ + int rc = f; \ + if ( rc < 0 ) { \ + printf("error executing %s: %s\n", #f, \ + ((errno * -1) == XENMEM_SHARING_OP_S_HANDLE_INVALID) ? \ + "problem with client handle" :\ + ((errno * -1) == XENMEM_SHARING_OP_C_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") ) + { + long rc; + if( argc != 2 ) + return usage(argv[0]); + + rc = xc_sharing_freed_pages(xch); + if ( rc < 0 ) + return 1; + + printf("used = %ld\n", rc); + rc = xc_sharing_used_frames(xch); + if ( rc < 0 ) + return 1; + printf("freed = %ld\n", rc); + } + 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)); + } + else if( !strcasecmp(cmd, "audit") ) + { + int rc = xc_memshr_audit(xch); + if ( rc < 0 ) + { + printf("error executing xc_memshr_audit: %s\n", strerror(errno)); + return rc; + } + printf("Audit returned %d errors.\n", rc); + } + else if( !strcasecmp(cmd, "range") ) + { + domid_t sdomid, cdomid; + int rc; + uint64_t first_gfn, last_gfn; + + if ( argc != 6 ) + return usage(argv[0]); + + sdomid = strtol(argv[2], NULL, 0); + cdomid = strtol(argv[3], NULL, 0); + first_gfn = strtoul(argv[4], NULL, 0); + last_gfn = strtoul(argv[5], NULL, 0); + + rc = xc_memshr_range_share(xch, sdomid, cdomid, first_gfn, last_gfn); + if ( rc < 0 ) + { + printf("error executing xc_memshr_range_share: %s\n", strerror(errno)); + return rc; + } + } + return 0; +} diff --git a/tools/tests/Makefile b/tools/tests/Makefile index 771715be0f..fc9b715951 100644 --- a/tools/tests/Makefile +++ b/tools/tests/Makefile @@ -4,7 +4,6 @@ include $(XEN_ROOT)/tools/Rules.mk SUBDIRS-y := SUBDIRS-$(CONFIG_X86) += cpu-policy SUBDIRS-$(CONFIG_X86) += mce-test -SUBDIRS-y += mem-sharing ifneq ($(clang),y) SUBDIRS-$(CONFIG_X86) += x86_emulator endif diff --git a/tools/tests/mem-sharing/Makefile b/tools/tests/mem-sharing/Makefile deleted file mode 100644 index 5cd96e4cc9..0000000000 --- a/tools/tests/mem-sharing/Makefile +++ /dev/null @@ -1,31 +0,0 @@ -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_RM) - -.PHONY: distclean -distclean: clean - -memshrtool: memshrtool.o - $(CC) -o $@ $< $(LDFLAGS) $(LDLIBS_libxenctrl) - --include $(DEPS_INCLUDE) - -install uninstall: diff --git a/tools/tests/mem-sharing/memshrtool.c b/tools/tests/mem-sharing/memshrtool.c deleted file mode 100644 index 8e5e22b9e9..0000000000 --- a/tools/tests/mem-sharing/memshrtool.c +++ /dev/null @@ -1,207 +0,0 @@ -/* - * 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> - -#define XC_WANT_COMPAT_MAP_FOREIGN_API -#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(" range <source-domid> <destination-domid> <first-gfn> <last-gfn>\n"); - printf(" - Share pages between domains in a range.\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"); - printf(" audit - Audit the sharing subsytem in Xen.\n"); - return 1; -} - -#define R(f) do { \ - int rc = f; \ - if ( rc < 0 ) { \ - printf("error executing %s: %s\n", #f, \ - ((errno * -1) == XENMEM_SHARING_OP_S_HANDLE_INVALID) ? \ - "problem with client handle" :\ - ((errno * -1) == XENMEM_SHARING_OP_C_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") ) - { - long rc; - if( argc != 2 ) - return usage(argv[0]); - - rc = xc_sharing_freed_pages(xch); - if ( rc < 0 ) - return 1; - - printf("used = %ld\n", rc); - rc = xc_sharing_used_frames(xch); - if ( rc < 0 ) - return 1; - printf("freed = %ld\n", rc); - } - 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)); - } - else if( !strcasecmp(cmd, "audit") ) - { - int rc = xc_memshr_audit(xch); - if ( rc < 0 ) - { - printf("error executing xc_memshr_audit: %s\n", strerror(errno)); - return rc; - } - printf("Audit returned %d errors.\n", rc); - } - else if( !strcasecmp(cmd, "range") ) - { - domid_t sdomid, cdomid; - int rc; - uint64_t first_gfn, last_gfn; - - if ( argc != 6 ) - return usage(argv[0]); - - sdomid = strtol(argv[2], NULL, 0); - cdomid = strtol(argv[3], NULL, 0); - first_gfn = strtoul(argv[4], NULL, 0); - last_gfn = strtoul(argv[5], NULL, 0); - - rc = xc_memshr_range_share(xch, sdomid, cdomid, first_gfn, last_gfn); - if ( rc < 0 ) - { - printf("error executing xc_memshr_range_share: %s\n", strerror(errno)); - return rc; - } - } - return 0; -} -- generated by git-patchbot for /home/xen/git/xen.git#staging
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |