aboutsummaryrefslogtreecommitdiffstats
path: root/sys-utils
diff options
context:
space:
mode:
authorKarel Zak <kzak@redhat.com>2020-07-15 16:25:15 +0200
committerKarel Zak <kzak@redhat.com>2020-11-13 09:19:02 +0100
commit314aa95fd51ffb2bc72ad64fe41f85d4b8f82386 (patch)
tree05f61d676085972fe45b7aeb4ee0cfddff46b501 /sys-utils
parent9d5f3b4873e0da8eb69ffe8fd02747a7ff9b9fc5 (diff)
downloadutil-linux-314aa95fd51ffb2bc72ad64fe41f85d4b8f82386.tar.gz
lscpu: add lscpu_read_topolgy_ids()
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'sys-utils')
-rw-r--r--sys-utils/lscpu-api.h1
-rw-r--r--sys-utils/lscpu-cpu.c25
-rw-r--r--sys-utils/lscpu-cputype.c11
3 files changed, 26 insertions, 11 deletions
diff --git a/sys-utils/lscpu-api.h b/sys-utils/lscpu-api.h
index a7883e03f6..e09ba65fd8 100644
--- a/sys-utils/lscpu-api.h
+++ b/sys-utils/lscpu-api.h
@@ -191,6 +191,7 @@ int lscpu_read_archext(struct lscpu_cxt *cxt);
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_topolgy_ids(struct lscpu_cxt *cxt);
struct lscpu_arch *lscpu_read_architecture(struct lscpu_cxt *cxt);
void lscpu_free_architecture(struct lscpu_arch *ar);
diff --git a/sys-utils/lscpu-cpu.c b/sys-utils/lscpu-cpu.c
index f31dcba4d5..78d9404f13 100644
--- a/sys-utils/lscpu-cpu.c
+++ b/sys-utils/lscpu-cpu.c
@@ -55,6 +55,7 @@ int lscpu_add_cpu(struct lscpu_cxt *cxt,
if (type) {
cpu->type = type;
lscpu_ref_cputype(type);
+ type->ncpus++;
}
return 0;
@@ -70,21 +71,33 @@ int lscpu_cpus_apply_type(struct lscpu_cxt *cxt, struct lscpu_cputype *type)
if (!cpu->type) {
cpu->type = type;
lscpu_ref_cputype(type);
+ type->ncpus++;
}
}
return 0;
}
-/* returns first CPU which represents the type */
-struct lscpu_cpu *lscpu_cpus_loopup_by_type(struct lscpu_cxt *cxt, struct lscpu_cputype *ct)
+
+int lscpu_read_topolgy_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];
-
- if (cpu->type == ct)
- return cpu;
+ int num = cpu->logical_id;
+
+ 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 NULL;
+
+ return 0;
}
+
+
diff --git a/sys-utils/lscpu-cputype.c b/sys-utils/lscpu-cputype.c
index cca7fb8981..88d391a8fa 100644
--- a/sys-utils/lscpu-cputype.c
+++ b/sys-utils/lscpu-cputype.c
@@ -213,15 +213,16 @@ static int cputype_read_topology(struct lscpu_cxt *cxt, struct lscpu_cputype *ct
for (i = 0; i < cxt->ncpus; i++) {
struct lscpu_cpu *cpu = cxt->cpus[i++];
- cpu_set_t *thread_siblings, *core_siblings;
- cpu_set_t *book_siblings, *drawer_siblings;
+ cpu_set_t *thread_siblings = NULL, *core_siblings = NULL;
+ cpu_set_t *book_siblings = NULL, *drawer_siblings = NULL;
int num;
if (cpu->type != ct)
continue;
num = cpu->logical_id;
- if (ul_path_accessf(sys, F_OK, "cpu%d/topology/thread_siblings", num) != 0)
+ if (ul_path_accessf(sys, F_OK,
+ "cpu%d/topology/thread_siblings", num) != 0)
continue;
/* read topology maps */
@@ -234,7 +235,6 @@ static int cputype_read_topology(struct lscpu_cxt *cxt, struct lscpu_cputype *ct
ul_path_readf_cpuset(sys, &drawer_siblings, cxt->maxcpus,
"cpu%d/topology/drawer_siblings", num);
-
/* Allocate arrays for topology maps.
*
* For each map we make sure that it can have up to ncpuspos
@@ -253,8 +253,8 @@ static int cputype_read_topology(struct lscpu_cxt *cxt, struct lscpu_cputype *ct
ct->drawermaps = xcalloc(npos, sizeof(cpu_set_t *));
/* add to topology maps */
- add_cpuset_to_array(ct->socketmaps, &ct->nsockets, core_siblings, setsize);
add_cpuset_to_array(ct->coremaps, &ct->ncores, thread_siblings, setsize);
+ add_cpuset_to_array(ct->socketmaps, &ct->nsockets, core_siblings, setsize);
if (book_siblings)
add_cpuset_to_array(ct->bookmaps, &ct->nbooks, book_siblings, setsize);
@@ -949,6 +949,7 @@ int main(int argc, char **argv)
lscpu_read_vulnerabilities(cxt);
lscpu_read_numas(cxt);
lscpu_read_topology(cxt);
+ lscpu_read_topolgy_ids(cxt);
lscpu_decode_arm(cxt);