Skip to content

Commit

Permalink
trace: remove code that depends on setting vcpu
Browse files Browse the repository at this point in the history
Now we no longer have any events that are for vcpus we can start
excising the code from the trace control. As the vcpu parameter is
encoded as part of QMP we just stub out the has_vcpu/vcpu parameters
rather than alter the API.

Reviewed-by: Stefan Hajnoczi <[email protected]>
Reviewed-by: Richard Henderson <[email protected]>
Signed-off-by: Alex Bennée <[email protected]>
Message-id: [email protected]
Message-Id: <[email protected]>
Signed-off-by: Stefan Hajnoczi <[email protected]>
  • Loading branch information
stsquad authored and stefanhaRH committed Jun 1, 2023
1 parent 5485e52 commit 89aafcf
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 285 deletions.
2 changes: 0 additions & 2 deletions hw/core/cpu-common.c
Original file line number Diff line number Diff line change
Expand Up @@ -211,15 +211,13 @@ static void cpu_common_realizefn(DeviceState *dev, Error **errp)
}

/* NOTE: latest generic point where the cpu is fully realized */
trace_init_vcpu(cpu);
}

static void cpu_common_unrealizefn(DeviceState *dev)
{
CPUState *cpu = CPU(dev);

/* NOTE: latest generic point before the cpu is fully unrealized */
trace_fini_vcpu(cpu);
cpu_exec_unrealizefn(cpu);
}

Expand Down
13 changes: 0 additions & 13 deletions stubs/trace-control.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,3 @@ void trace_event_set_state_dynamic(TraceEvent *ev, bool state)
}
}
}

void trace_event_set_vcpu_state_dynamic(CPUState *vcpu,
TraceEvent *ev, bool state)
{
/* should never be called on non-target binaries */
abort();
}

void trace_init_vcpu(CPUState *vcpu)
{
/* should never be called on non-target binaries */
abort();
}
10 changes: 0 additions & 10 deletions trace/control-internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,6 @@ static inline uint32_t trace_event_get_id(TraceEvent *ev)
return ev->id;
}

static inline uint32_t trace_event_get_vcpu_id(TraceEvent *ev)
{
return 0;
}

static inline bool trace_event_is_vcpu(TraceEvent *ev)
{
return false;
}

static inline const char * trace_event_get_name(TraceEvent *ev)
{
assert(ev != NULL);
Expand Down
108 changes: 9 additions & 99 deletions trace/control-target.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,112 +36,22 @@ void trace_event_set_state_dynamic_init(TraceEvent *ev, bool state)

void trace_event_set_state_dynamic(TraceEvent *ev, bool state)
{
CPUState *vcpu;
assert(trace_event_get_state_static(ev));
if (trace_event_is_vcpu(ev) && likely(first_cpu != NULL)) {
CPU_FOREACH(vcpu) {
trace_event_set_vcpu_state_dynamic(vcpu, ev, state);
}
} else {
/*
* Without the "vcpu" property, dstate can only be 1 or 0. With it, we
* haven't instantiated any vCPU yet, so we will set a global state
* instead, and trace_init_vcpu will reconcile it afterwards.
*/
bool state_pre = *ev->dstate;
if (state_pre != state) {
if (state) {
trace_events_enabled_count++;
*ev->dstate = 1;
} else {
trace_events_enabled_count--;
*ev->dstate = 0;
}
}
}
}

static void trace_event_synchronize_vcpu_state_dynamic(
CPUState *vcpu, run_on_cpu_data ignored)
{
bitmap_copy(vcpu->trace_dstate, vcpu->trace_dstate_delayed,
CPU_TRACE_DSTATE_MAX_EVENTS);
tcg_flush_jmp_cache(vcpu);
}

void trace_event_set_vcpu_state_dynamic(CPUState *vcpu,
TraceEvent *ev, bool state)
{
uint32_t vcpu_id;
bool state_pre;
assert(trace_event_get_state_static(ev));
assert(trace_event_is_vcpu(ev));
vcpu_id = trace_event_get_vcpu_id(ev);
state_pre = test_bit(vcpu_id, vcpu->trace_dstate);
/*
* There is no longer a "vcpu" property, dstate can only be 1 or
* 0. With it, we haven't instantiated any vCPU yet, so we will
* set a global state instead, and trace_init_vcpu will reconcile
* it afterwards.
*/
bool state_pre = *ev->dstate;
if (state_pre != state) {
if (state) {
trace_events_enabled_count++;
set_bit(vcpu_id, vcpu->trace_dstate_delayed);
(*ev->dstate)++;
*ev->dstate = 1;
} else {
trace_events_enabled_count--;
clear_bit(vcpu_id, vcpu->trace_dstate_delayed);
(*ev->dstate)--;
}
if (vcpu->created) {
/*
* Delay changes until next TB; we want all TBs to be built from a
* single set of dstate values to ensure consistency of generated
* tracing code.
*/
async_run_on_cpu(vcpu, trace_event_synchronize_vcpu_state_dynamic,
RUN_ON_CPU_NULL);
} else {
trace_event_synchronize_vcpu_state_dynamic(vcpu, RUN_ON_CPU_NULL);
}
}
}

static bool adding_first_cpu1(void)
{
CPUState *cpu;
size_t count = 0;
CPU_FOREACH(cpu) {
count++;
if (count > 1) {
return false;
}
}
return true;
}

static bool adding_first_cpu(void)
{
QEMU_LOCK_GUARD(&qemu_cpu_list_lock);

return adding_first_cpu1();
}

void trace_init_vcpu(CPUState *vcpu)
{
TraceEventIter iter;
TraceEvent *ev;
trace_event_iter_init_all(&iter);
while ((ev = trace_event_iter_next(&iter)) != NULL) {
if (trace_event_is_vcpu(ev) &&
trace_event_get_state_static(ev) &&
trace_event_get_state_dynamic(ev)) {
if (adding_first_cpu()) {
/* check preconditions */
assert(*ev->dstate == 1);
/* disable early-init state ... */
*ev->dstate = 0;
trace_events_enabled_count--;
/* ... and properly re-enable */
trace_event_set_vcpu_state_dynamic(vcpu, ev, true);
} else {
trace_event_set_vcpu_state_dynamic(vcpu, ev, true);
}
*ev->dstate = 0;
}
}
}
16 changes: 0 additions & 16 deletions trace/control-vcpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,6 @@
trace_event_get_vcpu_state_dynamic_by_vcpu_id( \
vcpu, _ ## id ## _EVENT.vcpu_id))

/**
* trace_event_get_vcpu_state_dynamic:
*
* Get the dynamic tracing state of an event for the given vCPU.
*/
static bool trace_event_get_vcpu_state_dynamic(CPUState *vcpu, TraceEvent *ev);

#include "control-internal.h"

static inline bool
Expand All @@ -51,13 +44,4 @@ trace_event_get_vcpu_state_dynamic_by_vcpu_id(CPUState *vcpu,
}
}

static inline bool trace_event_get_vcpu_state_dynamic(CPUState *vcpu,
TraceEvent *ev)
{
uint32_t vcpu_id;
assert(trace_event_is_vcpu(ev));
vcpu_id = trace_event_get_vcpu_id(ev);
return trace_event_get_vcpu_state_dynamic_by_vcpu_id(vcpu, vcpu_id);
}

#endif
16 changes: 0 additions & 16 deletions trace/control.c
Original file line number Diff line number Diff line change
Expand Up @@ -262,22 +262,6 @@ void trace_init_file(void)
#endif
}

