Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 #include <errno.h>
0003 #include <memory.h>
0004 #include "../../../util/evsel.h"
0005 #include "../../../util/kvm-stat.h"
0006 #include "arm64_exception_types.h"
0007 #include "debug.h"
0008 
0009 define_exit_reasons_table(arm64_exit_reasons, kvm_arm_exception_type);
0010 define_exit_reasons_table(arm64_trap_exit_reasons, kvm_arm_exception_class);
0011 
0012 const char *kvm_trap_exit_reason = "esr_ec";
0013 const char *vcpu_id_str = "id";
0014 const int decode_str_len = 20;
0015 const char *kvm_exit_reason = "ret";
0016 const char *kvm_entry_trace = "kvm:kvm_entry";
0017 const char *kvm_exit_trace = "kvm:kvm_exit";
0018 
0019 const char *kvm_events_tp[] = {
0020     "kvm:kvm_entry",
0021     "kvm:kvm_exit",
0022     NULL,
0023 };
0024 
0025 static void event_get_key(struct evsel *evsel,
0026               struct perf_sample *sample,
0027               struct event_key *key)
0028 {
0029     key->info = 0;
0030     key->key = evsel__intval(evsel, sample, kvm_exit_reason);
0031     key->exit_reasons = arm64_exit_reasons;
0032 
0033     /*
0034      * TRAP exceptions carry exception class info in esr_ec field
0035      * and, hence, we need to use a different exit_reasons table to
0036      * properly decode event's est_ec.
0037      */
0038     if (key->key == ARM_EXCEPTION_TRAP) {
0039         key->key = evsel__intval(evsel, sample, kvm_trap_exit_reason);
0040         key->exit_reasons = arm64_trap_exit_reasons;
0041     }
0042 }
0043 
0044 static bool event_begin(struct evsel *evsel,
0045             struct perf_sample *sample __maybe_unused,
0046             struct event_key *key __maybe_unused)
0047 {
0048     return !strcmp(evsel->name, kvm_entry_trace);
0049 }
0050 
0051 static bool event_end(struct evsel *evsel,
0052               struct perf_sample *sample,
0053               struct event_key *key)
0054 {
0055     if (!strcmp(evsel->name, kvm_exit_trace)) {
0056         event_get_key(evsel, sample, key);
0057         return true;
0058     }
0059     return false;
0060 }
0061 
0062 static struct kvm_events_ops exit_events = {
0063     .is_begin_event = event_begin,
0064     .is_end_event   = event_end,
0065     .decode_key = exit_event_decode_key,
0066     .name       = "VM-EXIT"
0067 };
0068 
0069 struct kvm_reg_events_ops kvm_reg_events_ops[] = {
0070     {
0071         .name   = "vmexit",
0072         .ops    = &exit_events,
0073     },
0074     { NULL, NULL },
0075 };
0076 
0077 const char * const kvm_skip_events[] = {
0078     NULL,
0079 };
0080 
0081 int cpu_isa_init(struct perf_kvm_stat *kvm, const char *cpuid __maybe_unused)
0082 {
0083     kvm->exit_reasons_isa = "arm64";
0084     return 0;
0085 }