Loading...
1/* SPDX-License-Identifier: GPL-2.0 */
2#ifndef __PERF_KVM_STAT_H
3#define __PERF_KVM_STAT_H
4
5#ifdef HAVE_KVM_STAT_SUPPORT
6
7#include "tool.h"
8#include "stat.h"
9#include "record.h"
10
11struct evsel;
12struct evlist;
13struct perf_session;
14
15struct event_key {
16 #define INVALID_KEY (~0ULL)
17 u64 key;
18 int info;
19 struct exit_reasons_table *exit_reasons;
20};
21
22struct kvm_event_stats {
23 u64 time;
24 struct stats stats;
25};
26
27struct kvm_event {
28 struct list_head hash_entry;
29 struct rb_node rb;
30
31 struct event_key key;
32
33 struct kvm_event_stats total;
34
35 #define DEFAULT_VCPU_NUM 8
36 int max_vcpu;
37 struct kvm_event_stats *vcpu;
38};
39
40typedef int (*key_cmp_fun)(struct kvm_event*, struct kvm_event*, int);
41
42struct kvm_event_key {
43 const char *name;
44 key_cmp_fun key;
45};
46
47struct perf_kvm_stat;
48
49struct child_event_ops {
50 void (*get_key)(struct evsel *evsel,
51 struct perf_sample *sample,
52 struct event_key *key);
53 const char *name;
54};
55
56struct kvm_events_ops {
57 bool (*is_begin_event)(struct evsel *evsel,
58 struct perf_sample *sample,
59 struct event_key *key);
60 bool (*is_end_event)(struct evsel *evsel,
61 struct perf_sample *sample, struct event_key *key);
62 struct child_event_ops *child_ops;
63 void (*decode_key)(struct perf_kvm_stat *kvm, struct event_key *key,
64 char *decode);
65 const char *name;
66};
67
68struct exit_reasons_table {
69 unsigned long exit_code;
70 const char *reason;
71};
72
73#define EVENTS_BITS 12
74#define EVENTS_CACHE_SIZE (1UL << EVENTS_BITS)
75
76struct perf_kvm_stat {
77 struct perf_tool tool;
78 struct record_opts opts;
79 struct evlist *evlist;
80 struct perf_session *session;
81
82 const char *file_name;
83 const char *report_event;
84 const char *sort_key;
85 int trace_vcpu;
86
87 struct exit_reasons_table *exit_reasons;
88 const char *exit_reasons_isa;
89
90 struct kvm_events_ops *events_ops;
91 key_cmp_fun compare;
92 struct list_head kvm_events_cache[EVENTS_CACHE_SIZE];
93
94 u64 total_time;
95 u64 total_count;
96 u64 lost_events;
97 u64 duration;
98
99 struct intlist *pid_list;
100
101 struct rb_root result;
102
103 int timerfd;
104 unsigned int display_time;
105 bool live;
106 bool force;
107};
108
109struct kvm_reg_events_ops {
110 const char *name;
111 struct kvm_events_ops *ops;
112};
113
114void exit_event_get_key(struct evsel *evsel,
115 struct perf_sample *sample,
116 struct event_key *key);
117bool exit_event_begin(struct evsel *evsel,
118 struct perf_sample *sample,
119 struct event_key *key);
120bool exit_event_end(struct evsel *evsel,
121 struct perf_sample *sample,
122 struct event_key *key);
123void exit_event_decode_key(struct perf_kvm_stat *kvm,
124 struct event_key *key,
125 char *decode);
126
127bool kvm_exit_event(struct evsel *evsel);
128bool kvm_entry_event(struct evsel *evsel);
129int setup_kvm_events_tp(struct perf_kvm_stat *kvm);
130
131#define define_exit_reasons_table(name, symbols) \
132 static struct exit_reasons_table name[] = { \
133 symbols, { -1, NULL } \
134 }
135
136/*
137 * arch specific callbacks and data structures
138 */
139int cpu_isa_init(struct perf_kvm_stat *kvm, const char *cpuid);
140
141extern const char *kvm_events_tp[];
142extern struct kvm_reg_events_ops kvm_reg_events_ops[];
143extern const char * const kvm_skip_events[];
144extern const char *vcpu_id_str;
145extern const int decode_str_len;
146extern const char *kvm_exit_reason;
147extern const char *kvm_entry_trace;
148extern const char *kvm_exit_trace;
149#endif /* HAVE_KVM_STAT_SUPPORT */
150
151extern int kvm_add_default_arch_event(int *argc, const char **argv);
152#endif /* __PERF_KVM_STAT_H */
1/* SPDX-License-Identifier: GPL-2.0 */
2#ifndef __PERF_KVM_STAT_H
3#define __PERF_KVM_STAT_H
4
5#include "../perf.h"
6#include "evsel.h"
7#include "evlist.h"
8#include "session.h"
9#include "tool.h"
10#include "stat.h"
11
12struct event_key {
13 #define INVALID_KEY (~0ULL)
14 u64 key;
15 int info;
16 struct exit_reasons_table *exit_reasons;
17};
18
19struct kvm_event_stats {
20 u64 time;
21 struct stats stats;
22};
23
24struct kvm_event {
25 struct list_head hash_entry;
26 struct rb_node rb;
27
28 struct event_key key;
29
30 struct kvm_event_stats total;
31
32 #define DEFAULT_VCPU_NUM 8
33 int max_vcpu;
34 struct kvm_event_stats *vcpu;
35};
36
37typedef int (*key_cmp_fun)(struct kvm_event*, struct kvm_event*, int);
38
39struct kvm_event_key {
40 const char *name;
41 key_cmp_fun key;
42};
43
44struct perf_kvm_stat;
45
46struct child_event_ops {
47 void (*get_key)(struct perf_evsel *evsel,
48 struct perf_sample *sample,
49 struct event_key *key);
50 const char *name;
51};
52
53struct kvm_events_ops {
54 bool (*is_begin_event)(struct perf_evsel *evsel,
55 struct perf_sample *sample,
56 struct event_key *key);
57 bool (*is_end_event)(struct perf_evsel *evsel,
58 struct perf_sample *sample, struct event_key *key);
59 struct child_event_ops *child_ops;
60 void (*decode_key)(struct perf_kvm_stat *kvm, struct event_key *key,
61 char *decode);
62 const char *name;
63};
64
65struct exit_reasons_table {
66 unsigned long exit_code;
67 const char *reason;
68};
69
70#define EVENTS_BITS 12
71#define EVENTS_CACHE_SIZE (1UL << EVENTS_BITS)
72
73struct perf_kvm_stat {
74 struct perf_tool tool;
75 struct record_opts opts;
76 struct perf_evlist *evlist;
77 struct perf_session *session;
78
79 const char *file_name;
80 const char *report_event;
81 const char *sort_key;
82 int trace_vcpu;
83
84 struct exit_reasons_table *exit_reasons;
85 const char *exit_reasons_isa;
86
87 struct kvm_events_ops *events_ops;
88 key_cmp_fun compare;
89 struct list_head kvm_events_cache[EVENTS_CACHE_SIZE];
90
91 u64 total_time;
92 u64 total_count;
93 u64 lost_events;
94 u64 duration;
95
96 struct intlist *pid_list;
97
98 struct rb_root result;
99
100 int timerfd;
101 unsigned int display_time;
102 bool live;
103 bool force;
104};
105
106struct kvm_reg_events_ops {
107 const char *name;
108 struct kvm_events_ops *ops;
109};
110
111void exit_event_get_key(struct perf_evsel *evsel,
112 struct perf_sample *sample,
113 struct event_key *key);
114bool exit_event_begin(struct perf_evsel *evsel,
115 struct perf_sample *sample,
116 struct event_key *key);
117bool exit_event_end(struct perf_evsel *evsel,
118 struct perf_sample *sample,
119 struct event_key *key);
120void exit_event_decode_key(struct perf_kvm_stat *kvm,
121 struct event_key *key,
122 char *decode);
123
124bool kvm_exit_event(struct perf_evsel *evsel);
125bool kvm_entry_event(struct perf_evsel *evsel);
126int setup_kvm_events_tp(struct perf_kvm_stat *kvm);
127
128#define define_exit_reasons_table(name, symbols) \
129 static struct exit_reasons_table name[] = { \
130 symbols, { -1, NULL } \
131 }
132
133/*
134 * arch specific callbacks and data structures
135 */
136int cpu_isa_init(struct perf_kvm_stat *kvm, const char *cpuid);
137
138extern const char *kvm_events_tp[];
139extern struct kvm_reg_events_ops kvm_reg_events_ops[];
140extern const char * const kvm_skip_events[];
141extern const char *vcpu_id_str;
142extern const int decode_str_len;
143extern const char *kvm_exit_reason;
144extern const char *kvm_entry_trace;
145extern const char *kvm_exit_trace;
146
147#endif /* __PERF_KVM_STAT_H */