xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Chao Peng <chao.p.peng@linux.intel.com>
To: xen-devel@lists.xen.org
Cc: keir@xen.org, Ian.Campbell@citrix.com,
	stefano.stabellini@eu.citrix.com, George.Dunlap@eu.citrix.com,
	andrew.cooper3@citrix.com, Ian.Jackson@eu.citrix.com,
	JBeulich@suse.com, dgdegra@tycho.nsa.gov
Subject: [PATCH v15 06/11] x86: dynamically attach/detach QoS monitoring service for a guest
Date: Fri,  5 Sep 2014 16:37:24 +0800	[thread overview]
Message-ID: <1409906249-6057-7-git-send-email-chao.p.peng@linux.intel.com> (raw)
In-Reply-To: <1409906249-6057-1-git-send-email-chao.p.peng@linux.intel.com>

Add hypervisor side support for dynamically attach and detach QoS
monitoring services for a certain guest.

When attach Qos monitoring service for a guest, system will allocate an
RMID for it. When detach or guest is shutdown, the RMID will be
recycled for future use.

Signed-off-by: Dongxiao Xu <dongxiao.xu@intel.com>
Signed-off-by: Chao Peng <chao.p.peng@linux.intel.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
---
 xen/arch/x86/domain.c        |    3 +++
 xen/arch/x86/domctl.c        |   29 ++++++++++++++++++++++++++
 xen/arch/x86/pqos.c          |   46 ++++++++++++++++++++++++++++++++++++++++++
 xen/include/asm-x86/domain.h |    2 ++
 xen/include/asm-x86/pqos.h   |    9 +++++++++
 xen/include/public/domctl.h  |   12 +++++++++++
 6 files changed, 101 insertions(+)

diff --git a/xen/arch/x86/domain.c b/xen/arch/x86/domain.c
index f7e0e78..99fce11 100644
--- a/xen/arch/x86/domain.c
+++ b/xen/arch/x86/domain.c
@@ -60,6 +60,7 @@
 #include <xen/numa.h>
 #include <xen/iommu.h>
 #include <compat/vcpu.h>
+#include <asm/pqos.h>
 
 DEFINE_PER_CPU(struct vcpu *, curr_vcpu);
 DEFINE_PER_CPU(unsigned long, cr4);
@@ -644,6 +645,8 @@ void arch_domain_destroy(struct domain *d)
 
     free_xenheap_page(d->shared_info);
     cleanup_domain_irq_mapping(d);
+
+    pqos_monitor_free_rmid(d);
 }
 
 unsigned long pv_guest_cr4_fixup(const struct vcpu *v, unsigned long guest_cr4)
diff --git a/xen/arch/x86/domctl.c b/xen/arch/x86/domctl.c
index 7a5de43..c90eaf5 100644
--- a/xen/arch/x86/domctl.c
+++ b/xen/arch/x86/domctl.c
@@ -35,6 +35,7 @@
 #include <asm/mem_sharing.h>
 #include <asm/xstate.h>
 #include <asm/debugger.h>
+#include <asm/pqos.h>
 
 static int gdbsx_guest_mem_io(
     domid_t domid, struct xen_domctl_gdbsx_memio *iop)
@@ -1319,6 +1320,34 @@ long arch_do_domctl(
     }
     break;
 
+    case XEN_DOMCTL_pqos_monitor_op:
+        if ( !pqos_monitor_enabled() )
+        {
+            ret = -ENODEV;
+            break;
+        }
+
+        switch ( domctl->u.pqos_monitor_op.cmd )
+        {
+        case XEN_DOMCTL_PQOS_MONITOR_OP_ATTACH:
+            ret = pqos_monitor_alloc_rmid(d);
+            break;
+        case XEN_DOMCTL_PQOS_MONITOR_OP_DETACH:
+            if ( d->arch.pqos_rmid > 0 )
+                pqos_monitor_free_rmid(d);
+            else
+                ret = -ENOENT;
+            break;
+        case XEN_DOMCTL_PQOS_MONITOR_OP_QUERY_RMID:
+            domctl->u.pqos_monitor_op.data = d->arch.pqos_rmid;
+            copyback = 1;
+            break;
+        default:
+            ret = -ENOSYS;
+            break;
+        }
+        break;
+
     default:
         ret = iommu_do_domctl(domctl, d, u_domctl);
         break;
diff --git a/xen/arch/x86/pqos.c b/xen/arch/x86/pqos.c
index aca9ea2..885bd9b 100644
--- a/xen/arch/x86/pqos.c
+++ b/xen/arch/x86/pqos.c
@@ -15,6 +15,7 @@
  */
 #include <xen/init.h>
 #include <xen/cpu.h>
