Delay connect() until first event

Prevents enabling more channels than required until we observe an event
of that model. Ideally we should implement this logic in the probe hook
when the models can report if they are being used in the metadata.
This commit is contained in:
Rodrigo Arias 2023-02-17 17:37:07 +01:00 committed by Rodrigo Arias Mallo
parent 8310127e78
commit d34a25a62d
8 changed files with 46 additions and 5 deletions

View File

@ -52,6 +52,17 @@ process_ev(struct emu *emu)
int
kernel_event(struct emu *emu)
{
static int enabled = 0;
if (!enabled) {
if (kernel_connect(emu) != 0) {
err("kernel_connect failed");
return -1;
}
enabled = 1;
}
dbg("in kernel_event");
if (emu->ev->m != 'K') {
err("unexpected event model %c\n", emu->ev->m);

View File

@ -7,7 +7,7 @@ struct model_spec model_kernel = {
.name = model_name,
.model = model_id,
.create = kernel_create,
.connect = kernel_connect,
// .connect = kernel_connect,
.event = kernel_event,
.probe = kernel_probe,
};
@ -29,7 +29,7 @@ static const int pvt_type[] = {
};
static const char *pcf_prefix[CH_MAX] = {
[CH_CS] = "Kernel subsystem",
[CH_CS] = "Kernel context switch",
};
static const struct pcf_value_label kernel_cs_values[] = {

View File

@ -509,6 +509,16 @@ process_ev(struct emu *emu)
int
nanos6_event(struct emu *emu)
{
static int enabled = 0;
if (!enabled) {
if (nanos6_connect(emu) != 0) {
err("nanos6_connect failed");
return -1;
}
enabled = 1;
}
if (emu->ev->m != '6') {
err("unexpected event model %c\n", emu->ev->m);
return -1;

View File

@ -7,7 +7,7 @@ struct model_spec model_nanos6 = {
.name = model_name,
.model = model_id,
.create = nanos6_create,
.connect = nanos6_connect,
// .connect = nanos6_connect,
.event = nanos6_event,
.probe = nanos6_probe,
.finish = nanos6_finish,

View File

@ -94,6 +94,16 @@ process_ev(struct emu *emu)
int
nodes_event(struct emu *emu)
{
static int enabled = 0;
if (!enabled) {
if (nodes_connect(emu) != 0) {
err("nodes_connect failed");
return -1;
}
enabled = 1;
}
dbg("in nodes_event");
if (emu->ev->m != 'D') {
err("unexpected event model %c\n", emu->ev->m);

View File

@ -7,7 +7,7 @@ struct model_spec model_nodes = {
.name = model_name,
.model = model_id,
.create = nodes_create,
.connect = nodes_connect,
// .connect = nodes_connect,
.event = nodes_event,
.probe = nodes_probe,
.finish = nodes_finish,

View File

@ -507,6 +507,16 @@ process_ev(struct emu *emu)
int
nosv_event(struct emu *emu)
{
static int enabled = 0;
if (!enabled) {
if (nosv_connect(emu) != 0) {
err("nosv_connect failed");
return -1;
}
enabled = 1;
}
dbg("in nosv_event");
if (emu->ev->m != 'V') {
err("unexpected event model %c\n", emu->ev->m);

View File

@ -7,7 +7,7 @@ struct model_spec model_nosv = {
.name = model_name,
.model = model_id,
.create = nosv_create,
.connect = nosv_connect,
// .connect = nosv_connect,
.event = nosv_event,
.probe = nosv_probe,
.finish = nosv_finish,