From patchwork Wed Jun 15 09:21:07 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: 635775 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3rV1H840c3z9t1q for ; Wed, 15 Jun 2016 19:21:40 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=DGIg/RXt; dkim-atps=neutral Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753334AbcFOJVj (ORCPT ); Wed, 15 Jun 2016 05:21:39 -0400 Received: from mail-pf0-f193.google.com ([209.85.192.193]:35444 "EHLO mail-pf0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752183AbcFOJVh (ORCPT ); Wed, 15 Jun 2016 05:21:37 -0400 Received: by mail-pf0-f193.google.com with SMTP id t190so1386215pfb.2; Wed, 15 Jun 2016 02:21:37 -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=Za5cOGf9XjluN13hB52mhsI4bc9tpYc3IidZ9XGk/mo=; b=DGIg/RXtPp0V2ljK/5nU2AN86fEFDD54JKdnsWAhfM+OfIO19S8N84O4zjzpr+jx9g nhIhkefKxnyvil8m+mq7Y22YjE/quJZX5hySvXebxuOrx5TyWFjXowOg/uMsTBx6ypU8 PJM0dN5myj32gq81rG3A6J9K3UgwVVaQbu/D1D0pxr+/4vQ8L1wBNb41HtX4W1d98C6c Wy4TVYIHZcxPjvWYVHdbgxg7zVn0uHGascN6QZrVWAoMqj0zKnBGQDyL2fqZvN7/fl/U lhuvl8zLRNplTJfyFvqApX6XecLxGJSTz1Pah7bQT6VjwCgpy1ms+z8X3JzqQ/G5TFpo z2Vw== 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=Za5cOGf9XjluN13hB52mhsI4bc9tpYc3IidZ9XGk/mo=; b=AwzVXlGTuFQMV+qgq9m9MTkyEOeQWA8njcSF0LiLMC8mQjMoRBUXZN0cdgm53tRBYR 8xtoxNJF6HH87+vudl7h9PQhQjhqpaOb1TcD4Wlxhjvnh7gJMr2iQqkmpoPlNuc334hs mOHbuLjzzW9s5ZRan7BnXyFMEuVrC/oD9DU9HxAaZooaxNtWaCsGYTkt53s0eMnjL2Y7 SKh3koRjT1AMDdPznPNYrQEPMZU4KrFOX4CxLdcRhTJM+mYUj0FqxgbqSOzX+rRqfW3W BmAFG2OC2dXMo1s/yryl8Kyf+bMEMlMZcNPkxHgcYgCeF2GLkdHNQ7qRDtO/OlIByfZi DkcA== X-Gm-Message-State: ALyK8tKwMo0pjEXe7ZURWm2EMzu6AqS+FL/xc4zNYKzduaoDwcWTNcPnMsLre1Y6QmMrGg== X-Received: by 10.98.31.140 with SMTP id l12mr2823253pfj.51.1465982496727; Wed, 15 Jun 2016 02:21:36 -0700 (PDT) Received: from dyn253.ozlabs.ibm.com ([122.99.82.10]) by smtp.gmail.com with ESMTPSA id i5sm35423845pfk.14.2016.06.15.02.21.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 15 Jun 2016 02:21:36 -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, Suraj Jitindar Singh Subject: [PATCH 3/4] kvm/stats: Add provisioning for 64-bit vcpu statistics Date: Wed, 15 Jun 2016 19:21:07 +1000 Message-Id: <1465982468-18833-3-git-send-email-sjitindarsingh@gmail.com> X-Mailer: git-send-email 2.5.5 In-Reply-To: <1465982468-18833-1-git-send-email-sjitindarsingh@gmail.com> References: <1465982468-18833-1-git-send-email-sjitindarsingh@gmail.com> Sender: kvm-ppc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm-ppc@vger.kernel.org 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. 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 02e98f3..ac47ffb 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)