From patchwork Mon Jul 11 07:08:32 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: 9222957 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 B17F8604DB for ; Mon, 11 Jul 2016 07:09:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9E1722793B for ; Mon, 11 Jul 2016 07:09:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8FD8327B2F; Mon, 11 Jul 2016 07:09:35 +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 149062793B for ; Mon, 11 Jul 2016 07:09:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757918AbcGKHJc (ORCPT ); Mon, 11 Jul 2016 03:09:32 -0400 Received: from mail-pa0-f68.google.com ([209.85.220.68]:34287 "EHLO mail-pa0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757900AbcGKHJa (ORCPT ); Mon, 11 Jul 2016 03:09:30 -0400 Received: by mail-pa0-f68.google.com with SMTP id hh10so2767283pac.1; Mon, 11 Jul 2016 00:09:30 -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=idZIy6CiDiMRkceRehtNYWf2XdDim2I4+ARORAgbms8=; b=qsB2xtfvCGgZk/EtzYd+l0MUJzBE5E5gqnvHU1I6AULXP2OQYpc6OMBzc1O2xyHX8z ywISYTQJzmLPuJM+8fskhGOQKrFaTlq76Dn5KgGrdpGf+MTLMEVlJmZPuPQxkwvx5bkk JGVnA96MLBsln0iA3fqDu2rUshBez9h9h3zw8jGcDIrxvxl5gHvuPm+Jb+woXFeE7+NV SBKy1iBcX2CCmSNB26Eqv/45AwpdCTFims+X7RecyPLxk6yMI6WHyjt8Bi/3ErT5r3+u 9TVxBPiINs8lXQEC4vmc+S8GUeKaNKgN8QuCR9v3a6ABludnh0kKovTUOn4yxwoR6Q3M FKEA== 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=idZIy6CiDiMRkceRehtNYWf2XdDim2I4+ARORAgbms8=; b=GOcdEPjwbpb188Q8kuMBWn+LdfkZSwcjZxQ5wPtnDd5Jsn+a7ezjBf2xQHLZt7tKIP yMcpbR1Gamno+9UMEqulxGA9P6N9WqxmMkCCa8OS813v/UULR8ANtFb+R5lZb5c7ugP0 afkQvl8t4vq6t5NVwiF768uGmjTSqvKPsqumuEdngiG+CVpQqLgqCl7rDJqDMdPjQDdZ 9eIrs9GL8Bv1NLamk2aaVDzOLy07LGgnDC2cN8Uj/1m+RH7ZnNTPUc0NoIVmriUwSDQ6 oXUbPxV7n8CeO2f+V6Bcz8cef4BaUwNX0kkyTJy2K2nf9GygXbEwzVEFcaGn0RCUn+Rm ZxJA== X-Gm-Message-State: ALyK8tIrBZ+mTHmaKlcdVbCAWsvA1XgUBrPUdRTYM7CdpQ4TsIDcaIlvlB6dae9S4unzew== X-Received: by 10.66.111.164 with SMTP id ij4mr32328920pab.18.1468220969765; Mon, 11 Jul 2016 00:09:29 -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.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 11 Jul 2016 00:09:29 -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 5/5] powerpc/kvm/stats: Implement existing and add new halt polling vcpu stats Date: Mon, 11 Jul 2016 17:08:32 +1000 Message-Id: <1468220912-22828-5-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 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. --- Change Log: V1 -> V2: - Nothing 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 610f393..66a7198 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) ;