diff --git a/src/emu/cpu.c b/src/emu/cpu.c index ddccf44..7ab2f8f 100644 --- a/src/emu/cpu.c +++ b/src/emu/cpu.c @@ -52,6 +52,12 @@ cpu_set_gindex(struct cpu *cpu, int64_t gindex) cpu->gindex = gindex; } +void +cpu_set_loom(struct cpu *cpu, struct loom *loom) +{ + cpu->loom = loom; +} + void cpu_set_name(struct cpu *cpu, const char *name) { diff --git a/src/emu/cpu.h b/src/emu/cpu.h index b78f7fa..a154d01 100644 --- a/src/emu/cpu.h +++ b/src/emu/cpu.h @@ -37,6 +37,9 @@ struct cpu { /* Physical id: as reported by lscpu(1) */ int phyid; + /* Required to find threads that can run in this CPU */ + struct loom *loom; + size_t nthreads; size_t nth_running; size_t nth_active; @@ -66,6 +69,7 @@ void cpu_init_begin(struct cpu *cpu, int phyid, int is_virtual); int cpu_get_phyid(struct cpu *cpu); //int cpu_get_index(struct cpu *cpu); void cpu_set_gindex(struct cpu *cpu, int64_t gindex); +void cpu_set_loom(struct cpu *cpu, struct loom *loom); void cpu_set_name(struct cpu *cpu, const char *name); int cpu_init_end(struct cpu *cpu); int cpu_connect(struct cpu *cpu, struct bay *bay, struct recorder *rec); diff --git a/src/emu/loom.c b/src/emu/loom.c index 7b9d99e..2a987b2 100644 --- a/src/emu/loom.c +++ b/src/emu/loom.c @@ -68,6 +68,7 @@ loom_init_begin(struct loom *loom, const char *name) loom->id = loom->name; cpu_init_begin(&loom->vcpu, -1, 1); + cpu_set_loom(&loom->vcpu, loom); dbg("creating new loom %s", loom->id); @@ -121,6 +122,8 @@ loom_add_cpu(struct loom *loom, struct cpu *cpu) //DL_SORT2(loom->cpus, cmp_cpus, lprev, lnext); // Maybe? loom->ncpus++; + cpu_set_loom(cpu, loom); + return 0; } @@ -223,6 +226,8 @@ loom_add_proc(struct loom *loom, struct proc *proc) HASH_ADD_INT(loom->procs, pid, proc); loom->nprocs++; + proc_set_loom(proc, loom); + return 0; } diff --git a/src/emu/proc.c b/src/emu/proc.c index f4f2b52..3d0f05a 100644 --- a/src/emu/proc.c +++ b/src/emu/proc.c @@ -95,6 +95,12 @@ proc_set_gindex(struct proc *proc, int64_t gindex) proc->gindex = gindex; } +void +proc_set_loom(struct proc *proc, struct loom *loom) +{ + proc->loom = loom; +} + int proc_load_metadata(struct proc *proc, JSON_Object *meta) { diff --git a/src/emu/proc.h b/src/emu/proc.h index f3055dd..5504c11 100644 --- a/src/emu/proc.h +++ b/src/emu/proc.h @@ -27,6 +27,10 @@ struct proc { int nthreads; struct thread *threads; + /* Required to find if a thread belongs to the same loom as a + * CPU */ + struct loom *loom; + /* Loom list */ struct proc *lnext; struct proc *lprev; @@ -45,6 +49,7 @@ int proc_init_begin(struct proc *proc, const char *id); int proc_init_end(struct proc *proc); int proc_get_pid(struct proc *proc); void proc_set_gindex(struct proc *proc, int64_t gindex); +void proc_set_loom(struct proc *proc, struct loom *loom); void proc_sort(struct proc *proc); int proc_load_metadata(struct proc *proc, JSON_Object *meta); struct thread *proc_find_thread(struct proc *proc, int tid);