Skip to content

Commit 52839e6

Browse files
Andi Kleenacmel
authored andcommitted
perf tools: Add support for printing new mem_info encodings
Add decoding for the new "lvlx" and "snoopx" meminfo fields added earlier to the kernel so that "perf mem report" and other tools can print it properly. v2: Merge with persistent memory patch. Switch to new bit encoding for each combination. v3: Switch to generic lvlnum field. Signed-off-by: Andi Kleen <ak@linux.intel.com> Acked-by: Peter Zijlstra <peterz@infradead.org> Cc: Jiri Olsa <jolsa@kernel.org> Link: http://lkml.kernel.org/r/20170816222156.19953-4-andi@firstfloor.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent 41d3d6d commit 52839e6

2 files changed

Lines changed: 68 additions & 5 deletions

File tree

‎tools/include/uapi/linux/perf_event.h‎

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -954,14 +954,20 @@ union perf_mem_data_src {
954954
mem_snoop:5, /* snoop mode */
955955
mem_lock:2, /* lock instr */
956956
mem_dtlb:7, /* tlb access */
957-
mem_rsvd:31;
957+
mem_lvl_num:4, /* memory hierarchy level number */
958+
mem_remote:1, /* remote */
959+
mem_snoopx:2, /* snoop mode, ext */
960+
mem_rsvd:24;
958961
};
959962
};
960963
#elif defined(__BIG_ENDIAN_BITFIELD)
961964
union perf_mem_data_src {
962965
__u64 val;
963966
struct {
964-
__u64 mem_rsvd:31,
967+
__u64 mem_rsvd:24,
968+
mem_snoopx:2, /* snoop mode, ext */
969+
mem_remote:1, /* remote */
970+
mem_lvl_num:4, /* memory hierarchy level number */
965971
mem_dtlb:7, /* tlb access */
966972
mem_lock:2, /* lock instr */
967973
mem_snoop:5, /* snoop mode */
@@ -998,6 +1004,22 @@ union perf_mem_data_src {
9981004
#define PERF_MEM_LVL_UNC 0x2000 /* Uncached memory */
9991005
#define PERF_MEM_LVL_SHIFT 5
10001006

1007+
#define PERF_MEM_REMOTE_REMOTE 0x01 /* Remote */
1008+
#define PERF_MEM_REMOTE_SHIFT 37
1009+
1010+
#define PERF_MEM_LVLNUM_L1 0x01 /* L1 */
1011+
#define PERF_MEM_LVLNUM_L2 0x02 /* L2 */
1012+
#define PERF_MEM_LVLNUM_L3 0x03 /* L3 */
1013+
#define PERF_MEM_LVLNUM_L4 0x04 /* L4 */
1014+
/* 5-0xa available */
1015+
#define PERF_MEM_LVLNUM_ANY_CACHE 0x0b /* Any cache */
1016+
#define PERF_MEM_LVLNUM_LFB 0x0c /* LFB */
1017+
#define PERF_MEM_LVLNUM_RAM 0x0d /* RAM */
1018+
#define PERF_MEM_LVLNUM_PMEM 0x0e /* PMEM */
1019+
#define PERF_MEM_LVLNUM_NA 0x0f /* N/A */
1020+
1021+
#define PERF_MEM_LVLNUM_SHIFT 33
1022+
10011023
/* snoop mode */
10021024
#define PERF_MEM_SNOOP_NA 0x01 /* not available */
10031025
#define PERF_MEM_SNOOP_NONE 0x02 /* no snoop */
@@ -1006,6 +1028,10 @@ union perf_mem_data_src {
10061028
#define PERF_MEM_SNOOP_HITM 0x10 /* snoop hit modified */
10071029
#define PERF_MEM_SNOOP_SHIFT 19
10081030

1031+
#define PERF_MEM_SNOOPX_FWD 0x01 /* forward */
1032+
/* 1 free */
1033+
#define PERF_MEM_SNOOPX_SHIFT 37
1034+
10091035
/* locked instruction */
10101036
#define PERF_MEM_LOCK_NA 0x01 /* not available */
10111037
#define PERF_MEM_LOCK_LOCKED 0x02 /* locked transaction */

‎tools/perf/util/mem-events.c‎

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,11 +166,20 @@ static const char * const mem_lvl[] = {
166166
"Uncached",
167167
};
168168

169+
static const char * const mem_lvlnum[] = {
170+
[PERF_MEM_LVLNUM_ANY_CACHE] = "Any cache",
171+
[PERF_MEM_LVLNUM_LFB] = "LFB",
172+
[PERF_MEM_LVLNUM_RAM] = "RAM",
173+
[PERF_MEM_LVLNUM_PMEM] = "PMEM",
174+
[PERF_MEM_LVLNUM_NA] = "N/A",
175+
};
176+
169177
int perf_mem__lvl_scnprintf(char *out, size_t sz, struct mem_info *mem_info)
170178
{
171179
size_t i, l = 0;
172180
u64 m = PERF_MEM_LVL_NA;
173181
u64 hit, miss;
182+
int printed;
174183

175184
if (mem_info)
176185
m = mem_info->data_src.mem_lvl;
@@ -184,17 +193,37 @@ int perf_mem__lvl_scnprintf(char *out, size_t sz, struct mem_info *mem_info)
184193
/* already taken care of */
185194
m &= ~(PERF_MEM_LVL_HIT|PERF_MEM_LVL_MISS);
186195

196+
197+
if (mem_info && mem_info->data_src.mem_remote) {
198+
strcat(out, "Remote ");
199+
l += 7;
200+
}
201+
202+
printed = 0;
187203
for (i = 0; m && i < ARRAY_SIZE(mem_lvl); i++, m >>= 1) {
188204
if (!(m & 0x1))
189205
continue;
190-
if (l) {
206+
if (printed++) {
191207
strcat(out, " or ");
192208
l += 4;
193209
}
194210
l += scnprintf(out + l, sz - l, mem_lvl[i]);
195211
}
196-
if (*out == '\0')
197-
l += scnprintf(out, sz - l, "N/A");
212+
213+
if (mem_info && mem_info->data_src.mem_lvl_num) {
214+
int lvl = mem_info->data_src.mem_lvl_num;
215+
if (printed++) {
216+
strcat(out, " or ");
217+
l += 4;
218+
}
219+
if (mem_lvlnum[lvl])
220+
l += scnprintf(out + l, sz - l, mem_lvlnum[lvl]);
221+
else
222+
l += scnprintf(out + l, sz - l, "L%d", lvl);
223+
}
224+
225+
if (l == 0)
226+
l += scnprintf(out + l, sz - l, "N/A");
198227
if (hit)
199228
l += scnprintf(out + l, sz - l, " hit");
200229
if (miss)
@@ -231,6 +260,14 @@ int perf_mem__snp_scnprintf(char *out, size_t sz, struct mem_info *mem_info)
231260
}
232261
l += scnprintf(out + l, sz - l, snoop_access[i]);
233262
}
263+
if (mem_info &&
264+
(mem_info->data_src.mem_snoopx & PERF_MEM_SNOOPX_FWD)) {
265+
if (l) {
266+
strcat(out, " or ");
267+
l += 4;
268+
}
269+
l += scnprintf(out + l, sz - l, "Fwd");
270+
}
234271

235272
if (*out == '\0')
236273
l += scnprintf(out, sz - l, "N/A");

0 commit comments

Comments
 (0)