From patchwork Mon Jul 11 07:08:31 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: 9222955 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 EBEB9604DB for ; Mon, 11 Jul 2016 07:09:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DA6A92793B for ; Mon, 11 Jul 2016 07:09:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CEC2827B2F; Mon, 11 Jul 2016 07:09:30 +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 58B7B2793B for ; Mon, 11 Jul 2016 07:09:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757901AbcGKHJ2 (ORCPT ); Mon, 11 Jul 2016 03:09:28 -0400 Received: from mail-pf0-f196.google.com ([209.85.192.196]:35329 "EHLO mail-pf0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757833AbcGKHJ0 (ORCPT ); Mon, 11 Jul 2016 03:09:26 -0400 Received: by mail-pf0-f196.google.com with SMTP id t190so12942684pfb.2; Mon, 11 Jul 2016 00:09:25 -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:in-reply-to:references; bh=SCjBN5cqhTYrX1qLa9qBAj8C9KPHGd7WllOEjtqt80A=; b=KVrrqW71qhnZpXbEGVse+Fia0voylXrx1kXv8BoeWOytEoECZGmaoDHSquIJ0xxXjU E95rLffGwHw+ut/R/2IN1PEodEHF234yENRvO43tSXfV4dnPvSEuyhu4tZqfdwky4epb nfo48Z9DDwfstNLpDyf6/CfJ4jSYApFHlQgSSMgUDk+IWWn/OYQInKTrzbTgEfbAzNkj oxaHC5usp/cr5UN+Qe9oU68RB3naIqiA2tc7lCU90q40T9Jt1xW7Qp9gfmfRL/p4X31f ssjBnjWMtf/HhnmA5fpbxGaQQuqHCqANLaUOyT/MUaH5TPwRDHXcJtsCb/TyhGcaP0E7 aHoQ== 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:in-reply-to :references; bh=SCjBN5cqhTYrX1qLa9qBAj8C9KPHGd7WllOEjtqt80A=; b=J0o8xubdKJKjWKEpNsMBSa/G/AgA1SPxGnnA46iG462+Cy21BiYrPRwo/OyYjlmjcL De1us9n5Ez0oZSVRzJtkxDnnFCn4ZkFFgCcNzOtL62pJosSw5cHP39Lsj2Ib5a4utGRV iDA3VuCMDD3Cns7SYawdFK3lQpQD5PAE6QthHKZf8IjyXz+xkJOTMQHSOipShnMYz4Ke 7Qy6CX1TqgKcsiTimPkbEbN5/4z16zkDUgaVpZ9uWj/NHTjjWufmhBllDzzjQ+Qo/LbX VZhl4wYAStPHApf0henJe1YJGUMFhJ7ClSO1KC/QevOxIm2gTbj5bTG4Esv8h/nTb7gl CGng== X-Gm-Message-State: ALyK8tJyUzQVJ3Ph25lOWvPq9L3GirkEP+WLITc2HFze1cPZRzyD+y2qxE2I5an8DkFUMQ== X-Received: by 10.98.14.72 with SMTP id w69mr21425678pfi.119.1468220965107; Mon, 11 Jul 2016 00:09:25 -0700 (PDT) Received: from dyn253.ozlabs.ibm.com ([122.99.82.10]) by smtp.gmail.com with ESMTPSA id 4sm2019179pav.33.2016.07.11.00.09.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 11 Jul 2016 00:09:24 -0700 (PDT) From: Suraj Jitindar Singh To: linuxppc-dev@lists.ozlabs.org Cc: kvm-ppc@vger.kernel.org, mpe@ellerman.id.au, paulus@samba.org, benh@kernel.crashing.org, kvm@vger.kernel.org, pbonzini@redhat.com, agraf@suse.com, rkrcmar@redhat.com, sjitindarsingh@gmail.com Subject: [PATCH V2 4/5] kvm/stats: Add provisioning for 64-bit vcpu statistics Date: Mon, 11 Jul 2016 17:08:31 +1000 Message-Id: <1468220912-22828-4-git-send-email-sjitindarsingh@gmail.com> X-Mailer: git-send-email 2.5.5 In-Reply-To: <1468220912-22828-1-git-send-email-sjitindarsingh@gmail.com> References: <1468220912-22828-1-git-send-email-sjitindarsingh@gmail.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP vcpus have statistics associated with them which can be viewed within the debugfs. Currently it is assumed within the vcpu_stat_get() and vcpu_stat_get_per_vm() functions that all of these statistics are represented as 32-bit numbers. The next patch adds some 64-bit statistics, so add provisioning for the display of 64-bit vcpu statistics. --- Change Log: V1 -> V2: - Nothing Signed-off-by: Suraj Jitindar Singh --- arch/powerpc/kvm/book3s.c | 1 + include/linux/kvm_host.h | 1 + virt/kvm/kvm_main.c | 60 +++++++++++++++++++++++++++++++++++++++++++---- 3 files changed, 58 insertions(+), 4 deletions(-) diff --git a/arch/powerpc/kvm/book3s.c b/arch/powerpc/kvm/book3s.c index 47018fc..ed9132b 100644 --- a/arch/powerpc/kvm/book3s.c +++ b/arch/powerpc/kvm/book3s.c @@ -40,6 +40,7 @@ #include "trace.h" #define VCPU_STAT(x) offsetof(struct kvm_vcpu, stat.x), KVM_STAT_VCPU +#define VCPU_STAT_U64(x) offsetof(struct kvm_vcpu, stat.x), KVM_STAT_VCPU_U64 /* #define EXIT_DEBUG */ diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h index 1c9c973..667b30e 100644 --- a/include/linux/kvm_host.h +++ b/include/linux/kvm_host.h @@ -991,6 +991,7 @@ static inline bool kvm_is_error_gpa(struct kvm *kvm, gpa_t gpa) enum kvm_stat_kind { KVM_STAT_VM, KVM_STAT_VCPU, + KVM_STAT_VCPU_U64, }; struct kvm_stat_data { diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index 48bd520..7ab5901 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -3566,6 +3566,20 @@ static int vcpu_stat_get_per_vm(void *data, u64 *val) return 0; } +static int vcpu_stat_u64_get_per_vm(void *data, u64 *val) +{ + int i; + struct kvm_stat_data *stat_data = (struct kvm_stat_data *)data; + struct kvm_vcpu *vcpu; + + *val = 0; + + kvm_for_each_vcpu(i, vcpu, stat_data->kvm) + *val += *(u64 *)((void *)vcpu + stat_data->offset); + + return 0; +} + static int vcpu_stat_get_per_vm_open(struct inode *inode, struct file *file) { __simple_attr_check_format("%llu\n", 0ull); @@ -3573,6 +3587,13 @@ static int vcpu_stat_get_per_vm_open(struct inode *inode, struct file *file) NULL, "%llu\n"); } +static int vcpu_stat_u64_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_u64_get_per_vm, + NULL, "%llu\n"); +} + static const struct file_operations vcpu_stat_get_per_vm_fops = { .owner = THIS_MODULE, .open = vcpu_stat_get_per_vm_open, @@ -3582,9 +3603,19 @@ static const struct file_operations vcpu_stat_get_per_vm_fops = { .llseek = generic_file_llseek, }; +static const struct file_operations vcpu_stat_u64_get_per_vm_fops = { + .owner = THIS_MODULE, + .open = vcpu_stat_u64_get_per_vm_open, + .release = kvm_debugfs_release, + .read = simple_attr_read, + .write = simple_attr_write, + .llseek = generic_file_llseek, +}; + static const struct file_operations *stat_fops_per_vm[] = { - [KVM_STAT_VCPU] = &vcpu_stat_get_per_vm_fops, - [KVM_STAT_VM] = &vm_stat_get_per_vm_fops, + [KVM_STAT_VCPU] = &vcpu_stat_get_per_vm_fops, + [KVM_STAT_VCPU_U64] = &vcpu_stat_u64_get_per_vm_fops, + [KVM_STAT_VM] = &vm_stat_get_per_vm_fops, }; static int vm_stat_get(void *_offset, u64 *val) @@ -3627,9 +3658,30 @@ static int vcpu_stat_get(void *_offset, u64 *val) DEFINE_SIMPLE_ATTRIBUTE(vcpu_stat_fops, vcpu_stat_get, NULL, "%llu\n"); +static int vcpu_stat_u64_get(void *_offset, u64 *val) +{ + unsigned offset = (long)_offset; + struct kvm *kvm; + struct kvm_stat_data stat_tmp = {.offset = offset}; + u64 tmp_val; + + *val = 0; + spin_lock(&kvm_lock); + list_for_each_entry(kvm, &vm_list, vm_list) { + stat_tmp.kvm = kvm; + vcpu_stat_u64_get_per_vm((void *)&stat_tmp, &tmp_val); + *val += tmp_val; + } + spin_unlock(&kvm_lock); + return 0; +} + +DEFINE_SIMPLE_ATTRIBUTE(vcpu_stat_u64_fops, vcpu_stat_u64_get, NULL, "%llu\n"); + static const struct file_operations *stat_fops[] = { - [KVM_STAT_VCPU] = &vcpu_stat_fops, - [KVM_STAT_VM] = &vm_stat_fops, + [KVM_STAT_VCPU] = &vcpu_stat_fops, + [KVM_STAT_VCPU_U64] = &vcpu_stat_u64_fops, + [KVM_STAT_VM] = &vm_stat_fops, }; static int kvm_init_debug(void)