ia64/xen-unstable

changeset 10506:12aaf4a2486b

[XEN] localtime support for paravirtualized guests

It is quite minimal
in its approach, satisfying the purposes of the paravirtualized
NetWare operating system as well as any others that expect the time
base to be provided in localtime.

Signed-off-by: Bruce Rogers <brogers@novell.com>
author kaf24@firebug.cl.cam.ac.uk
date Wed Jun 21 17:09:14 2006 +0100 (2006-06-21)
parents 79ea1d8a5bb2
children 94e354294cca
files tools/libxc/xc_domain.c tools/libxc/xenctrl.h tools/python/xen/lowlevel/xc/xc.c tools/python/xen/xend/XendDomainInfo.py tools/python/xen/xm/create.py xen/arch/x86/time.c xen/common/dom0_ops.c xen/include/public/dom0_ops.h xen/include/xen/sched.h
line diff
     1.1 --- a/tools/libxc/xc_domain.c	Wed Jun 21 16:55:25 2006 +0100
     1.2 +++ b/tools/libxc/xc_domain.c	Wed Jun 21 17:09:14 2006 +0100
     1.3 @@ -286,6 +286,17 @@ int xc_domain_setmaxmem(int xc_handle,
     1.4      return do_dom0_op(xc_handle, &op);
     1.5  }
     1.6  
     1.7 +int xc_domain_set_time_offset(int xc_handle,
     1.8 +                              uint32_t domid,
     1.9 +                              int32_t time_offset_seconds)
    1.10 +{
    1.11 +    DECLARE_DOM0_OP;
    1.12 +    op.cmd = DOM0_SETTIMEOFFSET;
    1.13 +    op.u.settimeoffset.domain = (domid_t)domid;
    1.14 +    op.u.settimeoffset.time_offset_seconds = time_offset_seconds;
    1.15 +    return do_dom0_op(xc_handle, &op);
    1.16 +}
    1.17 +
    1.18  int xc_domain_memory_increase_reservation(int xc_handle,
    1.19                                            uint32_t domid,
    1.20                                            unsigned long nr_extents,
     2.1 --- a/tools/libxc/xenctrl.h	Wed Jun 21 16:55:25 2006 +0100
     2.2 +++ b/tools/libxc/xenctrl.h	Wed Jun 21 17:09:14 2006 +0100
     2.3 @@ -410,6 +410,10 @@ int xc_domain_setmaxmem(int xc_handle,
     2.4                          uint32_t domid,
     2.5                          unsigned int max_memkb);
     2.6  
     2.7 +int xc_domain_set_time_offset(int xc_handle,
     2.8 +                              uint32_t domid,
     2.9 +                              int32_t time_offset_seconds);
    2.10 +
    2.11  int xc_domain_memory_increase_reservation(int xc_handle,
    2.12                                            uint32_t domid,
    2.13                                            unsigned long nr_extents,
     3.1 --- a/tools/python/xen/lowlevel/xc/xc.c	Wed Jun 21 16:55:25 2006 +0100
     3.2 +++ b/tools/python/xen/lowlevel/xc/xc.c	Wed Jun 21 17:09:14 2006 +0100
     3.3 @@ -869,6 +869,30 @@ static PyObject *pyxc_domain_iomem_permi
     3.4      return zero;
     3.5  }
     3.6  
     3.7 +static PyObject *pyxc_domain_set_time_offset(XcObject *self, PyObject *args)
     3.8 +{
     3.9 +    uint32_t dom;
    3.10 +    int32_t time_offset_seconds;
    3.11 +    time_t calendar_time;
    3.12 +    struct tm local_time;
    3.13 +    struct tm utc_time;
    3.14 +
    3.15 +    if (!PyArg_ParseTuple(args, "i", &dom))
    3.16 +        return NULL;
    3.17 +
    3.18 +    calendar_time = time(NULL);
    3.19 +    localtime_r(&calendar_time, &local_time);
    3.20 +    gmtime_r(&calendar_time, &utc_time);
    3.21 +    /* set up to get calendar time based on utc_time, with local dst setting */
    3.22 +    utc_time.tm_isdst = local_time.tm_isdst;
    3.23 +    time_offset_seconds = (int32_t)difftime(calendar_time, mktime(&utc_time));
    3.24 +
    3.25 +    if (xc_domain_set_time_offset(self->xc_handle, dom, time_offset_seconds) != 0)
    3.26 +        return NULL;
    3.27 +
    3.28 +    Py_INCREF(zero);
    3.29 +    return zero;
    3.30 +}
    3.31  
    3.32  static PyObject *dom_op(XcObject *self, PyObject *args,
    3.33                          int (*fn)(int, uint32_t))
    3.34 @@ -1208,6 +1232,13 @@ static PyMethodDef pyxc_methods[] = {
    3.35        "Returns: [int]: The size in KiB of memory spanning the given number "
    3.36        "of pages.\n" },
    3.37  
    3.38 +    { "domain_set_time_offset",
    3.39 +      (PyCFunction)pyxc_domain_set_time_offset,
    3.40 +      METH_VARARGS, "\n"
    3.41 +      "Set a domain's time offset to Dom0's localtime\n"
    3.42 +      " dom        [int]: Domain whose time offset is being set.\n"
    3.43 +      "Returns: [int] 0 on success; -1 on error.\n" },
    3.44 +
    3.45      { NULL, NULL, 0, NULL }
    3.46  };
    3.47  
     4.1 --- a/tools/python/xen/xend/XendDomainInfo.py	Wed Jun 21 16:55:25 2006 +0100
     4.2 +++ b/tools/python/xen/xend/XendDomainInfo.py	Wed Jun 21 17:09:14 2006 +0100
     4.3 @@ -135,6 +135,7 @@ ROUNDTRIPPING_CONFIG_ENTRIES = [
     4.4      ('bootloader', str),
     4.5      ('bootloader_args', str),
     4.6      ('features', str),
     4.7 +    ('localtime', int),
     4.8      ]
     4.9  
    4.10  ROUNDTRIPPING_CONFIG_ENTRIES += VM_CONFIG_PARAMS
    4.11 @@ -1260,6 +1261,10 @@ class XendDomainInfo:
    4.12                                        self.info['image'],
    4.13                                        self.info['device'])
    4.14  
    4.15 +            localtime = self.info['localtime']
    4.16 +            if localtime is not None and localtime == 1:
    4.17 +                xc.domain_set_time_offset(self.domid)
    4.18 +
    4.19              xc.domain_setcpuweight(self.domid, self.info['cpu_weight'])
    4.20  
    4.21              # repin domain vcpus if a restricted cpus list is provided
     5.1 --- a/tools/python/xen/xm/create.py	Wed Jun 21 16:55:25 2006 +0100
     5.2 +++ b/tools/python/xen/xm/create.py	Wed Jun 21 17:09:14 2006 +0100
     5.3 @@ -672,6 +672,8 @@ def make_config(vals):
     5.4          config.append(['backend', ['netif']])
     5.5      if vals.tpmif:
     5.6          config.append(['backend', ['tpmif']])
     5.7 +    if vals.localtime:
     5.8 +        config.append(['localtime', vals.localtime])
     5.9  
    5.10      config_image = configure_image(vals)
    5.11      if vals.bootloader:
     6.1 --- a/xen/arch/x86/time.c	Wed Jun 21 16:55:25 2006 +0100
     6.2 +++ b/xen/arch/x86/time.c	Wed Jun 21 17:09:14 2006 +0100
     6.3 @@ -699,7 +699,7 @@ void update_domain_wallclock_time(struct
     6.4  {
     6.5      spin_lock(&wc_lock);
     6.6      version_update_begin(&d->shared_info->wc_version);
     6.7 -    d->shared_info->wc_sec  = wc_sec;
     6.8 +    d->shared_info->wc_sec  = wc_sec + d->time_offset_seconds;
     6.9      d->shared_info->wc_nsec = wc_nsec;
    6.10      version_update_end(&d->shared_info->wc_version);
    6.11      spin_unlock(&wc_lock);
     7.1 --- a/xen/common/dom0_ops.c	Wed Jun 21 16:55:25 2006 +0100
     7.2 +++ b/xen/common/dom0_ops.c	Wed Jun 21 17:09:14 2006 +0100
     7.3 @@ -693,6 +693,21 @@ long do_dom0_op(XEN_GUEST_HANDLE(dom0_op
     7.4      break;
     7.5  #endif
     7.6  
     7.7 +    case DOM0_SETTIMEOFFSET:
     7.8 +    {
     7.9 +        struct domain *d;
    7.10 +
    7.11 +        ret = -ESRCH;
    7.12 +        d = find_domain_by_id(op->u.settimeoffset.domain);
    7.13 +        if ( d != NULL )
    7.14 +        {
    7.15 +            d->time_offset_seconds = op->u.settimeoffset.time_offset_seconds;
    7.16 +            put_domain(d);
    7.17 +            ret = 0;
    7.18 +        }
    7.19 +    }
    7.20 +    break;
    7.21 +
    7.22      default:
    7.23          ret = arch_do_dom0_op(op, u_dom0_op);
    7.24          break;
     8.1 --- a/xen/include/public/dom0_ops.h	Wed Jun 21 16:55:25 2006 +0100
     8.2 +++ b/xen/include/public/dom0_ops.h	Wed Jun 21 17:09:14 2006 +0100
     8.3 @@ -527,6 +527,14 @@ typedef struct dom0_domain_setup {
     8.4  } dom0_domain_setup_t;
     8.5  DEFINE_XEN_GUEST_HANDLE(dom0_domain_setup_t);
     8.6  
     8.7 +#define DOM0_SETTIMEOFFSET    50
     8.8 +struct dom0_settimeoffset {
     8.9 +    domid_t  domain;
    8.10 +    int32_t  time_offset_seconds; /* applied to domain wallclock time */
    8.11 +};
    8.12 +typedef struct dom0_settimeoffset dom0_settimeoffset_t;
    8.13 +DEFINE_XEN_GUEST_HANDLE(dom0_settimeoffset_t);
    8.14 +
    8.15  struct dom0_op {
    8.16      uint32_t cmd;
    8.17      uint32_t interface_version; /* DOM0_INTERFACE_VERSION */
    8.18 @@ -569,6 +577,7 @@ struct dom0_op {
    8.19          struct dom0_iomem_permission  iomem_permission;
    8.20          struct dom0_hypercall_init    hypercall_init;
    8.21          struct dom0_domain_setup      domain_setup;
    8.22 +        struct dom0_settimeoffset     settimeoffset;
    8.23          uint8_t                       pad[128];
    8.24      } u;
    8.25  };
     9.1 --- a/xen/include/xen/sched.h	Wed Jun 21 16:55:25 2006 +0100
     9.2 +++ b/xen/include/xen/sched.h	Wed Jun 21 17:09:14 2006 +0100
     9.3 @@ -159,6 +159,7 @@ struct domain
     9.4  
     9.5      /* OProfile support. */
     9.6      struct xenoprof *xenoprof;
     9.7 +    int32_t time_offset_seconds;
     9.8  };
     9.9  
    9.10  struct domain_setup_info