kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Suraj Jitindar Singh <sjitindarsingh@gmail.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: kvm@vger.kernel.org, rkrcmar@redhat.com
Subject: Re: [PATCH] kvm/stats: Update kvm stats to clear on write to their debugfs entry
Date: Tue, 18 Oct 2016 17:20:57 +1100	[thread overview]
Message-ID: <1476771657.2150.3.camel@gmail.com> (raw)
In-Reply-To: <1551761682.4111493.1476723030110.JavaMail.zimbra@redhat.com>

On Mon, 2016-10-17 at 12:50 -0400, Paolo Bonzini wrote:
> 
> ----- Original Message -----
> > 
> > From: "Suraj Jitindar Singh" <sjitindarsingh@gmail.com>
> > To: kvm@vger.kernel.org
> > Cc: pbonzini@redhat.com, rkrcmar@redhat.com, "Suraj Jitindar Singh"
> > <sjitindarsingh@gmail.com>
> > Sent: Friday, October 14, 2016 8:02:42 AM
> > Subject: [PATCH] kvm/stats: Update kvm stats to clear on write to
> > their debugfs entry
> > 
> > Various kvm vm and vcpu stats are provided via debugfs entries.
> > Currently there is no way to reset these stats back to zero for the
> > system
> > except by stopping all vms.
> > 
> > Add the ability to clear (reset back to zero) these stats on a per
> > stat
> > basis by writing to the debugfs files. The stats are just reset to
> > zero
> > irrespective of what is actually written to the file.
> Even though this is a debug interface, people will still rely on
> underspecified APIs.  Please make it fail with EINVAL unless 0 is
> written.  Apart from this, it's a good idea.
Ok, I'll update this and send a V2
> 
> Paolo
> 
> > 
> > 
> > Signed-off-by: Suraj Jitindar Singh <sjitindarsingh@gmail.com>
> > ---
> >  virt/kvm/kvm_main.c | 66
> >  ++++++++++++++++++++++++++++++++++++++++++++++++-----
> >  1 file changed, 60 insertions(+), 6 deletions(-)
> > 
> > diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
> > index 81dfc73..141fc03 100644
> > --- a/virt/kvm/kvm_main.c
> > +++ b/virt/kvm/kvm_main.c
> > @@ -595,7 +595,7 @@ static int kvm_create_vm_debugfs(struct kvm
> > *kvm, int fd)
> >  		stat_data->kvm = kvm;
> >  		stat_data->offset = p->offset;
> >  		kvm->debugfs_stat_data[p - debugfs_entries] =
> > stat_data;
> > -		if (!debugfs_create_file(p->name, 0444,
> > +		if (!debugfs_create_file(p->name, 0644,
> >  					 kvm->debugfs_dentry,
> >  					 stat_data,
> >  					 stat_fops_per_vm[p-
> > >kind]))
> > @@ -3658,11 +3658,20 @@ static int vm_stat_get_per_vm(void *data,
> > u64 *val)
> >  	return 0;
> >  }
> >  
> > +static int vm_stat_clear_per_vm(void *data, u64 val)
> > +{
> > +	struct kvm_stat_data *stat_data = (struct kvm_stat_data
> > *)data;
> > +
> > +	*(ulong *)((void *)stat_data->kvm + stat_data->offset) =
> > 0;
> > +
> > +	return 0;
> > +}
> > +
> >  static int vm_stat_get_per_vm_open(struct inode *inode, struct
> > file *file)
> >  {
> >  	__simple_attr_check_format("%llu\n", 0ull);
> >  	return kvm_debugfs_open(inode, file, vm_stat_get_per_vm,
> > -				NULL, "%llu\n");
> > +				vm_stat_clear_per_vm, "%llu\n");
> >  }
> >  
> >  static const struct file_operations vm_stat_get_per_vm_fops = {
> > @@ -3688,11 +3697,23 @@ static int vcpu_stat_get_per_vm(void *data,
> > u64 *val)
> >  	return 0;
> >  }
> >  
> > +static int vcpu_stat_clear_per_vm(void *data, u64 val)
> > +{
> > +	int i;
> > +	struct kvm_stat_data *stat_data = (struct kvm_stat_data
> > *)data;
> > +	struct kvm_vcpu *vcpu;
> > +
> > +	kvm_for_each_vcpu(i, vcpu, stat_data->kvm)
> > +		*(u64 *)((void *)vcpu + stat_data->offset) = 0;
> > +
> > +	return 0;
> > +}
> > +
> >  static int vcpu_stat_get_per_vm_open(struct inode *inode, struct
> > file *file)
> >  {
> >  	__simple_attr_check_format("%llu\n", 0ull);
> >  	return kvm_debugfs_open(inode, file, vcpu_stat_get_per_vm,
> > -				 NULL, "%llu\n");
> > +				 vcpu_stat_clear_per_vm,
> > "%llu\n");
> >  }
> >  
> >  static const struct file_operations vcpu_stat_get_per_vm_fops = {
> > @@ -3727,7 +3748,23 @@ static int vm_stat_get(void *_offset, u64
> > *val)
> >  	return 0;
> >  }
> >  
> > -DEFINE_SIMPLE_ATTRIBUTE(vm_stat_fops, vm_stat_get, NULL,
> > "%llu\n");
> > +static int vm_stat_clear(void *_offset, u64 val)
> > +{
> > +	unsigned offset = (long)_offset;
> > +	struct kvm *kvm;
> > +	struct kvm_stat_data stat_tmp = {.offset = offset};
> > +
> > +	spin_lock(&kvm_lock);
> > +	list_for_each_entry(kvm, &vm_list, vm_list) {
> > +		stat_tmp.kvm = kvm;
> > +		vm_stat_clear_per_vm((void *)&stat_tmp, 0);
> > +	}
> > +	spin_unlock(&kvm_lock);
> > +
> > +	return 0;
> > +}
> > +
> > +DEFINE_SIMPLE_ATTRIBUTE(vm_stat_fops, vm_stat_get, vm_stat_clear,
> > "%llu\n");
> >  
> >  static int vcpu_stat_get(void *_offset, u64 *val)
> >  {
> > @@ -3747,7 +3784,24 @@ static int vcpu_stat_get(void *_offset, u64
> > *val)
> >  	return 0;
> >  }
> >  
> > -DEFINE_SIMPLE_ATTRIBUTE(vcpu_stat_fops, vcpu_stat_get, NULL,
> > "%llu\n");
> > +static int vcpu_stat_clear(void *_offset, u64 val)
> > +{
> > +	unsigned offset = (long)_offset;
> > +	struct kvm *kvm;
> > +	struct kvm_stat_data stat_tmp = {.offset = offset};
> > +
> > +	spin_lock(&kvm_lock);
> > +	list_for_each_entry(kvm, &vm_list, vm_list) {
> > +		stat_tmp.kvm = kvm;
> > +		vcpu_stat_clear_per_vm((void *)&stat_tmp, 0);
> > +	}
> > +	spin_unlock(&kvm_lock);
> > +
> > +	return 0;
> > +}
> > +
> > +DEFINE_SIMPLE_ATTRIBUTE(vcpu_stat_fops, vcpu_stat_get,
> > vcpu_stat_clear,
> > +			"%llu\n");
> >  
> >  static const struct file_operations *stat_fops[] = {
> >  	[KVM_STAT_VCPU] = &vcpu_stat_fops,
> > @@ -3765,7 +3819,7 @@ static int kvm_init_debug(void)
> >  
> >  	kvm_debugfs_num_entries = 0;
> >  	for (p = debugfs_entries; p->name; ++p,
> > kvm_debugfs_num_entries++) {
> > -		if (!debugfs_create_file(p->name, 0444,
> > kvm_debugfs_dir,
> > +		if (!debugfs_create_file(p->name, 0644,
> > kvm_debugfs_dir,
> >  					 (void *)(long)p->offset,
> >  					 stat_fops[p->kind]))
> >  			goto out_dir;
> > --
> > 2.5.5
> > 
> > 

      reply	other threads:[~2016-10-18  6:21 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-14  6:02 [PATCH] kvm/stats: Update kvm stats to clear on write to their debugfs entry Suraj Jitindar Singh
2016-10-17 13:40 ` Radim Krčmář
2016-10-17 13:48   ` Christian Borntraeger
2016-10-18  7:18     ` Suraj Jitindar Singh
2016-10-18  7:16   ` Suraj Jitindar Singh
2016-10-17 16:50 ` Paolo Bonzini
2016-10-18  6:20   ` Suraj Jitindar Singh [this message]

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=1476771657.2150.3.camel@gmail.com \
    --to=sjitindarsingh@gmail.com \
    --cc=kvm@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=rkrcmar@redhat.com \
    /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).