KVM: PPC: Implement existing and add new halt polling vcpu stats
authorSuraj Jitindar Singh <sjitindarsingh@gmail.com>
Tue, 2 Aug 2016 04:03:23 +0000 (14:03 +1000)
committerPaul Mackerras <paulus@ozlabs.org>
Thu, 8 Sep 2016 02:25:37 +0000 (12:25 +1000)
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_success_ns, halt_poll_fail_ns and
halt_wait_ns to be used to accumulate the total time spend polling
successfully, polling unsuccessfully and waiting respectively, and
halt_successful_wait to accumulate the number of times the vcpu waits.
Given that halt_poll_success_ns, halt_poll_fail_ns and halt_wait_ns 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 <sjitindarsingh@gmail.com>
Reviewed-by: David Matlack <dmatlack@google.com>
Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
arch/powerpc/include/asm/kvm_host.h
arch/powerpc/kvm/book3s.c
arch/powerpc/kvm/book3s_hv.c

index 5ec1dcf300f615b5a61f7957cefd7d7beb9f4047..373003f4551d3d974ad892bb05d43d53668bc117 100644 (file)
@@ -116,8 +116,12 @@ struct kvm_vcpu_stat {
        u64 emulated_inst_exits;
        u64 dec_exits;
        u64 ext_intr_exits;
+       u64 halt_poll_success_ns;
+       u64 halt_poll_fail_ns;
+       u64 halt_wait_ns;
        u64 halt_successful_poll;
        u64 halt_attempted_poll;
+       u64 halt_successful_wait;
        u64 halt_poll_invalid;
        u64 halt_wakeup;
        u64 dbell_exits;
index 47018fcbf7d6aa3dd02caeef441dccd52ed476a4..71eb8f3d3b54ccdd206843f01825f41193774830 100644 (file)
@@ -52,8 +52,12 @@ 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_success_ns",       VCPU_STAT(halt_poll_success_ns) },
+       { "halt_poll_fail_ns",          VCPU_STAT(halt_poll_fail_ns) },
+       { "halt_wait_ns",               VCPU_STAT(halt_wait_ns) },
        { "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) },
index 3c85c3b28fc5256d4785c704ffcf9466202f3f23..30ff8ab5aba1f85421cdce694330d15e2555e208 100644 (file)
@@ -2680,15 +2680,16 @@ static int kvmppc_vcore_check_block(struct kvmppc_vcore *vc)
  */
 static void kvmppc_vcore_blocked(struct kvmppc_vcore *vc)
 {
+       ktime_t cur, start_poll, start_wait;
        int do_sleep = 1;
-       ktime_t cur, start;
        u64 block_ns;
        DECLARE_SWAITQUEUE(wait);
 
        /* Poll for pending exceptions and ceded state */
-       cur = start = ktime_get();
+       cur = start_poll = ktime_get();
        if (vc->halt_poll_ns) {
-               ktime_t stop = ktime_add_ns(start, vc->halt_poll_ns);
+               ktime_t stop = ktime_add_ns(start_poll, vc->halt_poll_ns);
+               ++vc->runner->stat.halt_attempted_poll;
 
                vc->vcore_state = VCORE_POLLING;
                spin_unlock(&vc->lock);
@@ -2704,8 +2705,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);
@@ -2713,9 +2716,14 @@ 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;
        }
 
+       start_wait = ktime_get();
+
        vc->vcore_state = VCORE_SLEEPING;
        trace_kvmppc_vcore_blocked(vc, 0);
        spin_unlock(&vc->lock);
@@ -2724,11 +2732,29 @@ 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);
+       block_ns = ktime_to_ns(cur) - ktime_to_ns(start_poll);
+
+       /* Attribute wait time */
+       if (do_sleep) {
+               vc->runner->stat.halt_wait_ns +=
+                       ktime_to_ns(cur) - ktime_to_ns(start_wait);
+               /* Attribute failed poll time */
+               if (vc->halt_poll_ns)
+                       vc->runner->stat.halt_poll_fail_ns +=
+                               ktime_to_ns(start_wait) -
+                               ktime_to_ns(start_poll);
+       } else {
+               /* Attribute successful poll time */
+               if (vc->halt_poll_ns)
+                       vc->runner->stat.halt_poll_success_ns +=
+                               ktime_to_ns(cur) -
+                               ktime_to_ns(start_poll);
+       }
 
        /* Adjust poll time */
        if (halt_poll_max_ns) {