WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-devel

[Xen-devel] [PATCH 5/6]xl: Add 'xl tmem-set' command

To: "xen-devel@xxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxx>
Subject: [Xen-devel] [PATCH 5/6]xl: Add 'xl tmem-set' command
From: Yang Hongyang <yanghy@xxxxxxxxxxxxxx>
Date: Wed, 19 May 2010 16:33:57 +0800
Cc: Dan Magenheimer <dan.magenheimer@xxxxxxxxxx>, Keir Fraser <keir.fraser@xxxxxxxxxxxxx>, Stefano Stabellini <stefano.stabellini@xxxxxxxxxxxxx>
Delivery-date: Wed, 19 May 2010 01:36:57 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
In-reply-to: <4BF39FB9.3050005@xxxxxxxxxxxxxx>
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
References: <4BF39FB9.3050005@xxxxxxxxxxxxxx>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.9) Gecko/20100415 Thunderbird/3.0.4
Add 'xl tmem-set' command

Signed-off-by: Yang Hongyang<yanghy@xxxxxxxxxxxxxx> 

diff -r f5c579127b26 tools/libxl/libxl.c
--- a/tools/libxl/libxl.c       Wed May 19 23:35:17 2010 +0800
+++ b/tools/libxl/libxl.c       Wed May 19 23:37:09 2010 +0800
@@ -2885,3 +2885,35 @@
 
     return rc;
 }
+
+static int32_t tmem_setop_from_string(char *set_name)
+{
+    if (!strcmp(set_name, "weight"))
+        return TMEMC_SET_WEIGHT;
+    else if (!strcmp(set_name, "cap"))
+        return TMEMC_SET_CAP;
+    else if (!strcmp(set_name, "compress"))
+        return TMEMC_SET_COMPRESS;
+    else
+        return -1;
+}
+
+int libxl_tmem_set(struct libxl_ctx *ctx, uint32_t domid, char* name, uint32_t 
set)
+{
+    int rc;
+    int32_t subop = tmem_setop_from_string(name);
+
+    if (subop == -1) {
+        XL_LOG_ERRNOVAL(ctx, XL_LOG_ERROR, -1,
+            "Invalid set, valid sets are <weight|cap|compress>");
+        return -1;
+    }
+    rc = xc_tmem_control(ctx->xch, -1, subop, domid, set, 0, 0, NULL);
+    if (rc < 0) {
+        XL_LOG_ERRNOVAL(ctx, XL_LOG_ERROR, rc,
+            "Can not set tmem %s", name);
+        return -1;
+    }
+
+    return rc;
+}
diff -r f5c579127b26 tools/libxl/libxl.h
--- a/tools/libxl/libxl.h       Wed May 19 23:35:17 2010 +0800
+++ b/tools/libxl/libxl.h       Wed May 19 23:37:09 2010 +0800
@@ -517,5 +517,7 @@
 int libxl_tmem_freeze(struct libxl_ctx *ctx, uint32_t domid);
 int libxl_tmem_destroy(struct libxl_ctx *ctx, uint32_t domid);
 int libxl_tmem_thaw(struct libxl_ctx *ctx, uint32_t domid);
+int libxl_tmem_set(struct libxl_ctx *ctx, uint32_t domid, char* name,
+                   uint32_t set);
 #endif /* LIBXL_H */
 
diff -r f5c579127b26 tools/libxl/xl_cmdimpl.c
--- a/tools/libxl/xl_cmdimpl.c  Wed May 19 23:35:17 2010 +0800
+++ b/tools/libxl/xl_cmdimpl.c  Wed May 19 23:37:09 2010 +0800
@@ -3822,3 +3822,64 @@
     exit(0);
 }
 
+int main_tmem_set(int argc, char **argv)
+{
+    char *dom = NULL;
+    uint32_t weight = 0, cap = 0, compress = 0;
+    int opt_w = 0, opt_c = 0, opt_p = 0;
+    int all = 0;
+    int opt;
+
+    while ((opt = getopt(argc, argv, "aw:c:p:h")) != -1) {
+        switch (opt) {
+        case 'a':
+            all = 1;
+            break;
+        case 'w':
+            weight = strtol(optarg, NULL, 10);
+            opt_w = 1;
+            break;
+        case 'c':
+            cap = strtol(optarg, NULL, 10);
+            opt_c = 1;
+            break;
+        case 'p':
+            compress = strtol(optarg, NULL, 10);
+            opt_p = 1;
+            break;
+        case 'h':
+            help("tmem-set");
+            exit(0);
+        default:
+            fprintf(stderr, "option `%c' not supported.\n", opt);
+            break;
+        }
+    }
+
+    dom = argv[optind];
+    if (!dom && all == 0) {
+        fprintf(stderr, "You must specify -a or a domain id.\n\n");
+        help("tmem-set");
+        exit(1);
+    }
+
+    if (all)
+        domid = -1;
+    else
+        find_domain(dom);
+
+    if (!opt_w && !opt_c && !opt_p) {
+        fprintf(stderr, "No set value specified.\n\n");
+        help("tmem-set");
+        exit(1);
+    }
+
+    if (opt_w)
+        libxl_tmem_set(&ctx, domid, "weight", weight);
+    if (opt_c)
+        libxl_tmem_set(&ctx, domid, "cap", cap);
+    if (opt_p)
+        libxl_tmem_set(&ctx, domid, "compress", compress);
+
+    exit(0);
+}
diff -r f5c579127b26 tools/libxl/xl_cmdimpl.h
--- a/tools/libxl/xl_cmdimpl.h  Wed May 19 23:35:17 2010 +0800
+++ b/tools/libxl/xl_cmdimpl.h  Wed May 19 23:37:09 2010 +0800
@@ -56,6 +56,7 @@
 int main_tmem_freeze(int argc, char **argv);
 int main_tmem_destroy(int argc, char **argv);
 int main_tmem_thaw(int argc, char **argv);
+int main_tmem_set(int argc, char **argv);
 
 void help(char *command);
 
diff -r f5c579127b26 tools/libxl/xl_cmdtable.c
--- a/tools/libxl/xl_cmdtable.c Wed May 19 23:35:17 2010 +0800
+++ b/tools/libxl/xl_cmdtable.c Wed May 19 23:37:09 2010 +0800
@@ -248,6 +248,15 @@
       "[<Domain>|-a]",
       "  -a                             Thaw all tmem",
     },
+    { "tmem-set",
+      &main_tmem_set,
+      "Change tmem settings",
+      "[<Domain>|-a] [-w[=WEIGHT]|-c[=CAP]|-p[=COMPRESS]]",
+      "  -a                             Operate on all tmem\n"
+      "  -w WEIGHT                      Weight (int)\n"
+      "  -c CAP                         Cap (int)\n"
+      "  -p COMPRESS                    Compress (int)",
+    },
 };
 
 int cmdtable_len = sizeof(cmd_table)/sizeof(struct cmd_spec);

-- 
Regards
Yang Hongyang

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel