From: Hemant Kumar <hemant@linux.vnet.ibm.com>
To: linux-kernel@vger.kernel.org
Cc: maddy@linux.vnet.ibm.com, srikar@linux.vnet.ibm.com,
peterz@infradead.org, agraf@suse.de, kvm-ppc@vger.kernel.org,
Hemant Kumar <hemant@linux.vnet.ibm.com>,
mingo@redhat.com, paulus@samba.org, acme@kernel.org,
warrier@linux.vnet.ibm.com, linuxppc-dev@lists.ozlabs.org
Subject: [RFC PATCH 1/1] perf/script: Script to display the ganged exits count on powerpc
Date: Fri, 15 May 2015 09:44:26 +0530 [thread overview]
Message-ID: <1431663266-13954-2-git-send-email-hemant@linux.vnet.ibm.com> (raw)
In-Reply-To: <1431663266-13954-1-git-send-email-hemant@linux.vnet.ibm.com>
In powerpc, when a thread running in the guest context needs to exit to
the hypervisor to serve interrupts like the external interrupt, or the
hcall interrupt, etc, all the threads running in that specific vcore
inside the guest exit. These events can be classified as gang exits
which mean that they are forced exits. Only if the other vcpus cede,
then it won't be counted as a ganged exit.
What this script does is, it post processes the perf.data file to look
for two events : kvm_hv:kvmppc_run_core and kvm_hv:kvm_guest_exit. For a
kvm_hv:kvmppc_run_core tracepoint event, it initializes :
- if its an 'Entry', it gets the tgid and for that tgid, it initializes
gang-exit count and cedes count.
- if its an 'Exit', it gets the runnable thread count and subtracts it
from the no of cedes to see (if) how many runnable threads were in
that core and how many of them ceded. If the difference is more than
1 (its 1 because, we have to exclude the running thread itself), then
its a ganged exit.
For a kvm_hv:kvm_guest_exit event, it checks if the vcpu ceded. If it
ceded, then increment the counter for cedes.
Usage :
# perf record -e kvm_hv:kvm_guest_exit -e kvm_hv:kvmppc_run_core -a sleep 10
[ perf record: Woken up 96 times to write data ]
[ perf record: Captured and wrote 26.198 MB perf.data (~1144590 samples)]
# perf script -s gang-exits.py
Ganged exits summary
Ganged exits for process 14000 : 535
Ganged exits for process 13988 : 25314
=======================================
Signed-off-by: Hemant Kumar <hemant@linux.vnet.ibm.com>
---
tools/perf/scripts/python/gang_exits.py | 65 +++++++++++++++++++++++++++++++++
1 file changed, 65 insertions(+)
create mode 100644 tools/perf/scripts/python/gang_exits.py
diff --git a/tools/perf/scripts/python/gang_exits.py b/tools/perf/scripts/python/gang_exits.py
new file mode 100644
index 0000000..011aa56
--- /dev/null
+++ b/tools/perf/scripts/python/gang_exits.py
@@ -0,0 +1,65 @@
+# gang-exits.py: Count the ganged exits of a VM
+#
+# In case of powerpc, When a thread running inside a guest needs to exit to
+# the hypervisor to serve interrupts like the external interrupt, or the hcall
+# interrupts, etc., all the threads running in that specific vcore
+# inside the guest exit to the host. These events are called as ganged exits.
+# These exits are forced. Only if the vcpus cede, then it/they won't be counted
+# as ganged exit(s).
+#
+# Usage :
+# So, if in powerpc, first we do :
+# perf record -e kvm_hv:kvm_guest_exit -e kvm_hv:kvmppc_run_core -aR sleep <nsecs>
+# Using the perf.data, we have to do :
+# perf script -s gang-exits
+
+import os
+import sys
+
+sys.path.append(os.environ['PERF_EXEC_PATH'] + \
+ '/scripts/python/Perf-Trace-Util/lib/Perf/Trace')
+
+from perf_trace_context import *
+from Core import *
+
+usage = "perf script -s gang_exits.py\n";
+
+stats = {}
+pid_tgid = {}
+
+def trace_begin():
+ print "Ganged exits summary"
+
+def trace_end():
+ print_ganged_exits()
+
+def kvm_hv__kvm_guest_exit(event_name, context, common_cpu,
+ common_secs, common_nsecs, common_pid, common_comm,
+ vcpu_id, reason, nip, msr, ceded):
+
+ if common_pid in pid_tgid:
+ if ceded: # vcpu ceded ?
+ stats[pid_tgid[common_pid]]['nr_cedes'] += ceded
+
+def kvm_hv__kvmppc_run_core(event_name, context, common_cpu,
+ common_secs, common_nsecs, common_pid, common_comm,
+ n_runnable, runner_vcpu, where, tgid):
+
+ if (where): # kvmppc_run_core: Exit
+ if tgid in stats:
+ forced = n_runnable - stats[tgid]['nr_cedes']
+ if (forced > 1):
+ stats[tgid]['gang-exits'] += 1
+ else: # kvmppc_run_core: Enter, init the counts
+ if tgid in stats:
+ stats[tgid]['nr_cedes'] = 0
+ else:
+ stats[tgid] = {'gang-exits': 0, 'nr_cedes': 0}
+ if common_pid not in pid_tgid:
+ pid_tgid[common_pid] = tgid
+
+def print_ganged_exits():
+ for i in stats.keys():
+ print "\nGanged exits for process %d : %20d" %(i, stats[i]['gang-exits'])
+
+ print "======================================="
--
1.9.3
prev parent reply other threads:[~2015-05-15 4:15 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-05-15 4:14 [RFC PATCH 0/1] perf/script: Ganged exits and VM topology Hemant Kumar
2015-05-15 4:14 ` Hemant Kumar [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1431663266-13954-2-git-send-email-hemant@linux.vnet.ibm.com \
--to=hemant@linux.vnet.ibm.com \
--cc=acme@kernel.org \
--cc=agraf@suse.de \
--cc=kvm-ppc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=maddy@linux.vnet.ibm.com \
--cc=mingo@redhat.com \
--cc=paulus@samba.org \
--cc=peterz@infradead.org \
--cc=srikar@linux.vnet.ibm.com \
--cc=warrier@linux.vnet.ibm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).