From: Karel Zak Date: Thu, 16 Jul 2020 10:41:35 +0000 (+0200) Subject: lsblk: add lscpu_read_topology_polarization() X-Git-Tag: v2.37-rc1~355 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=fd35a1dae62f5232cab5fba5bbe1fbef5a92d777;p=thirdparty%2Futil-linux.git lsblk: add lscpu_read_topology_polarization() Signed-off-by: Karel Zak --- diff --git a/sys-utils/lscpu-api.h b/sys-utils/lscpu-api.h index 2cfff7e349..614512f420 100644 --- a/sys-utils/lscpu-api.h +++ b/sys-utils/lscpu-api.h @@ -46,10 +46,9 @@ struct lscpu_cputype { char *flags; char *mtid; /* maximum thread id (s390) */ char *addrsz; /* address sizes */ - int dispatching; /* none, horizontal or vertical */ + int dispatching; /* -1 if not evailable, DIST_* */ int freqboost; /* -1 if not evailable */ - int *polarization; /* cpu polarization */ int *addresses; /* physical cpu addresses */ int *configured; /* cpu configured */ int physsockets; /* Physical sockets (modules) */ @@ -69,6 +68,21 @@ struct lscpu_cputype { cpu_set_t **drawermaps; }; +/* dispatching modes */ +enum { + DISP_HORIZONTAL = 0, + DISP_VERTICAL = 1 +}; + +/* cpu polarization */ +enum { + POLAR_UNKNOWN = 0, + POLAR_VLOW, + POLAR_VMEDIUM, + POLAR_VHIGH, + POLAR_HORIZONTAL +}; + struct lscpu_cpu { int refcount; struct lscpu_cputype *type; @@ -83,6 +97,9 @@ struct lscpu_cpu { int socketid; int bookid; int drawerid; + + int polarization; /* POLAR_* */ + }; struct lscpu_arch { @@ -193,6 +210,7 @@ int lscpu_read_numas(struct lscpu_cxt *cxt); int lscpu_read_topology(struct lscpu_cxt *cxt); int lscpu_read_topology_ids(struct lscpu_cxt *cxt); +int lscpu_read_topology_polarization(struct lscpu_cxt *cxt); void lscpu_cputype_free_topology(struct lscpu_cputype *ct); struct lscpu_arch *lscpu_read_architecture(struct lscpu_cxt *cxt); diff --git a/sys-utils/lscpu-cputype.c b/sys-utils/lscpu-cputype.c index 66cc904540..662b26ae7c 100644 --- a/sys-utils/lscpu-cputype.c +++ b/sys-utils/lscpu-cputype.c @@ -301,6 +301,8 @@ static int cpuinfo_parse_line( struct lscpu_cputype **ct, buf[v - p] = '\0'; v++; + fprintf(stderr, "key='%s', value='%s'\n", buf, v); + rtrim_whitespace((unsigned char *)buf); /* search in cpu-types patterns */ @@ -358,6 +360,7 @@ int lscpu_read_cpuinfo(struct lscpu_cxt *cxt) struct lscpu_cputype *type = NULL; struct lscpu_cpu *cpu = NULL; FILE *fp; + size_t ncpus = 0; char buf[BUFSIZ]; DBG(GATHER, ul_debugobj(cxt, "reading cpuinfo")); @@ -372,10 +375,11 @@ int lscpu_read_cpuinfo(struct lscpu_cxt *cxt) if (fgets(buf, sizeof(buf), fp) != NULL) p = skip_space(buf); - if (p == NULL || (*buf && !*p)) { - if (cpu) + if (p == NULL || (*buf && !*p)) { /* empty line */ + if (cpu) { lscpu_add_cpu(cxt, cpu, type); - else if (type) { + ncpus++; + } else if (type) { /* Generic non-cpu data. For some architectures * cpuinfo contains description block (at the * beginning of the file (IBM s390) or at the @@ -408,6 +412,9 @@ int lscpu_read_cpuinfo(struct lscpu_cxt *cxt) lscpu_unref_cpu(cpu); lscpu_unref_cputype(type); fclose(fp); + + DBG(GATHER, ul_debug("cpuinfo done: CPUs: %zu, types: %zu", + ncpus, cxt->ncputypes)); return 0; } @@ -815,6 +822,7 @@ int main(int argc, char **argv) lscpu_read_numas(cxt); lscpu_read_topology(cxt); lscpu_read_topology_ids(cxt); + lscpu_read_topology_polarization(cxt); lscpu_decode_arm(cxt); diff --git a/sys-utils/lscpu-topology.c b/sys-utils/lscpu-topology.c index 6094b96c1d..1923a13cf6 100644 --- a/sys-utils/lscpu-topology.c +++ b/sys-utils/lscpu-topology.c @@ -156,7 +156,6 @@ int lscpu_read_topology_ids(struct lscpu_cxt *cxt) struct path_cxt *sys = cxt->syscpu; size_t i; - for (i = 0; i < cxt->ncpus; i++) { struct lscpu_cpu *cpu = cxt->cpus[i]; int num = cpu->logical_id; @@ -175,3 +174,36 @@ int lscpu_read_topology_ids(struct lscpu_cxt *cxt) return 0; } + +int lscpu_read_topology_polarization(struct lscpu_cxt *cxt) +{ + struct path_cxt *sys = cxt->syscpu; + size_t i; + + for (i = 0; i < cxt->ncpus; i++) { + struct lscpu_cpu *cpu = cxt->cpus[i]; + int num = cpu->logical_id; + char mode[64]; + + if (!cpu->type || cpu->type->dispatching < 0) + continue; + if (ul_path_accessf(sys, F_OK, "cpu%d/polarization", num) != 0) + continue; + + ul_path_readf_buffer(sys, mode, sizeof(mode), "cpu%d/polarization", num); + + DBG(CPU, ul_debugobj(cpu, "#%d polar=%s", num, mode)); + + if (strncmp(mode, "vertical:low", sizeof(mode)) == 0) + cpu->polarization = POLAR_VLOW; + else if (strncmp(mode, "vertical:medium", sizeof(mode)) == 0) + cpu->polarization = POLAR_VMEDIUM; + else if (strncmp(mode, "vertical:high", sizeof(mode)) == 0) + cpu->polarization = POLAR_VHIGH; + else if (strncmp(mode, "horizontal", sizeof(mode)) == 0) + cpu->polarization = POLAR_HORIZONTAL; + else + cpu->polarization = POLAR_UNKNOWN; + } + return 0; +}