]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
perf mem: Add 'cache' and 'memory' output fields
authorNamhyung Kim <namhyung@kernel.org>
Wed, 30 Apr 2025 20:55:46 +0000 (13:55 -0700)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Fri, 2 May 2025 18:36:14 +0000 (15:36 -0300)
This is a breakdown of perf_mem_data_src.mem_lvl_num.  But it's also
divided into two parts because the combination is bigger than 8.

Since there are many entries for different cache levels, 'cache' field
focuses on them.  I generalized buffers like LFB, MAB and MHB to L1-buf
and L2-buf.

The rest goes to 'memory' field which can be RAM, CXL, PMEM, IO, etc.

  $ perf mem report -F cache,mem,dso --stdio
  ...
  #
  # -------------- Cache --------------  --- Memory ---
  #      L1     L2     L3 L1-buf  Other      RAM  Other  Shared Object
  # ...................................  ..............  ....................................
  #
      53.9%   3.6%  16.2%  21.6%   4.8%     4.8%  95.2%  [kernel.kallsyms]
      64.7%   1.7%   3.5%  17.4%  12.8%    12.8%  87.2%  chrome (deleted)
      78.3%   2.8%   0.0%   1.0%  17.9%    17.9%  82.1%  libc.so.6
      39.6%   1.5%   0.0%   5.7%  53.2%    53.2%  46.8%  libxul.so
      26.2%   0.0%   0.0%   0.0%  73.8%    73.8%  26.2%  [unknown]
      85.5%   0.0%   0.0%  14.5%   0.0%     0.0% 100.0%  libspa-audioconvert.so
      66.3%   4.4%   0.0%  29.4%   0.0%     0.0% 100.0%  libglib-2.0.so.0.8200.1 (deleted)
       1.9%   0.0%   0.0%   0.0%  98.1%    98.1%   1.9%  libmutter-cogl-15.so.0.0.0 (deleted)
      10.6%   0.0%   0.0%  89.4%   0.0%     0.0% 100.0%  libpulsecommon-16.1.so
       0.0%   0.0%   0.0% 100.0%   0.0%     0.0% 100.0%  libfreeblpriv3.so (deleted)
       ...

Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Leo Yan <leo.yan@arm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ravi Bangoria <ravi.bangoria@amd.com>
Link: https://lore.kernel.org/r/20250430205548.789750-10-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/ui/browsers/hists.c
tools/perf/ui/hist.c
tools/perf/util/hist.h
tools/perf/util/mem-events.c
tools/perf/util/mem-events.h
tools/perf/util/sort.c

index 66a4c769b2d7643693c5fc37bce6b0be70ec9671..675dd64067747126f9de6a4790d2b5bb8b7cef96 100644 (file)
@@ -1285,6 +1285,8 @@ __HPP_COLOR_PERCENT_FN(overhead_guest_us, period_guest_us, PERF_HPP_FMT_TYPE__PE
 __HPP_COLOR_ACC_PERCENT_FN(overhead_acc, period, PERF_HPP_FMT_TYPE__PERCENT)
 __HPP_COLOR_ACC_PERCENT_FN(latency_acc, latency, PERF_HPP_FMT_TYPE__LATENCY)
 __HPP_COLOR_MEM_STAT_FN(op, OP)
+__HPP_COLOR_MEM_STAT_FN(cache, CACHE)
+__HPP_COLOR_MEM_STAT_FN(memory, MEMORY)
 
 #undef __HPP_COLOR_PERCENT_FN
 #undef __HPP_COLOR_ACC_PERCENT_FN
@@ -1310,6 +1312,10 @@ void hist_browser__init_hpp(void)
                                hist_browser__hpp_color_latency_acc;
        perf_hpp__format[PERF_HPP__MEM_STAT_OP].color =
                                hist_browser__hpp_color_mem_stat_op;
+       perf_hpp__format[PERF_HPP__MEM_STAT_CACHE].color =
+                               hist_browser__hpp_color_mem_stat_cache;
+       perf_hpp__format[PERF_HPP__MEM_STAT_MEMORY].color =
+                               hist_browser__hpp_color_mem_stat_memory;
 
        res_sample_init();
 }
index 661922c4d786322442812448290fbc1f16e516f3..7fc09c738ed02acb54c17677aa803a78642a0116 100644 (file)
@@ -348,6 +348,10 @@ static enum mem_stat_type hpp__mem_stat_type(struct perf_hpp_fmt *fmt)
        switch (fmt->idx) {
        case PERF_HPP__MEM_STAT_OP:
                return PERF_MEM_STAT_OP;
+       case PERF_HPP__MEM_STAT_CACHE:
+               return PERF_MEM_STAT_CACHE;
+       case PERF_HPP__MEM_STAT_MEMORY:
+               return PERF_MEM_STAT_MEMORY;
        default:
                break;
        }
@@ -644,6 +648,8 @@ HPP_AVERAGE_FNS(weight2, weight2)
 HPP_AVERAGE_FNS(weight3, weight3)
 
 HPP_MEM_STAT_FNS(op, OP)
+HPP_MEM_STAT_FNS(cache, CACHE)
+HPP_MEM_STAT_FNS(memory, MEMORY)
 
 static int64_t hpp__nop_cmp(struct perf_hpp_fmt *fmt __maybe_unused,
                            struct hist_entry *a __maybe_unused,
@@ -748,6 +754,8 @@ struct perf_hpp_fmt perf_hpp__format[] = {
        HPP__PRINT_FNS("Weight2", weight2, WEIGHT2),
        HPP__PRINT_FNS("Weight3", weight3, WEIGHT3),
        HPP__MEM_STAT_PRINT_FNS("Mem Op", op, OP),
+       HPP__MEM_STAT_PRINT_FNS("Cache", cache, CACHE),
+       HPP__MEM_STAT_PRINT_FNS("Memory", memory, MEMORY),
 };
 
 struct perf_hpp_list perf_hpp_list = {
@@ -1103,6 +1111,8 @@ void perf_hpp__reset_width(struct perf_hpp_fmt *fmt, struct hists *hists)
                break;
 
        case PERF_HPP__MEM_STAT_OP:
+       case PERF_HPP__MEM_STAT_CACHE:
+       case PERF_HPP__MEM_STAT_MEMORY:
                fmt->len = MEM_STAT_LEN * MEM_STAT_PRINT_LEN;
                break;
 
index fa5e886e5b04ec9b46fa1e4704648ea42af7719f..9de50d929ad1268c0893a2ce070919dd4afc8a86 100644 (file)
@@ -589,6 +589,8 @@ enum {
        PERF_HPP__WEIGHT2,
        PERF_HPP__WEIGHT3,
        PERF_HPP__MEM_STAT_OP,
+       PERF_HPP__MEM_STAT_CACHE,
+       PERF_HPP__MEM_STAT_MEMORY,
 
        PERF_HPP__MAX_INDEX
 };
index 1c44ccc026fe997488353fd2f2c2885ac469c1df..6822815278a4b2135de4c2b3db352f2152388c00 100644 (file)
@@ -823,6 +823,40 @@ int mem_stat_index(const enum mem_stat_type mst, const u64 val)
                                return MEM_STAT_OP_EXEC;
                        return MEM_STAT_OP_OTHER;
                }
+       case PERF_MEM_STAT_CACHE:
+               switch (src.mem_lvl_num) {
+               case PERF_MEM_LVLNUM_L1:
+                       return MEM_STAT_CACHE_L1;
+               case PERF_MEM_LVLNUM_L2:
+                       return MEM_STAT_CACHE_L2;
+               case PERF_MEM_LVLNUM_L3:
+                       return MEM_STAT_CACHE_L3;
+               case PERF_MEM_LVLNUM_L4:
+                       return MEM_STAT_CACHE_L4;
+               case PERF_MEM_LVLNUM_LFB:
+                       return MEM_STAT_CACHE_L1_BUF;
+               case PERF_MEM_LVLNUM_L2_MHB:
+                       return MEM_STAT_CACHE_L2_BUF;
+               default:
+                       return MEM_STAT_CACHE_OTHER;
+               }
+       case PERF_MEM_STAT_MEMORY:
+               switch (src.mem_lvl_num) {
+               case PERF_MEM_LVLNUM_MSC:
+                       return MEM_STAT_MEMORY_MSC;
+               case PERF_MEM_LVLNUM_RAM:
+                       return MEM_STAT_MEMORY_RAM;
+               case PERF_MEM_LVLNUM_UNC:
+                       return MEM_STAT_MEMORY_UNC;
+               case PERF_MEM_LVLNUM_CXL:
+                       return MEM_STAT_MEMORY_CXL;
+               case PERF_MEM_LVLNUM_IO:
+                       return MEM_STAT_MEMORY_IO;
+               case PERF_MEM_LVLNUM_PMEM:
+                       return MEM_STAT_MEMORY_PMEM;
+               default:
+                       return MEM_STAT_MEMORY_OTHER;
+               }
        default:
                break;
        }
@@ -846,9 +880,44 @@ const char *mem_stat_name(const enum mem_stat_type mst, const int idx)
                case MEM_STAT_OP_EXEC:
                        return "Exec";
                case MEM_STAT_OP_OTHER:
+               default:
+                       return "Other";
+               }
+       case PERF_MEM_STAT_CACHE:
+               switch (idx) {
+               case MEM_STAT_CACHE_L1:
+                       return "L1";
+               case MEM_STAT_CACHE_L2:
+                       return "L2";
+               case MEM_STAT_CACHE_L3:
+                       return "L3";
+               case MEM_STAT_CACHE_L4:
+                       return "L4";
+               case MEM_STAT_CACHE_L1_BUF:
+                       return "L1-buf";
+               case MEM_STAT_CACHE_L2_BUF:
+                       return "L2-buf";
+               case MEM_STAT_CACHE_OTHER:
+               default:
                        return "Other";
+               }
+       case PERF_MEM_STAT_MEMORY:
+               switch (idx) {
+               case MEM_STAT_MEMORY_RAM:
+                       return "RAM";
+               case MEM_STAT_MEMORY_MSC:
+                       return "MSC";
+               case MEM_STAT_MEMORY_UNC:
+                       return "Uncach";
+               case MEM_STAT_MEMORY_CXL:
+                       return "CXL";
+               case MEM_STAT_MEMORY_IO:
+                       return "IO";
+               case MEM_STAT_MEMORY_PMEM:
+                       return "PMEM";
+               case MEM_STAT_MEMORY_OTHER:
                default:
-                       break;
+                       return "Other";
                }
        default:
                break;
index 55e5e2607fb732b47182338828363d7b8f7b6fcc..002e2772400e3ddaf3dfdcd5ecaf1a8421dae2a7 100644 (file)
@@ -91,8 +91,12 @@ void c2c_add_stats(struct c2c_stats *stats, struct c2c_stats *add);
 
 enum mem_stat_type {
        PERF_MEM_STAT_OP,
+       PERF_MEM_STAT_CACHE,
+       PERF_MEM_STAT_MEMORY,
 };
 
+#define MEM_STAT_PRINT_LEN  7  /* 1 space + 5 digits + 1 percent sign */
+
 enum mem_stat_op {
        MEM_STAT_OP_LOAD,
        MEM_STAT_OP_STORE,
@@ -102,7 +106,25 @@ enum mem_stat_op {
        MEM_STAT_OP_OTHER,
 };
 
-#define MEM_STAT_PRINT_LEN  7  /* 1 space + 5 digits + 1 percent sign */
+enum mem_stat_cache {
+       MEM_STAT_CACHE_L1,
+       MEM_STAT_CACHE_L2,
+       MEM_STAT_CACHE_L3,
+       MEM_STAT_CACHE_L4,
+       MEM_STAT_CACHE_L1_BUF,
+       MEM_STAT_CACHE_L2_BUF,
+       MEM_STAT_CACHE_OTHER,
+};
+
+enum mem_stat_memory {
+       MEM_STAT_MEMORY_RAM,
+       MEM_STAT_MEMORY_MSC,
+       MEM_STAT_MEMORY_UNC,
+       MEM_STAT_MEMORY_CXL,
+       MEM_STAT_MEMORY_IO,
+       MEM_STAT_MEMORY_PMEM,
+       MEM_STAT_MEMORY_OTHER,
+};
 
 int mem_stat_index(const enum mem_stat_type mst, const u64 data_src);
 const char *mem_stat_name(const enum mem_stat_type mst, const int idx);
index 53fcb9191ea0cdc3220c472281c82199bc428964..2ad88f7de95a224759cfbe68adb7e4f0972d579f 100644 (file)
@@ -2624,6 +2624,8 @@ static struct hpp_dimension hpp_sort_dimensions[] = {
        DIM(PERF_HPP__WEIGHT3, "p_stage_cyc"),
        /* used for output only when SORT_MODE__MEM */
        DIM_MEM(PERF_HPP__MEM_STAT_OP, "op"),
+       DIM_MEM(PERF_HPP__MEM_STAT_CACHE, "cache"),
+       DIM_MEM(PERF_HPP__MEM_STAT_MEMORY, "memory"),
 };
 
 #undef DIM_MEM