]> git.proxmox.com Git - mirror_qemu.git/blame - trace/control-target.c
rbd: Fix to cleanly reject -drive without pool or image
[mirror_qemu.git] / trace / control-target.c
CommitLineData
48151859
LV
1/*
2 * Interface for configuring and controlling the state of tracing events.
3 *
4 * Copyright (C) 2014-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#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
17void 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
37void trace_event_set_state_dynamic(TraceEvent *ev, bool state)
38{
39 CPUState *vcpu;
40 assert(trace_event_get_state_static(ev));
41 if (trace_event_is_vcpu(ev)) {
42 CPU_FOREACH(vcpu) {
43 trace_event_set_vcpu_state_dynamic(vcpu, ev, state);
44 }
45 } else {
8eb1b9db 46 /* Without the "vcpu" property, dstate can only be 1 or 0 */
93977402 47 bool state_pre = *ev->dstate;
8eb1b9db
LV
48 if (state_pre != state) {
49 if (state) {
50 trace_events_enabled_count++;
93977402 51 *ev->dstate = 1;
8eb1b9db
LV
52 } else {
53 trace_events_enabled_count--;
93977402 54 *ev->dstate = 0;
8eb1b9db
LV
55 }
56 }
48151859
LV
57 }
58}
59
60void trace_event_set_vcpu_state_dynamic(CPUState *vcpu,
61 TraceEvent *ev, bool state)
62{
ef4c9fc8 63 uint32_t vcpu_id;
48151859
LV
64 bool state_pre;
65 assert(trace_event_get_state_static(ev));
66 assert(trace_event_is_vcpu(ev));
48151859
LV
67 vcpu_id = trace_event_get_vcpu_id(ev);
68 state_pre = test_bit(vcpu_id, vcpu->trace_dstate);
69 if (state_pre != state) {
70 if (state) {
71 trace_events_enabled_count++;
72 set_bit(vcpu_id, vcpu->trace_dstate);
93977402 73 (*ev->dstate)++;
48151859
LV
74 } else {
75 trace_events_enabled_count--;
76 clear_bit(vcpu_id, vcpu->trace_dstate);
93977402 77 (*ev->dstate)--;
48151859
LV
78 }
79 }
80}
2bfe11c8 81
fff895df 82static bool adding_first_cpu1(void)
2bfe11c8
LV
83{
84 CPUState *cpu;
85 size_t count = 0;
86 CPU_FOREACH(cpu) {
87 count++;
88 if (count > 1) {
89 return false;
90 }
91 }
92 return true;
93}
94
fff895df
LV
95static bool adding_first_cpu(void)
96{
97 bool res;
98 cpu_list_lock();
99 res = adding_first_cpu1();
100 cpu_list_unlock();
101 return res;
102}
103
2bfe11c8
LV
104void trace_init_vcpu(CPUState *vcpu)
105{
0d4e995c
DB
106 TraceEventIter iter;
107 TraceEvent *ev;
108 trace_event_iter_init(&iter, NULL);
109 while ((ev = trace_event_iter_next(&iter)) != NULL) {
2bfe11c8
LV
110 if (trace_event_is_vcpu(ev) &&
111 trace_event_get_state_static(ev) &&
112 trace_event_get_state_dynamic(ev)) {
2bfe11c8
LV
113 if (adding_first_cpu()) {
114 /* check preconditions */
93977402 115 assert(*ev->dstate == 1);
2bfe11c8 116 /* disable early-init state ... */
93977402 117 *ev->dstate = 0;
2bfe11c8
LV
118 trace_events_enabled_count--;
119 /* ... and properly re-enable */
120 trace_event_set_vcpu_state_dynamic(vcpu, ev, true);
121 } else {
122 trace_event_set_vcpu_state_dynamic(vcpu, ev, true);
123 }
124 }
125 }
b9d72215 126 trace_guest_cpu_enter(vcpu);
2bfe11c8 127}