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" 12 #include "trace/control.h" 13 #include "translate-all.h" 14 15 16 void trace_event_set_state_dynamic_init(TraceEvent *ev, bool state) 17 { 18 TraceEventID id = trace_event_get_id(ev); 19 bool state_pre; 20 assert(trace_event_get_state_static(ev)); 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 */ 25 state_pre = trace_events_dstate[id]; 26 if (state_pre != state) { 27 if (state) { 28 trace_events_enabled_count++; 29 trace_events_dstate[id] = 1; 30 } else { 31 trace_events_enabled_count--; 32 trace_events_dstate[id] = 0; 33 } 34 } 35 } 36 37 void 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 { 46 /* Without the "vcpu" property, dstate can only be 1 or 0 */ 47 TraceEventID id = trace_event_get_id(ev); 48 bool state_pre = trace_events_dstate[id]; 49 if (state_pre != state) { 50 if (state) { 51 trace_events_enabled_count++; 52 trace_events_dstate[id] = 1; 53 } else { 54 trace_events_enabled_count--; 55 trace_events_dstate[id] = 0; 56 } 57 } 58 } 59 } 60 61 void trace_event_set_vcpu_state_dynamic(CPUState *vcpu, 62 TraceEvent *ev, bool state) 63 { 64 TraceEventID id; 65 TraceEventVCPUID vcpu_id; 66 bool state_pre; 67 assert(trace_event_get_state_static(ev)); 68 assert(trace_event_is_vcpu(ev)); 69 id = trace_event_get_id(ev); 70 vcpu_id = trace_event_get_vcpu_id(ev); 71 state_pre = test_bit(vcpu_id, vcpu->trace_dstate); 72 if (state_pre != state) { 73 if (state) { 74 trace_events_enabled_count++; 75 set_bit(vcpu_id, vcpu->trace_dstate); 76 trace_events_dstate[id]++; 77 } else { 78 trace_events_enabled_count--; 79 clear_bit(vcpu_id, vcpu->trace_dstate); 80 trace_events_dstate[id]--; 81 } 82 } 83 } 84