diff --git a/src/emu/cpu.c b/src/emu/cpu.c index 07dbb99..16220a7 100644 --- a/src/emu/cpu.c +++ b/src/emu/cpu.c @@ -132,6 +132,12 @@ cpu_connect(struct cpu *cpu, struct bay *bay, struct recorder *rec) return 0; } +struct pcf_value * +cpu_add_to_pcf_type(struct cpu *cpu, struct pcf_type *type) +{ + return pcf_add_value(type, cpu->gindex + 1, cpu->name); +} + static struct thread * find_thread(struct cpu *cpu, struct thread *thread) { diff --git a/src/emu/cpu.h b/src/emu/cpu.h index cf89790..ff07e4a 100644 --- a/src/emu/cpu.h +++ b/src/emu/cpu.h @@ -79,5 +79,6 @@ int cpu_remove_thread(struct cpu *cpu, struct thread *thread); int cpu_migrate_thread(struct cpu *cpu, struct thread *thread, struct cpu *newcpu); struct chan *cpu_get_th_chan(struct cpu *cpu, enum track_th mode); +struct pcf_value *cpu_add_to_pcf_type(struct cpu *cpu, struct pcf_type *type); #endif /* CPU_H */ diff --git a/src/emu/system.c b/src/emu/system.c index 53c4b28..e5cc382 100644 --- a/src/emu/system.c +++ b/src/emu/system.c @@ -566,6 +566,14 @@ system_connect(struct system *sys, struct bay *bay, struct recorder *rec) } } + struct pcf *pcf_th = pvt_get_pcf(pvt_th); + if (thread_create_pcf_types(pcf_th) != 0) { + err("thread_create_pcf_types failed"); + return -1; + } + + struct pcf_type *affinity_type = thread_get_affinity_pcf_type(pcf_th); + for (struct cpu *cpu = sys->cpus; cpu; cpu = cpu->next) { if (cpu_connect(cpu, bay, rec) != 0) { err("cpu_connect failed\n"); @@ -577,6 +585,8 @@ system_connect(struct system *sys, struct bay *bay, struct recorder *rec) err("prf_add failed for cpu '%s'", cpu->name); return -1; } + + cpu_add_to_pcf_type(cpu, affinity_type); } return 0; diff --git a/src/emu/thread.c b/src/emu/thread.c index a340c12..12a62e0 100644 --- a/src/emu/thread.c +++ b/src/emu/thread.c @@ -20,6 +20,26 @@ static const int chan_type[] = { [TH_CHAN_CPU] = 6, }; +static const char *pvt_name[] = { + [TH_CHAN_CPU] = "Thread: CPU affinity", + [TH_CHAN_TID] = "Thread: TID of the ACTIVE thread", + [TH_CHAN_STATE] = "Thread: thread state", +}; + +static const struct pcf_value_label state_name[] = { + { TH_ST_UNKNOWN, "Unknown" }, + { TH_ST_RUNNING, "Running" }, + { TH_ST_PAUSED, "Paused" }, + { TH_ST_DEAD, "Dead" }, + { TH_ST_COOLING, "Cooling" }, + { TH_ST_WARMING, "Warming" }, + { -1, NULL }, +}; + +static const struct pcf_value_label (*pcf_labels[TH_CHAN_MAX])[] = { + [TH_CHAN_STATE] = &state_name, +}; + static int get_tid(const char *id, int *tid) { @@ -123,6 +143,39 @@ thread_init_end(struct thread *th) return 0; } +static int +create_values(struct pcf_type *t, int i) +{ + const struct pcf_value_label(*q)[] = pcf_labels[i]; + + if (q == NULL) + return 0; + + for (const struct pcf_value_label *p = *q; p->label != NULL; p++) + pcf_add_value(t, p->value, p->label); + + return 0; +} + +static int +create_type(struct pcf *pcf, int i) +{ + long type = chan_type[i]; + + if (type == -1) + return 0; + + const char *label = pvt_name[i]; + struct pcf_type *pcftype = pcf_add_type(pcf, type, label); + + if (create_values(pcftype, i) != 0) { + err("create_values failed"); + return -1; + } + + return 0; +} + int thread_connect(struct thread *th, struct bay *bay, struct recorder *rec) { @@ -148,7 +201,13 @@ thread_connect(struct thread *th, struct bay *bay, struct recorder *rec) long type = chan_type[i]; long row = th->gindex; - if (prv_register(prv, row, type, bay, c, PRV_DUP)) { + long flags = PRV_DUP; + + /* Add one to the cpu gindex in the PRV output */ + if (i == TH_CHAN_CPU) + flags |= PRV_NEXT; + + if (prv_register(prv, row, type, bay, c, flags)) { err("prv_register failed"); return -1; } @@ -157,6 +216,25 @@ thread_connect(struct thread *th, struct bay *bay, struct recorder *rec) return 0; } +int +thread_create_pcf_types(struct pcf *pcf) +{ + for (int i = 0; i < TH_CHAN_MAX; i++) { + if (create_type(pcf, i) != 0) { + err("create_type failed"); + return -1; + } + } + return 0; +} + +struct pcf_type * +thread_get_affinity_pcf_type(struct pcf *pcf) +{ + int type_id = chan_type[TH_CHAN_CPU]; + return pcf_find_type(pcf, type_id); +} + int thread_get_tid(struct thread *thread) { diff --git a/src/emu/thread.h b/src/emu/thread.h index f3dfae0..ee1fad2 100644 --- a/src/emu/thread.h +++ b/src/emu/thread.h @@ -88,4 +88,7 @@ int thread_select_active(struct mux *mux, struct value value, struct mux_input * int thread_select_running(struct mux *mux, struct value value, struct mux_input **input); int thread_select_any(struct mux *mux, struct value value, struct mux_input **input); +int thread_create_pcf_types(struct pcf *pcf); +struct pcf_type *thread_get_affinity_pcf_type(struct pcf *pcf); + #endif /* THREAD_H */