[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [RFC PATCH 4/7] xen: libxc: libxl: report per-CPU cache occupancy up to libxl
Signed-off-by: Dario Faggioli <dario.faggioli@xxxxxxxxxx> --- tools/libxc/include/xenctrl.h | 2 + tools/libxc/xc_psr.c | 19 +++++++++++++ tools/libxl/libxl.h | 4 +++ tools/libxl/libxl_psr.c | 59 +++++++++++++++++++++++++++++++++++++++++ xen/arch/x86/sysctl.c | 14 ++++++++++ xen/include/public/sysctl.h | 5 +++ 6 files changed, 103 insertions(+) diff --git a/tools/libxc/include/xenctrl.h b/tools/libxc/include/xenctrl.h index 4e9537e..d038e40 100644 --- a/tools/libxc/include/xenctrl.h +++ b/tools/libxc/include/xenctrl.h @@ -2702,6 +2702,8 @@ int xc_psr_cmt_get_l3_upscaling_factor(xc_interface *xch, int xc_psr_cmt_get_l3_event_mask(xc_interface *xch, uint32_t *event_mask); int xc_psr_cmt_get_l3_cache_size(xc_interface *xch, uint32_t cpu, uint32_t *l3_cache_size); +int xc_psr_cmt_get_cpu_rmid(xc_interface *xch, uint32_t cpu, + uint32_t *rmid); int xc_psr_cmt_get_data(xc_interface *xch, uint32_t rmid, uint32_t cpu, uint32_t psr_cmt_type, uint64_t *monitor_data, uint64_t *tsc); diff --git a/tools/libxc/xc_psr.c b/tools/libxc/xc_psr.c index e367a80..088cf66 100644 --- a/tools/libxc/xc_psr.c +++ b/tools/libxc/xc_psr.c @@ -158,6 +158,25 @@ int xc_psr_cmt_get_l3_cache_size(xc_interface *xch, uint32_t cpu, return rc; } +int xc_psr_cmt_get_cpu_rmid(xc_interface *xch, uint32_t cpu, + uint32_t *rmid) +{ + int rc; + DECLARE_SYSCTL; + + sysctl.cmd = XEN_SYSCTL_psr_cmt_op; + sysctl.u.psr_cmt_op.cmd = XEN_SYSCTL_PSR_CMT_get_cpu_rmid; + sysctl.u.psr_cmt_op.u.cpu_rmid.cpu = cpu; + sysctl.u.psr_cmt_op.flags = 0; + + rc = xc_sysctl(xch, &sysctl); + if ( rc ) + return -1; + + *rmid = sysctl.u.psr_cmt_op.u.data; + return 0; +} + int xc_psr_cmt_get_data(xc_interface *xch, uint32_t rmid, uint32_t cpu, xc_psr_cmt_type type, uint64_t *monitor_data, uint64_t *tsc) diff --git a/tools/libxl/libxl.h b/tools/libxl/libxl.h index 6bc75c5..23e266d 100644 --- a/tools/libxl/libxl.h +++ b/tools/libxl/libxl.h @@ -1521,6 +1521,10 @@ int libxl_psr_cmt_get_cache_occupancy(libxl_ctx *ctx, uint32_t domid, uint32_t socketid, uint32_t *l3_cache_occupancy); +int libxl_psr_cmt_cpu_attached(libxl_ctx *ctx, uint32_t cpu); +int libxl_psr_cmt_get_cpu_cache_occupancy(libxl_ctx *ctx, + uint32_t cpu, + uint32_t *l3_cache_occupancy); #endif #ifdef LIBXL_HAVE_PSR_MBM diff --git a/tools/libxl/libxl_psr.c b/tools/libxl/libxl_psr.c index 3e1c792..f5688a3 100644 --- a/tools/libxl/libxl_psr.c +++ b/tools/libxl/libxl_psr.c @@ -247,6 +247,65 @@ out: return rc; } +int libxl_psr_cmt_cpu_attached(libxl_ctx *ctx, uint32_t cpu) +{ + int rc; + uint32_t rmid; + + rc = xc_psr_cmt_get_cpu_rmid(ctx->xch, cpu, &rmid); + if (rc) + return ERROR_FAIL; + + return !!rmid; +} + +int libxl_psr_cmt_get_cpu_cache_occupancy(libxl_ctx *ctx, + uint32_t cpu, + uint32_t *l3_cache_occupancy) +{ + GC_INIT(ctx); + unsigned int rmid; + uint32_t upscale; + uint64_t data; + int rc = 0; + + if (!l3_cache_occupancy) { + LOGE(ERROR, "invalid parameter for returning cpu cache occupancy"); + rc = ERROR_INVAL; + goto out; + } + + rc = xc_psr_cmt_get_cpu_rmid(ctx->xch, cpu, &rmid); + if (rc || rmid == 0) { + LOGE(ERROR, "fail to get rmid or cpu not attached to monitoring"); + rc = ERROR_FAIL; + goto out; + } + + rc = xc_psr_cmt_get_data(ctx->xch, rmid, cpu, + LIBXL_PSR_CMT_TYPE_CACHE_OCCUPANCY - 1, + &data, NULL); + if (rc) { + LOGE(ERROR, "failed to get monitoring data"); + rc = ERROR_FAIL; + goto out; + } + + rc = xc_psr_cmt_get_l3_upscaling_factor(ctx->xch, &upscale); + if (rc) { + LOGE(ERROR, "failed to get L3 upscaling factor"); + rc = ERROR_FAIL; + goto out; + } + + data *= upscale; + *l3_cache_occupancy = data / 1024; + + out: + GC_FREE; + return rc; +} + /* * Local variables: * mode: C diff --git a/xen/arch/x86/sysctl.c b/xen/arch/x86/sysctl.c index 611a291..fc9838c 100644 --- a/xen/arch/x86/sysctl.c +++ b/xen/arch/x86/sysctl.c @@ -160,6 +160,20 @@ long arch_do_sysctl( case XEN_SYSCTL_PSR_CMT_get_l3_event_mask: sysctl->u.psr_cmt_op.u.data = psr_cmt->l3.features; break; + case XEN_SYSCTL_PSR_CMT_get_cpu_rmid: + { + unsigned int cpu = sysctl->u.psr_cmt_op.u.cpu_rmid.cpu; + + if ( (cpu >= nr_cpu_ids) || !cpu_online(cpu) ) + { + ret = -ENODEV; + sysctl->u.psr_cmt_op.u.data = 0; + break; + } + + sysctl->u.psr_cmt_op.u.data = per_cpu(pcpu_rmid, cpu); + break; + } default: sysctl->u.psr_cmt_op.u.data = 0; ret = -ENOSYS; diff --git a/xen/include/public/sysctl.h b/xen/include/public/sysctl.h index 711441f..11c26c6 100644 --- a/xen/include/public/sysctl.h +++ b/xen/include/public/sysctl.h @@ -647,6 +647,7 @@ DEFINE_XEN_GUEST_HANDLE(xen_sysctl_coverage_op_t); #define XEN_SYSCTL_PSR_CMT_get_l3_cache_size 2 #define XEN_SYSCTL_PSR_CMT_enabled 3 #define XEN_SYSCTL_PSR_CMT_get_l3_event_mask 4 +#define XEN_SYSCTL_PSR_CMT_get_cpu_rmid 5 struct xen_sysctl_psr_cmt_op { uint32_t cmd; /* IN: XEN_SYSCTL_PSR_CMT_* */ uint32_t flags; /* padding variable, may be extended for future use */ @@ -656,6 +657,10 @@ struct xen_sysctl_psr_cmt_op { uint32_t cpu; /* IN */ uint32_t rsvd; } l3_cache; + struct { + uint32_t cpu; /* IN */ + uint32_t rsvd; + } cpu_rmid; } u; }; typedef struct xen_sysctl_psr_cmt_op xen_sysctl_psr_cmt_op_t; _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxx http://lists.xen.org/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |