]> git.ipfire.org Git - thirdparty/util-linux.git/blobdiff - sys-utils/lscpu.c
libblkid: do not interpret NTFS as MBR
[thirdparty/util-linux.git] / sys-utils / lscpu.c
index c967837ff52016e1943777d74cc726898c702f66..4f1ab47e90380ad58ca56fd6a6fea57e43807f0e 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 }
 };
 
 
@@ -626,8 +636,10 @@ read_basicinfo(struct lscpu_desc *desc, struct lscpu_modifier *mod)
                read_physical_info_powerpc(desc);
 
        if ((fp = ul_path_fopen(desc->procfs, "r", "sysinfo"))) {
-               while (fgets(buf, sizeof(buf), fp) != NULL && !desc->machinetype)
-                       lookup(buf, "Type", &desc->machinetype);
+               while (fgets(buf, sizeof(buf), fp) != NULL) {
+                       if (lookup(buf, "Type", &desc->machinetype))
+                               break;
+               }
                fclose(fp);
        }
 
@@ -1352,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),
@@ -1680,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);
@@ -1691,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))
@@ -1778,10 +1821,12 @@ print_cpus_parsable(struct lscpu_desc *desc, int cols[], int ncols,
                int c;
                int cpu = real_cpu_num(desc, i);
 
-               if (!mod->offline && desc->online && !is_cpu_online(desc, cpu))
-                       continue;
-               if (!mod->online && desc->online && is_cpu_online(desc, cpu))
-                       continue;
+               if (desc->online) {
+                       if (!mod->offline && !is_cpu_online(desc, cpu))
+                               continue;
+                       if (!mod->online && is_cpu_online(desc, cpu))
+                               continue;
+               }
                if (desc->present && !is_cpu_present(desc, cpu))
                        continue;
                for (c = 0; c < ncols; c++) {
@@ -1835,10 +1880,12 @@ print_cpus_readable(struct lscpu_desc *desc, int cols[], int ncols,
                struct libscols_line *line;
                int cpu = real_cpu_num(desc, i);
 
-               if (!mod->offline && desc->online && !is_cpu_online(desc, cpu))
-                       continue;
-               if (!mod->online && desc->online && is_cpu_online(desc, cpu))
-                       continue;
+               if (desc->online) {
+                       if (!mod->offline && !is_cpu_online(desc, cpu))
+                               continue;
+                       if (!mod->online && is_cpu_online(desc, cpu))
+                               continue;
+               }
                if (desc->present && !is_cpu_present(desc, cpu))
                        continue;
 
@@ -1875,7 +1922,8 @@ static void __attribute__ ((__format__(printf, 3, 4)))
                err(EXIT_FAILURE, _("failed to allocate output line"));
 
        /* description column */
-       scols_line_set_data(ln, 0, txt);
+       if (txt && scols_line_set_data(ln, 0, txt))
+               err(EXIT_FAILURE, _("failed to add output data"));
 
        /* data column */
        va_start(args, fmt);
@@ -1925,6 +1973,8 @@ static int get_cache_full_size(struct lscpu_desc *desc,
        /* Correction for CPU threads */
        if (desc->nthreads > desc->ncores)
                nshares /= (desc->nthreads / desc->ncores);
+       if (nshares < 1)
+               nshares = 1;
 
        *res = (desc->ncores / nshares) * ca->size;
        return 0;
@@ -1954,7 +2004,7 @@ print_summary(struct lscpu_desc *desc, struct lscpu_modifier *mod)
        }
 
        if (scols_table_new_column(tb, "field", 0, 0) == NULL ||
-           scols_table_new_column(tb, "data", 0, SCOLS_FL_NOEXTREMES) == NULL)
+           scols_table_new_column(tb, "data", 0, SCOLS_FL_NOEXTREMES | SCOLS_FL_WRAP) == NULL)
                err(EXIT_FAILURE, _("failed to initialize output column"));
 
        add_summary_s(tb, _("Architecture:"), desc->arch);
@@ -2117,7 +2167,7 @@ print_summary(struct lscpu_desc *desc, struct lscpu_modifier *mod)
                                tmp = size_to_human_string(
                                        SIZE_SUFFIX_3LETTER | SIZE_SUFFIX_SPACE,
                                        sz);
-                       snprintf(buf, sizeof(buf), _("%s cache: "), ca->name);
+                       snprintf(buf, sizeof(buf), _("%s cache:"), ca->name);
                        add_summary_s(tb, buf, tmp);
                        free(tmp);
                }
@@ -2135,7 +2185,7 @@ print_summary(struct lscpu_desc *desc, struct lscpu_modifier *mod)
                                tmp = size_to_human_string(
                                        SIZE_SUFFIX_3LETTER | SIZE_SUFFIX_SPACE,
                                        ca->size);
-                       snprintf(buf, sizeof(buf), _("%s cache: "), ca->name);
+                       snprintf(buf, sizeof(buf), _("%s cache:"), ca->name);
                        add_summary_s(tb, buf, tmp);
                        free(tmp);
                }
@@ -2154,7 +2204,7 @@ print_summary(struct lscpu_desc *desc, struct lscpu_modifier *mod)
 
        if (desc->vuls) {
                for (i = 0; i < desc->nvuls; i++) {
-                       snprintf(buf, sizeof(buf), ("Vulnerability %s: "), desc->vuls[i].name);
+                       snprintf(buf, sizeof(buf), ("Vulnerability %s:"), desc->vuls[i].name);
                        add_summary_s(tb, buf, desc->vuls[i].text);
                }
        }
@@ -2246,7 +2296,7 @@ int main(int argc, char *argv[])
        setlocale(LC_ALL, "");
        bindtextdomain(PACKAGE, LOCALEDIR);
        textdomain(PACKAGE);
-       atexit(close_stdout);
+       close_stdout_atexit();
 
        while ((c = getopt_long(argc, argv, "aBbC::ce::hJp::s:xyV", longopts, NULL)) != -1) {
 
@@ -2280,8 +2330,6 @@ int main(int argc, char *argv[])
                        }
                        mod->mode = OUTPUT_CACHES;
                        break;
-               case 'h':
-                       usage();
                case 'J':
                        mod->json = 1;
                        break;
@@ -2308,12 +2356,14 @@ int main(int argc, char *argv[])
                case 'y':
                        mod->physical = 1;
                        break;
-               case 'V':
-                       printf(UTIL_LINUX_VERSION);
-                       return EXIT_SUCCESS;
                case OPT_OUTPUT_ALL:
                        all = 1;
                        break;
+
+               case 'h':
+                       usage();
+               case 'V':
+                       print_version(EXIT_SUCCESS);
                default:
                        errtryhelp(EXIT_FAILURE);
                }
@@ -2405,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;