+#include <xen/sched.h>
 #include <asm/pqos.h>
 
 #define PQOS_MONITOR        (1<<0)
@@ -97,6 +98,51 @@ void __init init_platform_qos(void)
         init_pqos_monitor(opt_rmid_max);
 }
 
+/* Called with domain lock held, no pqos specific lock needed */
+int pqos_monitor_alloc_rmid(struct domain *d)
+{
+    unsigned int rmid;
+
+    ASSERT(pqos_monitor_enabled());
+
+    if ( d->arch.pqos_rmid > 0 )
+        return -EEXIST;
+
+    for ( rmid = 1; rmid <= pqosm->rmid_max; rmid++ )
+    {
+        if ( pqosm->rmid_to_dom[rmid] != DOMID_INVALID)
+            continue;
+
+        pqosm->rmid_to_dom[rmid] = d->domain_id;
+        break;
+    }
+
+    /* No RMID available, assign RMID=0 by default */
+    if ( rmid > pqosm->rmid_max )
+    {
+        d->arch.pqos_rmid = 0;
+        return -EUSERS;
+    }
+
+    d->arch.pqos_rmid = rmid;
+
+    return 0;
+}
+
+/* Called with domain lock held, no pqos specific lock needed */
+void pqos_monitor_free_rmid(struct domain *d)
+{
+    unsigned int rmid;
+
+    rmid = d->arch.pqos_rmid;
+    /* We do not free system reserved "RMID=0" */
+    if ( rmid == 0 )
+        return;
+
+    pqosm->rmid_to_dom[rmid] = DOMID_INVALID;
+    d->arch.pqos_rmid = 0;
+}
+
 /*
  * Local variables:
  * mode: C
diff --git a/xen/include/asm-x86/domain.h b/xen/include/asm-x86/domain.h
index 83329ed..ca295fa 100644
--- a/xen/include/asm-x86/domain.h
+++ b/xen/include/asm-x86/domain.h
@@ -313,6 +313,8 @@ struct arch_domain
     /* Shared page for notifying that explicit PIRQ EOI is required. */
     unsigned long *pirq_eoi_map;
     unsigned long pirq_eoi_map_mfn;
+
+    unsigned int pqos_rmid; /* QoS monitoring RMID assigned to the domain */
 } __cacheline_aligned;
 
 #define has_arch_pdevs(d)    (!list_empty(&(d)->arch.pdev_list))
diff --git a/xen/include/asm-x86/pqos.h b/xen/include/asm-x86/pqos.h
index 96bfdc6..5737b51 100644
--- a/xen/include/asm-x86/pqos.h
+++ b/xen/include/asm-x86/pqos.h
@@ -16,6 +16,8 @@
 #ifndef __ASM_PQOS_H__
 #define __ASM_PQOS_H__
 
+#include <xen/types.h>
+
 /* QoS Resource Type Enumeration */
 #define QOS_MONITOR_TYPE_L3            0x2
 
