From: Ian Campbell <ian.campbell@citrix.com>
To: Chao Peng <chao.p.peng@linux.intel.com>
Cc: keir@xen.org, stefano.stabellini@eu.citrix.com,
andrew.cooper3@citrix.com, Ian.Jackson@eu.citrix.com,
xen-devel@lists.xen.org, will.auld@intel.com, JBeulich@suse.com,
wei.liu2@citrix.com, dgdegra@tycho.nsa.gov
Subject: Re: [PATCH v4 11/12] tools: add tools support for Intel CAT
Date: Thu, 16 Apr 2015 12:20:06 +0100 [thread overview]
Message-ID: <1429183206.25195.89.camel@citrix.com> (raw)
In-Reply-To: <1428571105-3604-12-git-send-email-chao.p.peng@linux.intel.com>
On Thu, 2015-04-09 at 17:18 +0800, Chao Peng wrote:
> +=item B<psr-cat-cbm-set> [I<OPTIONS>] [I<domain-id>] [I<cbm>]
> +
> +Set cache capacity bitmasks(CBM) for a domain.
I can see from the example in the commit log that I<cbm> is a number,
but a) I can't tell that from these docs and b) I have no idea what that
number actually does based on these docs.
Also, are I<domain-id> and I<cmb> really optional to this command as
implied by the surrounding []'s
> diff --git a/tools/libxl/libxl.h b/tools/libxl/libxl.h
> index 5eec092..3800738 100644
> --- a/tools/libxl/libxl.h
> +++ b/tools/libxl/libxl.h
> @@ -718,6 +718,13 @@ void libxl_mac_copy(libxl_ctx *ctx, libxl_mac *dst, libxl_mac *src);
> * If this is defined, the Memory Bandwidth Monitoring feature is supported.
> */
> #define LIBXL_HAVE_PSR_MBM 1
> +
> +/*
> + * LIBXL_HAVE_PSR_CAT
> + *
> + * If this is defined, the Cache Allocation Technology feature is supported.
> + */
> +#define LIBXL_HAVE_PSR_CAT 1
> #endif
>
> typedef char **libxl_string_list;
> @@ -1513,6 +1520,25 @@ int libxl_psr_cmt_get_sample(libxl_ctx *ctx,
> uint64_t *tsc_r);
> #endif
>
> +#ifdef LIBXL_HAVE_PSR_CAT
> +
> +#define LIBXL_PSR_TARGET_ALL (~0U)
> +int libxl_psr_cat_set_cbm(libxl_ctx *ctx, uint32_t domid,
> + libxl_psr_cbm_type type, uint32_t target,
> + uint64_t cbm);
> +int libxl_psr_cat_get_cbm(libxl_ctx *ctx, uint32_t domid,
> + libxl_psr_cbm_type type, uint32_t target,
> + uint64_t *cbm_r);
> +
> +/*
> + * On success, the function returns an array of elements in 'info',
> + * and the length in 'nr'.
> 'info' is from malloc so it must be freed
> + * by the caller.
This is true of all libxl interfaces and is documented generically near
the top, so no need to repeat it here.
It's also strictly speaking required to call libxl_psr_cat_info_dispose
on each list element. We usually provide a libxl_psr_cat_info_list_free
helper which does all of the disposes and then frees the containing
array. See libxl_vcpuinfo_list_free (and a bunch of others near it in
libxl_utils.c) for example.
> + */
> +int libxl_psr_cat_get_l3_info(libxl_ctx *ctx, libxl_psr_cat_info **info,
> + uint32_t *nr);
> @@ -247,6 +308,99 @@ out:
> return rc;
> }
>
> +int libxl_psr_cat_set_cbm(libxl_ctx *ctx, uint32_t domid,
> + libxl_psr_cbm_type type, uint32_t target,
> + uint64_t cbm)
> +{
> + GC_INIT(ctx);
> + int rc;
> + uint32_t i, nr_sockets;
> +
> + if (target != LIBXL_PSR_TARGET_ALL) {
> + rc = xc_psr_cat_set_domain_data(ctx->xch, domid, type, target, cbm);
Per CODING_STYLE a variable called rc must only ever contain a libxl
error code, which xc_* doesn't return. You should use a second variable
called r or some such.
> + if (rc < 0) {
> + libxl__psr_cat_log_err_msg(gc, errno);
> + rc = ERROR_FAIL;
> + }
> + } else {
> + rc = libxl__count_physical_sockets(gc, &nr_sockets);
> + if (rc) {
> + LOGE(ERROR, "failed to get system socket count");
> + rc = ERROR_FAIL;
In this case rc should already (correctly) contain a libxl error code
from the call to libxl__count_physical_sockets, which should be
propagated.
> + goto out;
> + }
> + for (i = 0; i < nr_sockets; i++) {
> + rc = xc_psr_cat_set_domain_data(ctx->xch, domid, type, i, cbm);
But here again you should use a variable other than rc.
> + if (rc < 0) {
> + libxl__psr_cat_log_err_msg(gc, errno);
> + rc = ERROR_FAIL;
> + goto out;
> + }
> + }
> + }
> +
> +out:
> + GC_FREE;
> + return rc;
> +}
> +
> +int libxl_psr_cat_get_cbm(libxl_ctx *ctx, uint32_t domid,
> + libxl_psr_cbm_type type, uint32_t target,
> + uint64_t *cbm_r)
> +{
> + GC_INIT(ctx);
> + int rc;
> +
> + rc = xc_psr_cat_get_domain_data(ctx->xch, domid, type, target, cbm_r);
Don't use rc here.
> + if (rc < 0) {
> + libxl__psr_cat_log_err_msg(gc, errno);
> + rc = ERROR_FAIL;
> + }
> +
> + GC_FREE;
> + return rc;
> +}
> +
> +int libxl_psr_cat_get_l3_info(libxl_ctx *ctx, libxl_psr_cat_info **info,
> + uint32_t *nr)
> +{
> + GC_INIT(ctx);
> + int rc;
> + uint32_t i, nr_sockets;
> + libxl_psr_cat_info *ptr;
> +
> + rc = libxl__count_physical_sockets(gc, &nr_sockets);
> + if (rc) {
> + LOGE(ERROR, "failed to get system socket count");
> + rc = ERROR_FAIL;
Don't overwrite rc here.
> + goto out;
> + }
> +
> + ptr = malloc(nr_sockets * sizeof(libxl_psr_cat_info));
> + if (!ptr) {
As Wei says use libxl__malloc with NOGC and then you don't need to check
for failure.
> + LOGE(ERROR, "failed to allocate cat info");
> + rc = ERROR_FAIL;
> + goto out;
> + }
> +
> + for (i = 0; i < nr_sockets; i++) {
> + rc = xc_psr_cat_get_l3_info(ctx->xch, i, &ptr[i].cos_max,
> + &ptr[i].cbm_len);
Don't use rc here.
> + if (rc) {
> + libxl__psr_cat_log_err_msg(gc, errno);
> + rc = ERROR_FAIL;
> + free(ptr);
> + goto out;
> + }
> + }
> +
> + *info = ptr;
> + *nr = nr_sockets;
> +out:
> + GC_FREE;
> + return rc;
> +}
> +
> /*
> * Local variables:
> * mode: C
> diff --git a/tools/libxl/xl_cmdimpl.c b/tools/libxl/xl_cmdimpl.c
> index 04faf98..0a5f436 100644
> --- a/tools/libxl/xl_cmdimpl.c
> +++ b/tools/libxl/xl_cmdimpl.c
> +
> + printf("\n");
> +}
> +
> +static int psr_cat_print_domain_cbm(uint32_t domid, uint32_t socket)
> +{
> + int i, nr_domains;
> + libxl_dominfo *list;
> +
> + if (domid != INVALID_DOMID) {
> + psr_cat_print_one_domain_cbm(domid, socket);
> + return 0;
> + }
> +
> + if (!(list = libxl_list_domain(ctx, &nr_domains))) {
> + fprintf(stderr, "Failed to get domain list for cbm display\n");
> + return -1;
> + }
> +
> + for (i = 0; i < nr_domains; i++)
> + psr_cat_print_one_domain_cbm(list[i].domid, socket);
> + libxl_dominfo_list_free(list, nr_domains);
> +
> + printf("\n");
Since psr_cat_print_one_domain_cbm ends with this too do you not end up
with an extra blank line?
> +static int psr_cat_show(uint32_t domid)
> +{
> + uint32_t socket, nr_sockets;
> + int rc;
> + libxl_psr_cat_info *info;
> +
> + rc = libxl_psr_cat_get_l3_info(ctx, &info, &nr_sockets);
> + if (rc) {
> + fprintf(stderr, "Failed to get cat info\n");
> + return rc;
> + }
> +
> + for (socket = 0; socket < nr_sockets; socket++) {
> + rc = psr_cat_print_socket(domid, socket, info + socket);
> + if (rc)
> + goto out;
> + }
> +
> +out:
> + free(info);
Should use (to be added) libxl_psr_cat_info_list_free.
> + if (strlen(ptr) > 2 && ptr[0] == '0' && ptr[1] == 'x')
> + cbm = strtoll(ptr, NULL , 16);
> + else
> + cbm = strtoll(ptr, NULL , 10);
Passing 0 as the base (third) parameter to strtoll does the right thing
wrt 0x prefixes etc. No need to replicate manually.
A bunch of pretty minor comments but it is mostly looking good, thanks.
Ian.
next prev parent reply other threads:[~2015-04-16 11:20 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-04-09 9:18 [PATCH v4 00/12] enable Cache Allocation Technology (CAT) for VMs Chao Peng
2015-04-09 9:18 ` [PATCH v4 01/12] x86: clean up psr boot parameter parsing Chao Peng
2015-04-09 20:38 ` Andrew Cooper
2015-04-09 9:18 ` [PATCH v4 02/12] x86: improve psr scheduling code Chao Peng
2015-04-09 21:01 ` Andrew Cooper
2015-04-10 7:24 ` Chao Peng
2015-04-10 9:28 ` Andrew Cooper
2015-04-09 9:18 ` [PATCH v4 03/12] x86: detect and initialize Intel CAT feature Chao Peng
2015-04-09 21:30 ` Andrew Cooper
2015-04-09 9:18 ` [PATCH v4 04/12] x86: maintain COS to CBM mapping for each socket Chao Peng
2015-04-09 21:35 ` Andrew Cooper
2015-04-10 7:26 ` Chao Peng
2015-04-09 9:18 ` [PATCH v4 05/12] x86: maintain socket CPU mask for CAT Chao Peng
2015-04-09 21:45 ` Andrew Cooper
2015-04-10 7:33 ` Chao Peng
2015-04-10 9:48 ` Andrew Cooper
2015-04-09 9:18 ` [PATCH v4 06/12] x86: add COS information for each domain Chao Peng
2015-04-09 21:54 ` Andrew Cooper
2015-04-10 7:35 ` Chao Peng
2015-04-09 9:18 ` [PATCH v4 07/12] x86: expose CBM length and COS number information Chao Peng
2015-04-09 21:54 ` Andrew Cooper
2015-04-09 9:18 ` [PATCH v4 08/12] x86: dynamically get/set CBM for a domain Chao Peng
2015-04-09 22:06 ` Andrew Cooper
2015-04-10 7:37 ` Chao Peng
2015-04-09 9:18 ` [PATCH v4 09/12] x86: add scheduling support for Intel CAT Chao Peng
2015-04-09 22:12 ` Andrew Cooper
2015-04-10 7:41 ` Chao Peng
2015-04-09 9:18 ` [PATCH v4 10/12] xsm: add CAT related xsm policies Chao Peng
2015-04-09 9:18 ` [PATCH v4 11/12] tools: add tools support for Intel CAT Chao Peng
2015-04-09 10:50 ` Wei Liu
2015-04-16 11:20 ` Ian Campbell [this message]
2015-04-09 9:18 ` [PATCH v4 12/12] docs: add xl-psr.markdown Chao Peng
2015-04-09 11:29 ` Andrew Cooper
2015-04-10 7:45 ` Chao Peng
2015-04-16 11:58 ` Ian Campbell
2015-04-17 14:39 ` Chao Peng
2015-04-09 22:15 ` [PATCH v4 00/12] enable Cache Allocation Technology (CAT) for VMs Andrew Cooper
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1429183206.25195.89.camel@citrix.com \
--to=ian.campbell@citrix.com \
--cc=Ian.Jackson@eu.citrix.com \
--cc=JBeulich@suse.com \
--cc=andrew.cooper3@citrix.com \
--cc=chao.p.peng@linux.intel.com \
--cc=dgdegra@tycho.nsa.gov \
--cc=keir@xen.org \
--cc=stefano.stabellini@eu.citrix.com \
--cc=wei.liu2@citrix.com \
--cc=will.auld@intel.com \
--cc=xen-devel@lists.xen.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.