xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] tools/tests/mem-sharing/memshrtool share-all test
@ 2013-03-18 13:34 Tamas Lengyel
  2013-03-21 12:17 ` Tim Deegan
  0 siblings, 1 reply; 7+ messages in thread
From: Tamas Lengyel @ 2013-03-18 13:34 UTC (permalink / raw)
  To: xen-devel

Update memshrtool test program to allow sharing of all pages of two domains
with identical memory sizes. Currently the tool only allows sharing of
specific pages. With this patch we can quickly share all pages between clones
and check how many pages were successfully deduplicated. The pages' content
are not checked, therefore this mode is only safe for clone domains.

v2: fix typo of source_info

Signed-off-by: Tamas Lengyel <tamas.lengyel@zentific.com>
---
 tools/tests/mem-sharing/memshrtool.c |   58 ++++++++++++++++++++++++++++++++++
 1 files changed, 58 insertions(+), 0 deletions(-)

diff --git a/tools/tests/mem-sharing/memshrtool.c b/tools/tests/mem-sharing/memshrtool.c
index db44294..b3fd415 100644
--- a/tools/tests/mem-sharing/memshrtool.c
+++ b/tools/tests/mem-sharing/memshrtool.c
@@ -10,9 +10,12 @@
 #include <errno.h>
 #include <string.h>
 #include <sys/mman.h>
+#include <inttypes.h>
 
 #include "xenctrl.h"
 
+#define PAGE_SIZE_KB (XC_PAGE_SIZE/1024)
+
 static int usage(const char* prog)
 {
     printf("usage: %s <command> [args...]\n", prog);
@@ -24,6 +27,8 @@ static int usage(const char* prog)
     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("  share-all <domid> <source>\n");
+    printf("                          - Share all pages.\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");
@@ -131,6 +136,59 @@ int main(int argc, const char** argv)
             munmap(map, 4096);
         R((int)!map);
     }
+    else if( !strcasecmp(cmd, "share-all") )
+    {
+        domid_t domid;
+        uint64_t handle;
+        domid_t source_domid;
+        uint64_t source_handle;
+        xc_dominfo_t info, source_info;
+        uint64_t pages, source_pages;
+        uint64_t total_shared=0;
+        int ret;
+        uint64_t share_page;
+
+        if( argc != 4 )
+            return usage(argv[0]);
+
+        domid = strtol(argv[2], NULL, 0);
+        source_domid = strtol(argv[3], NULL, 0);
+
+        ret=xc_domain_getinfo(xch, domid, 1, &info);
+        if(ret!=1 || info.domid != domid)
+            return usage(argv[0]);
+        pages=info.max_memkb/PAGE_SIZE_KB;
+
+        ret=xc_domain_getinfo(xch, source_domid, 1, &source_info);
+        if(ret!=1 || source_info.domid != source_domid)
+            return usage(argv[0]);
+        source_pages=source_info.max_memkb/PAGE_SIZE_KB;
+
+        if(pages != source_pages) {
+            printf("Page count in source and destination domain doesn't match "
+                   "(source: %"PRIu64", destination %"PRIu64")\n", source_pages, pages);
+            return 1;
+        }
+
+        for(share_page=0;share_page<=pages;++share_page) {
+
+            ret=xc_memshr_nominate_gfn(xch, domid, share_page, &handle);
+            if(ret<0) {
+                continue;
+            }
+
+            ret=xc_memshr_nominate_gfn(xch, source_domid, share_page, &source_handle);
+            if(ret<0) {
+                continue;
+            }
+
+            ret=xc_memshr_share_gfns(xch, source_domid, share_page, source_handle, domid, share_page, handle);
+            if(ret>=0) total_shared++;
+        }
+
+        printf("Shared pages: %"PRIu64" out of %"PRIu64"\n", total_shared, pages);
+
+    }
     else if( !strcasecmp(cmd, "add-to-physmap") )
     {
         domid_t domid;
-- 
1.7.2.5

^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2013-04-22 14:46 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-03-18 13:34 [PATCH v2] tools/tests/mem-sharing/memshrtool share-all test Tamas Lengyel
2013-03-21 12:17 ` Tim Deegan
2013-03-22 19:25   ` Andres Lagar-Cavilla
2013-03-23 18:07     ` Tamas Lengyel
2013-04-22 12:07     ` Ian Campbell
2013-04-22 12:11       ` George Dunlap
2013-04-22 14:46         ` Andres Lagar-Cavilla

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).