]> granicus.if.org Git - sysstat/commitdiff
mpstat: Display negative values if topology cannot be read
authorSebastien GODARD <sysstat@users.noreply.github.com>
Mon, 25 Nov 2019 07:37:44 +0000 (08:37 +0100)
committerSebastien GODARD <sysstat@users.noreply.github.com>
Mon, 25 Nov 2019 07:37:44 +0000 (08:37 +0100)
Display socket and core numbers as -1 if the topology couldn't be read.

Signed-off-by: Sebastien GODARD <sysstat@users.noreply.github.com>
mpstat.c
mpstat.h

index b5e240532679dbc2c6fc5770e86d347ee2d02545..b0033011d25daf1b9b6718f4a630a5644f86f87f 100644 (file)
--- a/mpstat.c
+++ b/mpstat.c
@@ -361,7 +361,7 @@ void read_topology(int nr_cpus, struct cpu_topology *cpu_topo)
        struct cpu_topology *cpu_topo_i;
        FILE *fp;
        char filename[MAX_PF_NAME];
-       int cpu;
+       int cpu, rc;
 
        /* Init system topology */
        memset(st_cpu_topology, 0, sizeof(struct cpu_topology) * nr_cpus);
@@ -375,8 +375,12 @@ void read_topology(int nr_cpus, struct cpu_topology *cpu_topo)
                filename[MAX_PF_NAME - 1] = '\0';
 
                if ((fp = fopen(filename, "r")) != NULL) {
-                       fscanf(fp, "%d", &cpu_topo_i->phys_package_id);
+                       rc = fscanf(fp, "%d", &cpu_topo_i->phys_package_id);
                        fclose(fp);
+
+                       if (rc < 1) {
+                               cpu_topo_i->phys_package_id = -1;
+                       }
                }
 
                /* Read current CPU's logical core id number */
@@ -384,8 +388,12 @@ void read_topology(int nr_cpus, struct cpu_topology *cpu_topo)
                filename[MAX_PF_NAME - 1] = '\0';
 
                if ((fp = fopen(filename, "r")) != NULL) {
-                       fscanf(fp, "%d", &cpu_topo_i->logical_core_id);
+                       rc = fscanf(fp, "%d", &cpu_topo_i->logical_core_id);
                        fclose(fp);
+
+                       if (rc < 1) {
+                               cpu_topo_i->logical_core_id = -1;
+                       }
                }
        }
 }
index 112174ad5d30b234ca1eeff46e296422fa8a3199..a20acfad06205fcec53b0893b6d231e0533bdf09 100644 (file)
--- a/mpstat.h
+++ b/mpstat.h
@@ -91,8 +91,8 @@ struct stats_irqcpu {
 };
 
 struct cpu_topology {
-       unsigned int phys_package_id;
-       unsigned int logical_core_id;
+       int phys_package_id;
+       int logical_core_id;
 };
 
 #define STATS_IRQCPU_SIZE      (sizeof(struct stats_irqcpu))