[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [RFC PATCH 5/7] xen: libxc: libxl: allow for attaching and detaching a CPU to CMT



Signed-off-by: Dario Faggioli <dario.faggioli@xxxxxxxxxx>
---
 tools/libxc/include/xenctrl.h |    2 ++
 tools/libxc/xc_psr.c          |   34 ++++++++++++++++++++++++++++++++++
 tools/libxl/libxl.h           |    2 ++
 tools/libxl/libxl_psr.c       |   30 ++++++++++++++++++++++++++++++
 xen/arch/x86/sysctl.c         |   28 ++++++++++++++++++++++++++++
 xen/include/public/sysctl.h   |    2 ++
 6 files changed, 98 insertions(+)

diff --git a/tools/libxc/include/xenctrl.h b/tools/libxc/include/xenctrl.h
index d038e40..7c17e3e 100644
--- a/tools/libxc/include/xenctrl.h
+++ b/tools/libxc/include/xenctrl.h
@@ -2707,6 +2707,8 @@ int xc_psr_cmt_get_cpu_rmid(xc_interface *xch, uint32_t 
cpu,
 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);
+int xc_psr_cmt_cpu_attach(xc_interface *xch, uint32_t cpu);
+int xc_psr_cmt_cpu_detach(xc_interface *xch, uint32_t cpu);
 int xc_psr_cmt_enabled(xc_interface *xch);
 #endif
 
diff --git a/tools/libxc/xc_psr.c b/tools/libxc/xc_psr.c
index 088cf66..3d1b1cb 100644
--- a/tools/libxc/xc_psr.c
+++ b/tools/libxc/xc_psr.c
@@ -177,6 +177,40 @@ int xc_psr_cmt_get_cpu_rmid(xc_interface *xch, uint32_t 
cpu,
     return 0;
 }
 
+int xc_psr_cmt_cpu_attach(xc_interface *xch, uint32_t cpu)
+{
+    int rc;
+    DECLARE_SYSCTL;
+
+    sysctl.cmd = XEN_SYSCTL_psr_cmt_op;
+    sysctl.u.psr_cmt_op.cmd = XEN_SYSCTL_PSR_CMT_cpu_rmid_attach;
+    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;
+
+    return 0;
+}
+
+int xc_psr_cmt_cpu_detach(xc_interface *xch, uint32_t cpu)
+{
+    int rc;
+    DECLARE_SYSCTL;
+
+    sysctl.cmd = XEN_SYSCTL_psr_cmt_op;
+    sysctl.u.psr_cmt_op.cmd = XEN_SYSCTL_PSR_CMT_cpu_rmid_detach;
+    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;
+
+    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 23e266d..1c1d5f0 100644
--- a/tools/libxl/libxl.h
+++ b/tools/libxl/libxl.h
@@ -1525,6 +1525,8 @@ 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);
+int libxl_psr_cmt_cpu_attach(libxl_ctx *ctx, uint32_t cpu);
+int libxl_psr_cmt_cpu_detach(libxl_ctx *ctx, uint32_t cpu);
 #endif
 
 #ifdef LIBXL_HAVE_PSR_MBM
diff --git a/tools/libxl/libxl_psr.c b/tools/libxl/libxl_psr.c
index f5688a3..6b7a7ba 100644
--- a/tools/libxl/libxl_psr.c
+++ b/tools/libxl/libxl_psr.c
@@ -306,6 +306,36 @@ int libxl_psr_cmt_get_cpu_cache_occupancy(libxl_ctx *ctx,
     return rc;
 }
 
+int libxl_psr_cmt_cpu_attach(libxl_ctx *ctx, uint32_t cpu)
+{
+    GC_INIT(ctx);
+    int rc;
+
+    rc = xc_psr_cmt_cpu_attach(ctx->xch, cpu);
+    if (rc) {
+        libxl__psr_cmt_log_err_msg(gc, errno);
+        rc = ERROR_FAIL;
+    }
+
+    GC_FREE;
+    return rc;
+}
+
+int libxl_psr_cmt_cpu_detach(libxl_ctx *ctx, uint32_t cpu)
+{
+    GC_INIT(ctx);
+    int rc;
+
+    rc = xc_psr_cmt_cpu_detach(ctx->xch, cpu);
+    if (rc) {
+        libxl__psr_cmt_log_err_msg(gc, errno);
+        rc = ERROR_FAIL;
+    }
+
+    GC_FREE;
+    return rc;
+}
+
 /*
  * Local variables:
  * mode: C
diff --git a/xen/arch/x86/sysctl.c b/xen/arch/x86/sysctl.c
index fc9838c..93837e5 100644
--- a/xen/arch/x86/sysctl.c
+++ b/xen/arch/x86/sysctl.c
@@ -174,6 +174,34 @@ long arch_do_sysctl(
             sysctl->u.psr_cmt_op.u.data = per_cpu(pcpu_rmid, cpu);
             break;
         }
+        case XEN_SYSCTL_PSR_CMT_cpu_rmid_attach:
+        {
+            unsigned int cpu = sysctl->u.psr_cmt_op.u.cpu_rmid.cpu;
+
+            if ( (cpu >= nr_cpu_ids) || !cpu_online(cpu) )
+            {
+                ret = -ENODEV;
+                break;
+            }
+            ret = psr_alloc_pcpu_rmid(cpu);
+            break;
+        }
+        case XEN_SYSCTL_PSR_CMT_cpu_rmid_detach:
+        {
+            unsigned int cpu = sysctl->u.psr_cmt_op.u.cpu_rmid.cpu;
+
+            if ( (cpu >= nr_cpu_ids) || !cpu_online(cpu) )
+            {
+                ret = -ENODEV;
+                break;
+            }
+
+            if ( per_cpu(pcpu_rmid, cpu) )
+                psr_free_pcpu_rmid(cpu);
+            else
+                return -ENOENT;
+            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 11c26c6..0ae8758 100644
--- a/xen/include/public/sysctl.h
+++ b/xen/include/public/sysctl.h
@@ -648,6 +648,8 @@ DEFINE_XEN_GUEST_HANDLE(xen_sysctl_coverage_op_t);
 #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
+#define XEN_SYSCTL_PSR_CMT_cpu_rmid_attach           6
+#define XEN_SYSCTL_PSR_CMT_cpu_rmid_detach           7
 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 */


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.