ia64/xen-unstable

changeset 984:d63f2c8a7f71

bitkeeper revision 1.637 (3fca7701y4KoOnx1zp_ccoR7G153xg)

Add dom0 op to pin a domain to a specified CPU (or -1 to unpin).
This function is currently only supported for domains that have
been 'created' but not 'built' or 'started'.
author iap10@labyrinth.cl.cam.ac.uk
date Sun Nov 30 23:02:25 2003 +0000 (2003-11-30)
parents c6cfb98dc402
children acc6520a4d4f
files .rootkeys BitKeeper/etc/ignore tools/examples/pincpu.py tools/xc/lib/xc_domain.c tools/xc/py/Xc.c tools/xc/py/XenoUtil.py xen/common/dom0_ops.c xen/include/hypervisor-ifs/dom0_ops.h xen/include/xeno/sched.h
line diff
     1.1 --- a/.rootkeys	Tue Nov 25 15:36:17 2003 +0000
     1.2 +++ b/.rootkeys	Sun Nov 30 23:02:25 2003 +0000
     1.3 @@ -42,6 +42,7 @@ 3e6377dbGcgnisKw16DPCaND7oGO3Q tools/bal
     1.4  3fbe2f12OPAkzIUtumU3wRAihnhocQ tools/examples/createlinuxdom.py
     1.5  3fbe2f12dZbmXLlgQdMgkmnSUj23AQ tools/examples/destroydom.py
     1.6  3fbe2f12ltvweb13kBSsxqzZDAq4sg tools/examples/listdoms.py
     1.7 +3fca7700PVj36cZObaFZlQicRiw1pQ tools/examples/pincpu.py
     1.8  3fbe2f12Bnt8mwmr1ZCP6HWGS6yvYw tools/examples/stopdom.py
     1.9  3f776bd2Xd-dUcPKlPN2vG89VGtfvQ tools/misc/Makefile
    1.10  3f6dc136ZKOjd8PIqLbFBl_v-rnkGg tools/misc/miniterm/Makefile
     2.1 --- a/BitKeeper/etc/ignore	Tue Nov 25 15:36:17 2003 +0000
     2.2 +++ b/BitKeeper/etc/ignore	Sun Nov 30 23:02:25 2003 +0000
     2.3 @@ -513,3 +513,13 @@ xen/drivers/scsi/aic7xxx/aic79xx_osm.o
     2.4  xen/drivers/scsi/aic7xxx/aic79xx_osm_pci.o
     2.5  xen/drivers/scsi/aic7xxx/aic79xx_pci.o
     2.6  xen/drivers/scsi/aic7xxx/aic79xx_proc.o
     2.7 +tools/xc/lib/xc_bvtsched.o
     2.8 +tools/xc/lib/xc_domain.o
     2.9 +tools/xc/lib/xc_linux_build.o
    2.10 +tools/xc/lib/xc_linux_restore.o
    2.11 +tools/xc/lib/xc_linux_save.o
    2.12 +tools/xc/lib/xc_misc.o
    2.13 +tools/xc/lib/xc_private.o
    2.14 +tools/xc/lib/xc_vbd.o
    2.15 +tools/xc/lib/xc_vif.o
    2.16 +xen/xen.s
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/tools/examples/pincpu.py	Sun Nov 30 23:02:25 2003 +0000
     3.3 @@ -0,0 +1,16 @@
     3.4 +#!/usr/bin/env python
     3.5 +
     3.6 +#
     3.7 +# Destroy specified domain.
     3.8 +#
     3.9 +
    3.10 +import Xc, sys, re
    3.11 +
    3.12 +xc = Xc.new()
    3.13 +
    3.14 +if len(sys.argv) < 3:
    3.15 +    print "Specify a domain identifier and CPU"
    3.16 +    sys.exit()
    3.17 +
    3.18 +xc.domain_pincpu( dom=int(sys.argv[1]), cpu=int(sys.argv[2]))
    3.19 +
     4.1 --- a/tools/xc/lib/xc_domain.c	Tue Nov 25 15:36:17 2003 +0000
     4.2 +++ b/tools/xc/lib/xc_domain.c	Sun Nov 30 23:02:25 2003 +0000
     4.3 @@ -57,6 +57,18 @@ int xc_domain_destroy(int xc_handle,
     4.4      return do_dom0_op(xc_handle, &op);
     4.5  }
     4.6  
     4.7 +int xc_domain_pincpu(int xc_handle,
     4.8 +                      unsigned int domid, 
     4.9 +                      int cpu)
    4.10 +{
    4.11 +    dom0_op_t op;
    4.12 +    op.cmd = DOM0_PINCPUDOMAIN;
    4.13 +    op.u.pincpudomain.domain = domid;
    4.14 +    op.u.pincpudomain.cpu  = cpu;
    4.15 +    return do_dom0_op(xc_handle, &op);
    4.16 +}
    4.17 +
    4.18 +
    4.19  int xc_domain_getinfo(int xc_handle,
    4.20                        unsigned int first_domid,
    4.21                        unsigned int max_doms,
     5.1 --- a/tools/xc/py/Xc.c	Tue Nov 25 15:36:17 2003 +0000
     5.2 +++ b/tools/xc/py/Xc.c	Sun Nov 30 23:02:25 2003 +0000
     5.3 @@ -95,6 +95,26 @@ static PyObject *pyxc_domain_destroy(PyO
     5.4      return PyInt_FromLong(ret);
     5.5  }
     5.6  
     5.7 +static PyObject *pyxc_domain_pincpu(PyObject *self,
     5.8 +                                     PyObject *args,
     5.9 +                                     PyObject *kwds)
    5.10 +{
    5.11 +    XcObject *xc = (XcObject *)self;
    5.12 +
    5.13 +    unsigned int dom;
    5.14 +    int cpu, ret;
    5.15 +
    5.16 +    static char *kwd_list[] = { "dom", "cpu", NULL };
    5.17 +
    5.18 +    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "i|i", kwd_list, 
    5.19 +                                      &dom, &cpu) )
    5.20 +        return NULL;
    5.21 +
    5.22 +    ret = xc_domain_pincpu(xc->xc_handle, dom, cpu);
    5.23 +    
    5.24 +    return PyInt_FromLong(ret);
    5.25 +}
    5.26 +
    5.27  static PyObject *pyxc_domain_getinfo(PyObject *self,
    5.28                                       PyObject *args,
    5.29                                       PyObject *kwds)
    5.30 @@ -507,6 +527,14 @@ static PyMethodDef pyxc_methods[] = {
    5.31        " force [int, 0]: Bool - force immediate destruction?\n\n"
    5.32        "Returns: [int] 0 on success; -1 on error.\n" },
    5.33  
    5.34 +    { "domain_pincpu", 
    5.35 +      (PyCFunction)pyxc_domain_pincpu, 
    5.36 +      METH_VARARGS | METH_KEYWORDS, "\n"
    5.37 +      "Pin a domain to a specified CPU.\n"
    5.38 +      " dom   [int]:    Identifier of domain to be destroyed.\n"
    5.39 +      " force [int, -1]: CPU to pin to, or -1 to unpin\n\n"
    5.40 +      "Returns: [int] 0 on success; -1 on error.\n" },
    5.41 +
    5.42      { "domain_getinfo", 
    5.43        (PyCFunction)pyxc_domain_getinfo, 
    5.44        METH_VARARGS | METH_KEYWORDS, "\n"
     6.1 --- a/tools/xc/py/XenoUtil.py	Tue Nov 25 15:36:17 2003 +0000
     6.2 +++ b/tools/xc/py/XenoUtil.py	Sun Nov 30 23:02:25 2003 +0000
     6.3 @@ -128,3 +128,17 @@ def setup_vfr_rules_for_vif(dom,vif,addr
     6.4                ' proto=any\n' )
     6.5      os.close( fd )
     6.6      return None
     6.7 +
     6.8 +def addr_of_iface( iface ):
     6.9 +    fd = os.popen( '/sbin/ifconfig '+iface )
    6.10 +    lines = fd.readlines()
    6.11 +    for line in lines:
    6.12 +	m = re.search( 'inet addr:([0-9.]+)', line )
    6.13 +	if m: 
    6.14 +	    return m.group(1)
    6.15 +    return None
    6.16 +
    6.17 +def add_to_ip( ip, off ):
    6.18 +    l = string.split(ip,'.')
    6.19 +    return '%s.%s.%s.%d' % ( l[0],l[1],l[2],string.atoi(l[3])+off )
    6.20 +
     7.1 --- a/xen/common/dom0_ops.c	Tue Nov 25 15:36:17 2003 +0000
     7.2 +++ b/xen/common/dom0_ops.c	Sun Nov 30 23:02:25 2003 +0000
     7.3 @@ -184,6 +184,39 @@ long do_dom0_op(dom0_op_t *u_dom0_op)
     7.4      }
     7.5      break;
     7.6  
     7.7 +    case DOM0_PINCPUDOMAIN:
     7.8 +    {
     7.9 +        struct task_struct * p = find_domain_by_id(op.u.pincpudomain.domain);
    7.10 +	int cpu = op.u.pincpudomain.cpu;
    7.11 +        ret = -EINVAL;
    7.12 +        if ( p != NULL )
    7.13 +        {
    7.14 +	    if( cpu == -1 )
    7.15 +	      p->cpupinned = 0;
    7.16 +	    else
    7.17 +	      {
    7.18 +		/* For the moment, we are unable to move running
    7.19 +		domains between CPUs. (We need a way of cleanly stopping 
    7.20 +		running domains). For now, if we discover the domain is
    7.21 +		running then cowardly bail out with ENOSYS */
    7.22 +
    7.23 +		if(p->flags & PF_CONSTRUCTED) 
    7.24 +		  ret = -ENOSYS;
    7.25 +		else
    7.26 +		  {
    7.27 +		    cpu = cpu % smp_num_cpus;
    7.28 +		    p->processor = cpu;
    7.29 +		    p->cpupinned = 1;
    7.30 +		  }
    7.31 +	      }
    7.32 +
    7.33 +	    ret = 0;
    7.34 +            put_task_struct(p);
    7.35 +        }
    7.36 +     	
    7.37 +    }
    7.38 +    break;
    7.39 +
    7.40      case DOM0_BVTCTL:
    7.41      {
    7.42          unsigned long  ctx_allow = op.u.bvtctl.ctx_allow;
     8.1 --- a/xen/include/hypervisor-ifs/dom0_ops.h	Tue Nov 25 15:36:17 2003 +0000
     8.2 +++ b/xen/include/hypervisor-ifs/dom0_ops.h	Sun Nov 30 23:02:25 2003 +0000
     8.3 @@ -197,6 +197,17 @@ typedef struct dom0_readconsole_st
     8.4      unsigned int cmd;
     8.5  } dom0_readconsole_t;
     8.6  
     8.7 +/* 
     8.8 + * Pin Domain to a particular CPU  (use -1 to unpin)
     8.9 + */
    8.10 +#define DOM0_PINCPUDOMAIN     20
    8.11 +typedef struct dom0_pincpudomain_st
    8.12 +{
    8.13 +    /* IN variables. */
    8.14 +    unsigned int domain;
    8.15 +    int          cpu;  /* -1 implies unpin */
    8.16 +} dom0_pincpudomain_t;
    8.17 +
    8.18  typedef struct dom0_op_st
    8.19  {
    8.20      unsigned long cmd;
    8.21 @@ -218,7 +229,12 @@ typedef struct dom0_op_st
    8.22  	dom0_debug_t            debug;
    8.23  	dom0_settime_t          settime;
    8.24  	dom0_readconsole_t	readconsole;
    8.25 +	dom0_pincpudomain_t     pincpudomain;
    8.26      } u;
    8.27  } dom0_op_t;
    8.28  
    8.29 +
    8.30 +
    8.31 +
    8.32 +
    8.33  #endif
     9.1 --- a/xen/include/xeno/sched.h	Tue Nov 25 15:36:17 2003 +0000
     9.2 +++ b/xen/include/xeno/sched.h	Sun Nov 30 23:02:25 2003 +0000
     9.3 @@ -102,7 +102,8 @@ struct task_struct
     9.4      struct list_head run_list;
     9.5      int              has_cpu;
     9.6      int state;                  /* current run state */
     9.7 -    
     9.8 +    int cpupinned;              /* true if pinned to curent CPU */
     9.9 +
    9.10      s_time_t lastschd;              /* time this domain was last scheduled */
    9.11      s_time_t cpu_time;              /* total CPU time received till now */
    9.12      s_time_t wokenup;               /* time domain got woken up */