xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Yechen Li <lccycc123@gmail.com>
To: xen-devel@lists.xen.org
Cc: ufimtseva@gmail.com, dario.faggioli@citrix.com,
	Yechen Li <lccycc123@gmail.com>,
	Ian.Jackson@eu.citrix.com, Ian.Campbell@eu.citrix.com,
	JBeulich@suse.com
Subject: [RFC v2][PATCH 3/3] libxl: enable NUMA-aware memory operation
Date: Fri, 16 Aug 2013 12:15:57 +0800	[thread overview]
Message-ID: <1376626557-13739-1-git-send-email-lccycc123@gmail.com> (raw)

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@gmail.com>
---
 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

                 reply	other threads:[~2013-08-16  4:15 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=1376626557-13739-1-git-send-email-lccycc123@gmail.com \
    --to=lccycc123@gmail.com \
    --cc=Ian.Campbell@eu.citrix.com \
    --cc=Ian.Jackson@eu.citrix.com \
    --cc=JBeulich@suse.com \
    --cc=dario.faggioli@citrix.com \
    --cc=ufimtseva@gmail.com \
    --cc=xen-devel@lists.xen.org \
    /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).