Add missing PCF thread types

This commit is contained in:
Rodrigo Arias 2023-02-21 14:13:52 +01:00 committed by Rodrigo Arias Mallo
parent b1e3cf7403
commit 2eac823014
5 changed files with 99 additions and 1 deletions

View File

@ -132,6 +132,12 @@ cpu_connect(struct cpu *cpu, struct bay *bay, struct recorder *rec)
return 0; 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 * static struct thread *
find_thread(struct cpu *cpu, struct thread *thread) find_thread(struct cpu *cpu, struct thread *thread)
{ {

View File

@ -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); 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 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 */ #endif /* CPU_H */

View File

@ -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) { for (struct cpu *cpu = sys->cpus; cpu; cpu = cpu->next) {
if (cpu_connect(cpu, bay, rec) != 0) { if (cpu_connect(cpu, bay, rec) != 0) {
err("cpu_connect failed\n"); 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); err("prf_add failed for cpu '%s'", cpu->name);
return -1; return -1;
} }
cpu_add_to_pcf_type(cpu, affinity_type);
} }
return 0; return 0;

View File

@ -20,6 +20,26 @@ static const int chan_type[] = {
[TH_CHAN_CPU] = 6, [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 static int
get_tid(const char *id, int *tid) get_tid(const char *id, int *tid)
{ {
@ -123,6 +143,39 @@ thread_init_end(struct thread *th)
return 0; 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 int
thread_connect(struct thread *th, struct bay *bay, struct recorder *rec) 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 type = chan_type[i];
long row = th->gindex; 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"); err("prv_register failed");
return -1; return -1;
} }
@ -157,6 +216,25 @@ thread_connect(struct thread *th, struct bay *bay, struct recorder *rec)
return 0; 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 int
thread_get_tid(struct thread *thread) thread_get_tid(struct thread *thread)
{ {

View File

@ -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_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_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 */ #endif /* THREAD_H */