qemu with hax to log dma reads & writes jcs.org/2018/11/12/vfio

trace: Do not include qom/cpu.h into generated trace.h

docs/devel/tracing.txt explains "since many source files include
trace.h, [the generated trace.h use] a minimum of types and other
header files included to keep the namespace clean and compile times
and dependencies down."

Commit 4815185902 "trace: Add per-vCPU tracing states for events with
the 'vcpu' property" made them all include qom/cpu.h via
control-internal.h. qom/cpu.h in turn includes about thirty headers.
Ouch.

Per-vCPU tracing is currently not supported in sub-directories'
trace-events. In other words, qom/cpu.h can only be used in
trace-root.h, not in any trace.h.

Split trace/control-vcpu.h off trace/control.h and
trace/control-internal.h. Have the generated trace.h include
trace/control.h (which no longer includes qom/cpu.h), and trace-root.h
include trace/control-vcpu.h (which includes it).

The resulting improvement is a bit disappointing: in my "build
everything" tree, some 1100 out of 6600 objects (not counting tests
and objects that don't depend on qemu/osdep.h) depend on a trace.h,
and about 600 of them no longer depend on qom/cpu.h. But more than
1300 others depend on trace-root.h. More work is clearly needed.
Left for another day.

Cc: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Tested-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Message-Id: <20190812052359.30071-8-armbru@redhat.com>

