Skip to contentSkip to conversation

xend: fix rtc_timeoffset when localtime=1

PATCH In review Kouya Shimura 3 participants 6 messages Apr 1, 2009 – Apr 3, 2009

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xend: fix rtc_timeoffset when localtime=1

The rtc_timeoffset parameter in VM config is ignored when localtime=1. Also it is not preserved across reboot.

NOTE:
This patch changes the meaning of the xenstore /vm/<uuid>/rtc/timeoffset from utc offset to local offset. (it's OK for the ioemu)

tools/python/xen/xend/XendDomainInfo.py +4 -13
diff -r f6fd1c2e4da6 tools/python/xen/xend/XendDomainInfo.py
@@ -1605,9 +1605,6 @@ class XendDomainInfo:
         # convert two lists into a python dictionary
         vm_details = dict(zip(cfg_vm, vm_details))
 
-        if vm_details['rtc/timeoffset'] == None:
-            vm_details['rtc/timeoffset'] = "0"
-
         for arg, val in vm_details.items():
             if arg in XendConfig.LEGACY_CFG_TO_XENAPI_CFG:
                 xapiarg = XendConfig.LEGACY_CFG_TO_XENAPI_CFG[arg]
@@ -1629,10 +1626,10 @@ class XendDomainInfo:
             self.info.update_with_image_sxp(sxp.from_string(image_sxp))
             changed = True
 
-        # Check if the rtc offset has changes
-        if vm_details.get("rtc/timeoffset", "0") != self.info["platform"].get("rtc_timeoffset", "0"):
-            self.info["platform"]["rtc_timeoffset"] = vm_details.get("rtc/timeoffset", 0)
-            changed = True
+        # Update the rtc_timeoffset to be preserved across reboot.
+        # NB. No need to update xenstore domain section.
+        val = int(vm_details.get("rtc/timeoffset", 0))
+        self.info["platform"]["rtc_timeoffset"] = val
  
         if changed:
             # Update the domain section of the store, as this contains some
@@ -2439,12 +2436,6 @@ class XendDomainInfo:
         self._configureBootloader()
 
         try:
-            if self.info['platform'].get('localtime', 0):
-                if time.localtime(time.time())[8]:
-                    self.info['platform']['rtc_timeoffset'] = -time.altzone
-                else:
-                    self.info['platform']['rtc_timeoffset'] = -time.timezone
-
             self.image = image.create(self, self.info)
 
             # repin domain vcpus if a restricted cpus list is provided
tools/python/xen/xend/image.py +8 -3
diff -r f6fd1c2e4da6 tools/python/xen/xend/image.py
@@ -119,9 +119,14 @@ class ImageHandler:
         self.vncconsole = int(vmConfig['platform'].get('vncconsole', 0))
         self.dmargs = self.parseDeviceModelArgs(vmConfig)
         self.pid = None
-        rtc_timeoffset = vmConfig['platform'].get('rtc_timeoffset')
-        if rtc_timeoffset is not None:
-            xc.domain_set_time_offset(self.vm.getDomid(), int(rtc_timeoffset))
+        rtc_timeoffset = int(vmConfig['platform'].get('rtc_timeoffset', 0))
+        if vmConfig['platform'].get('localtime', 0):
+            if time.localtime(time.time())[8]:
+                rtc_timeoffset -= time.altzone
+            else:
+                rtc_timeoffset -= time.timezone
+        if rtc_timeoffset != 0:
+            xc.domain_set_time_offset(self.vm.getDomid(), rtc_timeoffset)
 
         self.cpuid = None
         self.cpuid_check = None
tools/python/xen/xm/create.py +1 -1
diff -r f6fd1c2e4da6 tools/python/xen/xm/create.py
@@ -204,7 +204,7 @@ gopts.var('cpus', val='CPUS',
           use="CPUS to run the domain on.")
 
 gopts.var('rtc_timeoffset', val='RTC_TIMEOFFSET',
-          fn=set_value, default="0",
+          fn=set_int, default=0,
           use="Set RTC offset.")
 
 gopts.var('pae', val='PAE',

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#1 lore raw

Kouya Shimura writes ("[Xen-devel] [PATCH] xend: fix rtc_timeoffset when localtime=1"):

Quoted 6 lines

The rtc_timeoffset parameter in VM config is ignored when localtime=1. Also it is not preserved across reboot.

NOTE:
This patch changes the meaning of the xenstore /vm/<uuid>/rtc/timeoffset from utc offset to local offset. (it's OK for the ioemu)

Are you sure that this is an appropriate change ? I'm not sure I follow exactly and have only skimread your patch. Can you explain why it is right to change the meaning of a xenstore value like this ?

Ian.

#2 lore raw
Quoted 11 lines · Ian Jackson

Kouya Shimura writes ("[Xen-devel] [PATCH] xend: fix rtc_timeoffset when localtime=1"):

Quoted 6 lines

The rtc_timeoffset parameter in VM config is ignored when localtime=1. Also it is not preserved across reboot.

NOTE:
This patch changes the meaning of the xenstore /vm/<uuid>/rtc/timeoffset from utc offset to local offset. (it's OK for the ioemu)

Are you sure that this is an appropriate change ? I'm not sure I follow exactly and have only skimread your patch. Can you explain why it is right to change the meaning of a xenstore value like this ?

Hi Ian,

I'm quite sure. From a ioemu point of view, the value is no concern of the ioemu. The ioemu receives the ioreq, accumulates the value, and then just passes it to the xenstore.
You can apply the attached patch. :-)

When a guest changes the real time clock, the hypervisor sends the difference between before and after via ioreq to the ioemu. see rtc_set_time@xen/arch/x86/hvm/rtc.c.
Thus, /rtc/timeoffset keeps correct offset from any initial value.

And xend is the only one to refer /rtc/timeoffset, and xend knows that it is a offset based on local time. So, my scheme works well.

In addition, PV domain doesn't use the xenstore /rtc/timeoffset.

Thanks,
Kouya

hw/xen_machine_fv.c +0 -3
index 9bca50a..a2ca3e7 100644
@@ -276,9 +276,6 @@ static void xen_init_fv(ram_addr_t ram_size, int vga_ram_size,
     free(page_array);
 #endif
 
-    timeoffset_get();
-
-
     pc_machine.init(ram_size, vga_ram_size, boot_device,
 		    kernel_filename, kernel_cmdline, initrd_filename,
 		    cpu_model, direct_pci);
i386-dm/helper2.c +5 -2
index 969241f..d95cfc9 100644
@@ -91,7 +91,8 @@ int domid_backend = 0;
    * domain case.
    */
 
-long time_offset = 0;
+static long time_offset = 0;
+static void timeoffset_get(void);
 
 shared_iopage_t *shared_page = NULL;
 
@@ -146,6 +147,8 @@ CPUX86State *cpu_x86_init(const char *cpu_model)
             }
             ioreq_local_port[i] = rc;
         }
+
+        timeoffset_get();
     }
 
     return env;
@@ -402,7 +405,7 @@ static void cpu_ioreq_move(CPUState *env, ioreq_t *req)
     }
 }
 
