lscpu: improve topology calculation

Let's make it more robust and readable. The sysinfo file on s390 may
contain zeros, so we need to check the values and fallback to data
from shared maps if necessary.

Signed-off-by: Karel Zak <kzak@redhat.com>
This commit is contained in:
Karel Zak 2020-11-03 09:46:45 +01:00
parent 6648a70eb2
commit 19ddc05e11
2 changed files with 11 additions and 21 deletions

View File

@ -102,7 +102,7 @@ static int cputype_read_topology(struct lscpu_cxt *cxt, struct lscpu_cputype *ct
DBG(TYPE, ul_debugobj(ct, "reading %s/%s/%s topology",
ct->vendor ?: "", ct->model ?: "", ct->modelname ?:""));
for (i = 0; i < npos; i++) {
for (i = 0; i < cxt->npossibles; i++) {
struct lscpu_cpu *cpu = cxt->cpus[i];
cpu_set_t *thread_siblings = NULL, *core_siblings = NULL;
cpu_set_t *book_siblings = NULL, *drawer_siblings = NULL;
@ -116,8 +116,6 @@ static int cputype_read_topology(struct lscpu_cxt *cxt, struct lscpu_cputype *ct
"cpu%d/topology/thread_siblings", num) != 0)
continue;
/*DBG(TYPE, ul_debugobj(ct, " #%d", num));*/
/* read topology maps */
ul_path_readf_cpuset(sys, &thread_siblings, cxt->maxcpus,
"cpu%d/topology/thread_siblings", num);
@ -192,22 +190,13 @@ static int cputype_read_topology(struct lscpu_cxt *cxt, struct lscpu_cputype *ct
fclose(fd);
}
if (ct->mtid)
ct->nthreads_per_core = atoi(ct->mtid) + 1;
else
ct->nthreads_per_core = nthreads;
ct->nthreads_per_core = ct->mtid ? atoi(ct->mtid) + 1 : nthreads;
if (!sw_topo) {
ct->ndrawers_per_system = ct->nbooks_per_drawer =
ct->nsockets_per_book = ct->ncores_per_socket = 0;
if (!ct->ncores_per_socket && ct->nsockets)
ct->ncores_per_socket = ct->ncores / ct->nsockets;
if (!ct->nsockets_per_book && ct->nbooks)
ct->nsockets_per_book = ct->nsockets / ct->nbooks;
if (!ct->nbooks_per_drawer && ct->ndrawers)
ct->nbooks_per_drawer = ct->nbooks / ct->ndrawers;
if (ct->ndrawers_per_system)
ct->ndrawers_per_system = ct->ndrawers;
ct->ncores_per_socket = ct->nsockets ? ct->ncores / ct->nsockets : 0;
ct->nsockets_per_book = ct->nbooks ? ct->nsockets / ct->nbooks : 0;
ct->nbooks_per_drawer = ct->ndrawers ? ct->nbooks / ct->ndrawers : 0;
ct->ndrawers_per_system = ct->ndrawers;
}
DBG(TYPE, ul_debugobj(ct, " nthreads: %zu (per core)", ct->nthreads_per_core));

View File

@ -832,15 +832,16 @@ print_summary_cputype(struct lscpu_cxt *cxt,
add_summary_n(tb, sec, _("Thread(s) per core:"), ct->nthreads_per_core);
add_summary_n(tb, sec, _("Core(s) per socket:"), ct->ncores_per_socket);
if (ct->nbooks) {
add_summary_n(tb, sec, _("Socket(s) per book:"), ct->nsockets_per_book);
if (ct->ndrawers_per_system) {
if (ct->ndrawers_per_system || ct->ndrawers) {
add_summary_n(tb, sec, _("Book(s) per drawer:"), ct->nbooks_per_drawer);
add_summary_n(tb, sec, _("Drawer(s):"), ct->ndrawers_per_system);
add_summary_n(tb, sec, _("Drawer(s):"), ct->ndrawers_per_system ?: ct->ndrawers);
} else
add_summary_n(tb, sec, _("Book(s):"), ct->nbooks);
add_summary_n(tb, sec, _("Book(s):"), ct->nbooks_per_drawer ?: ct->nbooks);
} else
add_summary_n(tb, sec, _("Socket(s):"), ct->nsockets);
add_summary_n(tb, sec, _("Socket(s):"), ct->nsockets_per_book ?: ct->nsockets);
if (ct->stepping)
add_summary_s(tb, sec, _("Stepping:"), ct->stepping);