blob: 0d1bc478833b9b85a3948d452d37cbd7428752f9 [file] [log] [blame]
Marcelo Tosatti229456f2009-06-17 09:22:14 -03001#if !defined(_TRACE_KVM_MAIN_H) || defined(TRACE_HEADER_MULTI_READ)
2#define _TRACE_KVM_MAIN_H
3
4#include <linux/tracepoint.h>
5
6#undef TRACE_SYSTEM
7#define TRACE_SYSTEM kvm
Marcelo Tosatti229456f2009-06-17 09:22:14 -03008
Gleb Natapov64be5002010-10-24 16:49:08 +02009#define ERSN(x) { KVM_EXIT_##x, "KVM_EXIT_" #x }
10
11#define kvm_trace_exit_reason \
12 ERSN(UNKNOWN), ERSN(EXCEPTION), ERSN(IO), ERSN(HYPERCALL), \
13 ERSN(DEBUG), ERSN(HLT), ERSN(MMIO), ERSN(IRQ_WINDOW_OPEN), \
14 ERSN(SHUTDOWN), ERSN(FAIL_ENTRY), ERSN(INTR), ERSN(SET_TPR), \
15 ERSN(TPR_ACCESS), ERSN(S390_SIEIC), ERSN(S390_RESET), ERSN(DCR),\
Cornelia Huckdcce0482012-06-11 18:39:50 +020016 ERSN(NMI), ERSN(INTERNAL_ERROR), ERSN(OSI), ERSN(PAPR_HCALL), \
Cornelia Huckf79ed822013-01-08 13:00:01 +010017 ERSN(S390_UCONTROL), ERSN(WATCHDOG), ERSN(S390_TSCH)
Gleb Natapov64be5002010-10-24 16:49:08 +020018
19TRACE_EVENT(kvm_userspace_exit,
20 TP_PROTO(__u32 reason, int errno),
21 TP_ARGS(reason, errno),
22
23 TP_STRUCT__entry(
24 __field( __u32, reason )
25 __field( int, errno )
26 ),
27
28 TP_fast_assign(
29 __entry->reason = reason;
30 __entry->errno = errno;
31 ),
32
33 TP_printk("reason %s (%d)",
34 __entry->errno < 0 ?
35 (__entry->errno == -EINTR ? "restart" : "error") :
36 __print_symbolic(__entry->reason, kvm_trace_exit_reason),
37 __entry->errno < 0 ? -__entry->errno : __entry->reason)
38);
39
Paolo Bonzinif7819512015-02-04 18:20:58 +010040TRACE_EVENT(kvm_vcpu_wakeup,
41 TP_PROTO(__u64 ns, bool waited),
42 TP_ARGS(ns, waited),
43
44 TP_STRUCT__entry(
45 __field( __u64, ns )
46 __field( bool, waited )
47 ),
48
49 TP_fast_assign(
50 __entry->ns = ns;
51 __entry->waited = waited;
52 ),
53
54 TP_printk("%s time %lld ns",
55 __entry->waited ? "wait" : "poll",
56 __entry->ns)
57);
58
Paolo Bonzinic77dcac2014-08-06 14:24:45 +020059#if defined(CONFIG_HAVE_KVM_IRQFD)
Marcelo Tosatti229456f2009-06-17 09:22:14 -030060TRACE_EVENT(kvm_set_irq,
Avi Kivityae8c1c42009-07-01 12:09:41 +030061 TP_PROTO(unsigned int gsi, int level, int irq_source_id),
62 TP_ARGS(gsi, level, irq_source_id),
Marcelo Tosatti229456f2009-06-17 09:22:14 -030063
64 TP_STRUCT__entry(
65 __field( unsigned int, gsi )
Avi Kivityae8c1c42009-07-01 12:09:41 +030066 __field( int, level )
67 __field( int, irq_source_id )
Marcelo Tosatti229456f2009-06-17 09:22:14 -030068 ),
69
70 TP_fast_assign(
71 __entry->gsi = gsi;
Avi Kivityae8c1c42009-07-01 12:09:41 +030072 __entry->level = level;
73 __entry->irq_source_id = irq_source_id;
Marcelo Tosatti229456f2009-06-17 09:22:14 -030074 ),
75
Avi Kivityae8c1c42009-07-01 12:09:41 +030076 TP_printk("gsi %u level %d source %d",
77 __entry->gsi, __entry->level, __entry->irq_source_id)
Marcelo Tosatti229456f2009-06-17 09:22:14 -030078);
Paolo Bonzinic77dcac2014-08-06 14:24:45 +020079#endif /* defined(CONFIG_HAVE_KVM_IRQFD) */
Marcelo Tosatti229456f2009-06-17 09:22:14 -030080
Christoffer Dalla1e4ccb2012-06-15 15:07:13 -040081#if defined(__KVM_HAVE_IOAPIC)
Gleb Natapov1000ff82009-07-07 16:00:57 +030082#define kvm_deliver_mode \
83 {0x0, "Fixed"}, \
84 {0x1, "LowPrio"}, \
85 {0x2, "SMI"}, \
86 {0x3, "Res3"}, \
87 {0x4, "NMI"}, \
88 {0x5, "INIT"}, \
89 {0x6, "SIPI"}, \
90 {0x7, "ExtINT"}
91
92TRACE_EVENT(kvm_ioapic_set_irq,
93 TP_PROTO(__u64 e, int pin, bool coalesced),
94 TP_ARGS(e, pin, coalesced),
95
96 TP_STRUCT__entry(
97 __field( __u64, e )
98 __field( int, pin )
99 __field( bool, coalesced )
100 ),
101
102 TP_fast_assign(
103 __entry->e = e;
104 __entry->pin = pin;
105 __entry->coalesced = coalesced;
106 ),
107
108 TP_printk("pin %u dst %x vec=%u (%s|%s|%s%s)%s",
109 __entry->pin, (u8)(__entry->e >> 56), (u8)__entry->e,
110 __print_symbolic((__entry->e >> 8 & 0x7), kvm_deliver_mode),
111 (__entry->e & (1<<11)) ? "logical" : "physical",
112 (__entry->e & (1<<15)) ? "level" : "edge",
113 (__entry->e & (1<<16)) ? "|masked" : "",
114 __entry->coalesced ? " (coalesced)" : "")
115);
116
Zhang Haoyu184564e2014-09-11 16:47:04 +0800117TRACE_EVENT(kvm_ioapic_delayed_eoi_inj,
118 TP_PROTO(__u64 e),
119 TP_ARGS(e),
120
121 TP_STRUCT__entry(
122 __field( __u64, e )
123 ),
124
125 TP_fast_assign(
126 __entry->e = e;
127 ),
128
129 TP_printk("dst %x vec=%u (%s|%s|%s%s)",
130 (u8)(__entry->e >> 56), (u8)__entry->e,
131 __print_symbolic((__entry->e >> 8 & 0x7), kvm_deliver_mode),
132 (__entry->e & (1<<11)) ? "logical" : "physical",
133 (__entry->e & (1<<15)) ? "level" : "edge",
134 (__entry->e & (1<<16)) ? "|masked" : "")
135);
136
Gleb Natapov1000ff82009-07-07 16:00:57 +0300137TRACE_EVENT(kvm_msi_set_irq,
138 TP_PROTO(__u64 address, __u64 data),
139 TP_ARGS(address, data),
140
141 TP_STRUCT__entry(
142 __field( __u64, address )
143 __field( __u64, data )
144 ),
145
146 TP_fast_assign(
147 __entry->address = address;
148 __entry->data = data;
149 ),
150
151 TP_printk("dst %u vec %x (%s|%s|%s%s)",
152 (u8)(__entry->address >> 12), (u8)__entry->data,
153 __print_symbolic((__entry->data >> 8 & 0x7), kvm_deliver_mode),
154 (__entry->address & (1<<2)) ? "logical" : "physical",
155 (__entry->data & (1<<15)) ? "level" : "edge",
156 (__entry->address & (1<<3)) ? "|rh" : "")
157);
Marcelo Tosatti229456f2009-06-17 09:22:14 -0300158
159#define kvm_irqchips \
160 {KVM_IRQCHIP_PIC_MASTER, "PIC master"}, \
161 {KVM_IRQCHIP_PIC_SLAVE, "PIC slave"}, \
162 {KVM_IRQCHIP_IOAPIC, "IOAPIC"}
163
Alexander Graf1c9f8522013-04-15 23:04:10 +0200164#endif /* defined(__KVM_HAVE_IOAPIC) */
165
Paolo Bonzinic77dcac2014-08-06 14:24:45 +0200166#if defined(CONFIG_HAVE_KVM_IRQFD)
Alexander Graf1c9f8522013-04-15 23:04:10 +0200167
Christian Borntraegercdef5112015-01-15 15:21:19 +0100168#ifdef kvm_irqchips
169#define kvm_ack_irq_string "irqchip %s pin %u"
170#define kvm_ack_irq_parm __print_symbolic(__entry->irqchip, kvm_irqchips), __entry->pin
171#else
172#define kvm_ack_irq_string "irqchip %d pin %u"
173#define kvm_ack_irq_parm __entry->irqchip, __entry->pin
174#endif
175
Marcelo Tosatti229456f2009-06-17 09:22:14 -0300176TRACE_EVENT(kvm_ack_irq,
177 TP_PROTO(unsigned int irqchip, unsigned int pin),
178 TP_ARGS(irqchip, pin),
179
180 TP_STRUCT__entry(
181 __field( unsigned int, irqchip )
182 __field( unsigned int, pin )
183 ),
184
185 TP_fast_assign(
186 __entry->irqchip = irqchip;
187 __entry->pin = pin;
188 ),
189
Christian Borntraegercdef5112015-01-15 15:21:19 +0100190 TP_printk(kvm_ack_irq_string, kvm_ack_irq_parm)
Marcelo Tosatti229456f2009-06-17 09:22:14 -0300191);
192
Paolo Bonzinic77dcac2014-08-06 14:24:45 +0200193#endif /* defined(CONFIG_HAVE_KVM_IRQFD) */
Marcelo Tosatti229456f2009-06-17 09:22:14 -0300194
195
Avi Kivityaec51dc2009-07-01 16:01:02 +0300196
197#define KVM_TRACE_MMIO_READ_UNSATISFIED 0
198#define KVM_TRACE_MMIO_READ 1
199#define KVM_TRACE_MMIO_WRITE 2
200
201#define kvm_trace_symbol_mmio \
202 { KVM_TRACE_MMIO_READ_UNSATISFIED, "unsatisfied-read" }, \
203 { KVM_TRACE_MMIO_READ, "read" }, \
204 { KVM_TRACE_MMIO_WRITE, "write" }
205
206TRACE_EVENT(kvm_mmio,
207 TP_PROTO(int type, int len, u64 gpa, u64 val),
208 TP_ARGS(type, len, gpa, val),
209
210 TP_STRUCT__entry(
211 __field( u32, type )
212 __field( u32, len )
213 __field( u64, gpa )
214 __field( u64, val )
215 ),
216
217 TP_fast_assign(
218 __entry->type = type;
219 __entry->len = len;
220 __entry->gpa = gpa;
221 __entry->val = val;
222 ),
223
224 TP_printk("mmio %s len %u gpa 0x%llx val 0x%llx",
225 __print_symbolic(__entry->type, kvm_trace_symbol_mmio),
226 __entry->len, __entry->gpa, __entry->val)
227);
228
Avi Kivity0c048512010-01-21 15:31:52 +0200229#define kvm_fpu_load_symbol \
230 {0, "unload"}, \
231 {1, "load"}
232
233TRACE_EVENT(kvm_fpu,
234 TP_PROTO(int load),
235 TP_ARGS(load),
236
237 TP_STRUCT__entry(
238 __field( u32, load )
239 ),
240
241 TP_fast_assign(
242 __entry->load = load;
243 ),
244
245 TP_printk("%s", __print_symbolic(__entry->load, kvm_fpu_load_symbol))
246);
247
Avi Kivity90bb6fc2009-12-31 12:10:16 +0200248TRACE_EVENT(kvm_age_page,
Andres Lagar-Cavilla8a9522d2014-09-23 12:34:54 -0700249 TP_PROTO(ulong gfn, int level, struct kvm_memory_slot *slot, int ref),
250 TP_ARGS(gfn, level, slot, ref),
Avi Kivity90bb6fc2009-12-31 12:10:16 +0200251
252 TP_STRUCT__entry(
253 __field( u64, hva )
254 __field( u64, gfn )
Andres Lagar-Cavilla8a9522d2014-09-23 12:34:54 -0700255 __field( u8, level )
Avi Kivity90bb6fc2009-12-31 12:10:16 +0200256 __field( u8, referenced )
257 ),
258
259 TP_fast_assign(
Andres Lagar-Cavilla8a9522d2014-09-23 12:34:54 -0700260 __entry->gfn = gfn;
261 __entry->level = level;
262 __entry->hva = ((gfn - slot->base_gfn) <<
263 PAGE_SHIFT) + slot->userspace_addr;
Avi Kivity90bb6fc2009-12-31 12:10:16 +0200264 __entry->referenced = ref;
265 ),
266
Andres Lagar-Cavilla8a9522d2014-09-23 12:34:54 -0700267 TP_printk("hva %llx gfn %llx level %u %s",
268 __entry->hva, __entry->gfn, __entry->level,
Avi Kivity90bb6fc2009-12-31 12:10:16 +0200269 __entry->referenced ? "YOUNG" : "OLD")
270);
271
Gleb Natapovaf585b92010-10-14 11:22:46 +0200272#ifdef CONFIG_KVM_ASYNC_PF
Xiao Guangrong07303882010-11-01 16:59:39 +0800273DECLARE_EVENT_CLASS(kvm_async_get_page_class,
274
Xiao Guangrongc9b263d2010-11-01 16:58:43 +0800275 TP_PROTO(u64 gva, u64 gfn),
Xiao Guangrong07303882010-11-01 16:59:39 +0800276
Xiao Guangrongc9b263d2010-11-01 16:58:43 +0800277 TP_ARGS(gva, gfn),
Gleb Natapovaf585b92010-10-14 11:22:46 +0200278
279 TP_STRUCT__entry(
Xiao Guangrong07303882010-11-01 16:59:39 +0800280 __field(__u64, gva)
Xiao Guangrongc9b263d2010-11-01 16:58:43 +0800281 __field(u64, gfn)
Xiao Guangrong07303882010-11-01 16:59:39 +0800282 ),
Gleb Natapovaf585b92010-10-14 11:22:46 +0200283
284 TP_fast_assign(
Xiao Guangrongc9b263d2010-11-01 16:58:43 +0800285 __entry->gva = gva;
286 __entry->gfn = gfn;
Xiao Guangrong07303882010-11-01 16:59:39 +0800287 ),
Gleb Natapovaf585b92010-10-14 11:22:46 +0200288
Xiao Guangrongc9b263d2010-11-01 16:58:43 +0800289 TP_printk("gva = %#llx, gfn = %#llx", __entry->gva, __entry->gfn)
Gleb Natapovaf585b92010-10-14 11:22:46 +0200290);
291
Xiao Guangrong07303882010-11-01 16:59:39 +0800292DEFINE_EVENT(kvm_async_get_page_class, kvm_try_async_get_page,
Gleb Natapovaf585b92010-10-14 11:22:46 +0200293
Xiao Guangrong07303882010-11-01 16:59:39 +0800294 TP_PROTO(u64 gva, u64 gfn),
Gleb Natapovaf585b92010-10-14 11:22:46 +0200295
Xiao Guangrong07303882010-11-01 16:59:39 +0800296 TP_ARGS(gva, gfn)
Gleb Natapovaf585b92010-10-14 11:22:46 +0200297);
298
Xiao Guangrong07303882010-11-01 16:59:39 +0800299DEFINE_EVENT(kvm_async_get_page_class, kvm_async_pf_doublefault,
300
301 TP_PROTO(u64 gva, u64 gfn),
302
303 TP_ARGS(gva, gfn)
304);
305
306DECLARE_EVENT_CLASS(kvm_async_pf_nopresent_ready,
307
Gleb Natapov7c907052010-10-14 11:22:53 +0200308 TP_PROTO(u64 token, u64 gva),
Xiao Guangrong07303882010-11-01 16:59:39 +0800309
Gleb Natapov7c907052010-10-14 11:22:53 +0200310 TP_ARGS(token, gva),
Gleb Natapovaf585b92010-10-14 11:22:46 +0200311
312 TP_STRUCT__entry(
Gleb Natapov7c907052010-10-14 11:22:53 +0200313 __field(__u64, token)
Gleb Natapovaf585b92010-10-14 11:22:46 +0200314 __field(__u64, gva)
Xiao Guangrong07303882010-11-01 16:59:39 +0800315 ),
Gleb Natapovaf585b92010-10-14 11:22:46 +0200316
317 TP_fast_assign(
Gleb Natapov7c907052010-10-14 11:22:53 +0200318 __entry->token = token;
Gleb Natapovaf585b92010-10-14 11:22:46 +0200319 __entry->gva = gva;
Xiao Guangrong07303882010-11-01 16:59:39 +0800320 ),
Gleb Natapovaf585b92010-10-14 11:22:46 +0200321
Xiao Guangrong07303882010-11-01 16:59:39 +0800322 TP_printk("token %#llx gva %#llx", __entry->token, __entry->gva)
323
324);
325
326DEFINE_EVENT(kvm_async_pf_nopresent_ready, kvm_async_pf_not_present,
327
328 TP_PROTO(u64 token, u64 gva),
329
330 TP_ARGS(token, gva)
331);
332
333DEFINE_EVENT(kvm_async_pf_nopresent_ready, kvm_async_pf_ready,
334
335 TP_PROTO(u64 token, u64 gva),
336
337 TP_ARGS(token, gva)
Gleb Natapovaf585b92010-10-14 11:22:46 +0200338);
339
340TRACE_EVENT(
341 kvm_async_pf_completed,
chai wenf2e10662013-10-14 22:22:33 +0800342 TP_PROTO(unsigned long address, u64 gva),
343 TP_ARGS(address, gva),
Gleb Natapovaf585b92010-10-14 11:22:46 +0200344
345 TP_STRUCT__entry(
346 __field(unsigned long, address)
Gleb Natapovaf585b92010-10-14 11:22:46 +0200347 __field(u64, gva)
348 ),
349
350 TP_fast_assign(
351 __entry->address = address;
Gleb Natapovaf585b92010-10-14 11:22:46 +0200352 __entry->gva = gva;
353 ),
354
chai wenf2e10662013-10-14 22:22:33 +0800355 TP_printk("gva %#llx address %#lx", __entry->gva,
356 __entry->address)
Gleb Natapovaf585b92010-10-14 11:22:46 +0200357);
358
Wanpeng Li2cbd7822015-09-03 22:07:39 +0800359TRACE_EVENT(kvm_halt_poll_ns,
360 TP_PROTO(bool grow, unsigned int vcpu_id, int new, int old),
361 TP_ARGS(grow, vcpu_id, new, old),
362
363 TP_STRUCT__entry(
364 __field(bool, grow)
365 __field(unsigned int, vcpu_id)
366 __field(int, new)
367 __field(int, old)
368 ),
369
370 TP_fast_assign(
371 __entry->grow = grow;
372 __entry->vcpu_id = vcpu_id;
373 __entry->new = new;
374 __entry->old = old;
375 ),
376
377 TP_printk("vcpu %u: halt_poll_ns %d (%s %d)",
378 __entry->vcpu_id,
379 __entry->new,
380 __entry->grow ? "grow" : "shrink",
381 __entry->old)
382);
383
384#define trace_kvm_halt_poll_ns_grow(vcpu_id, new, old) \
385 trace_kvm_halt_poll_ns(true, vcpu_id, new, old)
386#define trace_kvm_halt_poll_ns_shrink(vcpu_id, new, old) \
387 trace_kvm_halt_poll_ns(false, vcpu_id, new, old)
388
Gleb Natapovaf585b92010-10-14 11:22:46 +0200389#endif
390
Marcelo Tosatti229456f2009-06-17 09:22:14 -0300391#endif /* _TRACE_KVM_MAIN_H */
392
393/* This part must be outside protection */
394#include <trace/define_trace.h>