Patchwork [v2,2/5] vcpu: track hvm vcpu number on the system

login
register
mail settings
Submitter Chao Gao
Date May 11, 2017, 6:04 a.m.
Message ID <1494482652-42356-3-git-send-email-chao.gao@intel.com>
Download mbox | patch
Permalink /patch/241207/
State New
Headers show

Comments

Chao Gao - May 11, 2017, 6:04 a.m.
This number is used to calculate how many hvm vcpu on a pcpu on average.

Signed-off-by: Chao Gao <chao.gao@intel.com>
---
 xen/common/domain.c     | 8 ++++++++
 xen/include/xen/sched.h | 2 ++
 2 files changed, 10 insertions(+)
Wei Liu - May 11, 2017, 11:35 a.m.
On Thu, May 11, 2017 at 02:04:09PM +0800, Chao Gao wrote:
> This number is used to calculate how many hvm vcpu on a pcpu on average.
> 
> Signed-off-by: Chao Gao <chao.gao@intel.com>
> ---
>  xen/common/domain.c     | 8 ++++++++
>  xen/include/xen/sched.h | 2 ++
>  2 files changed, 10 insertions(+)
> 
> diff --git a/xen/common/domain.c b/xen/common/domain.c
> index b22aacc..d433d9e 100644
> --- a/xen/common/domain.c
> +++ b/xen/common/domain.c
> @@ -71,6 +71,9 @@ struct vcpu *idle_vcpu[NR_CPUS] __read_mostly;
>  
>  vcpu_info_t dummy_vcpu_info;
>  
> +/* how many hvm vcpu on this system? */
> +atomic_t num_hvm_vcpus;
> +

This is x86 specific and should go to x86/domain.c
Wei Liu - May 11, 2017, 11:37 a.m.
On Thu, May 11, 2017 at 12:35:11PM +0100, Wei Liu wrote:
> On Thu, May 11, 2017 at 02:04:09PM +0800, Chao Gao wrote:
> > This number is used to calculate how many hvm vcpu on a pcpu on average.
> > 
> > Signed-off-by: Chao Gao <chao.gao@intel.com>
> > ---
> >  xen/common/domain.c     | 8 ++++++++
> >  xen/include/xen/sched.h | 2 ++
> >  2 files changed, 10 insertions(+)
> > 
> > diff --git a/xen/common/domain.c b/xen/common/domain.c
> > index b22aacc..d433d9e 100644
> > --- a/xen/common/domain.c
> > +++ b/xen/common/domain.c
> > @@ -71,6 +71,9 @@ struct vcpu *idle_vcpu[NR_CPUS] __read_mostly;
> >  
> >  vcpu_info_t dummy_vcpu_info;
> >  
> > +/* how many hvm vcpu on this system? */
> > +atomic_t num_hvm_vcpus;
> > +
> 
> This is x86 specific and should go to x86/domain.c

... as with all the code that manipulates it. I'm sure you can find the
appropriate places like arch_initialise/destroy_vcpu.
Chao Gao - May 12, 2017, 8:23 a.m.
On Thu, May 11, 2017 at 12:37:37PM +0100, Wei Liu wrote:
>On Thu, May 11, 2017 at 12:35:11PM +0100, Wei Liu wrote:
>> On Thu, May 11, 2017 at 02:04:09PM +0800, Chao Gao wrote:
>> > This number is used to calculate how many hvm vcpu on a pcpu on average.
>> > 
>> > Signed-off-by: Chao Gao <chao.gao@intel.com>
>> > ---
>> >  xen/common/domain.c     | 8 ++++++++
>> >  xen/include/xen/sched.h | 2 ++
>> >  2 files changed, 10 insertions(+)
>> > 
>> > diff --git a/xen/common/domain.c b/xen/common/domain.c
>> > index b22aacc..d433d9e 100644
>> > --- a/xen/common/domain.c
>> > +++ b/xen/common/domain.c
>> > @@ -71,6 +71,9 @@ struct vcpu *idle_vcpu[NR_CPUS] __read_mostly;
>> >  
>> >  vcpu_info_t dummy_vcpu_info;
>> >  
>> > +/* how many hvm vcpu on this system? */
>> > +atomic_t num_hvm_vcpus;
>> > +
>> 
>> This is x86 specific and should go to x86/domain.c
>
>... as with all the code that manipulates it. I'm sure you can find the
>appropriate places like arch_initialise/destroy_vcpu.

Agree. I could make things better if thinking more about it.

Thanks
Chao

Patch

diff --git a/xen/common/domain.c b/xen/common/domain.c
index b22aacc..d433d9e 100644
--- a/xen/common/domain.c
+++ b/xen/common/domain.c
@@ -71,6 +71,9 @@  struct vcpu *idle_vcpu[NR_CPUS] __read_mostly;
 
 vcpu_info_t dummy_vcpu_info;
 
+/* how many hvm vcpu on this system? */
+atomic_t num_hvm_vcpus;
+
 static void __domain_finalise_shutdown(struct domain *d)
 {
     struct vcpu *v;
@@ -193,6 +196,9 @@  struct vcpu *alloc_vcpu(
     if ( !is_idle_domain(d) )
         domain_update_node_affinity(d);
 
+    if ( is_hvm_domain(d) )
+        atomic_inc(&num_hvm_vcpus);
+
     return v;
 }
 
@@ -803,6 +809,8 @@  static void complete_domain_destroy(struct rcu_head *head)
         vcpu_destroy(v);
         sched_destroy_vcpu(v);
         destroy_waitqueue_vcpu(v);
+        if ( is_hvm_domain(d) )
+            atomic_dec(&num_hvm_vcpus);
     }
 
     grant_table_destroy(d);
diff --git a/xen/include/xen/sched.h b/xen/include/xen/sched.h
index 1127ca9..5fb492d 100644
--- a/xen/include/xen/sched.h
+++ b/xen/include/xen/sched.h
@@ -139,6 +139,8 @@  void evtchn_destroy_final(struct domain *d); /* from complete_domain_destroy */
 
 struct waitqueue_vcpu;
 
+extern atomic_t num_hvm_vcpus;
+
 struct vcpu
 {
     int              vcpu_id;