Skip to contentSkip to conversation

libxl: support for "rtc_timeoffset" and "localtime"

PATCH Superseded Lin Ming 2 participants 5 messages Mar 19, 2012

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Lin Ming

author
#0 lore raw

PATCH v2 1/1 libxl: support for "rtc_timeoffset" and "localtime"

Implement "rtc_timeoffset" and "localtime" options compatible as xm.

rtc_timeoffset is the offset between host time and guest time. localtime means to specify whether the emulted RTC appears as UTC or is offset by the host.

---
 docs/man/xl.cfg.pod.5       |    8 ++++++++
 tools/libxl/libxl_create.c  |    1 +
 tools/libxl/libxl_dom.c     |    3 +++
 tools/libxl/libxl_types.idl |    2 ++
 tools/libxl/xl_cmdimpl.c    |   14 ++++++++++++++
 5 files changed, 28 insertions(+), 0 deletions(-)

Changed since v1:
* Add tm_gmtoff, instead subtract, to rtc_timeoffset (Giam Teck Choon)
* Add docs for the newly supported options
* Include "bool localtime" in libxl API
* Remove the unneeded "rtc_timeoffset" output in printf_info_sexp()

docs/man/xl.cfg.pod.5 +8 -0
index 55f7e75..f93f1d6 100644
@@ -109,6 +109,14 @@ created online and the remainder will be offline.
 
 Start the guest with MBYTES megabytes of RAM.
 
+=item B<localtime=BOOLEAN>
+
+Set the real time clock to local time or to UTC. UTC by default.
+
+=item B<rtc_timeoffset=SECONDS>
+
+Set the real time clock offset in seconds. 0 by default.
+
 =item B<on_poweroff="ACTION">
 
 Specifies what should be done with the domain if it shuts itself down.
