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-changelog

[Xen-changelog] add support for memory suffix in user tools and in kerne

To: xen-changelog@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-changelog] add support for memory suffix in user tools and in kernel
From: BitKeeper Bot <riel@xxxxxxxxxxx>
Date: Tue, 05 Apr 2005 10:11:54 +0000
Delivery-date: Tue, 05 Apr 2005 13:03:17 +0000
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-changelog-request@lists.xensource.com?subject=help>
List-id: BK change log <xen-changelog.lists.xensource.com>
List-post: <mailto:xen-changelog@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=unsubscribe>
Reply-to: Xen Development List <xen-devel@xxxxxxxxxxxxxxxxxxxxx>
Sender: xen-changelog-bounces@xxxxxxxxxxxxxxxxxxx
ChangeSet 1.1443.2.2, 2005/04/05 11:11:54+01:00, vh249@xxxxxxxxxxxxxxxxxxxxxx

        add support for memory suffix in user tools and in kernel
        
        Signed-off-by: Vincent Hanquez <vincent@xxxxxxxxxxxxx>



 tools/python/xen/xm/main.py |   29 +++++++++++++++++++++++++++--
 xen/arch/x86/domain_build.c |    2 +-
 xen/common/kernel.c         |   18 ++++++++++++++++++
 xen/include/xen/init.h      |    6 +++++-
 4 files changed, 51 insertions(+), 4 deletions(-)


diff -Nru a/tools/python/xen/xm/main.py b/tools/python/xen/xm/main.py
--- a/tools/python/xen/xm/main.py       2005-04-05 09:03:22 -04:00
+++ b/tools/python/xen/xm/main.py       2005-04-05 09:03:22 -04:00
@@ -14,6 +14,31 @@
 from xen.xm import create, destroy, migrate, shutdown, sysrq
 from xen.xm.opts import *
 
+def unit(c):
+    if not c.isalpha():
+        return 0
+    base = 1
+    if c == 'G' or c == 'g': base = 1024 * 1024 * 1024
+    elif c == 'M' or c == 'm': base = 1024 * 1024
+    elif c == 'K' or c == 'k': base = 1024
+    else:
+        print 'ignoring unknown unit'
+    return base
+
+def int_unit(str, dest):
+    base = unit(str[-1])
+    if not base:
+        return int(str)
+
+    value = int(str[:-1])
+    dst_base = unit(dest)
+    if dst_base == 0:
+        dst_base = 1
+    if dst_base > base:
+        return value / (dst_base / base)
+    else:
+        return value * (base / dst_base)
+
 class Group:
 
     name = ""
@@ -475,7 +500,7 @@
     def main(self, args):
         if len(args) != 3: self.err("%s: Invalid argument(s)" % args[0])
         dom = args[1]
-        mem = int(args[2])
+        mem = int_unit(args[2], 'm')
         server.xend_domain_maxmem_set(dom, mem)
 
 xm.prog(ProgMaxmem)
@@ -493,7 +518,7 @@
     def main(self, args):
         if len(args) != 3: self.err("%s: Invalid argument(s)" % args[0])
         dom = args[1]
-        mem_target = int(args[2])
+        mem_target = int_unit(args[2], 'm')
         server.xend_domain_mem_target_set(dom, mem_target)
 
 xm.prog(ProgBalloon)
diff -Nru a/xen/arch/x86/domain_build.c b/xen/arch/x86/domain_build.c
--- a/xen/arch/x86/domain_build.c       2005-04-05 09:03:22 -04:00
+++ b/xen/arch/x86/domain_build.c       2005-04-05 09:03:22 -04:00
@@ -23,7 +23,7 @@
 
 /* opt_dom0_mem: Kilobytes of memory allocated to domain 0. */
 static unsigned int opt_dom0_mem = 0;
-integer_param("dom0_mem", opt_dom0_mem);
+integer_unit_param("dom0_mem", opt_dom0_mem);
 
 #if defined(__i386__)
 /* No ring-3 access in initial leaf page tables. */
diff -Nru a/xen/common/kernel.c b/xen/common/kernel.c
--- a/xen/common/kernel.c       2005-04-05 09:03:22 -04:00
+++ b/xen/common/kernel.c       2005-04-05 09:03:22 -04:00
@@ -55,6 +55,24 @@
                     *(unsigned int *)param->var =
                         simple_strtol(opt, (char **)&opt, 0);
                 break;
+            case OPT_UINT_UNIT:
+                if ( opt != NULL )
+                {
+                    int base = 1;
+                    unsigned int value;
+
+                    value = simple_strtoul(opt, (char **)&opt, 0);
+                    if (*opt == 'G' || *opt == 'g') {
+                        base = 1024 * 1024;
+                        opt++;
+                    } if (*opt == 'M' || *opt == 'm') {
+                        base = 1024;
+                        opt++;
+                    } else if (*opt == 'K' || *opt == 'k')
+                        opt++;
+                    *(unsigned int *) param->var = value * base;
+                }
+                break;
             case OPT_BOOL:
                 *(int *)param->var = 1;
                 break;
diff -Nru a/xen/include/xen/init.h b/xen/include/xen/init.h
--- a/xen/include/xen/init.h    2005-04-05 09:03:22 -04:00
+++ b/xen/include/xen/init.h    2005-04-05 09:03:22 -04:00
@@ -59,7 +59,7 @@
  */
 struct kernel_param {
     const char *name;
-    enum { OPT_STR, OPT_UINT, OPT_BOOL } type;
+    enum { OPT_STR, OPT_UINT, OPT_UINT_UNIT, OPT_BOOL } type;
     void *var;
     unsigned int len;
 };
@@ -74,6 +74,10 @@
     static char __setup_str_##_var[] __initdata = _name; \
     static struct kernel_param __setup_##_var __attribute_used__ \
         __initsetup = { __setup_str_##_var, OPT_UINT, &_var, sizeof(_var) }
+#define integer_unit_param(_name, _var) \
+    static char __setup_str_##_var[] __initdata = _name; \
+    static struct kernel_param __setup_##_var __attribute_used__ \
+        __initsetup = { __setup_str_##_var, OPT_UINT_UNIT, &_var, sizeof(_var) 
}
 #define string_param(_name, _var) \
     static char __setup_str_##_var[] __initdata = _name; \
     static struct kernel_param __setup_##_var __attribute_used__ \

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

<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-changelog] add support for memory suffix in user tools and in kernel, BitKeeper Bot <=