Commit 2bfe11c8 authored by Lluís Vilanova's avatar Lluís Vilanova Committed by Stefan Hajnoczi
Browse files

trace: Properly initialize dynamic event states in hot-plugged vCPUs



Every time a vCPU is hot-plugged, it will "inherit" its tracing state
from the global state array. That is, if *any* existing vCPU has an
event enabled, new vCPUs will have too.

Signed-off-by: default avatarLluís Vilanova <vilanova@ac.upc.edu>
Message-id: 147428970768.15111.7664565956870423529.stgit@fimbulvetr.bsc.es
Signed-off-by: default avatarStefan Hajnoczi <stefanha@redhat.com>
parent 331f5eb2
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -1133,7 +1133,6 @@ int main(int argc, char **argv)
        gdbserver_start (gdbstub_port);
        gdb_handlesig(cpu, 0);
    }
    trace_init_vcpu_events();
    cpu_loop(env);
    /* never exits */
    return 0;
+0 −1
Original line number Diff line number Diff line
@@ -4800,7 +4800,6 @@ int main(int argc, char **argv, char **envp)
        }
        gdb_handlesig(cpu, 0);
    }
    trace_init_vcpu_events();
    cpu_loop(env);
    /* never exits */
    return 0;
+3 −0
Original line number Diff line number Diff line
@@ -333,6 +333,9 @@ static void cpu_common_realizefn(DeviceState *dev, Error **errp)
        cpu_synchronize_post_init(cpu);
        cpu_resume(cpu);
    }

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

static void cpu_common_initfn(Object *obj)
+6 −0
Original line number Diff line number Diff line
@@ -44,3 +44,9 @@ void trace_event_set_vcpu_state_dynamic(CPUState *vcpu,
    /* should never be called on non-target binaries */
    abort();
}

void trace_init_vcpu(CPUState *vcpu)
{
    /* should never be called on non-target binaries */
    abort();
}
+37 −0
Original line number Diff line number Diff line
@@ -81,3 +81,40 @@ void trace_event_set_vcpu_state_dynamic(CPUState *vcpu,
        }
    }
}

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

void trace_init_vcpu(CPUState *vcpu)
{
    TraceEvent *ev = NULL;

    while ((ev = trace_event_pattern("*", ev)) != NULL) {
        if (trace_event_is_vcpu(ev) &&
            trace_event_get_state_static(ev) &&
            trace_event_get_state_dynamic(ev)) {
            TraceEventID id = trace_event_get_id(ev);
            if (adding_first_cpu()) {
                /* check preconditions */
                assert(trace_events_dstate[id] == 1);
                /* disable early-init state ... */
                trace_events_dstate[id] = 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);
            }
        }
    }
}
Loading