]>
Commit | Line | Data |
---|---|---|
48151859 LV |
1 | /* |
2 | * Interface for configuring and controlling the state of tracing events. | |
3 | * | |
f5956d71 | 4 | * Copyright (C) 2014-2017 Lluís Vilanova <vilanova@ac.upc.edu> |
48151859 LV |
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 | #include "qemu/osdep.h" | |
11 | #include "cpu.h" | |
0ab8ed18 | 12 | #include "trace-root.h" |
48151859 LV |
13 | #include "trace/control.h" |
14 | #include "translate-all.h" | |
15 | ||
16 | ||
a4d50b1d LV |
17 | void trace_event_set_state_dynamic_init(TraceEvent *ev, bool state) |
18 | { | |
8eb1b9db | 19 | bool state_pre; |
a4d50b1d | 20 | assert(trace_event_get_state_static(ev)); |
8eb1b9db LV |
21 | /* |
22 | * We ignore the "vcpu" property here, since no vCPUs have been created | |
23 | * yet. Then dstate can only be 1 or 0. | |
24 | */ | |
93977402 | 25 | state_pre = *ev->dstate; |
8eb1b9db LV |
26 | if (state_pre != state) { |
27 | if (state) { | |
28 | trace_events_enabled_count++; | |
93977402 | 29 | *ev->dstate = 1; |
8eb1b9db LV |
30 | } else { |
31 | trace_events_enabled_count--; | |
93977402 | 32 | *ev->dstate = 0; |
8eb1b9db LV |
33 | } |
34 | } | |
a4d50b1d LV |
35 | } |
36 | ||
48151859 LV |
37 | void trace_event_set_state_dynamic(TraceEvent *ev, bool state) |
38 | { | |
39 | CPUState *vcpu; | |
40 | assert(trace_event_get_state_static(ev)); | |
f5956d71 | 41 | if (trace_event_is_vcpu(ev) && likely(first_cpu != NULL)) { |
48151859 LV |
42 | CPU_FOREACH(vcpu) { |
43 | trace_event_set_vcpu_state_dynamic(vcpu, ev, state); | |
44 | } | |
45 | } else { | |
f5956d71 LV |
46 | /* |
47 | * Without the "vcpu" property, dstate can only be 1 or 0. With it, we | |
48 | * haven't instantiated any vCPU yet, so we will set a global state | |
49 | * instead, and trace_init_vcpu will reconcile it afterwards. | |
50 | */ | |
93977402 | 51 | bool state_pre = *ev->dstate; |
8eb1b9db LV |
52 | if (state_pre != state) { |
53 | if (state) { | |
54 | trace_events_enabled_count++; | |
93977402 | 55 | *ev->dstate = 1; |
8eb1b9db LV |
56 | } else { |
57 | trace_events_enabled_count--; | |
93977402 | 58 | *ev->dstate = 0; |
8eb1b9db LV |
59 | } |
60 | } | |
48151859 LV |
61 | } |
62 | } | |
63 | ||
d4381116 LV |
64 | static void trace_event_synchronize_vcpu_state_dynamic( |
65 | CPUState *vcpu, run_on_cpu_data ignored) | |
66 | { | |
67 | bitmap_copy(vcpu->trace_dstate, vcpu->trace_dstate_delayed, | |
68 | CPU_TRACE_DSTATE_MAX_EVENTS); | |
69 | } | |
70 | ||
48151859 LV |
71 | void trace_event_set_vcpu_state_dynamic(CPUState *vcpu, |
72 | TraceEvent *ev, bool state) | |
73 | { | |
ef4c9fc8 | 74 | uint32_t vcpu_id; |
48151859 LV |
75 | bool state_pre; |
76 | assert(trace_event_get_state_static(ev)); | |
77 | assert(trace_event_is_vcpu(ev)); | |
48151859 LV |
78 | vcpu_id = trace_event_get_vcpu_id(ev); |
79 | state_pre = test_bit(vcpu_id, vcpu->trace_dstate); | |
80 | if (state_pre != state) { | |
81 | if (state) { | |
82 | trace_events_enabled_count++; | |
d4381116 | 83 | set_bit(vcpu_id, vcpu->trace_dstate_delayed); |
93977402 | 84 | (*ev->dstate)++; |
48151859 LV |
85 | } else { |
86 | trace_events_enabled_count--; | |
d4381116 | 87 | clear_bit(vcpu_id, vcpu->trace_dstate_delayed); |
93977402 | 88 | (*ev->dstate)--; |
48151859 | 89 | } |
d4381116 LV |
90 | /* |
91 | * Delay changes until next TB; we want all TBs to be built from a | |
92 | * single set of dstate values to ensure consistency of generated | |
93 | * tracing code. | |
94 | */ | |
95 | async_run_on_cpu(vcpu, trace_event_synchronize_vcpu_state_dynamic, | |
96 | RUN_ON_CPU_NULL); | |
48151859 LV |
97 | } |
98 | } | |
2bfe11c8 | 99 | |
fff895df | 100 | static bool adding_first_cpu1(void) |
2bfe11c8 LV |
101 | { |
102 | CPUState *cpu; | |
103 | size_t count = 0; | |
104 | CPU_FOREACH(cpu) { | |
105 | count++; | |
106 | if (count > 1) { | |
107 | return false; | |
108 | } | |
109 | } | |
110 | return true; | |
111 | } | |
112 | ||
fff895df LV |
113 | static bool adding_first_cpu(void) |
114 | { | |
115 | bool res; | |
116 | cpu_list_lock(); | |
117 | res = adding_first_cpu1(); | |
118 | cpu_list_unlock(); | |
119 | return res; | |
120 | } | |
121 | ||
2bfe11c8 LV |
122 | void trace_init_vcpu(CPUState *vcpu) |
123 | { | |
0d4e995c DB |
124 | TraceEventIter iter; |
125 | TraceEvent *ev; | |
126 | trace_event_iter_init(&iter, NULL); | |
127 | while ((ev = trace_event_iter_next(&iter)) != NULL) { | |
2bfe11c8 LV |
128 | if (trace_event_is_vcpu(ev) && |
129 | trace_event_get_state_static(ev) && | |
130 | trace_event_get_state_dynamic(ev)) { | |
2bfe11c8 LV |
131 | if (adding_first_cpu()) { |
132 | /* check preconditions */ | |
93977402 | 133 | assert(*ev->dstate == 1); |
2bfe11c8 | 134 | /* disable early-init state ... */ |
93977402 | 135 | *ev->dstate = 0; |
2bfe11c8 LV |
136 | trace_events_enabled_count--; |
137 | /* ... and properly re-enable */ | |
138 | trace_event_set_vcpu_state_dynamic(vcpu, ev, true); | |
139 | } else { | |
140 | trace_event_set_vcpu_state_dynamic(vcpu, ev, true); | |
141 | } | |
142 | } | |
143 | } | |
b9d72215 | 144 | trace_guest_cpu_enter(vcpu); |
2bfe11c8 | 145 | } |