[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-changelog] [xen-unstable] libxl: expose a single get/setter for domain scheduler parameters
# HG changeset patch # User Ian Campbell <ian.campbell@xxxxxxxxxx> # Date 1338548781 -3600 # Node ID 68d46c5ea0a3769a9ed398f8cd7542db1a346dc3 # Parent 4f743faf755977697ad0060f888a93753dc40f54 libxl: expose a single get/setter for domain scheduler parameters This is consistent with having a single struct for all parameters. Effectively renames and exports libxl__sched_set_params as libxl_domain_sched_params_set. libxl_domain_sched_params_get is new. Improve const correctness of the setters while I'm here. Use shorter LOG macros when touching a line anyway. Signed-off-by: Ian Campbell <ian.campbell@xxxxxxxxxx> Acked-by: George Dunlap <george.dunlap@xxxxxxxxxxxxx> Acked-by: Ian Jackson <ian.jackson@xxxxxxxxxxxxx> Committed-by: Ian Campbell <ian.campbell@xxxxxxxxxx> --- diff -r 4f743faf7559 -r 68d46c5ea0a3 tools/libxl/libxl.c --- a/tools/libxl/libxl.c Fri Jun 01 12:06:20 2012 +0100 +++ b/tools/libxl/libxl.c Fri Jun 01 12:06:21 2012 +0100 @@ -3295,15 +3295,15 @@ libxl_scheduler libxl_get_scheduler(libx return sched; } -int libxl_sched_credit_domain_get(libxl_ctx *ctx, uint32_t domid, - libxl_domain_sched_params *scinfo) +static int sched_credit_domain_get(libxl__gc *gc, uint32_t domid, + libxl_domain_sched_params *scinfo) { struct xen_domctl_sched_credit sdom; int rc; - rc = xc_sched_credit_domain_get(ctx->xch, domid, &sdom); + rc = xc_sched_credit_domain_get(CTX->xch, domid, &sdom); if (rc != 0) { - LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "getting domain sched credit"); + LOGE(ERROR, "getting domain sched credit"); return ERROR_FAIL; } @@ -3315,32 +3315,31 @@ int libxl_sched_credit_domain_get(libxl_ return 0; } -int libxl_sched_credit_domain_set(libxl_ctx *ctx, uint32_t domid, - libxl_domain_sched_params *scinfo) +static int sched_credit_domain_set(libxl__gc *gc, uint32_t domid, + const libxl_domain_sched_params *scinfo) { struct xen_domctl_sched_credit sdom; xc_domaininfo_t domaininfo; int rc; - rc = xc_domain_getinfolist(ctx->xch, domid, 1, &domaininfo); + rc = xc_domain_getinfolist(CTX->xch, domid, 1, &domaininfo); if (rc < 0) { - LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "getting domain info list"); + LOGE(ERROR, "getting domain info list"); return ERROR_FAIL; } if (rc != 1 || domaininfo.domain != domid) return ERROR_INVAL; - rc = xc_sched_credit_domain_get(ctx->xch, domid, &sdom); + rc = xc_sched_credit_domain_get(CTX->xch, domid, &sdom); if (rc != 0) { - LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "getting domain sched credit"); + LOGE(ERROR, "getting domain sched credit"); return ERROR_FAIL; } if (scinfo->weight != LIBXL_DOMAIN_SCHED_PARAM_WEIGHT_DEFAULT) { if (scinfo->weight < 1 || scinfo->weight > 65535) { - LIBXL__LOG(ctx, LIBXL__LOG_ERROR, - "Cpu weight out of range, " - "valid values are within range from 1 to 65535"); + LOG(ERROR, "Cpu weight out of range, " + "valid values are within range from 1 to 65535"); return ERROR_INVAL; } sdom.weight = scinfo->weight; @@ -3349,18 +3348,17 @@ int libxl_sched_credit_domain_set(libxl_ if (scinfo->cap != LIBXL_DOMAIN_SCHED_PARAM_CAP_DEFAULT) { if (scinfo->cap < 0 || scinfo->cap > (domaininfo.max_vcpu_id + 1) * 100) { - LIBXL__LOG(ctx, LIBXL__LOG_ERROR, - "Cpu cap out of range, " + LOG(ERROR, "Cpu cap out of range, " "valid range is from 0 to %d for specified number of vcpus", - ((domaininfo.max_vcpu_id + 1) * 100)); + ((domaininfo.max_vcpu_id + 1) * 100)); return ERROR_INVAL; } sdom.cap = scinfo->cap; } - rc = xc_sched_credit_domain_set(ctx->xch, domid, &sdom); + rc = xc_sched_credit_domain_set(CTX->xch, domid, &sdom); if ( rc < 0 ) { - LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "setting domain sched credit"); + LOGE(ERROR, "setting domain sched credit"); return ERROR_FAIL; } @@ -3428,16 +3426,15 @@ int libxl_sched_credit_params_set(libxl_ return 0; } -int libxl_sched_credit2_domain_get(libxl_ctx *ctx, uint32_t domid, - libxl_domain_sched_params *scinfo) +static int sched_credit2_domain_get(libxl__gc *gc, uint32_t domid, + libxl_domain_sched_params *scinfo) { struct xen_domctl_sched_credit2 sdom; int rc; - rc = xc_sched_credit2_domain_get(ctx->xch, domid, &sdom); + rc = xc_sched_credit2_domain_get(CTX->xch, domid, &sdom); if (rc != 0) { - LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, - "getting domain sched credit2"); + LOGE(ERROR, "getting domain sched credit2"); return ERROR_FAIL; } @@ -3448,42 +3445,38 @@ int libxl_sched_credit2_domain_get(libxl return 0; } -int libxl_sched_credit2_domain_set(libxl_ctx *ctx, uint32_t domid, - libxl_domain_sched_params *scinfo) +static int sched_credit2_domain_set(libxl__gc *gc, uint32_t domid, + const libxl_domain_sched_params *scinfo) { struct xen_domctl_sched_credit2 sdom; int rc; - rc = xc_sched_credit2_domain_get(ctx->xch, domid, &sdom); + rc = xc_sched_credit2_domain_get(CTX->xch, domid, &sdom); if (rc != 0) { - LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, - "getting domain sched credit2"); + LOGE(ERROR, "getting domain sched credit2"); return ERROR_FAIL; } if (scinfo->weight != LIBXL_DOMAIN_SCHED_PARAM_WEIGHT_DEFAULT) { if (scinfo->weight < 1 || scinfo->weight > 65535) { - LIBXL__LOG(ctx, LIBXL__LOG_ERROR, - "Cpu weight out of range, " - "valid values are within range from " - "1 to 65535"); + LOG(ERROR, "Cpu weight out of range, " + "valid values are within range from 1 to 65535"); return ERROR_INVAL; } sdom.weight = scinfo->weight; } - rc = xc_sched_credit2_domain_set(ctx->xch, domid, &sdom); + rc = xc_sched_credit2_domain_set(CTX->xch, domid, &sdom); if ( rc < 0 ) { - LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, - "setting domain sched credit2"); + LOGE(ERROR, "setting domain sched credit2"); return ERROR_FAIL; } return 0; } -int libxl_sched_sedf_domain_get(libxl_ctx *ctx, uint32_t domid, - libxl_domain_sched_params *scinfo) +static int sched_sedf_domain_get(libxl__gc *gc, uint32_t domid, + libxl_domain_sched_params *scinfo) { uint64_t period; uint64_t slice; @@ -3492,10 +3485,10 @@ int libxl_sched_sedf_domain_get(libxl_ct uint16_t weight; int rc; - rc = xc_sedf_domain_get(ctx->xch, domid, &period, &slice, &latency, + rc = xc_sedf_domain_get(CTX->xch, domid, &period, &slice, &latency, &extratime, &weight); if (rc != 0) { - LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "getting domain sched sedf"); + LOGE(ERROR, "getting domain sched sedf"); return ERROR_FAIL; } @@ -3510,8 +3503,8 @@ int libxl_sched_sedf_domain_get(libxl_ct return 0; } -int libxl_sched_sedf_domain_set(libxl_ctx *ctx, uint32_t domid, - libxl_domain_sched_params *scinfo) +static int sched_sedf_domain_set(libxl__gc *gc, uint32_t domid, + const libxl_domain_sched_params *scinfo) { uint64_t period; uint64_t slice; @@ -3521,10 +3514,10 @@ int libxl_sched_sedf_domain_set(libxl_ct int ret; - ret = xc_sedf_domain_get(ctx->xch, domid, &period, &slice, &latency, + ret = xc_sedf_domain_get(CTX->xch, domid, &period, &slice, &latency, &extratime, &weight); if (ret != 0) { - LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "getting domain sched sedf"); + LOGE(ERROR, "getting domain sched sedf"); return ERROR_FAIL; } @@ -3539,20 +3532,21 @@ int libxl_sched_sedf_domain_set(libxl_ct if (scinfo->weight != LIBXL_DOMAIN_SCHED_PARAM_WEIGHT_DEFAULT) weight = scinfo->weight; - ret = xc_sedf_domain_set(ctx->xch, domid, period, slice, latency, + ret = xc_sedf_domain_set(CTX->xch, domid, period, slice, latency, extratime, weight); if ( ret < 0 ) { - LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "setting domain sched sedf"); + LOGE(ERROR, "setting domain sched sedf"); return ERROR_FAIL; } return 0; } -int libxl__sched_set_params(libxl__gc *gc, uint32_t domid, - libxl_domain_sched_params *scparams) +int libxl_domain_sched_params_set(libxl_ctx *ctx, uint32_t domid, + const libxl_domain_sched_params *scinfo) { - libxl_scheduler sched = scparams->sched; + GC_INIT(ctx); + libxl_scheduler sched = scinfo->sched; int ret; if (sched == LIBXL_SCHEDULER_UNKNOWN) @@ -3560,19 +3554,51 @@ int libxl__sched_set_params(libxl__gc *g switch (sched) { case LIBXL_SCHEDULER_SEDF: - ret=libxl_sched_sedf_domain_set(CTX, domid, scparams); + ret=sched_sedf_domain_set(gc, domid, scinfo); break; case LIBXL_SCHEDULER_CREDIT: - ret=libxl_sched_credit_domain_set(CTX, domid, scparams); + ret=sched_credit_domain_set(gc, domid, scinfo); break; case LIBXL_SCHEDULER_CREDIT2: - ret=libxl_sched_credit2_domain_set(CTX, domid, scparams); + ret=sched_credit2_domain_set(gc, domid, scinfo); break; default: LOG(ERROR, "Unknown scheduler"); ret=ERROR_INVAL; break; } + + GC_FREE; + return ret; +} + +int libxl_domain_sched_params_get(libxl_ctx *ctx, uint32_t domid, + libxl_domain_sched_params *scinfo) +{ + GC_INIT(ctx); + int ret; + + libxl_domain_sched_params_init(scinfo); + + scinfo->sched = libxl__domain_scheduler(gc, domid); + + switch (scinfo->sched) { + case LIBXL_SCHEDULER_SEDF: + ret=sched_sedf_domain_get(gc, domid, scinfo); + break; + case LIBXL_SCHEDULER_CREDIT: + ret=sched_credit_domain_get(gc, domid, scinfo); + break; + case LIBXL_SCHEDULER_CREDIT2: + ret=sched_credit2_domain_get(gc, domid, scinfo); + break; + default: + LOG(ERROR, "Unknown scheduler"); + ret=ERROR_INVAL; + break; + } + + GC_FREE; return ret; } diff -r 4f743faf7559 -r 68d46c5ea0a3 tools/libxl/libxl.h --- a/tools/libxl/libxl.h Fri Jun 01 12:06:20 2012 +0100 +++ b/tools/libxl/libxl.h Fri Jun 01 12:06:21 2012 +0100 @@ -783,18 +783,11 @@ int libxl_sched_credit_params_set(libxl_ #define LIBXL_DOMAIN_SCHED_PARAM_LATENCY_DEFAULT -1 #define LIBXL_DOMAIN_SCHED_PARAM_EXTRATIME_DEFAULT -1 -int libxl_sched_credit_domain_get(libxl_ctx *ctx, uint32_t domid, - libxl_domain_sched_params *scinfo); -int libxl_sched_credit_domain_set(libxl_ctx *ctx, uint32_t domid, - libxl_domain_sched_params *scinfo); -int libxl_sched_credit2_domain_get(libxl_ctx *ctx, uint32_t domid, - libxl_domain_sched_params *scinfo); -int libxl_sched_credit2_domain_set(libxl_ctx *ctx, uint32_t domid, - libxl_domain_sched_params *scinfo); -int libxl_sched_sedf_domain_get(libxl_ctx *ctx, uint32_t domid, - libxl_domain_sched_params *scinfo); -int libxl_sched_sedf_domain_set(libxl_ctx *ctx, uint32_t domid, - libxl_domain_sched_params *scinfo); +int libxl_domain_sched_params_get(libxl_ctx *ctx, uint32_t domid, + libxl_domain_sched_params *params); +int libxl_domain_sched_params_set(libxl_ctx *ctx, uint32_t domid, + const libxl_domain_sched_params *params); + int libxl_send_trigger(libxl_ctx *ctx, uint32_t domid, libxl_trigger trigger, uint32_t vcpuid); int libxl_send_sysrq(libxl_ctx *ctx, uint32_t domid, char sysrq); diff -r 4f743faf7559 -r 68d46c5ea0a3 tools/libxl/libxl_dom.c --- a/tools/libxl/libxl_dom.c Fri Jun 01 12:06:20 2012 +0100 +++ b/tools/libxl/libxl_dom.c Fri Jun 01 12:06:21 2012 +0100 @@ -174,7 +174,7 @@ int libxl__build_post(libxl__gc *gc, uin char **ents, **hvm_ents; int i; - libxl__sched_set_params (gc, domid, &(info->sched_params)); + libxl_domain_sched_params_set(CTX, domid, &info->sched_params); libxl_cpuid_apply_policy(ctx, domid); if (info->cpuid != NULL) diff -r 4f743faf7559 -r 68d46c5ea0a3 tools/libxl/xl_cmdimpl.c --- a/tools/libxl/xl_cmdimpl.c Fri Jun 01 12:06:20 2012 +0100 +++ b/tools/libxl/xl_cmdimpl.c Fri Jun 01 12:06:21 2012 +0100 @@ -4363,24 +4363,33 @@ int main_sharing(int argc, char **argv) return 0; } -static int sched_credit_domain_get(int domid, libxl_domain_sched_params *scinfo) +static int sched_domain_get(libxl_scheduler sched, int domid, + libxl_domain_sched_params *scinfo) { int rc; - rc = libxl_sched_credit_domain_get(ctx, domid, scinfo); - if (rc) - fprintf(stderr, "libxl_sched_credit_domain_get failed.\n"); - - return rc; -} - -static int sched_credit_domain_set(int domid, libxl_domain_sched_params *scinfo) + rc = libxl_domain_sched_params_get(ctx, domid, scinfo); + if (rc) { + fprintf(stderr, "libxl_domain_sched_params_get failed.\n"); + return rc; + } + if (scinfo->sched != sched) { + fprintf(stderr, "libxl_domain_sched_params_get returned %s not %s.\n", + libxl_scheduler_to_string(scinfo->sched), + libxl_scheduler_to_string(sched)); + return ERROR_INVAL; + } + + return 0; +} + +static int sched_domain_set(int domid, const libxl_domain_sched_params *scinfo) { int rc; - rc = libxl_sched_credit_domain_set(ctx, domid, scinfo); + rc = libxl_domain_sched_params_set(ctx, domid, scinfo); if (rc) - fprintf(stderr, "libxl_sched_credit_domain_set failed.\n"); + fprintf(stderr, "libxl_domain_sched_params_set failed.\n"); return rc; } @@ -4417,7 +4426,7 @@ static int sched_credit_domain_output(in printf("%-33s %4s %6s %4s\n", "Name", "ID", "Weight", "Cap"); return 0; } - rc = sched_credit_domain_get(domid, &scinfo); + rc = sched_domain_get(LIBXL_SCHEDULER_CREDIT, domid, &scinfo); if (rc) return rc; domname = libxl_domid_to_name(ctx, domid); @@ -4452,30 +4461,6 @@ static int sched_credit_pool_output(uint return 0; } -static int sched_credit2_domain_get( - int domid, libxl_domain_sched_params *scinfo) -{ - int rc; - - rc = libxl_sched_credit2_domain_get(ctx, domid, scinfo); - if (rc) - fprintf(stderr, "libxl_sched_credit2_domain_get failed.\n"); - - return rc; -} - -static int sched_credit2_domain_set( - int domid, libxl_domain_sched_params *scinfo) -{ - int rc; - - rc = libxl_sched_credit2_domain_set(ctx, domid, scinfo); - if (rc) - fprintf(stderr, "libxl_sched_credit2_domain_set failed.\n"); - - return rc; -} - static int sched_credit2_domain_output( int domid) { @@ -4487,7 +4472,7 @@ static int sched_credit2_domain_output( printf("%-33s %4s %6s\n", "Name", "ID", "Weight"); return 0; } - rc = sched_credit2_domain_get(domid, &scinfo); + rc = sched_domain_get(LIBXL_SCHEDULER_CREDIT2, domid, &scinfo); if (rc) return rc; domname = libxl_domid_to_name(ctx, domid); @@ -4500,29 +4485,6 @@ static int sched_credit2_domain_output( return 0; } -static int sched_sedf_domain_get( - int domid, libxl_domain_sched_params *scinfo) -{ - int rc; - - rc = libxl_sched_sedf_domain_get(ctx, domid, scinfo); - if (rc) - fprintf(stderr, "libxl_sched_sedf_domain_get failed.\n"); - - return rc; -} - -static int sched_sedf_domain_set( - int domid, libxl_domain_sched_params *scinfo) -{ - int rc; - - rc = libxl_sched_sedf_domain_set(ctx, domid, scinfo); - if (rc) - fprintf(stderr, "libxl_sched_sedf_domain_set failed.\n"); - return rc; -} - static int sched_sedf_domain_output( int domid) { @@ -4535,7 +4497,7 @@ static int sched_sedf_domain_output( "Slice", "Latency", "Extra", "Weight"); return 0; } - rc = sched_sedf_domain_get(domid, &scinfo); + rc = sched_domain_get(LIBXL_SCHEDULER_SEDF, domid, &scinfo); if (rc) return rc; domname = libxl_domid_to_name(ctx, domid); @@ -4746,7 +4708,7 @@ int main_sched_credit(int argc, char **a scinfo.weight = weight; if (opt_c) scinfo.cap = cap; - rc = sched_credit_domain_set(domid, &scinfo); + rc = sched_domain_set(domid, &scinfo); libxl_domain_sched_params_dispose(&scinfo); if (rc) return -rc; @@ -4821,7 +4783,7 @@ int main_sched_credit2(int argc, char ** scinfo.sched = LIBXL_SCHEDULER_CREDIT2; if (opt_w) scinfo.weight = weight; - rc = sched_credit2_domain_set(domid, &scinfo); + rc = sched_domain_set(domid, &scinfo); libxl_domain_sched_params_dispose(&scinfo); if (rc) return -rc; @@ -4941,7 +4903,7 @@ int main_sched_sedf(int argc, char **arg scinfo.period = 0; scinfo.slice = 0; } - rc = sched_sedf_domain_set(domid, &scinfo); + rc = sched_domain_set(domid, &scinfo); libxl_domain_sched_params_dispose(&scinfo); if (rc) return -rc; _______________________________________________ Xen-changelog mailing list Xen-changelog@xxxxxxxxxxxxx http://lists.xensource.com/xen-changelog
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |