From patchwork Wed Jun 15 09:21:08 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: 635783 X-Patchwork-Delegate: paulus@samba.org Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3rV1Qg2W0Wz9t0v for ; Wed, 15 Jun 2016 19:28:11 +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=SAE333s2; dkim-atps=neutral Received: from ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3rV1Qg1SM4zDqpn for ; Wed, 15 Jun 2016 19:28:11 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=SAE333s2; dkim-atps=neutral X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Received: from mail-pa0-x241.google.com (mail-pa0-x241.google.com [IPv6:2607:f8b0:400e:c03::241]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 3rV1HD18gFzDqjK for ; Wed, 15 Jun 2016 19:21:44 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=SAE333s2; dkim-atps=neutral Received: by mail-pa0-x241.google.com with SMTP id hf6so1175825pac.2 for ; Wed, 15 Jun 2016 02:21:44 -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=oBzAiT0FBQZDCWVwEETy3DlmLazpx5xhhsNedI0tweM=; b=SAE333s2+nbiDo6fMCx2lQh5MVLrq/zjTzeTbPiqi41WW1gVm7uAZlua5QQZZJJMw4 dkPkWqYwDkIeFSsAYvdjw6f9PZGuxCmWFzmmchLT7D3k+YorIy2f2+/QPSCqlwmZBEk5 LKHY86hwRoBrFITfg/MHSQZSFFrmm5Tcr2zObfH0JFiJAxU6lCrR5nKhvy4rR0NeFOe9 opTpooJrzDiizVuBpz/bLfh9v8ye8b3N8p0Ke+3D0P6Euj4Dv+3ltzIBzTAxmaeJeCUV wOkdQD44lEg+d+j0E0Z2NF0lS4i7dux6lHNI2/fpiOLei7NonDewJHXgSYKa09I6P/y5 Sg1g== 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=oBzAiT0FBQZDCWVwEETy3DlmLazpx5xhhsNedI0tweM=; b=cnK7UmUcgizVJtizn+klvM6/p6V24z0DmADiiAxWVi+2n+0n9GScwP+CiJgAMygC6H 87c6EdFI9cm6th3XWZrE+Qd7iiLlLeCJEU6gcUdN4eS3hTTAfqKQ8bJbzH/Mn9HYa1Pw bJQAgEQk7/lK1/IeV3IoOWX1dxG2WlCz8NV+D8d3DQdQWUAncNc9j70O4Ra/KD8d6xBL c3M1wAoaDSy5MNzSjqd/fmxRbHqE3u6++jTBTxs69hNeWfI1fGnSD7I15t4MvKEM8RUR hS2NQIfV8LFvgU164pe2rrwgPztHcD5v5HDlPotX6E7ul9+WBWeOC1UTooimbiwoSbL9 pH5A== X-Gm-Message-State: ALyK8tJ1qo0SuXM7URB+VUD/+zVmKx+wDppUgjJppeWyN0N3aIhEjp7hHoHdWlAL438SFg== X-Received: by 10.66.255.102 with SMTP id ap6mr2872208pad.2.1465982502154; Wed, 15 Jun 2016 02:21:42 -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.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 15 Jun 2016 02:21:41 -0700 (PDT) From: Suraj Jitindar Singh To: linuxppc-dev@lists.ozlabs.org Subject: [PATCH 4/4] powerpc/kvm/stats: Implement existing and add new halt polling vcpu stats Date: Wed, 15 Jun 2016 19:21:08 +1000 Message-Id: <1465982468-18833-4-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> X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kvm@vger.kernel.org, rkrcmar@redhat.com, kvm-ppc@vger.kernel.org, paulus@samba.org, Suraj Jitindar Singh , pbonzini@redhat.com, agraf@suse.com MIME-Version: 1.0 Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" vcpu stats are used to collect information about a vcpu which can be viewed in the debugfs. For example halt_attempted_poll and halt_successful_poll are used to keep track of the number of times the vcpu attempts to and successfully polls. These stats are currently not used on powerpc. Implement incrementation of the halt_attempted_poll and halt_successful_poll vcpu stats for powerpc. Since these stats are summed over all the vcpus for all running guests it doesn't matter which vcpu they are attributed to, thus we choose the current runner vcpu of the vcore. Also add new vcpu stats: halt_poll_time and halt_wait_time to be used to accumulate the total time spend polling and waiting respectively, and halt_successful_wait to accumulate the number of times the vcpu waits. Given that halt_poll_time and halt_wait_time are expressed in nanoseconds it is necessary to represent these as 64-bit quantities, otherwise they would overflow after only about 4 seconds. Given that the total time spend either polling or waiting will be known and the number of times that each was done, it will be possible to determine the average poll and wait times. This will give the ability to tune the kvm module parameters based on the calculated average wait and poll times. Signed-off-by: Suraj Jitindar Singh --- arch/powerpc/include/asm/kvm_host.h | 3 +++ arch/powerpc/kvm/book3s.c | 3 +++ arch/powerpc/kvm/book3s_hv.c | 14 +++++++++++++- 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/arch/powerpc/include/asm/kvm_host.h b/arch/powerpc/include/asm/kvm_host.h index b34efe8..2ece5fc 100644 --- a/arch/powerpc/include/asm/kvm_host.h +++ b/arch/powerpc/include/asm/kvm_host.h @@ -114,8 +114,11 @@ struct kvm_vcpu_stat { u32 emulated_inst_exits; u32 dec_exits; u32 ext_intr_exits; + u64 halt_poll_time; + u64 halt_wait_time; u32 halt_successful_poll; u32 halt_attempted_poll; + u32 halt_successful_wait; u32 halt_poll_invalid; u32 halt_wakeup; u32 dbell_exits; diff --git a/arch/powerpc/kvm/book3s.c b/arch/powerpc/kvm/book3s.c index ed9132b..6217bea 100644 --- a/arch/powerpc/kvm/book3s.c +++ b/arch/powerpc/kvm/book3s.c @@ -53,8 +53,11 @@ struct kvm_stats_debugfs_item debugfs_entries[] = { { "dec", VCPU_STAT(dec_exits) }, { "ext_intr", VCPU_STAT(ext_intr_exits) }, { "queue_intr", VCPU_STAT(queue_intr) }, + { "halt_poll_time_ns", VCPU_STAT_U64(halt_poll_time) }, + { "halt_wait_time_ns", VCPU_STAT_U64(halt_wait_time) }, { "halt_successful_poll", VCPU_STAT(halt_successful_poll), }, { "halt_attempted_poll", VCPU_STAT(halt_attempted_poll), }, + { "halt_successful_wait", VCPU_STAT(halt_successful_wait) }, { "halt_poll_invalid", VCPU_STAT(halt_poll_invalid) }, { "halt_wakeup", VCPU_STAT(halt_wakeup) }, { "pf_storage", VCPU_STAT(pf_storage) }, diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c index 0d8ce14..a0dae63 100644 --- a/arch/powerpc/kvm/book3s_hv.c +++ b/arch/powerpc/kvm/book3s_hv.c @@ -2688,6 +2688,7 @@ static void kvmppc_vcore_blocked(struct kvmppc_vcore *vc) cur = start = ktime_get(); if (vc->halt_poll_ns) { ktime_t stop = ktime_add_ns(start, vc->halt_poll_ns); + ++vc->runner->stat.halt_attempted_poll; vc->vcore_state = VCORE_POLLING; spin_unlock(&vc->lock); @@ -2703,8 +2704,10 @@ static void kvmppc_vcore_blocked(struct kvmppc_vcore *vc) spin_lock(&vc->lock); vc->vcore_state = VCORE_INACTIVE; - if (!do_sleep) + if (!do_sleep) { + ++vc->runner->stat.halt_successful_poll; goto out; + } } prepare_to_swait(&vc->wq, &wait, TASK_INTERRUPTIBLE); @@ -2712,6 +2715,9 @@ static void kvmppc_vcore_blocked(struct kvmppc_vcore *vc) if (kvmppc_vcore_check_block(vc)) { finish_swait(&vc->wq, &wait); do_sleep = 0; + /* If we polled, count this as a successful poll */ + if (vc->halt_poll_ns) + ++vc->runner->stat.halt_successful_poll; goto out; } @@ -2723,12 +2729,18 @@ static void kvmppc_vcore_blocked(struct kvmppc_vcore *vc) spin_lock(&vc->lock); vc->vcore_state = VCORE_INACTIVE; trace_kvmppc_vcore_blocked(vc, 1); + ++vc->runner->stat.halt_successful_wait; cur = ktime_get(); out: block_ns = ktime_to_ns(cur) - ktime_to_ns(start); + if (do_sleep) + vc->runner->stat.halt_wait_time += block_ns; + else if (vc->halt_poll_ns) + vc->runner->stat.halt_poll_time += block_ns; + if (halt_poll_max_ns) { if (block_ns <= vc->halt_poll_ns) ;