]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lscpu: add a new columns to --cache
authorKarel Zak <kzak@redhat.com>
Thu, 6 Jun 2019 12:05:26 +0000 (14:05 +0200)
committerKarel Zak <kzak@redhat.com>
Mon, 17 Jun 2019 13:46:10 +0000 (15:46 +0200)
References: https://www.kernel.org/doc/Documentation/ABI/testing/sysfs-devices-system-cpu
Signed-off-by: Karel Zak <kzak@redhat.com>
sys-utils/lscpu.c
sys-utils/lscpu.h

index 0e775805e6e24dcc027fd104f37313e6953b4098..7411994fad5ec3337baeb1df1f7fb9688f76633c 100644 (file)
@@ -178,6 +178,11 @@ enum {
        COL_CACHE_ONESIZE,
        COL_CACHE_TYPE,
        COL_CACHE_WAYS,
+       COL_CACHE_ALLOCPOL,
+       COL_CACHE_WRITEPOL,
+       COL_CACHE_PHYLINE,
+       COL_CACHE_SETS,
+       COL_CACHE_COHERENCYSIZE
 };
 
 
@@ -215,7 +220,12 @@ static struct lscpu_coldesc coldescs_cache[] =
        [COL_CACHE_NAME]       = { "NAME", N_("cache name") },
        [COL_CACHE_ONESIZE]    = { "ONE-SIZE", N_("size of one cache"), SCOLS_FL_RIGHT },
        [COL_CACHE_TYPE]       = { "TYPE", N_("cache type") },
-       [COL_CACHE_WAYS]       = { "WAYS", N_("ways of associativity"), SCOLS_FL_RIGHT }
+       [COL_CACHE_WAYS]       = { "WAYS", N_("ways of associativity"), SCOLS_FL_RIGHT },
+       [COL_CACHE_ALLOCPOL]   = { "ALLOC-POLICY", N_("allocation policy") },
+       [COL_CACHE_WRITEPOL]   = { "WRITE-POLICY", N_("write policy") },
+       [COL_CACHE_PHYLINE]    = { "PHY-LINE", N_("number of physical cache line per cache t"), SCOLS_FL_RIGHT },
+       [COL_CACHE_SETS]       = { "SETS", N_("number of sets in the cache; set lines has the same cache index"), SCOLS_FL_RIGHT },
+       [COL_CACHE_COHERENCYSIZE] = { "COHERENCY-SIZE", N_("minimum amount of data in bytes transferred from memory to cache"), SCOLS_FL_RIGHT }
 };
 
 
@@ -1354,9 +1364,19 @@ read_cache(struct lscpu_desc *desc, int idx)
 
                        ca->name = xstrdup(buf);
 
-                       /* cache ways */
-                       ul_path_readf_s32(desc->syscpu, &ca->ways,
+                       ul_path_readf_u32(desc->syscpu, &ca->ways_of_associativity,
                                        "cpu%d/cache/index%d/ways_of_associativity", num, i);
+                       ul_path_readf_u32(desc->syscpu, &ca->physical_line_partition,
+                                       "cpu%d/cache/index%d/physical_line_partition", num, i);
+                       ul_path_readf_u32(desc->syscpu, &ca->number_of_sets,
+                                       "cpu%d/cache/index%d/number_of_sets", num, i);
+                       ul_path_readf_u32(desc->syscpu, &ca->coherency_line_size,
+                                       "cpu%d/cache/index%d/coherency_line_size", num, i);
+
+                       ul_path_readf_string(desc->syscpu, &ca->allocation_policy,
+                                       "cpu%d/cache/index%d/allocation_policy", num, i);
+                       ul_path_readf_string(desc->syscpu, &ca->write_policy,
+                                       "cpu%d/cache/index%d/write_policy", num, i);
 
                        /* cache size */
                        if (ul_path_readf_buffer(desc->syscpu, buf, sizeof(buf),
@@ -1682,9 +1702,10 @@ print_caches_readable(struct lscpu_desc *desc, int cols[], int ncols,
                                break;
                        }
                        case COL_CACHE_WAYS:
-                               if (ca->ways)
-                                       xasprintf(&data, "%d", ca->ways);
+                               if (ca->ways_of_associativity)
+                                       xasprintf(&data, "%u", ca->ways_of_associativity);
                                break;
+
                        case COL_CACHE_TYPE:
                                if (ca->type)
                                        data = xstrdup(ca->type);
@@ -1693,6 +1714,26 @@ print_caches_readable(struct lscpu_desc *desc, int cols[], int ncols,
                                if (ca->level)
                                        xasprintf(&data, "%d", ca->level);
                                break;
+                       case COL_CACHE_ALLOCPOL:
+                               if (ca->allocation_policy)
+                                       data = xstrdup(ca->allocation_policy);
+                               break;
+                       case COL_CACHE_WRITEPOL:
+                               if (ca->write_policy)
+                                       data = xstrdup(ca->write_policy);
+                               break;
+                       case COL_CACHE_PHYLINE:
+                               if (ca->physical_line_partition)
+                                       xasprintf(&data, "%u", ca->physical_line_partition);
+                               break;
+                       case COL_CACHE_SETS:
+                               if (ca->number_of_sets)
+                                       xasprintf(&data, "%u", ca->number_of_sets);
+                               break;
+                       case COL_CACHE_COHERENCYSIZE:
+                               if (ca->coherency_line_size)
+                                       xasprintf(&data, "%u", ca->coherency_line_size);
+                               break;
                        }
 
                        if (data && scols_line_refer_data(line, c, data))
@@ -2414,6 +2455,9 @@ int main(int argc, char *argv[])
                        columns[ncolumns++] = COL_CACHE_WAYS;
                        columns[ncolumns++] = COL_CACHE_TYPE;
                        columns[ncolumns++] = COL_CACHE_LEVEL;
+                       columns[ncolumns++] = COL_CACHE_SETS;
+                       columns[ncolumns++] = COL_CACHE_PHYLINE;
+                       columns[ncolumns++] = COL_CACHE_COHERENCYSIZE;
                }
                print_caches_readable(desc, columns, ncolumns, mod);
                break;
index 56c97e2e86c19e1da03ea0b64e4d44fa997cb371..5bbdb348e043fd512b3b0d4b9293a645e25156eb 100644 (file)
@@ -49,10 +49,17 @@ enum {
 struct cpu_cache {
        char            *name;
        char            *type;
+       char            *allocation_policy;
+       char            *write_policy;
+
        int             level;
-       int             ways;
        uint64_t        size;
 
+       unsigned int    ways_of_associativity;
+       unsigned int    physical_line_partition;
+       unsigned int    number_of_sets;
+       unsigned int    coherency_line_size;
+
        int             nsharedmaps;
        cpu_set_t       **sharedmaps;
 };