]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lsblk: add lscpu_read_topology_polarization()
authorKarel Zak <kzak@redhat.com>
Thu, 16 Jul 2020 10:41:35 +0000 (12:41 +0200)
committerKarel Zak <kzak@redhat.com>
Fri, 13 Nov 2020 08:19:02 +0000 (09:19 +0100)
Signed-off-by: Karel Zak <kzak@redhat.com>
sys-utils/lscpu-api.h
sys-utils/lscpu-cputype.c
sys-utils/lscpu-topology.c

index 2cfff7e349d1dde2a693a8f4daab6aeba13ba6d3..614512f4205c134783f5ad7583abb2b744491644 100644 (file)
@@ -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);
index 66cc904540414f73ab686cd03db3038accff4e32..662b26ae7cb9cf269b2e0a4d10102b09664d324e 100644 (file)
@@ -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);
 
index 6094b96c1de8d58766dbbf2a0dc9349f163fc3a5..1923a13cf6b195f0893b3bcba86e09f4675f3783 100644 (file)
@@ -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;
+}