78e6c39b23
Powerpc provides hcall events that also provides insights into guest behaviour. Enhance perf kvm stat to record and analyze hcall events. - To trace hcall events : perf kvm stat record - To show the results : perf kvm stat report --event=hcall The result shows the number of hypervisor calls from the guest grouped by their respective reasons displayed with the frequency. This patch makes use of two additional tracepoints "kvm_hv:kvm_hcall_enter" and "kvm_hv:kvm_hcall_exit". To map the hcall codes to their respective names, it needs a mapping. Such mapping is added in this patch in book3s_hcalls.h. # pgrep qemu A sample output : 19378 60515 2 VMs running. # perf kvm stat record -a ^C[ perf record: Woken up 1 times to write data ] [ perf record: Captured and wrote 4.153 MB perf.data.guest (39624 samples) ] # perf kvm stat report -p 60515 --event=hcall Analyze events for all VMs, all VCPUs: HCALL-EVENT Samples Samples% Time% MinTime MaxTime AvgTime H_IPI 822 66.08% 88.10% 0.63us 11.38us 2.05us (+- 1.42%) H_SEND_CRQ 144 11.58% 3.77% 0.41us 0.88us 0.50us (+- 1.47%) H_VIO_SIGNAL 118 9.49% 2.86% 0.37us 0.83us 0.47us (+- 1.43%) H_PUT_TERM_CHAR 76 6.11% 2.07% 0.37us 0.90us 0.52us (+- 2.43%) H_GET_TERM_CHAR 74 5.95% 2.23% 0.37us 1.70us 0.58us (+- 4.77%) H_RTAS 6 0.48% 0.85% 1.10us 9.25us 2.70us (+-48.57%) H_PERFMON 4 0.32% 0.12% 0.41us 0.96us 0.59us (+-20.92%) Total Samples:1244, Total events handled time:1916.69us. Signed-off-by: Hemant Kumar <hemant@linux.vnet.ibm.com> Cc: Alexander Yarygin <yarygin@linux.vnet.ibm.com> Cc: David Ahern <dsahern@gmail.com> Cc: Michael Ellerman <mpe@ellerman.id.au> Cc: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com> Cc: Paul Mackerras <paulus@samba.org> Cc: Scott Wood <scottwood@freescale.com> Cc: Srikar Dronamraju <srikar@linux.vnet.ibm.com> Cc: linuxppc-dev@lists.ozlabs.org Link: http://lkml.kernel.org/r/1453962787-15376-4-git-send-email-hemant@linux.vnet.ibm.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
171 lines
3.9 KiB
C
171 lines
3.9 KiB
C
#include "util/kvm-stat.h"
|
|
#include "util/parse-events.h"
|
|
#include "util/debug.h"
|
|
|
|
#include "book3s_hv_exits.h"
|
|
#include "book3s_hcalls.h"
|
|
|
|
#define NR_TPS 4
|
|
|
|
const char *vcpu_id_str = "vcpu_id";
|
|
const int decode_str_len = 40;
|
|
const char *kvm_entry_trace = "kvm_hv:kvm_guest_enter";
|
|
const char *kvm_exit_trace = "kvm_hv:kvm_guest_exit";
|
|
|
|
define_exit_reasons_table(hv_exit_reasons, kvm_trace_symbol_exit);
|
|
define_exit_reasons_table(hcall_reasons, kvm_trace_symbol_hcall);
|
|
|
|
/* Tracepoints specific to ppc_book3s_hv */
|
|
const char *ppc_book3s_hv_kvm_tp[] = {
|
|
"kvm_hv:kvm_guest_enter",
|
|
"kvm_hv:kvm_guest_exit",
|
|
"kvm_hv:kvm_hcall_enter",
|
|
"kvm_hv:kvm_hcall_exit",
|
|
NULL,
|
|
};
|
|
|
|
/* 1 extra placeholder for NULL */
|
|
const char *kvm_events_tp[NR_TPS + 1];
|
|
const char *kvm_exit_reason;
|
|
|
|
static void hcall_event_get_key(struct perf_evsel *evsel,
|
|
struct perf_sample *sample,
|
|
struct event_key *key)
|
|
{
|
|
key->info = 0;
|
|
key->key = perf_evsel__intval(evsel, sample, "req");
|
|
}
|
|
|
|
static const char *get_hcall_exit_reason(u64 exit_code)
|
|
{
|
|
struct exit_reasons_table *tbl = hcall_reasons;
|
|
|
|
while (tbl->reason != NULL) {
|
|
if (tbl->exit_code == exit_code)
|
|
return tbl->reason;
|
|
tbl++;
|
|
}
|
|
|
|
pr_debug("Unknown hcall code: %lld\n",
|
|
(unsigned long long)exit_code);
|
|
return "UNKNOWN";
|
|
}
|
|
|
|
static bool hcall_event_end(struct perf_evsel *evsel,
|
|
struct perf_sample *sample __maybe_unused,
|
|
struct event_key *key __maybe_unused)
|
|
{
|
|
return (!strcmp(evsel->name, kvm_events_tp[3]));
|
|
}
|
|
|
|
static bool hcall_event_begin(struct perf_evsel *evsel,
|
|
struct perf_sample *sample, struct event_key *key)
|
|
{
|
|
if (!strcmp(evsel->name, kvm_events_tp[2])) {
|
|
hcall_event_get_key(evsel, sample, key);
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
static void hcall_event_decode_key(struct perf_kvm_stat *kvm __maybe_unused,
|
|
struct event_key *key,
|
|
char *decode)
|
|
{
|
|
const char *hcall_reason = get_hcall_exit_reason(key->key);
|
|
|
|
scnprintf(decode, decode_str_len, "%s", hcall_reason);
|
|
}
|
|
|
|
static struct kvm_events_ops hcall_events = {
|
|
.is_begin_event = hcall_event_begin,
|
|
.is_end_event = hcall_event_end,
|
|
.decode_key = hcall_event_decode_key,
|
|
.name = "HCALL-EVENT",
|
|
};
|
|
|
|
static struct kvm_events_ops exit_events = {
|
|
.is_begin_event = exit_event_begin,
|
|
.is_end_event = exit_event_end,
|
|
.decode_key = exit_event_decode_key,
|
|
.name = "VM-EXIT"
|
|
};
|
|
|
|
struct kvm_reg_events_ops kvm_reg_events_ops[] = {
|
|
{ .name = "vmexit", .ops = &exit_events },
|
|
{ .name = "hcall", .ops = &hcall_events },
|
|
{ NULL, NULL },
|
|
};
|
|
|
|
const char * const kvm_skip_events[] = {
|
|
NULL,
|
|
};
|
|
|
|
|
|
static int is_tracepoint_available(const char *str, struct perf_evlist *evlist)
|
|
{
|
|
struct parse_events_error err;
|
|
int ret;
|
|
|
|
err.str = NULL;
|
|
ret = parse_events(evlist, str, &err);
|
|
if (err.str)
|
|
pr_err("%s : %s\n", str, err.str);
|
|
return ret;
|
|
}
|
|
|
|
static int ppc__setup_book3s_hv(struct perf_kvm_stat *kvm,
|
|
struct perf_evlist *evlist)
|
|
{
|
|
const char **events_ptr;
|
|
int i, nr_tp = 0, err = -1;
|
|
|
|
/* Check for book3s_hv tracepoints */
|
|
for (events_ptr = ppc_book3s_hv_kvm_tp; *events_ptr; events_ptr++) {
|
|
err = is_tracepoint_available(*events_ptr, evlist);
|
|
if (err)
|
|
return -1;
|
|
nr_tp++;
|
|
}
|
|
|
|
for (i = 0; i < nr_tp; i++)
|
|
kvm_events_tp[i] = ppc_book3s_hv_kvm_tp[i];
|
|
|
|
kvm_events_tp[i] = NULL;
|
|
kvm_exit_reason = "trap";
|
|
kvm->exit_reasons = hv_exit_reasons;
|
|
kvm->exit_reasons_isa = "HV";
|
|
|
|
return 0;
|
|
}
|
|
|
|
/* Wrapper to setup kvm tracepoints */
|
|
static int ppc__setup_kvm_tp(struct perf_kvm_stat *kvm)
|
|
{
|
|
struct perf_evlist *evlist = perf_evlist__new();
|
|
|
|
if (evlist == NULL)
|
|
return -ENOMEM;
|
|
|
|
/* Right now, only supported on book3s_hv */
|
|
return ppc__setup_book3s_hv(kvm, evlist);
|
|
}
|
|
|
|
int setup_kvm_events_tp(struct perf_kvm_stat *kvm)
|
|
{
|
|
return ppc__setup_kvm_tp(kvm);
|
|
}
|
|
|
|
int cpu_isa_init(struct perf_kvm_stat *kvm, const char *cpuid __maybe_unused)
|
|
{
|
|
int ret;
|
|
|
|
ret = ppc__setup_kvm_tp(kvm);
|
|
if (ret) {
|
|
kvm->exit_reasons = NULL;
|
|
kvm->exit_reasons_isa = NULL;
|
|
}
|
|
|
|
return ret;
|
|
}
|