From 0134ceee9de2b46aa4eac6cde101f71fba3cfbbc Mon Sep 17 00:00:00 2001 From: Rodrigo Arias Date: Wed, 8 Mar 2023 18:11:56 +0100 Subject: [PATCH] Write .pcf and .row files for the breakdown --- src/emu/nanos6/breakdown.c | 55 +++++++++++++++++++++++++++++++++++- src/emu/nanos6/breakdown.h | 1 + src/emu/nanos6/nanos6_priv.h | 3 ++ src/emu/nanos6/setup.c | 5 ++++ 4 files changed, 63 insertions(+), 1 deletion(-) diff --git a/src/emu/nanos6/breakdown.c b/src/emu/nanos6/breakdown.c index 7151465..f90846c 100644 --- a/src/emu/nanos6/breakdown.c +++ b/src/emu/nanos6/breakdown.c @@ -38,7 +38,8 @@ model_nanos6_breakdown_create(struct emu *emu) /* Count phy cpus */ struct system *sys = &emu->system; - int nphycpus = sys->ncpus - sys->nlooms; + int64_t nphycpus = sys->ncpus - sys->nlooms; + bemu->nphycpus = nphycpus; /* Create a new Paraver trace */ struct recorder *rec = &emu->recorder; @@ -211,3 +212,55 @@ model_nanos6_breakdown_connect(struct emu *emu) return 0; } + +int +model_nanos6_breakdown_finish(struct emu *emu, + const struct pcf_value_label (**labels)[]) +{ + if (emu->args.breakdown == 0) + return 0; + + struct nanos6_emu *memu = EXT(emu, '6'); + struct breakdown_emu *bemu = &memu->brk; + struct pcf *pcf = pvt_get_pcf(bemu->pvt); + long typeid = PRV_NANOS6_BREAKDOWN; + char label[] = "CPU: Nanos6 Runtime/Idle/Task breakdown"; + struct pcf_type *pcftype = pcf_add_type(pcf, typeid, label); + const struct pcf_value_label *v = NULL; + + /* Emit subsystem values */ + for (v = *labels[CH_SUBSYSTEM]; v->label; v++) + pcf_add_value(pcftype, v->value, v->label); + + /* Emit idle values */ + for (v = *labels[CH_IDLE]; v->label; v++) + pcf_add_value(pcftype, v->value, v->label); + + /* Emit task_type values */ + struct system *sys = &emu->system; + for (struct proc *p = sys->procs; p; p = p->gnext) { + struct nanos6_proc *proc = EXT(p, '6'); + struct task_info *info = &proc->task_info; + if (task_create_pcf_types(pcftype, info->types) != 0) { + err("task_create_pcf_types failed"); + return -1; + } + } + + /* Also populate the row labels */ + struct prf *prf = pvt_get_prf(bemu->pvt); + for (int64_t row = 0; row < bemu->nphycpus; row++) { + char name[128]; + if (snprintf(name, 128, "~CPU %3ld", bemu->nphycpus - row) >= 128) { + err("label too long"); + return -1; + } + + if (prf_add(prf, row, name) != 0) { + err("prf_add failed for %s", name); + return -1; + } + } + + return 0; +} diff --git a/src/emu/nanos6/breakdown.h b/src/emu/nanos6/breakdown.h index 038c5c5..7458467 100644 --- a/src/emu/nanos6/breakdown.h +++ b/src/emu/nanos6/breakdown.h @@ -45,6 +45,7 @@ struct breakdown_cpu { }; struct breakdown_emu { + int64_t nphycpus; struct sort sort; struct pvt *pvt; }; diff --git a/src/emu/nanos6/nanos6_priv.h b/src/emu/nanos6/nanos6_priv.h index 620474d..1b12a47 100644 --- a/src/emu/nanos6/nanos6_priv.h +++ b/src/emu/nanos6/nanos6_priv.h @@ -10,6 +10,7 @@ #include "model_cpu.h" #include "model_thread.h" #include "breakdown.h" +#include "pv/pcf.h" /* Private enums */ @@ -96,5 +97,7 @@ int model_nanos6_finish(struct emu *emu); int model_nanos6_breakdown_create(struct emu *emu); int model_nanos6_breakdown_connect(struct emu *emu); +int model_nanos6_breakdown_finish(struct emu *emu, + const struct pcf_value_label (**labels)[]); #endif /* NANOS6_PRIV_H */ diff --git a/src/emu/nanos6/setup.c b/src/emu/nanos6/setup.c index 70b5bac..e76e7bd 100644 --- a/src/emu/nanos6/setup.c +++ b/src/emu/nanos6/setup.c @@ -393,6 +393,11 @@ model_nanos6_finish(struct emu *emu) return -1; } + if (model_nanos6_breakdown_finish(emu, pcf_labels) != 0) { + err("model_nanos6_breakdown_finish failed"); + return -1; + } + /* When running in linter mode perform additional checks */ if (emu->args.linter_mode && end_lint(emu) != 0) { err("end_lint failed");