# HG changeset patch # User Juergen Gross # Date 1337677423 -7200 # Node ID 953383741ff44d97587c2e75da79b092523d6e83 # Parent 19aaa30d7fdce2f1b56cb13399d603d955a61fb8 full support of setting scheduler parameters on domain creation Obtains default scheduler parameters before modifying any settings specified via domain config. Corrected an error for setting sedf parameters (setting .period multiple times). Signed-off-by: Juergen Gross diff -r 19aaa30d7fdc -r 953383741ff4 tools/libxl/libxl.h --- a/tools/libxl/libxl.h Tue May 22 10:31:30 2012 +0200 +++ b/tools/libxl/libxl.h Tue May 22 11:03:43 2012 +0200 @@ -605,6 +605,8 @@ int libxl_primary_console_exec(libxl_ctx /* May be called with info_r == NULL to check for domain's existance */ int libxl_domain_info(libxl_ctx*, libxl_dominfo *info_r, uint32_t domid); +int libxl_sched_set_defaults(libxl_ctx*, uint32_t poolid, + libxl_sched_params *scparams); libxl_dominfo * libxl_list_domain(libxl_ctx*, int *nb_domain); void libxl_dominfo_list_free(libxl_dominfo *list, int nr); libxl_cpupoolinfo * libxl_list_cpupool(libxl_ctx*, int *nb_pool); diff -r 19aaa30d7fdc -r 953383741ff4 tools/libxl/libxl_dom.c --- a/tools/libxl/libxl_dom.c Tue May 22 10:31:30 2012 +0200 +++ b/tools/libxl/libxl_dom.c Tue May 22 11:03:43 2012 +0200 @@ -42,17 +42,76 @@ libxl_domain_type libxl__domain_type(lib return LIBXL_DOMAIN_TYPE_PV; } +int libxl_sched_set_defaults(libxl_ctx *ctx, + uint32_t poolid, libxl_sched_params *scparams) +{ + libxl_cpupoolinfo *poolinfo; + struct xen_domctl_sched_credit credit_info; + struct xen_domctl_sched_credit2 credit2_info; + struct xen_domctl_sched_sedf sedf_info; + int n_pools, p; + int ret; + + poolinfo = libxl_list_cpupool(ctx, &n_pools); + if (!poolinfo) + return ERROR_NOMEM; + + ret = ERROR_INVAL; + for (p = 0; p < n_pools; p++) { + if (poolinfo[p].poolid == poolid) { + scparams->sched = poolinfo[p].sched; + ret = 0; + } + libxl_cpupoolinfo_dispose(poolinfo + p); + } + + if (!ret) { + switch (scparams->sched) { + case LIBXL_SCHEDULER_SEDF: + if (xc_sched_sedf_defaults_get(ctx->xch, poolid, + &sedf_info)) + ret = ERROR_FAIL; + else { + scparams->period = sedf_info.period; + scparams->slice = sedf_info.slice; + scparams->latency = sedf_info.latency; + scparams->extratime = sedf_info.extratime; + scparams->weight = sedf_info.weight; + } + break; + case LIBXL_SCHEDULER_CREDIT: + if (xc_sched_credit_defaults_get(ctx->xch, poolid, + &credit_info)) + ret = ERROR_FAIL; + else { + scparams->weight = credit_info.weight; + scparams->cap = credit_info.cap; + } + break; + case LIBXL_SCHEDULER_CREDIT2: + if (xc_sched_credit2_defaults_get(ctx->xch, poolid, + &credit2_info)) + ret = ERROR_FAIL; + else { + scparams->weight = credit2_info.weight; + } + break; + default: ret = ERROR_INVAL; + } + } + + return ret; +} + int libxl__sched_set_params(libxl__gc *gc, uint32_t domid, libxl_sched_params *scparams) { libxl_ctx *ctx = libxl__gc_owner(gc); - libxl_scheduler sched; libxl_sched_sedf_domain sedf_info; libxl_sched_credit_domain credit_info; libxl_sched_credit2_domain credit2_info; int ret; - sched = libxl_get_scheduler (ctx); - switch (sched) { + switch (scparams->sched) { case LIBXL_SCHEDULER_SEDF: sedf_info.period = scparams->period; sedf_info.slice = scparams->slice; diff -r 19aaa30d7fdc -r 953383741ff4 tools/libxl/libxl_types.idl --- a/tools/libxl/libxl_types.idl Tue May 22 10:31:30 2012 +0200 +++ b/tools/libxl/libxl_types.idl Tue May 22 11:03:43 2012 +0200 @@ -225,6 +225,7 @@ MemKB = UInt(64, init_val = "LIBXL_MEMKB MemKB = UInt(64, init_val = "LIBXL_MEMKB_DEFAULT") libxl_sched_params = Struct("sched_params",[ + ("sched", libxl_scheduler), ("weight", integer), ("cap", integer), ("tslice_ms", integer), diff -r 19aaa30d7fdc -r 953383741ff4 tools/libxl/xl_cmdimpl.c --- a/tools/libxl/xl_cmdimpl.c Tue May 22 10:31:30 2012 +0200 +++ b/tools/libxl/xl_cmdimpl.c Tue May 22 11:03:43 2012 +0200 @@ -628,6 +628,10 @@ static void parse_config_data(const char libxl_domain_build_info_init_type(b_info, c_info->type); /* the following is the actual config parsing with overriding values in the structures */ + if (libxl_sched_set_defaults(ctx, c_info->poolid, &b_info->sched_params)) { + fprintf(stderr, "Failed to set default scheduling parameters\n"); + exit(1); + } if (!xlu_cfg_get_long (config, "cpu_weight", &l, 0)) b_info->sched_params.weight = l; if (!xlu_cfg_get_long (config, "cap", &l, 0)) @@ -639,11 +643,11 @@ static void parse_config_data(const char if (!xlu_cfg_get_long (config, "period", &l, 0)) b_info->sched_params.period = l; if (!xlu_cfg_get_long (config, "slice", &l, 0)) - b_info->sched_params.period = l; + b_info->sched_params.slice = l; if (!xlu_cfg_get_long (config, "latency", &l, 0)) - b_info->sched_params.period = l; + b_info->sched_params.latency = l; if (!xlu_cfg_get_long (config, "extratime", &l, 0)) - b_info->sched_params.period = l; + b_info->sched_params.extratime = l; if (!xlu_cfg_get_long (config, "vcpus", &l, 0)) { b_info->max_vcpus = l;