xref: /openbmc/qemu/trace/control-internal.h (revision ef4c9fc8)
1 /*
2  * Interface for configuring and controlling the state of tracing events.
3  *
4  * Copyright (C) 2011-2016 Lluís Vilanova <vilanova@ac.upc.edu>
5  *
6  * This work is licensed under the terms of the GNU GPL, version 2 or later.
7  * See the COPYING file in the top-level directory.
8  */
9 
10 #ifndef TRACE__CONTROL_INTERNAL_H
11 #define TRACE__CONTROL_INTERNAL_H
12 
13 #include <stddef.h>                     /* size_t */
14 
15 #include "qom/cpu.h"
16 
17 
18 extern TraceEvent *trace_events[];
19 extern int trace_events_enabled_count;
20 
21 
22 static inline bool trace_event_is_pattern(const char *str)
23 {
24     assert(str != NULL);
25     return strchr(str, '*') != NULL;
26 }
27 
28 static inline uint32_t trace_event_get_id(TraceEvent *ev)
29 {
30     assert(ev != NULL);
31     return ev->id;
32 }
33 
34 static inline uint32_t trace_event_get_vcpu_id(TraceEvent *ev)
35 {
36     return ev->vcpu_id;
37 }
38 
39 static inline bool trace_event_is_vcpu(TraceEvent *ev)
40 {
41     return ev->vcpu_id != TRACE_VCPU_EVENT_NONE;
42 }
43 
44 static inline const char * trace_event_get_name(TraceEvent *ev)
45 {
46     assert(ev != NULL);
47     return ev->name;
48 }
49 
50 static inline bool trace_event_get_state_static(TraceEvent *ev)
51 {
52     assert(ev != NULL);
53     return ev->sstate;
54 }
55 
56 /* it's on fast path, avoid consistency checks (asserts) */
57 #define trace_event_get_state_dynamic_by_id(id) \
58     (unlikely(trace_events_enabled_count) && _ ## id ## _DSTATE)
59 
60 static inline bool trace_event_get_state_dynamic(TraceEvent *ev)
61 {
62     return unlikely(trace_events_enabled_count) && *ev->dstate;
63 }
64 
65 static inline bool
66 trace_event_get_vcpu_state_dynamic_by_vcpu_id(CPUState *vcpu,
67                                               uint32_t vcpu_id)
68 {
69     /* it's on fast path, avoid consistency checks (asserts) */
70     if (unlikely(trace_events_enabled_count)) {
71         return test_bit(vcpu_id, vcpu->trace_dstate);
72     } else {
73         return false;
74     }
75 }
76 
77 static inline bool trace_event_get_vcpu_state_dynamic(CPUState *vcpu,
78                                                       TraceEvent *ev)
79 {
80     uint32_t vcpu_id;
81     assert(trace_event_is_vcpu(ev));
82     vcpu_id = trace_event_get_vcpu_id(ev);
83     return trace_event_get_vcpu_state_dynamic_by_vcpu_id(vcpu, vcpu_id);
84 }
85 
86 #endif /* TRACE__CONTROL_INTERNAL_H */
87