diff --git a/emu.h b/emu.h index 55c59e1..717c417 100644 --- a/emu.h +++ b/emu.h @@ -142,14 +142,13 @@ enum ovni_cpu_state { }; struct ovni_cpu { - /* Physical id */ - int cpu_id; + /* Logical index: 0 to ncpus - 1 */ + int i; - /* Position in emu->cpu */ - int index; + /* Physical id: as reported by lscpu(1) */ + int phyid; enum ovni_cpu_state state; - //enum ovni_cpu_type type; size_t last_nthreads; @@ -161,11 +160,10 @@ struct ovni_cpu { struct ovni_emu { struct ovni_trace trace; - /* Physical CPUs */ int max_ncpus; + int max_phyid; int ncpus; struct ovni_cpu cpu[OVNI_MAX_CPU]; - int cpuind[OVNI_MAX_CPU]; /* Virtual CPU */ struct ovni_cpu vcpu; diff --git a/emu_ovni.c b/emu_ovni.c index 0db3aeb..47bd2c8 100644 --- a/emu_ovni.c +++ b/emu_ovni.c @@ -14,7 +14,7 @@ emu_get_cpu(struct ovni_emu *emu, int cpuid) return &emu->vcpu; } - return &emu->cpu[emu->cpuind[cpuid]]; + return &emu->cpu[cpuid]; } int @@ -246,47 +246,46 @@ ev_affinity(struct ovni_emu *emu) static void ev_cpu_count(struct ovni_emu *emu) { - int i, ncpus, maxcpu; + int i, max_ncpus, max_phyid; - ncpus = emu->cur_ev->payload.i32[0]; - maxcpu = emu->cur_ev->payload.i32[1]; + max_ncpus = emu->cur_ev->payload.i32[0]; + max_phyid = emu->cur_ev->payload.i32[1]; - assert(ncpus < OVNI_MAX_CPU); - assert(maxcpu < OVNI_MAX_CPU); + assert(max_ncpus < OVNI_MAX_CPU); + assert(max_phyid < OVNI_MAX_CPU); for(i=0; icpu[i].state = CPU_ST_UNKNOWN; - emu->cpu[i].cpu_id = -1; - emu->cpuind[i] = -1; + emu->cpu[i].i = -1; + emu->cpu[i].phyid = -1; } emu->ncpus = 0; - emu->max_ncpus = ncpus; + emu->max_ncpus = max_ncpus; + emu->max_phyid = max_phyid; } static void ev_cpu_id(struct ovni_emu *emu) { - int cpuid; + int i, phyid; - cpuid = emu->cur_ev->payload.i32[0]; + i = emu->cur_ev->payload.i32[0]; + phyid = emu->cur_ev->payload.i32[1]; - assert(cpuid < emu->max_ncpus); - assert(emu->ncpus < emu->max_ncpus); - assert(emu->ncpus < OVNI_MAX_CPU); + /* The logical id must match our index */ + assert(i == emu->ncpus); - assert(emu->cpu[emu->ncpus].state == CPU_ST_UNKNOWN); + assert(0 <= phyid && phyid <= emu->max_phyid); + + assert(emu->cpu[i].state == CPU_ST_UNKNOWN); emu->cpu[emu->ncpus].state = CPU_ST_READY; - emu->cpu[emu->ncpus].cpu_id = cpuid; - emu->cpu[emu->ncpus].index = emu->ncpus; + emu->cpu[emu->ncpus].i = i; + emu->cpu[emu->ncpus].phyid = phyid; - /* Fill the translation to cpu index too */ - assert(emu->cpuind[cpuid] == -1); - emu->cpuind[cpuid] = emu->ncpus; - - dbg("new cpu id=%d at %d\n", cpuid, emu->ncpus); + dbg("new cpu %d at phyid=%d\n", i, phyid); emu->ncpus++; } diff --git a/prv.c b/prv.c index 8232eae..f50ab40 100644 --- a/prv.c +++ b/prv.c @@ -22,11 +22,10 @@ prv_ev_autocpu(struct ovni_emu *emu, int type, int val) cpu = emu->cur_thread->cpu; assert(cpu); - assert(cpu->index >= 0); - assert(cpu->cpu_id >= 0); + assert(cpu->i >= 0); /* Begin at 1 */ - row = cpu->index + 1; + row = cpu->i + 1; prv_ev_row(emu, row, type, val); }