@@ -38,7 +40,14 @@ struct pqos_monitor {
 
 extern struct pqos_monitor *pqosm;
 
+static inline bool_t pqos_monitor_enabled(void)
+{
+    return !!pqosm;
+}
+
 void init_platform_qos(void);
+int pqos_monitor_alloc_rmid(struct domain *d);
+void pqos_monitor_free_rmid(struct domain *d);
 
 #endif /* __ASM_PQOS_H__ */
 
diff --git a/xen/include/public/domctl.h b/xen/include/public/domctl.h
index 5b11bbf..af9e775 100644
--- a/xen/include/public/domctl.h
+++ b/xen/include/public/domctl.h
@@ -936,6 +936,16 @@ typedef struct xen_domctl_vcpu_msrs xen_domctl_vcpu_msrs_t;
 DEFINE_XEN_GUEST_HANDLE(xen_domctl_vcpu_msrs_t);
 #endif
 
+struct xen_domctl_pqos_monitor_op {
+#define XEN_DOMCTL_PQOS_MONITOR_OP_DETACH         0
+#define XEN_DOMCTL_PQOS_MONITOR_OP_ATTACH         1
+#define XEN_DOMCTL_PQOS_MONITOR_OP_QUERY_RMID     2
+    uint32_t cmd;
+    uint32_t data;
+};
+typedef struct xen_domctl_pqos_op xen_domctl_pqos_op_t;
+DEFINE_XEN_GUEST_HANDLE(xen_domctl_pqos_op_t);
+
 struct xen_domctl {
     uint32_t cmd;
 #define XEN_DOMCTL_createdomain                   1
@@ -1008,6 +1018,7 @@ struct xen_domctl {
 #define XEN_DOMCTL_cacheflush                    71
 #define XEN_DOMCTL_get_vcpu_msrs                 72
 #define XEN_DOMCTL_set_vcpu_msrs                 73
+#define XEN_DOMCTL_pqos_monitor_op               74
 #define XEN_DOMCTL_gdbsx_guestmemio            1000
 #define XEN_DOMCTL_gdbsx_pausevcpu             1001
 #define XEN_DOMCTL_gdbsx_unpausevcpu           1002
@@ -1068,6 +1079,7 @@ struct xen_domctl {
         struct xen_domctl_cacheflush        cacheflush;
         struct xen_domctl_gdbsx_pauseunp_vcpu gdbsx_pauseunp_vcpu;
         struct xen_domctl_gdbsx_domstatus   gdbsx_domstatus;
+        struct xen_domctl_pqos_monitor_op   pqos_monitor_op;
         uint8_t                             pad[128];
     } u;
 };
-- 
1.7.9.5

  parent reply	other threads:[~2014-09-05  8:37 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-09-05  8:37 [PATCH v15 00/11] enable Cache QoS Monitoring (CQM) feature Chao Peng
2014-09-05  8:37 ` [PATCH v15 01/11] multicall: add no preemption ability between two calls Chao Peng
2014-09-05 10:46   ` Andrew Cooper
2014-09-09  6:43     ` Chao Peng
2014-09-09 10:39       ` Jan Beulich
2014-09-09 10:51         ` Andrew Cooper
2014-09-09 11:51           ` Jan Beulich
2014-09-09 12:44             ` Andrew Cooper
2014-09-09 13:15               ` Jan Beulich
2014-09-10  1:32                 ` Chao Peng
2014-09-10  9:43                   ` Andrew Cooper
2014-09-10 10:07                     ` Jan Beulich
2014-09-10 10:15                       ` Andrew Cooper
2014-09-10 10:25                         ` Jan Beulich
2014-09-10 11:12                           ` Andrew Cooper
2014-09-12  2:55                             ` Chao Peng
2014-09-17  9:22                               ` Chao Peng
2014-09-17  9:44                                 ` Jan Beulich
2014-09-18 13:45                                   ` Chao Peng
2014-09-18 14:22                                     ` Jan Beulich
2014-09-05  8:37 ` [PATCH v15 02/11] x86: add generic resource (e.g. MSR) access hypercall Chao Peng
2014-09-05 10:59   ` Andrew Cooper
2014-09-05 11:49     ` Jan Beulich
2014-09-10  2:55     ` Chao Peng
2014-09-29 18:52       ` Konrad Rzeszutek Wilk
2014-09-30  7:45         ` Jan Beulich
2014-09-05  8:37 ` [PATCH v15 03/11] xsm: add resource operation related xsm policy Chao Peng
2014-09-05  8:37 ` [PATCH v15 04/11] tools: provide interface for generic resource access Chao Peng
2014-09-05  8:37 ` [PATCH v15 05/11] x86: detect and initialize Platform QoS Monitoring feature Chao Peng
2014-09-05 11:05   ` Andrew Cooper
2014-09-05  8:37 ` Chao Peng [this message]
2014-09-05  8:37 ` [PATCH v15 07/11] x86: collect global QoS monitoring information Chao Peng
2014-09-05  8:37 ` [PATCH v15 08/11] x86: enable QoS monitoring for each domain RMID Chao Peng
2014-09-05  8:37 ` [PATCH v15 09/11] x86: add QoS monitoring related MSRs in allowed list Chao Peng
2014-09-05  8:37 ` [PATCH v15 10/11] xsm: add platform QoS related xsm policies Chao Peng
2014-09-05  8:37 ` [PATCH v15 11/11] tools: CMDs and APIs for Platform QoS Monitoring Chao Peng

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=1409906249-6057-7-git-send-email-chao.p.peng@linux.intel.com \
    --to=chao.p.peng@linux.intel.com \
    --cc=George.Dunlap@eu.citrix.com \
    --cc=Ian.Campbell@citrix.com \
    --cc=Ian.Jackson@eu.citrix.com \
    --cc=JBeulich@suse.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=dgdegra@tycho.nsa.gov \
    --cc=keir@xen.org \
    --cc=stefano.stabellini@eu.citrix.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).