direct-io.hg

changeset 13425:4cad44a3ad86

Allow vcpu_avail to be specified in the configuration file. Rationalise our
use of online_vcpus and max_vcpu_id, keeping track of the configured value in
vcpus_number.

Fix HVM SMP configuration to use the XendDomainInfo.getVCpuCount() call that
is used everywhere else, rather than parsing it out of the device config.

Fix xm list to show the configured VCPU count when the VM is down.

Signed-off-by: Ewan Mellor <ewan@xensource.com>
author Ewan Mellor <ewan@xensource.com>
date Thu Jan 18 17:48:59 2007 +0000 (2007-01-18)
parents bf3658f32651
children bba84748022d
files tools/python/xen/xend/XendConfig.py tools/python/xen/xend/XendDomainInfo.py tools/python/xen/xend/image.py tools/python/xen/xm/create.py tools/python/xen/xm/main.py tools/python/xen/xm/opts.py
line diff
     1.1 --- a/tools/python/xen/xend/XendConfig.py	Thu Jan 18 17:24:40 2007 +0000
     1.2 +++ b/tools/python/xen/xend/XendConfig.py	Thu Jan 18 17:48:59 2007 +0000
     1.3 @@ -78,6 +78,25 @@ def scrub_password(data):
     1.4      else:
     1.5          return data
     1.6  
     1.7 +#
     1.8 +# CPU fields:
     1.9 +#
    1.10 +# vcpus_number -- the maximum number of vcpus that this domain may ever have.
    1.11 +#                 aka XendDomainInfo.getVCpuCount().
    1.12 +# vcpus        -- the legacy configuration name for above.
    1.13 +# max_vcpu_id  -- vcpus_number - 1.  This is given to us by Xen.
    1.14 +#
    1.15 +# cpus         -- the list of pCPUs available to each vCPU.
    1.16 +#
    1.17 +#   vcpu_avail:  a bitmap telling the guest domain whether it may use each of
    1.18 +#                its VCPUs.  This is translated to
    1.19 +#                <dompath>/cpu/<id>/availability = {online,offline} for use
    1.20 +#                by the guest domain.
    1.21 +# online_vpcus -- the number of VCPUs currently up, as reported by Xen.  This
    1.22 +#                 is changed by changing vcpu_avail, and waiting for the
    1.23 +#                 domain to respond.
    1.24 +#
    1.25 +
    1.26  
    1.27  # Mapping from XendConfig configuration keys to the old
    1.28  # legacy configuration keys that map directly.
    1.29 @@ -185,7 +204,7 @@ LEGACY_CFG_TYPES = {
    1.30      'uuid':          str,
    1.31      'name':          str,
    1.32      'vcpus':         int,
    1.33 -    'vcpu_avail':    int,
    1.34 +    'vcpu_avail':    long,
    1.35      'memory':        int,
    1.36      'shadow_memory': int,
    1.37      'maxmem':        int,
    1.38 @@ -355,9 +374,6 @@ class XendConfig(dict):
    1.39              'cpu_weight': 256,
    1.40              'cpu_cap': 0,
    1.41              'vcpus_number': 1,
    1.42 -            'online_vcpus': 1,
    1.43 -            'max_vcpu_id': 0,
    1.44 -            'vcpu_avail': 1,
    1.45              'console_refs': [],
    1.46              'vif_refs': [],
    1.47              'vbd_refs': [],
    1.48 @@ -389,7 +405,7 @@ class XendConfig(dict):
    1.49                                        event)
    1.50  
    1.51      def _vcpus_sanity_check(self):
    1.52 -        if self.get('vcpus_number') != None:
    1.53 +        if 'vcpus_number' in self and 'vcpu_avail' not in self:
    1.54              self['vcpu_avail'] = (1 << self['vcpus_number']) - 1
    1.55  
    1.56      def _uuid_sanity_check(self):
    1.57 @@ -405,7 +421,7 @@ class XendConfig(dict):
    1.58      def _dominfo_to_xapi(self, dominfo):
    1.59          self['domid'] = dominfo['domid']
    1.60          self['online_vcpus'] = dominfo['online_vcpus']
    1.61 -        self['max_vcpu_id'] = dominfo['max_vcpu_id']
    1.62 +        self['vcpus_number'] = dominfo['max_vcpu_id'] + 1
    1.63          self['memory_dynamic_min'] = (dominfo['mem_kb'] + 1023)/1024
    1.64          self['memory_dynamic_max'] = (dominfo['maxmem_kb'] + 1023)/1024
    1.65          self['cpu_time'] = dominfo['cpu_time']/1e9
    1.66 @@ -636,9 +652,6 @@ class XendConfig(dict):
    1.67          self['memory_dynamic_max'] = self['memory_static_max']
    1.68          self['memory_dynamic_min'] = self['memory_static_min']
    1.69  
    1.70 -        # make sure max_vcpu_id is set correctly
    1.71 -        self['max_vcpu_id'] = self['vcpus_number'] - 1
    1.72 -
    1.73          # set device references in the configuration
    1.74          self['devices'] = cfg.get('devices', {})
    1.75          
    1.76 @@ -720,13 +733,11 @@ class XendConfig(dict):
    1.77          _set_cfg_if_exists('on_xend_stop')
    1.78          _set_cfg_if_exists('on_xend_start')
    1.79          _set_cfg_if_exists('vcpu_avail')
    1.80 -        _set_cfg_if_exists('max_vcpu_id') # needed for vcpuDomDetails
    1.81          _set_cfg_if_exists('cpu_weight')
    1.82          _set_cfg_if_exists('cpu_cap')
    1.83          
    1.84          # Parse and store runtime configuration 
    1.85          _set_cfg_if_exists('start_time')
    1.86 -        _set_cfg_if_exists('online_vcpus')
    1.87          _set_cfg_if_exists('cpu_time')
    1.88          _set_cfg_if_exists('shutdown_reason')
    1.89          _set_cfg_if_exists('up_time')
     2.1 --- a/tools/python/xen/xend/XendDomainInfo.py	Thu Jan 18 17:24:40 2007 +0000
     2.2 +++ b/tools/python/xen/xend/XendDomainInfo.py	Thu Jan 18 17:48:59 2007 +0000
     2.3 @@ -60,25 +60,6 @@ log = logging.getLogger("xend.XendDomain
     2.4  #log.setLevel(logging.TRACE)
     2.5  
     2.6  
     2.7 -#
     2.8 -# There are a number of CPU-related fields:
     2.9 -#
    2.10 -#   vcpus:       the number of virtual CPUs this domain is configured to use.
    2.11 -#   vcpu_avail:  a bitmap telling the guest domain whether it may use each of
    2.12 -#                its VCPUs.  This is translated to
    2.13 -#                <dompath>/cpu/<id>/availability = {online,offline} for use
    2.14 -#                by the guest domain.
    2.15 -#   cpumap:      a list of bitmaps, one for each VCPU, giving the physical
    2.16 -#                CPUs that that VCPU may use.
    2.17 -#   cpu:         a configuration setting requesting that VCPU 0 is pinned to
    2.18 -#                the specified physical CPU.
    2.19 -#
    2.20 -# vcpus and vcpu_avail settings persist with the VM (i.e. they are persistent
    2.21 -# across save, restore, migrate, and restart).  The other settings are only
    2.22 -# specific to the domain, so are lost when the VM moves.
    2.23 -#
    2.24 -
    2.25 -
    2.26  def create(config):
    2.27      """Creates and start a VM using the supplied configuration. 
    2.28  
    2.29 @@ -624,7 +605,7 @@ class XendDomainInfo:
    2.30                      ['name',       self.info['name_label']],
    2.31                      ['vcpu_count', self.info['vcpus_number']]]
    2.32  
    2.33 -            for i in range(0, self.info['max_vcpu_id']+1):
    2.34 +            for i in range(0, self.info['vcpus_number']):
    2.35                  info = xc.vcpu_getinfo(self.domid, i)
    2.36  
    2.37                  sxpr.append(['vcpu',
    2.38 @@ -908,8 +889,9 @@ class XendDomainInfo:
    2.39                  self._writeDom(self._vcpuDomDetails())
    2.40          else:
    2.41              self.info['vcpus_number'] = vcpus
    2.42 -            self.info['online_vcpus'] = vcpus
    2.43              xen.xend.XendDomain.instance().managed_config_save(self)
    2.44 +        log.info("Set VCPU count on domain %s to %d", self.info['name_label'],
    2.45 +                 vcpus)
    2.46  
    2.47      def getLabel(self):
    2.48          return security.get_security_info(self.info, 'label')
    2.49 @@ -1394,7 +1376,7 @@ class XendDomainInfo:
    2.50              # this is done prior to memory allocation to aide in memory
    2.51              # distribution for NUMA systems.
    2.52              if self.info['cpus'] is not None and len(self.info['cpus']) > 0:
    2.53 -                for v in range(0, self.info['max_vcpu_id']+1):
    2.54 +                for v in range(0, self.info['vcpus_number']):
    2.55                      xc.vcpu_setaffinity(self.domid, v, self.info['cpus'])
    2.56  
    2.57              # Use architecture- and image-specific calculations to determine
    2.58 @@ -2052,8 +2034,8 @@ class XendDomainInfo:
    2.59          # TODO: spec says that key is int, however, python does not allow
    2.60          #       non-string keys to dictionaries.
    2.61          vcpu_util = {}
    2.62 -        if 'max_vcpu_id' in self.info and self.domid != None:
    2.63 -            for i in range(0, self.info['max_vcpu_id']+1):
    2.64 +        if 'vcpus_number' in self.info and self.domid != None:
    2.65 +            for i in range(0, self.info['vcpus_number']):
    2.66                  info = xc.vcpu_getinfo(self.domid, i)
    2.67                  vcpu_util[str(i)] = info['cpu_time']/1000000000.0
    2.68                  
     3.1 --- a/tools/python/xen/xend/image.py	Thu Jan 18 17:24:40 2007 +0000
     3.2 +++ b/tools/python/xen/xend/image.py	Thu Jan 18 17:48:59 2007 +0000
     3.3 @@ -377,11 +377,12 @@ class HVMImageHandler(ImageHandler):
     3.4      # xm config file
     3.5      def parseDeviceModelArgs(self, imageConfig, deviceConfig):
     3.6          dmargs = [ 'boot', 'fda', 'fdb', 'soundhw',
     3.7 -                   'localtime', 'serial', 'stdvga', 'isa', 'vcpus',
     3.8 +                   'localtime', 'serial', 'stdvga', 'isa',
     3.9                     'acpi', 'usb', 'usbdevice', 'keymap' ]
    3.10 -        ret = []
    3.11          hvmDeviceConfig = imageConfig['hvm']['devices']
    3.12 -        
    3.13 +
    3.14 +        ret = ['-vcpus', str(self.vm.getVCpuCount())]
    3.15 +
    3.16          for a in dmargs:
    3.17              v = hvmDeviceConfig.get(a)
    3.18  
     4.1 --- a/tools/python/xen/xm/create.py	Thu Jan 18 17:24:40 2007 +0000
     4.2 +++ b/tools/python/xen/xm/create.py	Thu Jan 18 17:48:59 2007 +0000
     4.3 @@ -190,6 +190,10 @@ gopts.var('vcpus', val='VCPUS',
     4.4            fn=set_int, default=1,
     4.5            use="# of Virtual CPUS in domain.")
     4.6  
     4.7 +gopts.var('vcpu_avail', val='VCPUS',
     4.8 +          fn=set_long, default=None,
     4.9 +          use="Bitmask for virtual CPUs to make available immediately.")
    4.10 +
    4.11  gopts.var('cpu_cap', val='CAP',
    4.12            fn=set_int, default=None,
    4.13            use="""Set the maximum amount of cpu.
    4.14 @@ -740,7 +744,7 @@ def make_config(vals):
    4.15  
    4.16      map(add_conf, ['name', 'memory', 'maxmem', 'shadow_memory',
    4.17                     'restart', 'on_poweroff',
    4.18 -                   'on_reboot', 'on_crash', 'vcpus', 'features',
    4.19 +                   'on_reboot', 'on_crash', 'vcpus', 'vcpu_avail', 'features',
    4.20                     'on_xend_start', 'on_xend_stop'])
    4.21  
    4.22      if vals.uuid is not None:
     5.1 --- a/tools/python/xen/xm/main.py	Thu Jan 18 17:24:40 2007 +0000
     5.2 +++ b/tools/python/xen/xm/main.py	Thu Jan 18 17:48:59 2007 +0000
     5.3 @@ -693,12 +693,15 @@ def parse_doms_info(info):
     5.4          up_time = time.time() - start_time
     5.5  
     5.6      return {
     5.7 -        'domid'    : get_info('domid',        str,   ''),
     5.8 -        'name'     : get_info('name',         str,   '??'),
     5.9 +        'domid'    : get_info('domid',              str,   ''),
    5.10 +        'name'     : get_info('name',               str,   '??'),
    5.11          'mem'      : get_info('memory_dynamic_min', int,   0),
    5.12 -        'vcpus'    : get_info('online_vcpus',        int,   0),
    5.13 -        'state'    : get_info('state',        str,    ''),
    5.14 -        'cpu_time' : get_info('cpu_time',     float, 0),
    5.15 +        'state'    : get_info('state',              str,   ''),
    5.16 +        'cpu_time' : get_info('cpu_time',           float, 0.0),
    5.17 +        # VCPUs is the number online when the VM is up, or the number
    5.18 +        # configured otherwise.
    5.19 +        'vcpus'    : get_info('online_vcpus', int,
    5.20 +                              get_info('vcpus', int, 0)),
    5.21          'up_time'  : up_time,
    5.22          'seclabel' : security.get_security_printlabel(info),
    5.23          }
     6.1 --- a/tools/python/xen/xm/opts.py	Thu Jan 18 17:24:40 2007 +0000
     6.2 +++ b/tools/python/xen/xm/opts.py	Thu Jan 18 17:48:59 2007 +0000
     6.3 @@ -571,6 +571,14 @@ def set_int(opt, k, v):
     6.4          opt.opts.err('Invalid value: ' + str(v))
     6.5      opt.set(v)
     6.6  
     6.7 +def set_long(opt, k, v):
     6.8 +    """Set an option to a long integer value."""
     6.9 +    try:
    6.10 +        v = long(v)
    6.11 +    except:
    6.12 +        opt.opts.err('Invalid value: ' + str(v))
    6.13 +    opt.set(v)
    6.14 +
    6.15  def set_float(opt, k, v):
    6.16      """Set an option to a float value."""
    6.17      try: