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
)
19 TraceEventID id
= trace_event_get_id(ev
);
21 assert(trace_event_get_state_static(ev
));
23 * We ignore the "vcpu" property here, since no vCPUs have been created
24 * yet. Then dstate can only be 1 or 0.
26 state_pre
= trace_events_dstate
[id
];
27 if (state_pre
!= state
) {
29 trace_events_enabled_count
++;
30 trace_events_dstate
[id
] = 1;
32 trace_events_enabled_count
--;
33 trace_events_dstate
[id
] = 0;
38 void trace_event_set_state_dynamic(TraceEvent
*ev
, bool state
)
41 assert(trace_event_get_state_static(ev
));
42 if (trace_event_is_vcpu(ev
)) {
44 trace_event_set_vcpu_state_dynamic(vcpu
, ev
, state
);
47 /* Without the "vcpu" property, dstate can only be 1 or 0 */
48 TraceEventID id
= trace_event_get_id(ev
);
49 bool state_pre
= trace_events_dstate
[id
];
50 if (state_pre
!= state
) {
52 trace_events_enabled_count
++;
53 trace_events_dstate
[id
] = 1;
55 trace_events_enabled_count
--;
56 trace_events_dstate
[id
] = 0;
62 void trace_event_set_vcpu_state_dynamic(CPUState
*vcpu
,
63 TraceEvent
*ev
, bool state
)
66 TraceEventVCPUID vcpu_id
;
68 assert(trace_event_get_state_static(ev
));
69 assert(trace_event_is_vcpu(ev
));
70 id
= trace_event_get_id(ev
);
71 vcpu_id
= trace_event_get_vcpu_id(ev
);
72 state_pre
= test_bit(vcpu_id
, vcpu
->trace_dstate
);
73 if (state_pre
!= state
) {
75 trace_events_enabled_count
++;
76 set_bit(vcpu_id
, vcpu
->trace_dstate
);
77 trace_events_dstate
[id
]++;
79 trace_events_enabled_count
--;
80 clear_bit(vcpu_id
, vcpu
->trace_dstate
);
81 trace_events_dstate
[id
]--;
86 static bool adding_first_cpu(void)
99 void trace_init_vcpu(CPUState
*vcpu
)
101 TraceEvent
*ev
= NULL
;
103 while ((ev
= trace_event_pattern("*", ev
)) != NULL
) {
104 if (trace_event_is_vcpu(ev
) &&
105 trace_event_get_state_static(ev
) &&
106 trace_event_get_state_dynamic(ev
)) {
107 TraceEventID id
= trace_event_get_id(ev
);
108 if (adding_first_cpu()) {
109 /* check preconditions */
110 assert(trace_events_dstate
[id
] == 1);
111 /* disable early-init state ... */
112 trace_events_dstate
[id
] = 0;
113 trace_events_enabled_count
--;
114 /* ... and properly re-enable */
115 trace_event_set_vcpu_state_dynamic(vcpu
, ev
, true);
117 trace_event_set_vcpu_state_dynamic(vcpu
, ev
, true);
122 trace_guest_cpu_enter(vcpu
);