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@citrix.com>
Acked-by: George Dunlap <george.dunlap@eu.citrix.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
Committed-by: Ian Campbell <ian.campbell@citrix.com>
This commit is contained in:
Ian Campbell committed 2012-06-01 12:06:21 +01:00
1 parent b79aecb788
commit b48dc18487
4 files changed
+106 -125

No files matched your search

+77 -51
View File
@@ -3295,15 +3295,15 @@ libxl_scheduler libxl_get_scheduler(libxl_ctx *ctx)
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_ctx *ctx, uint32_t domid,
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_ctx *ctx, uint32_t domid,
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_ctx *ctx, uint32_t poolid,
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_ctx *ctx, uint32_t domid,
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_ctx *ctx, uint32_t domid,
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_ctx *ctx, uint32_t domid,
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_ctx *ctx, uint32_t domid,
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_ctx *ctx, uint32_t domid,
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 *gc, uint32_t domid,
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;
}
+5 -12
View File
@@ -783,18 +783,11 @@ int libxl_sched_credit_params_set(libxl_ctx *ctx, uint32_t poolid,
#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);
+1 -1
View File
@@ -174,7 +174,7 @@ int libxl__build_post(libxl__gc *gc, uint32_t domid,
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)
+23 -61
View File
@@ -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");
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 rc;
return 0;
}
static int sched_credit_domain_set(int domid, libxl_domain_sched_params *scinfo)
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(int domid)
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(uint32_t poolid)
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 **argv)
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 **argv)
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 **argv)
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;
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.