tools/libxl/libxl_create.c +1 -0
index 8417661..b0e76cb 100644
@@ -124,6 +124,7 @@ int libxl__domain_build_info_setdefault(libxl__gc *gc,
     if (b_info->target_memkb == LIBXL_MEMKB_DEFAULT)
         b_info->target_memkb = b_info->max_memkb;
 
+    libxl_defbool_setdefault(&b_info->localtime, false);
     libxl_defbool_setdefault(&b_info->disable_migrate, false);
 
     switch (b_info->type) {
tools/libxl/libxl_dom.c +3 -0
index 9b33267..0bdd654 100644
@@ -91,6 +91,9 @@ int libxl__build_pre(libxl__gc *gc, uint32_t domid,
     if (libxl_defbool_val(info->disable_migrate))
         xc_domain_disable_migrate(ctx->xch, domid);
 
+    if (info->rtc_timeoffset)
+        xc_domain_set_time_offset(ctx->xch, domid, info->rtc_timeoffset);
+
     if (info->type == LIBXL_DOMAIN_TYPE_HVM) {
         unsigned long shadow;
         shadow = (info->shadow_memkb + 1023) / 1024;
tools/libxl/libxl_types.idl +2 -0
index 413a1a6..09089b2 100644
@@ -238,6 +238,8 @@ libxl_domain_build_info = Struct("domain_build_info",[
     ("target_memkb",    MemKB),
     ("video_memkb",     MemKB),
     ("shadow_memkb",    MemKB),
+    ("rtc_timeoffset",  uint32),
+    ("localtime",       libxl_defbool),
     ("disable_migrate", libxl_defbool),
     ("cpuid",           libxl_cpuid_policy_list),
     
tools/libxl/xl_cmdimpl.c +14 -0
index 1d59b89..bcbea48 100644
@@ -697,6 +697,20 @@ static void parse_config_data(const char *configfile_filename_report,
         }
     }
 
+    if (!xlu_cfg_get_long(config, "rtc_timeoffset", &l, 0))
+        b_info->rtc_timeoffset = l;
+
+    xlu_cfg_get_defbool(config, "localtime", &b_info->localtime, 0);
+    if (libxl_defbool_val(b_info->localtime)) {
+        time_t t;
+        struct tm *tm;
+
+        t = time(NULL);
+        tm = localtime(&t);
+
+        b_info->rtc_timeoffset += tm->tm_gmtoff;
+    }
+
     if (!xlu_cfg_get_long (config, "videoram", &l, 0))
         b_info->video_memkb = l * 1024;
 
Signature · 1 line
1.7.2.5
#1 lore raw
Quoted 26 lines · Lin Ming

Implement "rtc_timeoffset" and "localtime" options compatible as xm.

rtc_timeoffset is the offset between host time and guest time. localtime means to specify whether the emulted RTC appears as UTC or is offset by the host.

---
 docs/man/xl.cfg.pod.5       |    8 ++++++++
 tools/libxl/libxl_create.c  |    1 +
 tools/libxl/libxl_dom.c     |    3 +++
 tools/libxl/libxl_types.idl |    2 ++
 tools/libxl/xl_cmdimpl.c    |   14 ++++++++++++++
 5 files changed, 28 insertions(+), 0 deletions(-)

Changed since v1:
* Add tm_gmtoff, instead subtract, to rtc_timeoffset (Giam Teck Choon)
* Add docs for the newly supported options
* Include "bool localtime" in libxl API
* Remove the unneeded "rtc_timeoffset" output in printf_info_sexp()

docs/man/xl.cfg.pod.5 +0 -0
index 55f7e75..f93f1d6 100644

docs/man/xl.cfg.pod.5 created online and the remainder will be offline. · line 114

Quoted 6 lines
docs/man/xl.cfg.pod.5 +3 -0
@@ -109,6 +109,14 @@ created online and the remainder will be offline.
 
 Start the guest with MBYTES megabytes of RAM.
 
+=item B<localtime=BOOLEAN>
+
+Set the real time clock to local time or to UTC. UTC by default.

Might be worth making it clearer which corresponds to true and which to false?

Also both of these options belong in the "Fully-virtualised (HVM) Guest Specific Options" section of the document.

Quoted 58 lines
docs/man/xl.cfg.pod.5 +5 -0
+
+=item B<rtc_timeoffset=SECONDS>
+
+Set the real time clock offset in seconds. 0 by default.
+
 =item B<on_poweroff="ACTION">
 
 Specifies what should be done with the domain if it shuts itself down.
tools/libxl/libxl_create.c +1 -0
index 8417661..b0e76cb 100644
@@ -124,6 +124,7 @@ int libxl__domain_build_info_setdefault(libxl__gc *gc,
     if (b_info->target_memkb == LIBXL_MEMKB_DEFAULT)
         b_info->target_memkb = b_info->max_memkb;
 
+    libxl_defbool_setdefault(&b_info->localtime, false);
     libxl_defbool_setdefault(&b_info->disable_migrate, false);
 
     switch (b_info->type) {
tools/libxl/libxl_dom.c +3 -0
index 9b33267..0bdd654 100644
@@ -91,6 +91,9 @@ int libxl__build_pre(libxl__gc *gc, uint32_t domid,
     if (libxl_defbool_val(info->disable_migrate))
         xc_domain_disable_migrate(ctx->xch, domid);
 
+    if (info->rtc_timeoffset)
+        xc_domain_set_time_offset(ctx->xch, domid, info->rtc_timeoffset);
+
     if (info->type == LIBXL_DOMAIN_TYPE_HVM) {
         unsigned long shadow;
         shadow = (info->shadow_memkb + 1023) / 1024;
tools/libxl/libxl_types.idl +2 -0
index 413a1a6..09089b2 100644
@@ -238,6 +238,8 @@ libxl_domain_build_info = Struct("domain_build_info",[
     ("target_memkb",    MemKB),
     ("video_memkb",     MemKB),
     ("shadow_memkb",    MemKB),
+    ("rtc_timeoffset",  uint32),
+    ("localtime",       libxl_defbool),
     ("disable_migrate", libxl_defbool),
     ("cpuid",           libxl_cpuid_policy_list),
 
tools/libxl/xl_cmdimpl.c +3 -0
index 1d59b89..bcbea48 100644
@@ -697,6 +697,20 @@ static void parse_config_data(const char *configfile_filename_report,
         }
     }
 
+    if (!xlu_cfg_get_long(config, "rtc_timeoffset", &l, 0))
+        b_info->rtc_timeoffset = l;
+

tools/libxl/xl_cmdimpl.c static void parse_config_data(const char *configfile_filename_report, · line 712

Quoted 10 lines
tools/libxl/xl_cmdimpl.c +10 -0
+    xlu_cfg_get_defbool(config, "localtime", &b_info->localtime, 0);
+    if (libxl_defbool_val(b_info->localtime)) {
+        time_t t;
+        struct tm *tm;
+
+        t = time(NULL);
+        tm = localtime(&t);
+
+        b_info->rtc_timeoffset += tm->tm_gmtoff;
+    }

This "if(...) { ... }" and the logic therein should be done inside libxl, I think in libxl__domain_build_info_setdefault() just after you set the default value

BT doesn't the above crash if localtime is not given at all in the config due to the lack of a specific value (which libxl_defbool_val requires has been set previously)

Ian.

Quoted 4 lines
tools/libxl/xl_cmdimpl.c +1 -0
+
     if (!xlu_cfg_get_long (config, "videoram", &l, 0))
         b_info->video_memkb = l * 1024;
 
author
#2 lore raw
Quoted 28 lines · Ian Campbell
Quoted 27 lines · Lin Ming

Implement "rtc_timeoffset" and "localtime" options compatible as xm.

rtc_timeoffset is the offset between host time and guest time. localtime means to specify whether the emulted RTC appears as UTC or is offset by the host.

---
 docs/man/xl.cfg.pod.5       |    8 ++++++++
 tools/libxl/libxl_create.c  |    1 +
 tools/libxl/libxl_dom.c     |    3 +++
 tools/libxl/libxl_types.idl |    2 ++
 tools/libxl/xl_cmdimpl.c    |   14 ++++++++++++++
 5 files changed, 28 insertions(+), 0 deletions(-)

Changed since v1:
* Add tm_gmtoff, instead subtract, to rtc_timeoffset (Giam Teck Choon)
* Add docs for the newly supported options
* Include "bool localtime" in libxl API
* Remove the unneeded "rtc_timeoffset" output in printf_info_sexp()

docs/man/xl.cfg.pod.5 +0 -0
index 55f7e75..f93f1d6 100644
@@ -109,6 +109,14 @@ created online and the remainder will be offline.
 
Quoted 8 lines

docs/man/xl.cfg.pod.5 created online and the remainder will be offline. · line 114

Quoted 5 lines
docs/man/xl.cfg.pod.5 +3 -0
 Start the guest with MBYTES megabytes of RAM.
 
+=item B<localtime=BOOLEAN>
+
+Set the real time clock to local time or to UTC. UTC by default.

Might be worth making it clearer which corresponds to true and which to false?

How about:

Set the real time clock to local time or to UTC. 0 by default, i.e. set to UTC.

Quoted 3 lines

Also both of these options belong in the "Fully-virtualised (HVM) Guest Specific Options" section of the document.

Move both to the end of that section.

See below patch.

Quoted 74 lines
Quoted 59 lines
docs/man/xl.cfg.pod.5 +5 -0
+
+=item B<rtc_timeoffset=SECONDS>
+
+Set the real time clock offset in seconds. 0 by default.
+
 =item B<on_poweroff="ACTION">
 
 Specifies what should be done with the domain if it shuts itself down.
tools/libxl/libxl_create.c +1 -0
index 8417661..b0e76cb 100644
@@ -124,6 +124,7 @@ int libxl__domain_build_info_setdefault(libxl__gc *gc,
     if (b_info->target_memkb == LIBXL_MEMKB_DEFAULT)
         b_info->target_memkb = b_info->max_memkb;
 
+    libxl_defbool_setdefault(&b_info->localtime, false);
     libxl_defbool_setdefault(&b_info->disable_migrate, false);
 
     switch (b_info->type) {
tools/libxl/libxl_dom.c +3 -0
index 9b33267..0bdd654 100644
@@ -91,6 +91,9 @@ int libxl__build_pre(libxl__gc *gc, uint32_t domid,
     if (libxl_defbool_val(info->disable_migrate))
         xc_domain_disable_migrate(ctx->xch, domid);
 
+    if (info->rtc_timeoffset)
+        xc_domain_set_time_offset(ctx->xch, domid, info->rtc_timeoffset);
+
     if (info->type == LIBXL_DOMAIN_TYPE_HVM) {
         unsigned long shadow;
         shadow = (info->shadow_memkb + 1023) / 1024;
tools/libxl/libxl_types.idl +2 -0
index 413a1a6..09089b2 100644
@@ -238,6 +238,8 @@ libxl_domain_build_info = Struct("domain_build_info",[
     ("target_memkb",    MemKB),
     ("video_memkb",     MemKB),
     ("shadow_memkb",    MemKB),
+    ("rtc_timeoffset",  uint32),
+    ("localtime",       libxl_defbool),
     ("disable_migrate", libxl_defbool),
     ("cpuid",           libxl_cpuid_policy_list),
 
tools/libxl/xl_cmdimpl.c +3 -0
index 1d59b89..bcbea48 100644
@@ -697,6 +697,20 @@ static void parse_config_data(const char *configfile_filename_report,
         }
     }
 
+    if (!xlu_cfg_get_long(config, "rtc_timeoffset", &l, 0))
+        b_info->rtc_timeoffset = l;
+

tools/libxl/xl_cmdimpl.c static void parse_config_data(const char *configfile_filename_report, · line 712

Quoted 10 lines
tools/libxl/xl_cmdimpl.c +10 -0
+    xlu_cfg_get_defbool(config, "localtime", &b_info->localtime, 0);
+    if (libxl_defbool_val(b_info->localtime)) {
+        time_t t;
+        struct tm *tm;
+
+        t = time(NULL);
+        tm = localtime(&t);
+
+        b_info->rtc_timeoffset += tm->tm_gmtoff;
+    }

This "if(...) { ... }" and the logic therein should be done inside libxl, I think in libxl__domain_build_info_setdefault() just after you set the default value

Quoted 3 lines

BT doesn't the above crash if localtime is not given at all in the config due to the lack of a specific value (which libxl_defbool_val requires has been set previously)

(I have problem to run xen-unstable, will re-send this patch after I get xen-unstable running and more test).

How about below compile-test-only patch?

Quoted 1 line

From 0614ad85fc5956d95d988b88689cc4967b4d8af8 Mon Sep 17 00:00:00 2001

From: Lin Ming <[email protected]>
Date: Sun, 18 Mar 2012 13:14:32 +0800
Subject: [PATCH] libxl: support for "rtc_timeoffset" and "localtime"

Implement "rtc_timeoffset" and "localtime" options compatible as xm.

rtc_timeoffset is the offset between host time and guest time. localtime means to specify whether the emulted RTC appears as UTC or is offset by the host.

---
 docs/man/xl.cfg.pod.5       |    8 ++++++++
 tools/libxl/libxl_create.c  |   11 +++++++++++
 tools/libxl/libxl_dom.c     |    3 +++
 tools/libxl/libxl_types.idl |    2 ++
 tools/libxl/xl_cmdimpl.c    |    5 +++++
 5 files changed, 29 insertions(+), 0 deletions(-)
docs/man/xl.cfg.pod.5 +8 -0
index 55f7e75..8d5a4ee 100644
@@ -767,6 +767,14 @@ Set mode for Virtual Timers XXX ??? should be an enum of particular
 values. See C<HVM_PARAM_TIMER_MODE> in
 F<xen/include/public/hvm/params.h>.
 
+=item B<localtime=BOOLEAN>
+
+Set the real time clock to local time or to UTC. 0 by default, i.e. set to UTC.
+
+=item B<rtc_timeoffset=SECONDS>
+
+Set the real time clock offset in seconds. 0 by default.
+
 =back
 
 =head2 Device-Model Options
tools/libxl/libxl_create.c +11 -0
index 8417661..d39ecbe 100644
@@ -124,6 +124,17 @@ int libxl__domain_build_info_setdefault(libxl__gc *gc,
     if (b_info->target_memkb == LIBXL_MEMKB_DEFAULT)
         b_info->target_memkb = b_info->max_memkb;
 
+    libxl_defbool_setdefault(&b_info->localtime, false);
+    if (libxl_defbool_val(b_info->localtime)) {
+        time_t t;
+        struct tm *tm;
+
+        t = time(NULL);
+        tm = localtime(&t);
+
+        b_info->rtc_timeoffset += tm->tm_gmtoff;
+    }
+
     libxl_defbool_setdefault(&b_info->disable_migrate, false);
 
     switch (b_info->type) {
tools/libxl/libxl_dom.c +3 -0
index 9b33267..0bdd654 100644
@@ -91,6 +91,9 @@ int libxl__build_pre(libxl__gc *gc, uint32_t domid,
     if (libxl_defbool_val(info->disable_migrate))
         xc_domain_disable_migrate(ctx->xch, domid);
 
+    if (info->rtc_timeoffset)
+        xc_domain_set_time_offset(ctx->xch, domid, info->rtc_timeoffset);
+
     if (info->type == LIBXL_DOMAIN_TYPE_HVM) {
         unsigned long shadow;
         shadow = (info->shadow_memkb + 1023) / 1024;
tools/libxl/libxl_types.idl +2 -0
index 413a1a6..09089b2 100644
@@ -238,6 +238,8 @@ libxl_domain_build_info = Struct("domain_build_info",[
     ("target_memkb",    MemKB),
     ("video_memkb",     MemKB),
     ("shadow_memkb",    MemKB),
+    ("rtc_timeoffset",  uint32),
+    ("localtime",       libxl_defbool),
     ("disable_migrate", libxl_defbool),
     ("cpuid",           libxl_cpuid_policy_list),
     
tools/libxl/xl_cmdimpl.c +5 -0
index 1d59b89..0736357 100644
@@ -697,6 +697,11 @@ static void parse_config_data(const char *configfile_filename_report,
         }
     }
 
+    if (!xlu_cfg_get_long(config, "rtc_timeoffset", &l, 0))
+        b_info->rtc_timeoffset = l;
+
+    xlu_cfg_get_defbool(config, "localtime", &b_info->localtime, 0);
+
     if (!xlu_cfg_get_long (config, "videoram", &l, 0))
         b_info->video_memkb = l * 1024;
 
Signature · 1 line
1.7.2.5
Acked-by
#3 lore raw
Quoted 5 lines · Lin Ming

From 0614ad85fc5956d95d988b88689cc4967b4d8af8 Mon Sep 17 00:00:00 2001
From: Lin Ming <[email protected]>
Date: Sun, 18 Mar 2012 13:14:32 +0800
Subject: [PATCH] libxl: support for "rtc_timeoffset" and "localtime"

Quoted 7 lines

Implement "rtc_timeoffset" and "localtime" options compatible as xm.

rtc_timeoffset is the offset between host time and guest time. localtime means to specify whether the emulted RTC appears as UTC or is offset by the host.

Looks good to me, thanks!

Although when you repost please can you fix the following:

docs/man/xl.cfg.pod.5 Set mode for Virtual Timers XXX ??? should be an enum of particular · line 768

Quoted 4 lines

[...]

docs/man/xl.cfg.pod.5 +0 -0
@@ -767,6 +767,14 @@ Set mode for Virtual Timers XXX ??? should be an enum of particular
 values. See C<HVM_PARAM_TIMER_MODE> in
 F<xen/include/public/hvm/params.h>.

The is the end of a sub section entitled "Unclassified HVM Specific Options". I think these new options belong in the "Guest Virtual Time Controls" subsection or perhaps "Miscellaneous Emulated Hardware".

Ian.

Quoted 77 lines
docs/man/xl.cfg.pod.5 +8 -0
+=item B<localtime=BOOLEAN>
+
+Set the real time clock to local time or to UTC. 0 by default, i.e. set to UTC.
+
+=item B<rtc_timeoffset=SECONDS>
+
+Set the real time clock offset in seconds. 0 by default.
+
 =back
 
 =head2 Device-Model Options
tools/libxl/libxl_create.c +11 -0
index 8417661..d39ecbe 100644
@@ -124,6 +124,17 @@ int libxl__domain_build_info_setdefault(libxl__gc *gc,
     if (b_info->target_memkb == LIBXL_MEMKB_DEFAULT)
         b_info->target_memkb = b_info->max_memkb;
 
+    libxl_defbool_setdefault(&b_info->localtime, false);
+    if (libxl_defbool_val(b_info->localtime)) {
+        time_t t;
+        struct tm *tm;
+
+        t = time(NULL);
+        tm = localtime(&t);
+
+        b_info->rtc_timeoffset += tm->tm_gmtoff;
+    }
+
     libxl_defbool_setdefault(&b_info->disable_migrate, false);
 
     switch (b_info->type) {
tools/libxl/libxl_dom.c +3 -0
index 9b33267..0bdd654 100644
@@ -91,6 +91,9 @@ int libxl__build_pre(libxl__gc *gc, uint32_t domid,
     if (libxl_defbool_val(info->disable_migrate))
         xc_domain_disable_migrate(ctx->xch, domid);
 
+    if (info->rtc_timeoffset)
+        xc_domain_set_time_offset(ctx->xch, domid, info->rtc_timeoffset);
+
     if (info->type == LIBXL_DOMAIN_TYPE_HVM) {
         unsigned long shadow;
         shadow = (info->shadow_memkb + 1023) / 1024;
tools/libxl/libxl_types.idl +2 -0
index 413a1a6..09089b2 100644
@@ -238,6 +238,8 @@ libxl_domain_build_info = Struct("domain_build_info",[
     ("target_memkb",    MemKB),
     ("video_memkb",     MemKB),
     ("shadow_memkb",    MemKB),
+    ("rtc_timeoffset",  uint32),
+    ("localtime",       libxl_defbool),
     ("disable_migrate", libxl_defbool),
     ("cpuid",           libxl_cpuid_policy_list),
 
tools/libxl/xl_cmdimpl.c +5 -0
index 1d59b89..0736357 100644
@@ -697,6 +697,11 @@ static void parse_config_data(const char *configfile_filename_report,
         }
     }
 
+    if (!xlu_cfg_get_long(config, "rtc_timeoffset", &l, 0))
+        b_info->rtc_timeoffset = l;
+
+    xlu_cfg_get_defbool(config, "localtime", &b_info->localtime, 0);
+
     if (!xlu_cfg_get_long (config, "videoram", &l, 0))
         b_info->video_memkb = l * 1024;
 
author
#4 lore raw
Quoted 19 lines · Ian Campbell
Quoted 5 lines · Lin Ming

From 0614ad85fc5956d95d988b88689cc4967b4d8af8 Mon Sep 17 00:00:00 2001
From: Lin Ming <[email protected]>
Date: Sun, 18 Mar 2012 13:14:32 +0800
Subject: [PATCH] libxl: support for "rtc_timeoffset" and "localtime"

Quoted 7 lines

Implement "rtc_timeoffset" and "localtime" options compatible as xm.

rtc_timeoffset is the offset between host time and guest time. localtime means to specify whether the emulted RTC appears as UTC or is offset by the host.

Looks good to me, thanks!

Although when you repost please can you fix the following:

Quoted 8 lines
Quoted 4 lines

[...]

(quoted diff) +0 -0
@@ -767,6 +767,14 @@ Set mode for Virtual Timers XXX ??? should be an enum of particular

 values. See C<HVM_PARAM_TIMER_MODE> in
 F<xen/include/public/hvm/params.h>.

The is the end of a sub section entitled "Unclassified HVM Specific Options". I think these new options belong in the "Guest Virtual Time Controls" subsection or perhaps "Miscellaneous Emulated Hardware".

OK, "Guest Virtual Time Controls" looks better to me.

Will move there.

Quoted 2 lines

Ian.