From a2ba834e4f3988345661c1084765ea4c9a808941 Mon Sep 17 00:00:00 2001 From: Haozhong Zhang Date: Wed, 19 Aug 2015 16:26:29 +0800 Subject: [PATCH v2 15/15] tools/libxl: Add 'vtsc_khz' option to set guest TSC rate This patch adds an option 'vtsc_khz' to allow users to set vcpu's TSC rate in KHz. In the case that tsc_mode = 'default' or 'native_paravirt', the default value of 'vtsc_khz' option is the host TSC rate which is used when 'vtsc_khz' option is set to 0 or does not appear in the configuration. In all other cases of tsc_mode, 'vtsc_khz' option is just ignored. Another purpose of adding this option is to keep vcpu's TSC rate across guest reboot. In existing code, a new domain is created from the configuration of the previous domain which was just rebooted. vcpu's TSC rate is not stored in the configuration and the host TSC rate is the used as vcpu's TSC rate. This works fine unless the previous domain was migrated from another host machine with a different host TSC rate than the current one. Signed-off-by: Haozhong Zhang --- tools/libxl/libxl_types.idl | 1 + tools/libxl/libxl_x86.c | 4 +++- tools/libxl/xl_cmdimpl.c | 23 +++++++++++++++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/tools/libxl/libxl_types.idl b/tools/libxl/libxl_types.idl index 6808f2b..5480e46 100644 --- a/tools/libxl/libxl_types.idl +++ b/tools/libxl/libxl_types.idl @@ -420,6 +420,7 @@ libxl_domain_build_info = Struct("domain_build_info",[ ("vcpu_soft_affinity", Array(libxl_bitmap, "num_vcpu_soft_affinity")), ("numa_placement", libxl_defbool), ("tsc_mode", libxl_tsc_mode), + ("vtsc_khz", uint32), ("max_memkb", MemKB), ("target_memkb", MemKB), ("video_memkb", MemKB), diff --git a/tools/libxl/libxl_x86.c b/tools/libxl/libxl_x86.c index 183b6c2..f27b079 100644 --- a/tools/libxl/libxl_x86.c +++ b/tools/libxl/libxl_x86.c @@ -280,6 +280,7 @@ int libxl__arch_domain_create(libxl__gc *gc, libxl_domain_config *d_config, { int ret = 0; int tsc_mode; + uint32_t vtsc_khz; uint32_t rtc_timeoffset; libxl_ctx *ctx = libxl__gc_owner(gc); @@ -304,7 +305,8 @@ int libxl__arch_domain_create(libxl__gc *gc, libxl_domain_config *d_config, default: abort(); } - xc_domain_set_tsc_info(ctx->xch, domid, tsc_mode, 0, 0, 0); + vtsc_khz = d_config->b_info.vtsc_khz; + xc_domain_set_tsc_info(ctx->xch, domid, tsc_mode, 0, vtsc_khz, 0); if (libxl_defbool_val(d_config->b_info.disable_migrate)) xc_domain_disable_migrate(ctx->xch, domid); rtc_timeoffset = d_config->b_info.rtc_timeoffset; diff --git a/tools/libxl/xl_cmdimpl.c b/tools/libxl/xl_cmdimpl.c index 2b6371d..2705f8c 100644 --- a/tools/libxl/xl_cmdimpl.c +++ b/tools/libxl/xl_cmdimpl.c @@ -1464,6 +1464,29 @@ static void parse_config_data(const char *config_source, } } + /* "vtsc_khz" option works only if "tsc_mode" option is "default" + * or "native_paravirt". In this case, if "vtsc_khz" option is set + * to 0, we will reset it to the host TSC rate. In all other + * cases, we just ignore any given value and always set it to 0. + */ + if (!xlu_cfg_get_long(config, "vtsc_khz", &l, 0)) + b_info->vtsc_khz = l; + if (b_info->tsc_mode == LIBXL_TSC_MODE_DEFAULT || + b_info->tsc_mode == LIBXL_TSC_MODE_NATIVE_PARAVIRT) { + if (b_info->vtsc_khz == 0) { + libxl_physinfo physinfo; + if (!libxl_get_physinfo(ctx, &physinfo)) + b_info->vtsc_khz = physinfo.cpu_khz; + else + fprintf(stderr, "WARNING: cannot get host TSC rate.\n"); + } + } else { + fprintf(stderr, "WARNING: ignoring \"vtsc_khz\" option. " + "\"vtsc_khz\" option works only if " + "\"tsc_mode\" option is \"default\" or \"native_paravirt\".\n"); + b_info->vtsc_khz = 0; + } + if (!xlu_cfg_get_long(config, "rtc_timeoffset", &l, 0)) b_info->rtc_timeoffset = l; -- 2.4.8