-void timeoffset_get(void)
+static void timeoffset_get(void)
 {
     char *p;
 
qemu-xen.h +0 -4
index ec4cd94..9d4642d 100644
@@ -18,10 +18,6 @@ void     qemu_invalidate_map_cache(void);
 #define mapcache_lock()   ((void)0)
 #define mapcache_unlock() ((void)0)
 
-/* helper2.c */
-extern long time_offset;
-void timeoffset_get(void);
-
 /* xen_platform.c */
 #ifndef QEMU_TOOL
 void pci_xen_platform_init(PCIBus *bus);

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#3 lore raw
Quoted 1 line · Kouya Shimura

In addition, PV domain doesn't use the xenstore /rtc/timeoffset.

Are you positive about that? Solaris PV expects RTC in localtime.

The patch looked strange to me too but I haven't had time to look at it closely either.

regards
john

#4 lore raw
Quoted 8 lines · John Levon
Quoted 1 line · Kouya Shimura

In addition, PV domain doesn't use the xenstore /rtc/timeoffset.

Are you positive about that? Solaris PV expects RTC in localtime.

The patch looked strange to me too but I haven't had time to look at it closely either.

If solaris PV watches the xenstore /rtc/timeoffset, that's a problem. But I dont't think so.

/rtc/timeoffset is an interface between HVM->hypervisor->ioemu->xend (especially ioemu->xend), and xen hypervisor doesn't prepare an interface to change the xenstore /rtc/timeoffset for PV domain.

At least, xen PV domain even has no /rtc/timeoffset entry in xenstore.

Thanks,
Kouya

#5 lore raw
Quoted 9 lines · Kouya Shimura
Quoted 6 lines
Quoted 1 line

In addition, PV domain doesn't use the xenstore /rtc/timeoffset.

Are you positive about that? Solaris PV expects RTC in localtime.

The patch looked strange to me too but I haven't had time to look at it closely either.

If solaris PV watches the xenstore /rtc/timeoffset, that's a problem. But I dont't think so.

Right, it doesn't, I'd missed you were talking about the xenstore entry.

I think I understand the patch now.

regards
john