+74 -51
+1
block/block-backend.c
··· 15 15 #include "block/block_int.h" 16 16 #include "block/blockjob.h" 17 17 #include "block/throttle-groups.h" 18 + #include "hw/qdev-core.h" 18 19 #include "sysemu/blockdev.h" 19 20 #include "sysemu/sysemu.h" 20 21 #include "qapi/error.h"
+1
qom/object.c
··· 11 11 */ 12 12 13 13 #include "qemu/osdep.h" 14 + #include "hw/qdev-core.h" 14 15 #include "qapi/error.h" 15 16 #include "qom/object.h" 16 17 #include "qom/object_interfaces.h"
+1
scripts/tracetool/format/c.py
··· 28 28 out('/* This file is autogenerated by tracetool, do not edit. */', 29 29 '', 30 30 '#include "qemu/osdep.h"', 31 + '#include "qemu/module.h"', 31 32 '#include "%s"' % header, 32 33 '') 33 34
+6 -1
scripts/tracetool/format/h.py
··· 17 17 18 18 19 19 def generate(events, backend, group): 20 + if group == "root": 21 + header = "trace/control-vcpu.h" 22 + else: 23 + header = "trace/control.h" 24 + 20 25 out('/* This file is autogenerated by tracetool, do not edit. */', 21 26 '', 22 27 '#ifndef TRACE_%s_GENERATED_TRACERS_H' % group.upper(), 23 28 '#define TRACE_%s_GENERATED_TRACERS_H' % group.upper(), 24 29 '', 25 - '#include "trace/control.h"', 30 + '#include "%s"' % header, 26 31 '') 27 32 28 33 for e in events:
-25
trace/control-internal.h
··· 10 10 #ifndef TRACE__CONTROL_INTERNAL_H 11 11 #define TRACE__CONTROL_INTERNAL_H 12 12 13 - #include "qom/cpu.h" 14 - 15 - 16 13 extern int trace_events_enabled_count; 17 14 18 15 ··· 58 55 { 59 56 return unlikely(trace_events_enabled_count) && *ev->dstate; 60 57 } 61 - 62 - static inline bool 63 - trace_event_get_vcpu_state_dynamic_by_vcpu_id(CPUState *vcpu, 64 - uint32_t vcpu_id) 65 - { 66 - /* it's on fast path, avoid consistency checks (asserts) */ 67 - if (unlikely(trace_events_enabled_count)) { 68 - return test_bit(vcpu_id, vcpu->trace_dstate); 69 - } else { 70 - return false; 71 - } 72 - } 73 - 74 - static inline bool trace_event_get_vcpu_state_dynamic(CPUState *vcpu, 75 - TraceEvent *ev) 76 - { 77 - uint32_t vcpu_id; 78 - assert(trace_event_is_vcpu(ev)); 79 - vcpu_id = trace_event_get_vcpu_id(ev); 80 - return trace_event_get_vcpu_state_dynamic_by_vcpu_id(vcpu, vcpu_id); 81 - } 82 - 83 58 84 59 void trace_event_register_group(TraceEvent **events); 85 60
+63
trace/control-vcpu.h
··· 1 + /* 2 + * Interface for configuring and controlling the state of tracing events. 3 + * 4 + * Copyright (C) 2011-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 + #ifndef TRACE__CONTROL_VCPU_H 11 + #define TRACE__CONTROL_VCPU_H 12 + 13 + #include "control.h" 14 + #include "event-internal.h" 15 + #include "qom/cpu.h" 16 + 17 + /** 18 + * trace_event_get_vcpu_state: 19 + * @vcpu: Target vCPU. 20 + * @id: Event identifier name. 21 + * 22 + * Get the tracing state of an event (both static and dynamic) for the given 23 + * vCPU. 24 + * 25 + * If the event has the disabled property, the check will have no performance 26 + * impact. 27 + */ 28 + #define trace_event_get_vcpu_state(vcpu, id) \ 29 + ((id ##_ENABLED) && \ 30 + trace_event_get_vcpu_state_dynamic_by_vcpu_id( \ 31 + vcpu, _ ## id ## _EVENT.vcpu_id)) 32 + 33 + /** 34 + * trace_event_get_vcpu_state_dynamic: 35 + * 36 + * Get the dynamic tracing state of an event for the given vCPU. 37 + */ 38 + static bool trace_event_get_vcpu_state_dynamic(CPUState *vcpu, TraceEvent *ev); 39 + 40 + #include "control-internal.h" 41 + 42 + static inline bool 43 + trace_event_get_vcpu_state_dynamic_by_vcpu_id(CPUState *vcpu, 44 + uint32_t vcpu_id) 45 + { 46 + /* it's on fast path, avoid consistency checks (asserts) */ 47 + if (unlikely(trace_events_enabled_count)) { 48 + return test_bit(vcpu_id, vcpu->trace_dstate); 49 + } else { 50 + return false; 51 + } 52 + } 53 + 54 + static inline bool trace_event_get_vcpu_state_dynamic(CPUState *vcpu, 55 + TraceEvent *ev) 56 + { 57 + uint32_t vcpu_id; 58 + assert(trace_event_is_vcpu(ev)); 59 + vcpu_id = trace_event_get_vcpu_id(ev); 60 + return trace_event_get_vcpu_state_dynamic_by_vcpu_id(vcpu, vcpu_id); 61 + } 62 + 63 + #endif
-24
trace/control.h
··· 120 120 ((id ##_ENABLED) && id ##_BACKEND_DSTATE()) 121 121 122 122 /** 123 - * trace_event_get_vcpu_state: 124 - * @vcpu: Target vCPU. 125 - * @id: Event identifier name. 126 - * 127 - * Get the tracing state of an event (both static and dynamic) for the given 128 - * vCPU. 129 - * 130 - * If the event has the disabled property, the check will have no performance 131 - * impact. 132 - */ 133 - #define trace_event_get_vcpu_state(vcpu, id) \ 134 - ((id ##_ENABLED) && \ 135 - trace_event_get_vcpu_state_dynamic_by_vcpu_id( \ 136 - vcpu, _ ## id ## _EVENT.vcpu_id)) 137 - 138 - /** 139 123 * trace_event_get_state_static: 140 124 * @id: Event identifier. 141 125 * ··· 154 138 * If the event has the 'vcpu' property, gets the OR'ed state of all vCPUs. 155 139 */ 156 140 static bool trace_event_get_state_dynamic(TraceEvent *ev); 157 - 158 - /** 159 - * trace_event_get_vcpu_state_dynamic: 160 - * 161 - * Get the dynamic tracing state of an event for the given vCPU. 162 - */ 163 - static bool trace_event_get_vcpu_state_dynamic(CPUState *vcpu, TraceEvent *ev); 164 - 165 141 166 142 /** 167 143 * trace_event_set_state_dynamic:
+1 -1
trace/qmp.c
··· 10 10 #include "qemu/osdep.h" 11 11 #include "qapi/error.h" 12 12 #include "qapi/qapi-commands-trace.h" 13 - #include "control.h" 13 + #include "control-vcpu.h" 14 14 15 15 16 16 static CPUState *get_cpu(bool has_vcpu, int vcpu, Error **errp)
+1
ui/vnc.c
··· 28 28 #include "vnc.h" 29 29 #include "vnc-jobs.h" 30 30 #include "trace.h" 31 + #include "hw/qdev-core.h" 31 32 #include "sysemu/sysemu.h" 32 33 #include "qemu/error-report.h" 33 34 #include "qemu/module.h"