ia64/xen-unstable

changeset 10078:345464c2fd47

Allow to specify different time-of-day clock offsets for HVM guests.

There are some usage scenarios in which differing user domains want
to be using different base TOD clocks. This patch adds the ability
to specify the base TOD time difference. The patch also adds a
hook point to notify another entity when the domain changes this
offset. This might occur, for instance, on a Linux domain using
hwclock -w.

Signed-off-by: Ben Thomas <ben@virtualiron.com>
author kaf24@firebug.cl.cam.ac.uk
date Wed May 17 23:43:32 2006 +0100 (2006-05-17)
parents dbe396fd6fd8
children 81ab21f76a6f
files tools/ioemu/hw/mc146818rtc.c tools/ioemu/hw/pc.c tools/ioemu/vl.c tools/ioemu/vl.h
line diff
     1.1 --- a/tools/ioemu/hw/mc146818rtc.c	Wed May 17 23:41:59 2006 +0100
     1.2 +++ b/tools/ioemu/hw/mc146818rtc.c	Wed May 17 23:43:32 2006 +0100
     1.3 @@ -178,10 +178,27 @@ static inline int from_bcd(RTCState *s, 
     1.4      }
     1.5  }
     1.6  
     1.7 +static void send_timeoffset_msg(time_t delta)
     1.8 +{
     1.9 +
    1.10 +/* This routine is used to inform another entity that the
    1.11 +   base time offset has changed. For instance, if you
    1.12 +   were using xenstore, you might want to write to the store
    1.13 +   at this point.  Or, you might use some other method.
    1.14 +   Whatever you might choose, here's a hook point to implement it.
    1.15 +
    1.16 +   One item of note is that this delta is in addition to
    1.17 +   any existing offset you might be already using. */
    1.18 +
    1.19 +    return;
    1.20 +}
    1.21 +
    1.22  static void rtc_set_time(RTCState *s)
    1.23  {
    1.24      struct tm *tm = &s->current_tm;
    1.25 -
    1.26 +    time_t before, after;
    1.27 +    
    1.28 +    before = mktime(tm);
    1.29      tm->tm_sec = from_bcd(s, s->cmos_data[RTC_SECONDS]);
    1.30      tm->tm_min = from_bcd(s, s->cmos_data[RTC_MINUTES]);
    1.31      tm->tm_hour = from_bcd(s, s->cmos_data[RTC_HOURS] & 0x7f);
    1.32 @@ -193,6 +210,12 @@ static void rtc_set_time(RTCState *s)
    1.33      tm->tm_mday = from_bcd(s, s->cmos_data[RTC_DAY_OF_MONTH]);
    1.34      tm->tm_mon = from_bcd(s, s->cmos_data[RTC_MONTH]) - 1;
    1.35      tm->tm_year = from_bcd(s, s->cmos_data[RTC_YEAR]) + 100;
    1.36 +
    1.37 +    /* Compute, and send, the additional time delta
    1.38 +       We could compute the total time delta, but this is
    1.39 +       sufficient, and simple. */
    1.40 +    after = mktime(tm);
    1.41 +    send_timeoffset_msg(after-before);
    1.42  }
    1.43  
    1.44  static void rtc_copy_date(RTCState *s)
     2.1 --- a/tools/ioemu/hw/pc.c	Wed May 17 23:41:59 2006 +0100
     2.2 +++ b/tools/ioemu/hw/pc.c	Wed May 17 23:43:32 2006 +0100
     2.3 @@ -118,7 +118,7 @@ static void cmos_init_hd(int type_ofs, i
     2.4  }
     2.5  
     2.6  /* hd_table must contain 4 block drivers */
     2.7 -static void cmos_init(uint64_t ram_size, int boot_device, BlockDriverState **hd_table)
     2.8 +static void cmos_init(uint64_t ram_size, int boot_device, BlockDriverState **hd_table, time_t timeoffset)
     2.9  {
    2.10      RTCState *s = rtc_state;
    2.11      int val;
    2.12 @@ -129,6 +129,7 @@ static void cmos_init(uint64_t ram_size,
    2.13  
    2.14      /* set the CMOS date */
    2.15      time(&ti);
    2.16 +    ti += timeoffset;
    2.17      if (rtc_utc)
    2.18          tm = gmtime(&ti);
    2.19      else
    2.20 @@ -381,7 +382,7 @@ extern int acpi_init(unsigned int base);
    2.21  void pc_init(uint64_t ram_size, int vga_ram_size, int boot_device,
    2.22               DisplayState *ds, const char **fd_filename, int snapshot,
    2.23               const char *kernel_filename, const char *kernel_cmdline,
    2.24 -             const char *initrd_filename)
    2.25 +             const char *initrd_filename, time_t timeoffset)
    2.26  {
    2.27      SerialState *sp;
    2.28      char buf[1024];
    2.29 @@ -577,7 +578,7 @@ void pc_init(uint64_t ram_size, int vga_
    2.30  
    2.31      floppy_controller = fdctrl_init(6, 2, 0, 0x3f0, fd_table);
    2.32  
    2.33 -    cmos_init(ram_size, boot_device, bs_table);
    2.34 +    cmos_init(ram_size, boot_device, bs_table, timeoffset);
    2.35      acpi_init(0x8000);
    2.36  
    2.37      /* must be done after all PCI devices are instanciated */
     3.1 --- a/tools/ioemu/vl.c	Wed May 17 23:41:59 2006 +0100
     3.2 +++ b/tools/ioemu/vl.c	Wed May 17 23:43:32 2006 +0100
     3.3 @@ -147,6 +147,7 @@ int repeat_key = 1;
     3.4  TextConsole *vga_console;
     3.5  CharDriverState *serial_hds[MAX_SERIAL_PORTS];
     3.6  int xc_handle;
     3.7 +time_t timeoffset = 0;
     3.8  
     3.9  /***********************************************************/
    3.10  /* x86 ISA bus support */
    3.11 @@ -2247,9 +2248,10 @@ void help(void)
    3.12             "-s              wait gdb connection to port %d\n"
    3.13             "-p port         ioreq port for xen\n"
    3.14             "-d domain       domain that we're serving\n"
    3.15 -           "-domain-namn    domain name that we're serving\n"
    3.16 +           "-domain-name    domain name that we're serving\n"
    3.17             "-hdachs c,h,s   force hard disk 0 geometry (usually qemu can guess it)\n"
    3.18             "-L path         set the directory for the BIOS and VGA BIOS\n"
    3.19 +	   "-timeoffset     time offset (in seconds) from local time (Xen)\n"
    3.20  #ifdef USE_CODE_COPY
    3.21             "-no-code-copy   disable code copy acceleration\n"
    3.22  #endif
    3.23 @@ -2347,6 +2349,7 @@ enum {
    3.24      QEMU_OPTION_monitor,
    3.25      QEMU_OPTION_domainname,
    3.26      QEMU_OPTION_serial,
    3.27 +    QEMU_OPTION_timeoffset,
    3.28      QEMU_OPTION_loadvm,
    3.29      QEMU_OPTION_full_screen,
    3.30      QEMU_OPTION_vgaacc,
    3.31 @@ -2420,6 +2423,7 @@ const QEMUOption qemu_options[] = {
    3.32      { "std-vga", 0, QEMU_OPTION_std_vga },
    3.33      { "monitor", 1, QEMU_OPTION_monitor },
    3.34      { "domain-name", 1, QEMU_OPTION_domainname },
    3.35 +    { "timeoffset", HAS_ARG, QEMU_OPTION_timeoffset },
    3.36      { "serial", 1, QEMU_OPTION_serial },
    3.37      { "loadvm", HAS_ARG, QEMU_OPTION_loadvm },
    3.38      { "full-screen", 0, QEMU_OPTION_full_screen },
    3.39 @@ -2936,7 +2940,10 @@ int main(int argc, char **argv)
    3.40              case QEMU_OPTION_domainname:
    3.41                  strncat(domain_name, optarg, sizeof(domain_name) - 20);
    3.42                  break;
    3.43 -
    3.44 +	    case QEMU_OPTION_timeoffset:
    3.45 +                timeoffset = strtol(optarg, NULL, 0);
    3.46 +	    	break;
    3.47 + 
    3.48              }
    3.49          }
    3.50      }
    3.51 @@ -3227,7 +3234,7 @@ int main(int argc, char **argv)
    3.52  #if defined(TARGET_I386)
    3.53      pc_init(ram_size, vga_ram_size, boot_device,
    3.54              ds, fd_filename, snapshot,
    3.55 -            kernel_filename, kernel_cmdline, initrd_filename);
    3.56 +            kernel_filename, kernel_cmdline, initrd_filename, timeoffset);
    3.57  #elif defined(TARGET_PPC)
    3.58      ppc_init(ram_size, vga_ram_size, boot_device,
    3.59              ds, fd_filename, snapshot,
     4.1 --- a/tools/ioemu/vl.h	Wed May 17 23:41:59 2006 +0100
     4.2 +++ b/tools/ioemu/vl.h	Wed May 17 23:43:32 2006 +0100
     4.3 @@ -679,7 +679,7 @@ int pit_get_out(PITState *pit, int chann
     4.4  void pc_init(uint64_t ram_size, int vga_ram_size, int boot_device,
     4.5               DisplayState *ds, const char **fd_filename, int snapshot,
     4.6               const char *kernel_filename, const char *kernel_cmdline,
     4.7 -             const char *initrd_filename);
     4.8 +             const char *initrd_filename, time_t timeoffset);
     4.9  
    4.10  /* ppc.c */
    4.11  void ppc_init (int ram_size, int vga_ram_size, int boot_device,