=======================================
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
new file mode 100644
@@ -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 "======================================="