perf kvm: Use perf_evsel__intval

Using plain raw_field_value(evsel->tp_format) will look at the common
fields as well, and since this tool doesn't need those, speed it up a
bit by looking at just the event specific fields.

Also in general use just evsel and sample, just like was done in 'perf
sched'.

v2: Fixed up test against evsel->name, that contains the subsys name
too, by David Ahern.

Cc: David Ahern <dsahern@gmail.com>
Cc: Dong Hao <haodong@linux.vnet.ibm.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Namhyung Kim <namhyung@gmail.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: Xiao Guangrong <xiaoguangrong@linux.vnet.ibm.com>
Cc: Runzhen Wang <runzhen@linux.vnet.ibm.com>
Link: http://lkml.kernel.org/n/tip-v9x3q9rv4caxtox7wtjpchq5@git.kernel.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent bcf6edcd
...@@ -33,46 +33,49 @@ struct event_key { ...@@ -33,46 +33,49 @@ struct event_key {
}; };
struct kvm_events_ops { struct kvm_events_ops {
bool (*is_begin_event)(struct event_format *event, void *data, bool (*is_begin_event)(struct perf_evsel *evsel,
struct event_key *key); struct perf_sample *sample,
bool (*is_end_event)(struct event_format *event, void *data,
struct event_key *key); struct event_key *key);
bool (*is_end_event)(struct perf_evsel *evsel,
struct perf_sample *sample, struct event_key *key);
void (*decode_key)(struct event_key *key, char decode[20]); void (*decode_key)(struct event_key *key, char decode[20]);
const char *name; const char *name;
}; };
static void exit_event_get_key(struct event_format *event, void *data, static void exit_event_get_key(struct perf_evsel *evsel,
struct perf_sample *sample,
struct event_key *key) struct event_key *key)
{ {
key->info = 0; key->info = 0;
key->key = raw_field_value(event, "exit_reason", data); key->key = perf_evsel__intval(evsel, sample, "exit_reason");
} }
static bool kvm_exit_event(struct event_format *event) static bool kvm_exit_event(struct perf_evsel *evsel)
{ {
return !strcmp(event->name, "kvm_exit"); return !strcmp(evsel->name, "kvm:kvm_exit");
} }
static bool exit_event_begin(struct event_format *event, void *data, static bool exit_event_begin(struct perf_evsel *evsel,
struct event_key *key) struct perf_sample *sample, struct event_key *key)
{ {
if (kvm_exit_event(event)) { if (kvm_exit_event(evsel)) {
exit_event_get_key(event, data, key); exit_event_get_key(evsel, sample, key);
return true; return true;
} }
return false; return false;
} }
static bool kvm_entry_event(struct event_format *event) static bool kvm_entry_event(struct perf_evsel *evsel)
{ {
return !strcmp(event->name, "kvm_entry"); return !strcmp(evsel->name, "kvm:kvm_entry");
} }
static bool exit_event_end(struct event_format *event, void *data __maybe_unused, static bool exit_event_end(struct perf_evsel *evsel,
struct perf_sample *sample __maybe_unused,
struct event_key *key __maybe_unused) struct event_key *key __maybe_unused)
{ {
return kvm_entry_event(event); return kvm_entry_event(evsel);
} }
struct exit_reasons_table { struct exit_reasons_table {
...@@ -130,45 +133,45 @@ static struct kvm_events_ops exit_events = { ...@@ -130,45 +133,45 @@ static struct kvm_events_ops exit_events = {
* the time of MMIO write: kvm_mmio(KVM_TRACE_MMIO_WRITE...) -> kvm_entry * the time of MMIO write: kvm_mmio(KVM_TRACE_MMIO_WRITE...) -> kvm_entry
* the time of MMIO read: kvm_exit -> kvm_mmio(KVM_TRACE_MMIO_READ...). * the time of MMIO read: kvm_exit -> kvm_mmio(KVM_TRACE_MMIO_READ...).
*/ */
static void mmio_event_get_key(struct event_format *event, void *data, static void mmio_event_get_key(struct perf_evsel *evsel, struct perf_sample *sample,
struct event_key *key) struct event_key *key)
{ {
key->key = raw_field_value(event, "gpa", data); key->key = perf_evsel__intval(evsel, sample, "gpa");
key->info = raw_field_value(event, "type", data); key->info = perf_evsel__intval(evsel, sample, "type");
} }
#define KVM_TRACE_MMIO_READ_UNSATISFIED 0 #define KVM_TRACE_MMIO_READ_UNSATISFIED 0
#define KVM_TRACE_MMIO_READ 1 #define KVM_TRACE_MMIO_READ 1
#define KVM_TRACE_MMIO_WRITE 2 #define KVM_TRACE_MMIO_WRITE 2
static bool mmio_event_begin(struct event_format *event, void *data, static bool mmio_event_begin(struct perf_evsel *evsel,
struct event_key *key) struct perf_sample *sample, struct event_key *key)
{ {
/* MMIO read begin event in kernel. */ /* MMIO read begin event in kernel. */
if (kvm_exit_event(event)) if (kvm_exit_event(evsel))
return true; return true;
/* MMIO write begin event in kernel. */ /* MMIO write begin event in kernel. */
if (!strcmp(event->name, "kvm_mmio") && if (!strcmp(evsel->name, "kvm:kvm_mmio") &&
raw_field_value(event, "type", data) == KVM_TRACE_MMIO_WRITE) { perf_evsel__intval(evsel, sample, "type") == KVM_TRACE_MMIO_WRITE) {
mmio_event_get_key(event, data, key); mmio_event_get_key(evsel, sample, key);
return true; return true;
} }
return false; return false;
} }
static bool mmio_event_end(struct event_format *event, void *data, static bool mmio_event_end(struct perf_evsel *evsel, struct perf_sample *sample,
struct event_key *key) struct event_key *key)
{ {
/* MMIO write end event in kernel. */ /* MMIO write end event in kernel. */
if (kvm_entry_event(event)) if (kvm_entry_event(evsel))
return true; return true;
/* MMIO read end event in kernel.*/ /* MMIO read end event in kernel.*/
if (!strcmp(event->name, "kvm_mmio") && if (!strcmp(evsel->name, "kvm:kvm_mmio") &&
raw_field_value(event, "type", data) == KVM_TRACE_MMIO_READ) { perf_evsel__intval(evsel, sample, "type") == KVM_TRACE_MMIO_READ) {
mmio_event_get_key(event, data, key); mmio_event_get_key(evsel, sample, key);
return true; return true;
} }
...@@ -189,31 +192,31 @@ static struct kvm_events_ops mmio_events = { ...@@ -189,31 +192,31 @@ static struct kvm_events_ops mmio_events = {
}; };
/* The time of emulation pio access is from kvm_pio to kvm_entry. */ /* The time of emulation pio access is from kvm_pio to kvm_entry. */
static void ioport_event_get_key(struct event_format *event, void *data, static void ioport_event_get_key(struct perf_evsel *evsel,
struct perf_sample *sample,
struct event_key *key) struct event_key *key)
{ {
key->key = raw_field_value(event, "port", data); key->key = perf_evsel__intval(evsel, sample, "port");
key->info = raw_field_value(event, "rw", data); key->info = perf_evsel__intval(evsel, sample, "rw");
} }
static bool ioport_event_begin(struct event_format *event, void *data, static bool ioport_event_begin(struct perf_evsel *evsel,
struct perf_sample *sample,
struct event_key *key) struct event_key *key)
{ {
if (!strcmp(event->name, "kvm_pio")) { if (!strcmp(evsel->name, "kvm:kvm_pio")) {
ioport_event_get_key(event, data, key); ioport_event_get_key(evsel, sample, key);
return true; return true;
} }
return false; return false;
} }
static bool ioport_event_end(struct event_format *event, void *data __maybe_unused, static bool ioport_event_end(struct perf_evsel *evsel,
struct perf_sample *sample __maybe_unused,
struct event_key *key __maybe_unused) struct event_key *key __maybe_unused)
{ {
if (kvm_entry_event(event)) return kvm_entry_event(evsel);
return true;
return false;
} }
static void ioport_event_decode_key(struct event_key *key, char decode[20]) static void ioport_event_decode_key(struct event_key *key, char decode[20])
...@@ -430,41 +433,43 @@ static bool handle_end_event(struct vcpu_event_record *vcpu_record, ...@@ -430,41 +433,43 @@ static bool handle_end_event(struct vcpu_event_record *vcpu_record,
return update_kvm_event(event, vcpu_record->vcpu_id, time_diff); return update_kvm_event(event, vcpu_record->vcpu_id, time_diff);
} }
static struct vcpu_event_record static
*per_vcpu_record(struct thread *thread, struct event_format *event, void *data) struct vcpu_event_record *per_vcpu_record(struct thread *thread,
struct perf_evsel *evsel,
struct perf_sample *sample)
{ {
/* Only kvm_entry records vcpu id. */ /* Only kvm_entry records vcpu id. */
if (!thread->priv && kvm_entry_event(event)) { if (!thread->priv && kvm_entry_event(evsel)) {
struct vcpu_event_record *vcpu_record; struct vcpu_event_record *vcpu_record;
vcpu_record = zalloc(sizeof(struct vcpu_event_record)); vcpu_record = zalloc(sizeof(*vcpu_record));
if (!vcpu_record) { if (!vcpu_record) {
pr_err("Not enough memory\n"); pr_err("%s: Not enough memory\n", __func__);
return NULL; return NULL;
} }
vcpu_record->vcpu_id = raw_field_value(event, "vcpu_id", data); vcpu_record->vcpu_id = perf_evsel__intval(evsel, sample, "vcpu_id");
thread->priv = vcpu_record; thread->priv = vcpu_record;
} }
return (struct vcpu_event_record *)thread->priv; return thread->priv;
} }
static bool handle_kvm_event(struct thread *thread, struct event_format *event, static bool handle_kvm_event(struct thread *thread, struct perf_evsel *evsel,
void *data, u64 timestamp) struct perf_sample *sample)
{ {
struct vcpu_event_record *vcpu_record; struct vcpu_event_record *vcpu_record;
struct event_key key = {.key = INVALID_KEY}; struct event_key key = {.key = INVALID_KEY};
vcpu_record = per_vcpu_record(thread, event, data); vcpu_record = per_vcpu_record(thread, evsel, sample);
if (!vcpu_record) if (!vcpu_record)
return true; return true;
if (events_ops->is_begin_event(event, data, &key)) if (events_ops->is_begin_event(evsel, sample, &key))
return handle_begin_event(vcpu_record, &key, timestamp); return handle_begin_event(vcpu_record, &key, sample->time);
if (events_ops->is_end_event(event, data, &key)) if (events_ops->is_end_event(evsel, sample, &key))
return handle_end_event(vcpu_record, &key, timestamp); return handle_end_event(vcpu_record, &key, sample->time);
return true; return true;
} }
...@@ -645,8 +650,7 @@ static int process_sample_event(struct perf_tool *tool __maybe_unused, ...@@ -645,8 +650,7 @@ static int process_sample_event(struct perf_tool *tool __maybe_unused,
return -1; return -1;
} }
if (!handle_kvm_event(thread, evsel->tp_format, sample->raw_data, if (!handle_kvm_event(thread, evsel, sample))
sample->time))
return -1; return -1;
return 0; return 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment