ia64/xen-unstable

changeset 4470:3bfb0d7a5f6c

bitkeeper revision 1.1236.57.2 (4252646a-w2lxhow-zRG4FwNSoDk5A)

add support for memory suffix in user tools and in kernel

Signed-off-by: Vincent Hanquez <vincent@xensource.com>
author vh249@arcadians.cl.cam.ac.uk
date Tue Apr 05 10:11:54 2005 +0000 (2005-04-05)
parents 9dfa12fa3add
children 38d7ac8f210f
files tools/python/xen/xm/main.py xen/arch/x86/domain_build.c xen/common/kernel.c xen/include/xen/init.h
line diff
     1.1 --- a/tools/python/xen/xm/main.py	Tue Apr 05 09:07:08 2005 +0000
     1.2 +++ b/tools/python/xen/xm/main.py	Tue Apr 05 10:11:54 2005 +0000
     1.3 @@ -14,6 +14,31 @@ from xen.xend.XendClient import main as 
     1.4  from xen.xm import create, destroy, migrate, shutdown, sysrq
     1.5  from xen.xm.opts import *
     1.6  
     1.7 +def unit(c):
     1.8 +    if not c.isalpha():
     1.9 +        return 0
    1.10 +    base = 1
    1.11 +    if c == 'G' or c == 'g': base = 1024 * 1024 * 1024
    1.12 +    elif c == 'M' or c == 'm': base = 1024 * 1024
    1.13 +    elif c == 'K' or c == 'k': base = 1024
    1.14 +    else:
    1.15 +        print 'ignoring unknown unit'
    1.16 +    return base
    1.17 +
    1.18 +def int_unit(str, dest):
    1.19 +    base = unit(str[-1])
    1.20 +    if not base:
    1.21 +        return int(str)
    1.22 +
    1.23 +    value = int(str[:-1])
    1.24 +    dst_base = unit(dest)
    1.25 +    if dst_base == 0:
    1.26 +        dst_base = 1
    1.27 +    if dst_base > base:
    1.28 +        return value / (dst_base / base)
    1.29 +    else:
    1.30 +        return value * (base / dst_base)
    1.31 +
    1.32  class Group:
    1.33  
    1.34      name = ""
    1.35 @@ -475,7 +500,7 @@ class ProgMaxmem(Prog):
    1.36      def main(self, args):
    1.37          if len(args) != 3: self.err("%s: Invalid argument(s)" % args[0])
    1.38          dom = args[1]
    1.39 -        mem = int(args[2])
    1.40 +        mem = int_unit(args[2], 'm')
    1.41          server.xend_domain_maxmem_set(dom, mem)
    1.42  
    1.43  xm.prog(ProgMaxmem)
    1.44 @@ -493,7 +518,7 @@ MEMORY_TARGET megabytes"""
    1.45      def main(self, args):
    1.46          if len(args) != 3: self.err("%s: Invalid argument(s)" % args[0])
    1.47          dom = args[1]
    1.48 -        mem_target = int(args[2])
    1.49 +        mem_target = int_unit(args[2], 'm')
    1.50          server.xend_domain_mem_target_set(dom, mem_target)
    1.51  
    1.52  xm.prog(ProgBalloon)
     2.1 --- a/xen/arch/x86/domain_build.c	Tue Apr 05 09:07:08 2005 +0000
     2.2 +++ b/xen/arch/x86/domain_build.c	Tue Apr 05 10:11:54 2005 +0000
     2.3 @@ -23,7 +23,7 @@
     2.4  
     2.5  /* opt_dom0_mem: Kilobytes of memory allocated to domain 0. */
     2.6  static unsigned int opt_dom0_mem = 0;
     2.7 -integer_param("dom0_mem", opt_dom0_mem);
     2.8 +integer_unit_param("dom0_mem", opt_dom0_mem);
     2.9  
    2.10  #if defined(__i386__)
    2.11  /* No ring-3 access in initial leaf page tables. */
     3.1 --- a/xen/common/kernel.c	Tue Apr 05 09:07:08 2005 +0000
     3.2 +++ b/xen/common/kernel.c	Tue Apr 05 10:11:54 2005 +0000
     3.3 @@ -55,6 +55,24 @@ void cmdline_parse(char *cmdline)
     3.4                      *(unsigned int *)param->var =
     3.5                          simple_strtol(opt, (char **)&opt, 0);
     3.6                  break;
     3.7 +            case OPT_UINT_UNIT:
     3.8 +                if ( opt != NULL )
     3.9 +                {
    3.10 +                    int base = 1;
    3.11 +                    unsigned int value;
    3.12 +
    3.13 +                    value = simple_strtoul(opt, (char **)&opt, 0);
    3.14 +                    if (*opt == 'G' || *opt == 'g') {
    3.15 +                        base = 1024 * 1024;
    3.16 +                        opt++;
    3.17 +                    } if (*opt == 'M' || *opt == 'm') {
    3.18 +                        base = 1024;
    3.19 +                        opt++;
    3.20 +                    } else if (*opt == 'K' || *opt == 'k')
    3.21 +                        opt++;
    3.22 +                    *(unsigned int *) param->var = value * base;
    3.23 +                }
    3.24 +                break;
    3.25              case OPT_BOOL:
    3.26                  *(int *)param->var = 1;
    3.27                  break;
     4.1 --- a/xen/include/xen/init.h	Tue Apr 05 09:07:08 2005 +0000
     4.2 +++ b/xen/include/xen/init.h	Tue Apr 05 10:11:54 2005 +0000
     4.3 @@ -59,7 +59,7 @@ extern initcall_t __initcall_start, __in
     4.4   */
     4.5  struct kernel_param {
     4.6      const char *name;
     4.7 -    enum { OPT_STR, OPT_UINT, OPT_BOOL } type;
     4.8 +    enum { OPT_STR, OPT_UINT, OPT_UINT_UNIT, OPT_BOOL } type;
     4.9      void *var;
    4.10      unsigned int len;
    4.11  };
    4.12 @@ -74,6 +74,10 @@ extern struct kernel_param __setup_start
    4.13      static char __setup_str_##_var[] __initdata = _name; \
    4.14      static struct kernel_param __setup_##_var __attribute_used__ \
    4.15          __initsetup = { __setup_str_##_var, OPT_UINT, &_var, sizeof(_var) }
    4.16 +#define integer_unit_param(_name, _var) \
    4.17 +    static char __setup_str_##_var[] __initdata = _name; \
    4.18 +    static struct kernel_param __setup_##_var __attribute_used__ \
    4.19 +        __initsetup = { __setup_str_##_var, OPT_UINT_UNIT, &_var, sizeof(_var) }
    4.20  #define string_param(_name, _var) \
    4.21      static char __setup_str_##_var[] __initdata = _name; \
    4.22      static struct kernel_param __setup_##_var __attribute_used__ \