From patchwork Wed Oct 19 02:49:47 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suraj Jitindar Singh X-Patchwork-Id: 9383549 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 9C9D560487 for ; Wed, 19 Oct 2016 02:50:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8DFDD2985E for ; Wed, 19 Oct 2016 02:50:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7FE3C29865; Wed, 19 Oct 2016 02:50:21 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 156182985E for ; Wed, 19 Oct 2016 02:50:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933181AbcJSCuS (ORCPT ); Tue, 18 Oct 2016 22:50:18 -0400 Received: from mail-pf0-f196.google.com ([209.85.192.196]:33416 "EHLO mail-pf0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932197AbcJSCuQ (ORCPT ); Tue, 18 Oct 2016 22:50:16 -0400 Received: by mail-pf0-f196.google.com with SMTP id i85so1036521pfa.0 for ; Tue, 18 Oct 2016 19:50:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=CBDqeiTY+uebcbaVPQxJ5fIzS5Nzn+eU4YwOnhdu99E=; b=FM/FTFNKMbrYZW3jEQvdlm7AAKl0o5A/xf8nD4ushfL1iPzksBrQso3aX2fuMhXlVM NMtdUNErooYjqdSvhv3W4Rr7eBfUkZxiZEukkl4MWJISjorLFJqz1Tuhdiq5KlHJQozR oBNhtroc1z7dfi5+IGXRFsddt4vL3OUTBFwEL4JL+cFsHFv1bjhBPg9bUQQEt4giZkwf wL8AclKnGA5Fq/smYHu61r3mWSuL5Henu45vvC8PkVEqJ2rw3A8is5xaoJ2sh8bF8z9c MBYIJvz/GE3tXrvB0UirXUV03hTWlRTaM/hacJtBTxG5mfZkLa5Jhb7Sh8tSI+ju9x4J 23OQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=CBDqeiTY+uebcbaVPQxJ5fIzS5Nzn+eU4YwOnhdu99E=; b=Y4JK8GBku78jxILv9WCRbVR5PdBpT/vi1waVDmA3gNJrrKhLF73Uf7ATbmeXOOc7Ho 03OjrXdiQoZucfUMcbkiFi/JaeRUg7KC5whYR9pCLrvxwspcjyw7KpQcFBjLk57HYgvr qyITZlHcqAFqDnuylHKEC+J7vO+t6MSenpicV5y0rV1d2tRkd5zOkE6W+Y+VjWZvuxTZ jLNSVd7U0m9gG8xV9LnWJ0uGW4147PJ1FBYHr6OMmidQ422nhatF47EaVjms07qeoO27 J9wmfO9YQmHrbJbJBSkXo3RFiomRIokXuXJo4w+Aw7/RfYhS6wAeIqqu8XkD7yg7+a3U 7QsQ== X-Gm-Message-State: AA6/9RmV+z4DRKuSmRUWJ+g8uLQQojFdRNwyripG5iSK9jXnODOFkKxhqe4sAxqqr4O4VA== X-Received: by 10.99.121.2 with SMTP id u2mr5264930pgc.141.1476845415610; Tue, 18 Oct 2016 19:50:15 -0700 (PDT) Received: from dyn253.ozlabs.ibm.com ([122.99.82.10]) by smtp.gmail.com with ESMTPSA id x190sm58914176pfd.20.2016.10.18.19.50.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 18 Oct 2016 19:50:15 -0700 (PDT) From: Suraj Jitindar Singh To: kvm@vger.kernel.org Cc: pbonzini@redhat.com, rkrcmar@redhat.com, borntraeger@de.ibm.com, Suraj Jitindar Singh Subject: [PATCH V2] kvm/stats: Update kvm stats to clear on write to their debugfs entry Date: Wed, 19 Oct 2016 13:49:47 +1100 Message-Id: <1476845387-28276-1-git-send-email-sjitindarsingh@gmail.com> X-Mailer: git-send-email 2.5.5 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Various kvm vm and vcpu stats are provided via debugfs entries. Currently there is no way to reset these stats back to zero. Add the ability to clear (reset back to zero) these stats on a per stat basis by writing to the debugfs files. Only a write value of 0 is accepted. Signed-off-by: Suraj Jitindar Singh --- Change Log: V1 -> V2: - Return error on non-zero write value --- virt/kvm/kvm_main.c | 78 ++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 72 insertions(+), 6 deletions(-) diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index 81dfc73..a29f8c2 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,23 @@ 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; + + if (val) + return -EINVAL; + + *(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 +3700,26 @@ 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; + + if (val) + return -EINVAL; + + 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 +3754,26 @@ 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}; + + if (val) + return -EINVAL; + + 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 +3793,27 @@ 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}; + + if (val) + return -EINVAL; + + 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 +3831,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;