[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [RFC v2][PATCH 3/3] libxl: enable NUMA-aware memory operation



This patch expands the libxl API interface,
add two parameters to it so that user could specify physical
NUMA node request.

in tools/libxl/libxl.c, write the two parameters to the new
xenstore path: ~/memory/target_nid, so that balloon will know
the request.

the document of this path could be found in xenstore-paths.markdown

Signed-off-by: Yechen Li <lccycc123@xxxxxxxxx>
---
 tools/libxl/libxl.c       | 11 +++++++++++
 tools/libxl/libxl.h       |  3 +++
 tools/libxl/xl_cmdimpl.c  | 26 +++++++++++++++++++++-----
 tools/libxl/xl_cmdtable.c |  4 +++-
 4 files changed, 38 insertions(+), 6 deletions(-)

diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c
index 81785df..768adc9 100644
--- a/tools/libxl/libxl.c
+++ b/tools/libxl/libxl.c
@@ -3646,6 +3646,14 @@ retry:
 int libxl_set_memory_target(libxl_ctx *ctx, uint32_t domid,
         int32_t target_memkb, int relative, int enforce)
 {
+    return libxl_set_memory_target_node(ctx, domid, target_memkb, relative,
+                                        enforce, -1, 0);
+}
+
+int libxl_set_memory_target_node(libxl_ctx *ctx, uint32_t domid,
+                                 int32_t target_memkb, int relative,
+                                 int enforce, int pnid, bool nodeexact)
+{
     GC_INIT(ctx);
     int rc = 1, abort_transaction = 0;
     uint32_t memorykb = 0, videoram = 0;
@@ -3755,6 +3763,9 @@ retry_transaction:
         goto out;
     }
 
+       /* always write /memory/target_nid before /memory/target! */
+    libxl__xs_write(gc, t, libxl__sprintf(gc, "%s/memory/target_nid",
+                dompath), "%"PRId32" %"PRId32, pnid, nodeexact);
     libxl__xs_write(gc, t, libxl__sprintf(gc, "%s/memory/target",
                 dompath), "%"PRIu32, new_target_memkb);
     rc = xc_domain_getinfolist(ctx->xch, domid, 1, &info);
diff --git a/tools/libxl/libxl.h b/tools/libxl/libxl.h
index be19bf5..8b98aae 100644
--- a/tools/libxl/libxl.h
+++ b/tools/libxl/libxl.h
@@ -628,6 +628,9 @@ int libxl_domain_core_dump(libxl_ctx *ctx, uint32_t domid,
 
 int libxl_domain_setmaxmem(libxl_ctx *ctx, uint32_t domid, uint32_t 
target_memkb);
 int libxl_set_memory_target(libxl_ctx *ctx, uint32_t domid, int32_t 
target_memkb, int relative, int enforce);
+int libxl_set_memory_target_node(libxl_ctx *ctx, uint32_t domid,
+                                 int32_t target_memkb, int relative,
+                                 int enforce, int pnid, bool nodeexact);
 int libxl_get_memory_target(libxl_ctx *ctx, uint32_t domid, uint32_t 
*out_target);
 
 
diff --git a/tools/libxl/xl_cmdimpl.c b/tools/libxl/xl_cmdimpl.c
index 884f050..51ede74 100644
--- a/tools/libxl/xl_cmdimpl.c
+++ b/tools/libxl/xl_cmdimpl.c
@@ -2493,7 +2493,8 @@ int main_memmax(int argc, char **argv)
     return 0;
 }
 
-static void set_memory_target(uint32_t domid, const char *mem)
+static void set_memory_target_node(uint32_t domid, const char *mem,
+                                   int pnid, bool nodeexact)
 {
     long long int memorykb;
 
@@ -2503,7 +2504,8 @@ static void set_memory_target(uint32_t domid, const char 
*mem)
         exit(3);
     }
 
-    libxl_set_memory_target(ctx, domid, memorykb, 0, /* enforce */ 1);
+    libxl_set_memory_target_node(ctx, domid, memorykb, 0, /* enforce */ 1,
+                                 pnid, nodeexact);
 }
 
 int main_memset(int argc, char **argv)
@@ -2511,15 +2513,29 @@ int main_memset(int argc, char **argv)
     uint32_t domid;
     int opt = 0;
     const char *mem;
+    int pnid = -1;
+    bool nodeexact = false;
+    static const struct option opts[] = {
+        {"exact", 0, 0, 'e'},
+        {"node", 0, 0, 'n'},
+        COMMON_LONG_OPTS,
+        {0, 0, 0, 0}
+    };
 
-    SWITCH_FOREACH_OPT(opt, "", NULL, "mem-set", 2) {
-        /* No options */
+    SWITCH_FOREACH_OPT(opt, "n:e", opts, "mem-set", 2) {
+    case 'e':
+        nodeexact = true;
+        break;
+    case 'n':
+        fprintf(stderr, "%s\n", optarg);
+        pnid = strtol(optarg, NULL, 10);
+        break;
     }
 
     domid = find_domain(argv[optind]);
     mem = argv[optind + 1];
 
-    set_memory_target(domid, mem);
+    set_memory_target_node(domid, mem, pnid, nodeexact);
     return 0;
 }
 
diff --git a/tools/libxl/xl_cmdtable.c b/tools/libxl/xl_cmdtable.c
index 326a660..5f27cfd 100644
--- a/tools/libxl/xl_cmdtable.c
+++ b/tools/libxl/xl_cmdtable.c
@@ -197,7 +197,9 @@ struct cmd_spec cmd_table[] = {
     { "mem-set",
       &main_memset, 0, 1,
       "Set the current memory usage for a domain",
-      "<Domain> <MemMB['b'[bytes]|'k'[KB]|'m'[MB]|'g'[GB]|'t'[TB]]>",
+      "[OPTION] <Domain> <MemMB['b'[bytes]|'k'[KB]|'m'[MB]|'g'[GB]|'t'[TB]]>",
+      "-n <nodeID>     specified operation on node\n"
+      "-e              operation will be done exactly on this node"
     },
     { "button-press",
       &main_button_press, 0, 1,
-- 
1.8.1.4


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.