]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lscpu: add physical cpu address to parseable output
authorHeiko Carstens <heiko.carstens@de.ibm.com>
Wed, 10 Aug 2011 08:34:34 +0000 (10:34 +0200)
committerHeiko Carstens <heiko.carstens@de.ibm.com>
Sun, 14 Aug 2011 15:34:39 +0000 (17:34 +0200)
Print also the physical cpu address for each logical cpu in parsable
output if selected and present via sysfs.

Signed-off-by: Heiko Carstens <heiko.carstens@de.ibm.com>
sys-utils/lscpu.1
sys-utils/lscpu.c

index f9b8fa443724691dd46650e49fa40729032db963..684059092aa008bc1829ce8f1f64bfcbc7cee468 100644 (file)
@@ -32,8 +32,9 @@ separate CPU cache columns. If no CPU caches are identified, then the cache
 columns are not printed at all.
 
 The \fIlist\fP argument is comma delimited list of the columns. Currently
-supported are CPU, Core, Node, Socket, Book, Cache and Polarization columns. If the
-\fIlist\fP argument is given then always all requested columns are printed in
+supported are CPU, Core, Node, Socket, Book, Cache, Polarization and Address
+columns.
+If the \fIlist\fP argument is given then always all requested columns are printed in
 the defined order. The Cache columns are separated by ':'.
 
 Note that the optional \fIlist\fP argument cannot be separated from the
index 65ff96ce12f64b56c757e54a7336291e7e337221..fb65d8e272bfc3135f35a2be5aa72ff438859c0b 100644 (file)
@@ -168,6 +168,7 @@ struct lscpu_desc {
        struct cpu_cache *caches;
 
        int             *polarization;  /* cpu polarization */
+       int             *addresses;     /* physical cpu addresses */
 };
 
 static size_t sysrootlen;
@@ -199,7 +200,8 @@ enum {
        COL_NODE,
        COL_BOOK,
        COL_CACHE,
-       COL_POLARIZATION
+       COL_POLARIZATION,
+       COL_ADDRESS
 };
 
 static const char *colnames[] =
@@ -210,7 +212,8 @@ static const char *colnames[] =
        [COL_NODE] = "Node",
        [COL_BOOK] = "Book",
        [COL_CACHE] = "Cache",
-       [COL_POLARIZATION] = "Polarization"
+       [COL_POLARIZATION] = "Polarization",
+       [COL_ADDRESS] = "Address"
 };
 
 
@@ -762,6 +765,16 @@ read_polarization(struct lscpu_desc *desc, int num)
                desc->polarization[num] = POLAR_UNKNOWN;
 }
 
+static void
+read_address(struct lscpu_desc *desc, int num)
+{
+       if (!path_exist(_PATH_SYS_CPU "/cpu%d/address", num))
+               return;
+       if (!desc->addresses)
+               desc->addresses = xcalloc(desc->ncpus, sizeof(int));
+       desc->addresses[num] = path_getnum(_PATH_SYS_CPU "/cpu%d/address", num);
+}
+
 static int
 cachecmp(const void *a, const void *b)
 {
@@ -916,6 +929,10 @@ print_parsable_cell(struct lscpu_desc *desc, int i, int col, int compatible)
                if (desc->polarization)
                        printf("%s", polar_modes[desc->polarization[i]]);
                break;
+       case COL_ADDRESS:
+               if (desc->addresses)
+                       printf("%d", desc->addresses[i]);
+               break;
        }
 }
 
@@ -1230,6 +1247,7 @@ int main(int argc, char *argv[])
                read_topology(desc, i);
                read_cache(desc, i);
                read_polarization(desc, i);
+               read_address(desc, i);
        }
 
        qsort(desc->caches, desc->ncaches, sizeof(struct cpu_cache), cachecmp);