From: Karel Zak Date: Fri, 14 Aug 2020 10:07:18 +0000 (+0200) Subject: lscpu: hide all to lscpu_read_topology() X-Git-Tag: v2.37-rc1~345 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=2075eb60b5895688bb51452b08a67a64a6eeb5fa;p=thirdparty%2Futil-linux.git lscpu: hide all to lscpu_read_topology() Signed-off-by: Karel Zak --- diff --git a/sys-utils/lscpu-api.h b/sys-utils/lscpu-api.h index b3067dadd2..61932cb008 100644 --- a/sys-utils/lscpu-api.h +++ b/sys-utils/lscpu-api.h @@ -199,8 +199,6 @@ int lscpu_read_vulnerabilities(struct lscpu_cxt *cxt); 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 cd2aa775f3..ac96d7f1d0 100644 --- a/sys-utils/lscpu-cputype.c +++ b/sys-utils/lscpu-cputype.c @@ -872,8 +872,6 @@ int main(int argc, char **argv) lscpu_read_vulnerabilities(cxt); 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 3d12a7e783..036e1440c7 100644 --- a/sys-utils/lscpu-topology.c +++ b/sys-utils/lscpu-topology.c @@ -184,79 +184,75 @@ static int cputype_read_topology(struct lscpu_cxt *cxt, struct lscpu_cputype *ct return 0; } -int lscpu_read_topology(struct lscpu_cxt *cxt) +static int read_ids(struct lscpu_cxt *cxt, struct lscpu_cpu *cpu) { - size_t i; - int rc = 0; + struct path_cxt *sys = cxt->syscpu; + int num = cpu->logical_id; - for (i = 0; i < cxt->ncputypes; i++) - rc += cputype_read_topology(cxt, cxt->cputypes[i]); + if (ul_path_accessf(sys, F_OK, "cpu%d/topology", num) != 0) + return 0; - return rc; + DBG(CPU, ul_debugobj(cpu, "#%d reading IDs", num)); + + if (ul_path_readf_s32(sys, &cpu->coreid, "cpu%d/topology/core_id", num) != 0) + cpu->coreid = -1; + if (ul_path_readf_s32(sys, &cpu->socketid, "cpu%d/topology/physical_package_id", num) != 0) + cpu->socketid = -1; + if (ul_path_readf_s32(sys, &cpu->bookid, "cpu%d/topology/book_id", num) != 0) + cpu->bookid = -1; + if (ul_path_readf_s32(sys, &cpu->drawerid, "cpu%d/topology/drawer_id", num) != 0) + cpu->drawerid = -1; + + return 0; } -int lscpu_read_topology_ids(struct lscpu_cxt *cxt) +static int read_polarization(struct lscpu_cxt *cxt, struct lscpu_cpu *cpu) { struct path_cxt *sys = cxt->syscpu; - size_t i; - - for (i = 0; i < cxt->npossibles; i++) { - struct lscpu_cpu *cpu = cxt->cpus[i]; - int num; + int num = cpu->logical_id; + char mode[64]; - if (!cpu) - continue; + if (ul_path_accessf(sys, F_OK, "cpu%d/polarization", num) != 0) + return 0; - num = cpu->logical_id; - if (ul_path_accessf(sys, F_OK, "cpu%d/topology", num) != 0) - continue; + ul_path_readf_buffer(sys, mode, sizeof(mode), "cpu%d/polarization", num); - DBG(CPU, ul_debugobj(cpu, "#%d reading IDs", num)); + DBG(CPU, ul_debugobj(cpu, "#%d polar=%s", num, mode)); - if (ul_path_readf_s32(sys, &cpu->coreid, "cpu%d/topology/core_id", num) != 0) - cpu->coreid = -1; - if (ul_path_readf_s32(sys, &cpu->socketid, "cpu%d/topology/physical_package_id", num) != 0) - cpu->socketid = -1; - if (ul_path_readf_s32(sys, &cpu->bookid, "cpu%d/topology/book_id", num) != 0) - cpu->bookid = -1; - if (ul_path_readf_s32(sys, &cpu->drawerid, "cpu%d/topology/drawer_id", num) != 0) - cpu->drawerid = -1; - } + 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; } -int lscpu_read_topology_polarization(struct lscpu_cxt *cxt) +int lscpu_read_topology(struct lscpu_cxt *cxt) { - struct path_cxt *sys = cxt->syscpu; size_t i; + int rc = 0; + + for (i = 0; i < cxt->ncputypes; i++) + rc += cputype_read_topology(cxt, cxt->cputypes[i]); - for (i = 0; i < cxt->npossibles; i++) { + for (i = 0; rc == 0 && i < cxt->npossibles; i++) { struct lscpu_cpu *cpu = cxt->cpus[i]; - int num; - char mode[64]; - if (!cpu || !cpu->type || cpu->type->dispatching < 0) + if (!cpu || !cpu->type) continue; - num = cpu->logical_id; - if (ul_path_accessf(sys, F_OK, "cpu%d/polarization", num) != 0) - continue; + rc = read_ids(cxt, cpu); + if (rc == 0) + read_polarization(cxt, cpu); + } - ul_path_readf_buffer(sys, mode, sizeof(mode), "cpu%d/polarization", num); + return rc; +} - 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; -}