2 * Interface for configuring and controlling the state of tracing events.
4 * Copyright (C) 2014-2016 LluĂs Vilanova <vilanova@ac.upc.edu>
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.
10 #include "qemu/osdep.h"
13 #include "trace/control.h"
14 #include "translate-all.h"
17 void trace_event_set_state_dynamic_init(TraceEvent
*ev
, bool state
)
20 assert(trace_event_get_state_static(ev
));
22 * We ignore the "vcpu" property here, since no vCPUs have been created
23 * yet. Then dstate can only be 1 or 0.
25 state_pre
= *ev
->dstate
;
26 if (state_pre
!= state
) {
28 trace_events_enabled_count
++;
31 trace_events_enabled_count
--;
37 void trace_event_set_state_dynamic(TraceEvent
*ev
, bool state
)
40 assert(trace_event_get_state_static(ev
));
41 if (trace_event_is_vcpu(ev
)) {
43 trace_event_set_vcpu_state_dynamic(vcpu
, ev
, state
);
46 /* Without the "vcpu" property, dstate can only be 1 or 0 */
47 bool state_pre
= *ev
->dstate
;
48 if (state_pre
!= state
) {
50 trace_events_enabled_count
++;
53 trace_events_enabled_count
--;
60 void trace_event_set_vcpu_state_dynamic(CPUState
*vcpu
,
61 TraceEvent
*ev
, bool state
)
65 assert(trace_event_get_state_static(ev
));
66 assert(trace_event_is_vcpu(ev
));
67 vcpu_id
= trace_event_get_vcpu_id(ev
);
68 state_pre
= test_bit(vcpu_id
, vcpu
->trace_dstate
);
69 if (state_pre
!= state
) {
71 trace_events_enabled_count
++;
72 set_bit(vcpu_id
, vcpu
->trace_dstate
);
75 trace_events_enabled_count
--;
76 clear_bit(vcpu_id
, vcpu
->trace_dstate
);
82 static bool adding_first_cpu(void)
95 void trace_init_vcpu(CPUState
*vcpu
)
99 trace_event_iter_init(&iter
, NULL
);
100 while ((ev
= trace_event_iter_next(&iter
)) != NULL
) {
101 if (trace_event_is_vcpu(ev
) &&
102 trace_event_get_state_static(ev
) &&
103 trace_event_get_state_dynamic(ev
)) {
104 if (adding_first_cpu()) {
105 /* check preconditions */
106 assert(*ev
->dstate
== 1);
107 /* disable early-init state ... */
109 trace_events_enabled_count
--;
110 /* ... and properly re-enable */
111 trace_event_set_vcpu_state_dynamic(vcpu
, ev
, true);
113 trace_event_set_vcpu_state_dynamic(vcpu
, ev
, true);
117 trace_guest_cpu_enter(vcpu
);