[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH v6 7/7] tools: enable Cache QoS Monitoring feature for libxl/libxc
Introduced two new xl commands to attach/detach CQM service for a guest $ xl pqos-attach cqm domid $ xl pqos-detach cqm domid Introduce one new xl command to retrive guest CQM information $ xl pqos-list cqm (domid) Signed-off-by: Jiongxi Li <jiongxi.li@xxxxxxxxx> Signed-off-by: Dongxiao Xu <dongxiao.xu@xxxxxxxxx> --- tools/libxc/xc_domain.c | 47 +++++++++++++ tools/libxc/xenctrl.h | 11 +++ tools/libxl/Makefile | 3 +- tools/libxl/libxl.h | 6 ++ tools/libxl/libxl_pqos.c | 163 +++++++++++++++++++++++++++++++++++++++++++ tools/libxl/libxl_types.idl | 13 ++++ tools/libxl/xl.h | 3 + tools/libxl/xl_cmdimpl.c | 133 +++++++++++++++++++++++++++++++++++ tools/libxl/xl_cmdtable.c | 15 ++++ 9 files changed, 393 insertions(+), 1 deletion(-) create mode 100644 tools/libxl/libxl_pqos.c diff --git a/tools/libxc/xc_domain.c b/tools/libxc/xc_domain.c index 1ccafc5..769fae3 100644 --- a/tools/libxc/xc_domain.c +++ b/tools/libxc/xc_domain.c @@ -1776,6 +1776,53 @@ int xc_domain_set_max_evtchn(xc_interface *xch, uint32_t domid, return do_domctl(xch, &domctl); } +int xc_domain_pqos_attach(xc_interface *xch, uint32_t domid, uint64_t flags) +{ + DECLARE_DOMCTL; + domctl.cmd = XEN_DOMCTL_attach_pqos; + domctl.domain = (domid_t)domid; + domctl.u.qos_type.flags = flags; + return do_domctl(xch, &domctl); +} + +int xc_domain_pqos_detach(xc_interface *xch, uint32_t domid, uint64_t flags) +{ + DECLARE_DOMCTL; + domctl.cmd = XEN_DOMCTL_detach_pqos; + domctl.domain = (domid_t)domid; + domctl.u.qos_type.flags = flags; + return do_domctl(xch, &domctl); +} + +int xc_domain_getcqminfolist(xc_interface *xch, sysctl_cqminfo_t *info) +{ + int ret = 0; + xen_socket_cqmdata_t *data = info->cqmdata; + DECLARE_SYSCTL; + + DECLARE_HYPERCALL_BOUNCE(data, + info->num_rmids * info->num_sockets * sizeof(*data), + XC_HYPERCALL_BUFFER_BOUNCE_OUT); + + if ( xc_hypercall_bounce_pre(xch, data) ) + return -1; + + sysctl.cmd = XEN_SYSCTL_getcqminfo; + set_xen_guest_handle(sysctl.u.getcqminfo.buffer, data); + + if ( xc_sysctl(xch, &sysctl) < 0 ) + ret = -1; + else + { + info->num_sockets = sysctl.u.getcqminfo.num_sockets; + info->num_rmids = sysctl.u.getcqminfo.num_rmids; + } + + xc_hypercall_bounce_post(xch, data); + + return ret; +} + /* * Local variables: * mode: C diff --git a/tools/libxc/xenctrl.h b/tools/libxc/xenctrl.h index 4ac6b8a..a16f72e 100644 --- a/tools/libxc/xenctrl.h +++ b/tools/libxc/xenctrl.h @@ -2395,4 +2395,15 @@ int xc_kexec_load(xc_interface *xch, uint8_t type, uint16_t arch, */ int xc_kexec_unload(xc_interface *xch, int type); +struct xc_sysctl_getcqminfo +{ + uint32_t num_rmids; + uint32_t num_sockets; + xen_socket_cqmdata_t *cqmdata; +}; +typedef struct xc_sysctl_getcqminfo sysctl_cqminfo_t; + +int xc_domain_pqos_attach(xc_interface *xch, uint32_t domid, uint64_t flags); +int xc_domain_pqos_detach(xc_interface *xch, uint32_t domid, uint64_t flags); +int xc_domain_getcqminfolist(xc_interface *xch, sysctl_cqminfo_t *info); #endif /* XENCTRL_H */ diff --git a/tools/libxl/Makefile b/tools/libxl/Makefile index cf214bb..35f0b97 100644 --- a/tools/libxl/Makefile +++ b/tools/libxl/Makefile @@ -74,7 +74,8 @@ LIBXL_OBJS = flexarray.o libxl.o libxl_create.o libxl_dm.o libxl_pci.o \ libxl_internal.o libxl_utils.o libxl_uuid.o \ libxl_json.o libxl_aoutils.o libxl_numa.o \ libxl_save_callout.o _libxl_save_msgs_callout.o \ - libxl_qmp.o libxl_event.o libxl_fork.o $(LIBXL_OBJS-y) + libxl_qmp.o libxl_event.o libxl_fork.o libxl_pqos.o \ + $(LIBXL_OBJS-y) LIBXL_OBJS += _libxl_types.o libxl_flask.o _libxl_types_internal.o $(LIBXL_OBJS): CFLAGS += $(CFLAGS_LIBXL) -include $(XEN_ROOT)/tools/config.h diff --git a/tools/libxl/libxl.h b/tools/libxl/libxl.h index c7dceda..d2da424 100644 --- a/tools/libxl/libxl.h +++ b/tools/libxl/libxl.h @@ -1051,6 +1051,12 @@ int libxl_flask_getenforce(libxl_ctx *ctx); int libxl_flask_setenforce(libxl_ctx *ctx, int mode); int libxl_flask_loadpolicy(libxl_ctx *ctx, void *policy, uint32_t size); +int libxl_pqos_attach(libxl_ctx *ctx, uint32_t domid, const char * qos_type); +int libxl_pqos_detach(libxl_ctx *ctx, uint32_t domid, const char * qos_type); +libxl_cqminfo * libxl_get_cqm_info(libxl_ctx *ctx, + uint32_t first_domain, + unsigned int num_domains); + /* misc */ /* Each of these sets or clears the flag according to whether the diff --git a/tools/libxl/libxl_pqos.c b/tools/libxl/libxl_pqos.c new file mode 100644 index 0000000..f831007 --- /dev/null +++ b/tools/libxl/libxl_pqos.c @@ -0,0 +1,163 @@ +/* + * Copyright (C) 2013 Intel Corporation + * Author Jiongxi Li <jiongxi.li@xxxxxxxxx> + * Author Dongxiao Xu <dongxiao.xu@xxxxxxxxx> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation; version 2.1 only. with the special + * exception on linking described in file LICENSE. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +#include "libxl_osdeps.h" /* must come before any other headers */ +#include "libxl_internal.h" + +static const char * const msg[] = { + [EINVAL] = "invalid QoS resource type! Supported types: \"cqm\"", + [ENODEV] = "CQM is not supported in this system.", + [EEXIST] = "CQM is already attached to this domain.", + [ENOENT] = "CQM is not attached to this domain.", + [EUSERS] = "there is no free CQM RMID available.", + [ESRCH] = "is this Domain ID valid?", +}; + +static void libxl_pqos_err_msg(libxl_ctx *ctx, int err) +{ + GC_INIT(ctx); + + switch (err) { + case EINVAL: + case ENODEV: + case EEXIST: + case EUSERS: + case ESRCH: + case ENOENT: + LOGE(ERROR, "%s", msg[err]); + break; + default: + LOGE(ERROR, "errno: %d", err); + } + + GC_FREE; +} + +static int libxl_pqos_type2flags(const char * qos_type, uint64_t *flags) +{ + int rc = 0; + + if (!strcmp(qos_type, "cqm")) + *flags |= XEN_DOMCTL_pqos_cqm; + else + rc = -1; + + return rc; +} + +int libxl_pqos_attach(libxl_ctx *ctx, uint32_t domid, const char * qos_type) +{ + int rc; + uint64_t flags = 0; + + rc = libxl_pqos_type2flags(qos_type, &flags); + if (rc < 0) { + libxl_pqos_err_msg(ctx, EINVAL); + return ERROR_FAIL; + } + + rc = xc_domain_pqos_attach(ctx->xch, domid, flags); + if (rc < 0) { + libxl_pqos_err_msg(ctx, errno); + return ERROR_FAIL; + } + + return 0; +} + +int libxl_pqos_detach(libxl_ctx *ctx, uint32_t domid, const char * qos_type) +{ + int rc; + uint64_t flags = 0; + + rc = libxl_pqos_type2flags(qos_type, &flags); + if (rc < 0) { + libxl_pqos_err_msg(ctx, EINVAL); + return ERROR_FAIL; + } + + rc = xc_domain_pqos_detach(ctx->xch, domid, flags); + if (rc < 0) { + libxl_pqos_err_msg(ctx, errno); + return ERROR_FAIL; + } + + return 0; +} + +libxl_cqminfo * libxl_get_cqm_info(libxl_ctx *ctx, + uint32_t first_domain, + unsigned int num_domains) +{ + libxl_cqminfo *xlinfo; + int ret; + sysctl_cqminfo_t xcinfo; + uint32_t num_rmids = 256; + uint32_t num_sockets = 256; + GC_INIT(ctx); + + xlinfo = malloc(sizeof(libxl_cqminfo)); + if (!xlinfo) { + LOGE(ERROR, "allocating cqm xlinfo"); + return NULL; + } + + xlinfo->cqmdata = calloc(num_rmids * num_sockets, + sizeof(libxl_cqmdata)); + if (!xlinfo->cqmdata) { + LOGE(ERROR, "allocating cqm xlinfo->cqmdata"); + free(xlinfo); + return NULL; + } + + xcinfo.num_rmids = num_rmids; + xcinfo.num_sockets = num_sockets; + xcinfo.cqmdata = calloc(num_rmids * num_sockets, + sizeof(xen_socket_cqmdata_t)); + if (!xcinfo.cqmdata) { + LOGE(ERROR, "allocating cqm xcinfo->cqmdata"); + free(xlinfo->cqmdata); + free(xlinfo); + return NULL; + } + + ret = xc_domain_getcqminfolist(ctx->xch, &xcinfo); + if (ret < 0) { + LOGE(ERROR, "getting domain cqm info list"); + free(xcinfo.cqmdata); + free(xlinfo->cqmdata); + free(xlinfo); + return NULL; + } + + memcpy(xlinfo->cqmdata, xcinfo.cqmdata, + sizeof(libxl_cqmdata) * num_rmids * num_sockets); + xlinfo->num_rmids = xcinfo.num_rmids; + xlinfo->num_sockets = xcinfo.num_sockets; + + free(xcinfo.cqmdata); + + GC_FREE; + return xlinfo; +} + +/* + * Local variables: + * mode: C + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/tools/libxl/libxl_types.idl b/tools/libxl/libxl_types.idl index de5bac3..9ecbc2b 100644 --- a/tools/libxl/libxl_types.idl +++ b/tools/libxl/libxl_types.idl @@ -593,3 +593,16 @@ libxl_event = Struct("event",[ ])), ("domain_create_console_available", Struct(None, [])), ]))]) + +libxl_cqmdata = Struct("cqmdata",[ + ("l3c_occupancy", uint64), + ("socket", uint32), + ("domid", uint16), + ("valid", uint8), + ]) + +libxl_cqminfo = Struct("cqminfo", [ + ("num_rmids", uint32), + ("num_sockets", uint32), + ("cqmdata", Array(libxl_cqmdata, "num_items")) + ]) diff --git a/tools/libxl/xl.h b/tools/libxl/xl.h index e005c39..994d3be 100644 --- a/tools/libxl/xl.h +++ b/tools/libxl/xl.h @@ -105,6 +105,9 @@ int main_getenforce(int argc, char **argv); int main_setenforce(int argc, char **argv); int main_loadpolicy(int argc, char **argv); int main_remus(int argc, char **argv); +int main_pqosattach(int argc, char **argv); +int main_pqosdetach(int argc, char **argv); +int main_pqoslist(int argc, char **argv); void help(const char *command); diff --git a/tools/libxl/xl_cmdimpl.c b/tools/libxl/xl_cmdimpl.c index 8690ec7..19bcf25 100644 --- a/tools/libxl/xl_cmdimpl.c +++ b/tools/libxl/xl_cmdimpl.c @@ -7193,6 +7193,139 @@ int main_remus(int argc, char **argv) return -ERROR_FAIL; } +int main_pqosattach(int argc, char **argv) +{ + uint32_t domid; + int opt, rc; + const char *qos_type = NULL; + + SWITCH_FOREACH_OPT(opt, "", NULL, "pqos-attach", 2) { + /* No options */ + } + + qos_type = argv[optind]; + domid = find_domain(argv[optind + 1]); + + rc = libxl_pqos_attach(ctx, domid, qos_type); + + return rc; +} + +int main_pqosdetach(int argc, char **argv) +{ + uint32_t domid; + int opt, rc; + const char *qos_type = NULL; + + SWITCH_FOREACH_OPT(opt, "", NULL, "pqos-detach", 2) { + /* No options */ + } + + qos_type = argv[optind]; + domid = find_domain(argv[optind + 1]); + + rc = libxl_pqos_detach(ctx, domid, qos_type); + + return rc; +} + +static void print_cqm_info(const libxl_cqminfo *info, uint32_t first_domain, + unsigned int num_domains) +{ + unsigned long i, j, k; + libxl_cqmdata *cqmdata; + char *domname; + int print_header; + int print_newdom; + int cqm_domains = 0; + + if (info->num_rmids == 0) + printf("System doesn't support CQM.\n"); + else { + print_header = 1; + for (i = first_domain; i < (first_domain + num_domains); i++) { + print_newdom = 1; + for (j = 0; j < (info->num_rmids * info->num_sockets); j++) { + cqmdata = info->cqmdata + j; + if (!cqmdata->valid || cqmdata->domid != i) + continue; + + if (print_header) { + printf("Name ID"); + for (k = 0; k < info->num_sockets; k++) + printf("\tSocketID\tL3C_Usage"); + print_header = 0; + } + + if (print_newdom) { + domname = libxl_domid_to_name(ctx, cqmdata->domid); + printf("\n%-40s %5d", domname, cqmdata->domid); + free(domname); + print_newdom = 0; + cqm_domains++; + } + printf("%10u %16lu ", cqmdata->socket, cqmdata->l3c_occupancy); + } + } + if (!cqm_domains) + printf("No RMID is assigned to domains.\n"); + else + printf("\n"); + printf("\nRMID count %5d\tRMID available %5d\n", + info->num_rmids, info->num_rmids - cqm_domains - 1); + } +} + +int main_pqoslist(int argc, char **argv) +{ + int opt; + const char *qos_type = NULL; + + SWITCH_FOREACH_OPT(opt, "", NULL, "pqos-list", 1) { + /* No options */ + } + + qos_type = argv[optind]; + + if (!strcmp(qos_type, "cqm")) { + uint32_t first_domain; + unsigned int num_domains; + libxl_cqminfo *info; + + if (optind + 1 >= argc) { + first_domain = 0; + num_domains = 1024; + } else if (optind + 1 == argc - 1) { + first_domain = find_domain(argv[optind + 1]); + num_domains = 1; + if (!libxl_domid_to_name(ctx, first_domain)) { + fprintf(stderr, "Invalid domain id: %d.\n", first_domain); + return 1; + } + } else { + help("pqos-list"); + return 2; + } + + info = libxl_get_cqm_info(ctx, first_domain, num_domains); + if (!info) { + fprintf(stderr, "Failed to get domain CQM info.\n"); + return 1; + } + + print_cqm_info(info, first_domain, num_domains); + + free(info->cqmdata); + free(info); + } else { + fprintf(stderr, "QoS resource type supported is: cqm.\n"); + help("pqos-list"); + return 2; + } + + return 0; +} + /* * Local variables: * mode: C diff --git a/tools/libxl/xl_cmdtable.c b/tools/libxl/xl_cmdtable.c index 326a660..6ced416 100644 --- a/tools/libxl/xl_cmdtable.c +++ b/tools/libxl/xl_cmdtable.c @@ -488,6 +488,21 @@ struct cmd_spec cmd_table[] = { " of the domain." }, + { "pqos-attach", + &main_pqosattach, 0, 1, + "Allocate and map qos resource", + "<Resource> <Domain>", + }, + { "pqos-detach", + &main_pqosdetach, 0, 1, + "Reliquish qos resource", + "<Resource> <Domain>", + }, + { "pqos-list", + &main_pqoslist, 0, 0, + "List qos information about all/some domains", + "<Resource> [Domain]", + }, }; int cmdtable_len = sizeof(cmd_table)/sizeof(struct cmd_spec); -- 1.7.9.5 _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxx http://lists.xen.org/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |