Make some internal routines common so that total/local memory bandwidth monitoring in the next patch can make use of them.
Signed-off-by: Chao Peng <chao.p.p...@linux.intel.com> Acked-by: Wei Liu <wei.l...@citrix.com> --- tools/libxl/libxl_psr.c | 44 +++++++++++++++++++++++++++------------ tools/libxl/xl_cmdimpl.c | 54 +++++++++++++++++++++++++++++------------------- 2 files changed, 64 insertions(+), 34 deletions(-) diff --git a/tools/libxl/libxl_psr.c b/tools/libxl/libxl_psr.c index ec3b6e9..1e1f7ee 100644 --- a/tools/libxl/libxl_psr.c +++ b/tools/libxl/libxl_psr.c @@ -161,20 +161,18 @@ out: return rc; } -int libxl_psr_cmt_get_cache_occupancy(libxl_ctx *ctx, - uint32_t domid, - uint32_t socketid, - uint32_t *l3_cache_occupancy) +static int libxl__psr_cmt_get_l3_monitoring_data(libxl__gc *gc, + uint32_t domid, + xc_psr_cmt_type type, + uint32_t socketid, + uint64_t *data_r) { - GC_INIT(ctx); - unsigned int rmid; uint32_t upscaling_factor; uint64_t monitor_data; int cpu, rc; - xc_psr_cmt_type type; - rc = xc_psr_cmt_get_domain_rmid(ctx->xch, domid, &rmid); + rc = xc_psr_cmt_get_domain_rmid(CTX->xch, domid, &rmid); if (rc < 0 || rmid == 0) { LOGE(ERROR, "fail to get the domain rmid, " "or domain is not attached with platform QoS monitoring service"); @@ -189,23 +187,43 @@ int libxl_psr_cmt_get_cache_occupancy(libxl_ctx *ctx, goto out; } - type = XC_PSR_CMT_L3_OCCUPANCY; - rc = xc_psr_cmt_get_data(ctx->xch, rmid, cpu, type, &monitor_data); + rc = xc_psr_cmt_get_data(CTX->xch, rmid, cpu, type, &monitor_data); if (rc < 0) { LOGE(ERROR, "failed to get monitoring data"); rc = ERROR_FAIL; goto out; } - rc = xc_psr_cmt_get_l3_upscaling_factor(ctx->xch, &upscaling_factor); + rc = xc_psr_cmt_get_l3_upscaling_factor(CTX->xch, &upscaling_factor); if (rc < 0) { LOGE(ERROR, "failed to get L3 upscaling factor"); rc = ERROR_FAIL; goto out; } - *l3_cache_occupancy = upscaling_factor * monitor_data / 1024; - rc = 0; + *data_r = monitor_data * upscaling_factor; + +out: + return rc; +} + +int libxl_psr_cmt_get_cache_occupancy(libxl_ctx *ctx, + uint32_t domid, + uint32_t socketid, + uint32_t *l3_cache_occupancy) +{ + GC_INIT(ctx); + uint64_t data; + int rc; + + rc = libxl__psr_cmt_get_l3_monitoring_data(gc, domid, + XC_PSR_CMT_L3_OCCUPANCY, + socketid, &data); + if (rc < 0) + goto out; + + *l3_cache_occupancy = data / 1024; + out: GC_FREE; return rc; diff --git a/tools/libxl/xl_cmdimpl.c b/tools/libxl/xl_cmdimpl.c index 8fce979..a0b50e7 100644 --- a/tools/libxl/xl_cmdimpl.c +++ b/tools/libxl/xl_cmdimpl.c @@ -7807,8 +7807,9 @@ out: } #ifdef LIBXL_HAVE_PSR_CMT -static void psr_cmt_print_domain_cache_occupancy(libxl_dominfo *dominfo, - uint32_t nr_sockets) +static void psr_cmt_print_domain_l3_info(libxl_dominfo *dominfo, + libxl_psr_cmt_type type, + uint32_t nr_sockets) { char *domain_name; uint32_t socketid; @@ -7822,15 +7823,23 @@ static void psr_cmt_print_domain_cache_occupancy(libxl_dominfo *dominfo, free(domain_name); for (socketid = 0; socketid < nr_sockets; socketid++) { - if (!libxl_psr_cmt_get_cache_occupancy(ctx, dominfo->domid, socketid, - &l3_cache_occupancy)) - printf("%13u KB", l3_cache_occupancy); + switch (type) { + case LIBXL_PSR_CMT_TYPE_CACHE_OCCUPANCY: + if (!libxl_psr_cmt_get_cache_occupancy(ctx, + dominfo->domid, + socketid, + &l3_cache_occupancy)) + printf("%13u KB", l3_cache_occupancy); + break; + default: + return; + } } printf("\n"); } -static int psr_cmt_show_cache_occupancy(uint32_t domid) +static int psr_cmt_show_l3_info(libxl_psr_cmt_type type, uint32_t domid) { uint32_t i, socketid, nr_sockets, total_rmid; uint32_t l3_cache_size; @@ -7866,19 +7875,22 @@ static int psr_cmt_show_cache_occupancy(uint32_t domid) printf("%14s %d", "Socket", socketid); printf("\n"); - /* Total L3 cache size */ - printf("%-46s", "Total L3 Cache Size"); - for (socketid = 0; socketid < nr_sockets; socketid++) { - rc = libxl_psr_cmt_get_l3_cache_size(ctx, socketid, &l3_cache_size); - if (rc < 0) { - fprintf(stderr, - "Failed to get system l3 cache size for socket:%d\n", - socketid); - return -1; - } - printf("%13u KB", l3_cache_size); + if (type == LIBXL_PSR_CMT_TYPE_CACHE_OCCUPANCY) { + /* Total L3 cache size */ + printf("%-46s", "Total L3 Cache Size"); + for (socketid = 0; socketid < nr_sockets; socketid++) { + rc = libxl_psr_cmt_get_l3_cache_size(ctx, socketid, + &l3_cache_size); + if (rc < 0) { + fprintf(stderr, + "Failed to get system l3 cache size for socket:%d\n", + socketid); + return -1; + } + printf("%13u KB", l3_cache_size); + } + printf("\n"); } - printf("\n"); /* Each domain */ if (domid != INVALID_DOMID) { @@ -7887,7 +7899,7 @@ static int psr_cmt_show_cache_occupancy(uint32_t domid) fprintf(stderr, "Failed to get domain info for %d\n", domid); return -1; } - psr_cmt_print_domain_cache_occupancy(&dominfo, nr_sockets); + psr_cmt_print_domain_l3_info(&dominfo, type, nr_sockets); } else { @@ -7897,7 +7909,7 @@ static int psr_cmt_show_cache_occupancy(uint32_t domid) return -1; } for (i = 0; i < nr_domains; i++) - psr_cmt_print_domain_cache_occupancy(list + i, nr_sockets); + psr_cmt_print_domain_l3_info(list + i, type, nr_sockets); libxl_dominfo_list_free(list, nr_domains); } return 0; @@ -7956,7 +7968,7 @@ int main_psr_cmt_show(int argc, char **argv) switch (type) { case LIBXL_PSR_CMT_TYPE_CACHE_OCCUPANCY: - ret = psr_cmt_show_cache_occupancy(domid); + ret = psr_cmt_show_l3_info(type, domid); break; default: help("psr-cmt-show"); -- 1.9.1 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xen.org http://lists.xen.org/xen-devel