void trace_fini_vcpu(CPUState *vcpu)
{
TraceEventIter iter;
TraceEvent *ev;

trace_event_iter_init_all(&iter);
while ((ev = trace_event_iter_next(&iter)) != NULL) {
if (trace_event_is_vcpu(ev) &&
trace_event_get_state_static(ev) &&
trace_event_get_vcpu_state_dynamic(vcpu, ev)) {
/* must disable to affect the global counter */
trace_event_set_vcpu_state_dynamic(vcpu, ev, false);
}
}
}

bool trace_init_backends(void)
{
#ifdef CONFIG_TRACE_SIMPLE
Expand Down
48 changes: 0 additions & 48 deletions trace/control.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,23 +89,6 @@ static bool trace_event_is_pattern(const char *str);
*/
static uint32_t trace_event_get_id(TraceEvent *ev);

/**
* trace_event_get_vcpu_id:
*
* Get the per-vCPU identifier of an event.
*
* Special value #TRACE_VCPU_EVENT_NONE means the event is not vCPU-specific
* (does not have the "vcpu" property).
*/
static uint32_t trace_event_get_vcpu_id(TraceEvent *ev);

/**
* trace_event_is_vcpu:
*
* Whether this is a per-vCPU event.
*/
static bool trace_event_is_vcpu(TraceEvent *ev);

/**
* trace_event_get_name:
*
Expand Down Expand Up @@ -172,21 +155,6 @@ static bool trace_event_get_state_dynamic(TraceEvent *ev);
*/
void trace_event_set_state_dynamic(TraceEvent *ev, bool state);

/**
* trace_event_set_vcpu_state_dynamic:
*
* Set the dynamic tracing state of an event for the given vCPU.
*
* Pre-condition: trace_event_get_vcpu_state_static(ev) == true
*
* Note: Changes for execution-time events with the 'tcg' property will not be
* propagated until the next TB is executed (iff executing in TCG mode).
*/
void trace_event_set_vcpu_state_dynamic(CPUState *vcpu,
TraceEvent *ev, bool state);



/**
* trace_init_backends:
*
Expand All @@ -205,22 +173,6 @@ bool trace_init_backends(void);
*/
void trace_init_file(void);

/**
* trace_init_vcpu:
* @vcpu: Added vCPU.
*
* Set initial dynamic event state for a hot-plugged vCPU.
*/
void trace_init_vcpu(CPUState *vcpu);

/**
* trace_fini_vcpu:
* @vcpu: Removed vCPU.
*
* Disable dynamic event state for a hot-unplugged vCPU.
*/
void trace_fini_vcpu(CPUState *vcpu);

/**
* trace_list_events:
* @f: Where to send output.
Expand Down
Loading

0 comments on commit 89aafcf

Please sign in to comment.