From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751389AbdFBUNS (ORCPT ); Fri, 2 Jun 2017 16:13:18 -0400 Received: from mga06.intel.com ([134.134.136.31]:35246 "EHLO mga06.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751277AbdFBUMu (ORCPT ); Fri, 2 Jun 2017 16:12:50 -0400 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.39,286,1493708400"; d="scan'208";a="94110302" From: Andi Kleen To: peterz@infradead.org, acme@kernel.org Cc: eranian@google.com, jolsa@kernel.org, linux-kernel@vger.kernel.org, Andi Kleen Subject: [PATCH 3/6] perf, tools: Add support for printing new mem_info encodings Date: Fri, 2 Jun 2017 13:12:30 -0700 Message-Id: <20170602201233.19490-3-andi@firstfloor.org> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170602201233.19490-1-andi@firstfloor.org> References: <20170602201233.19490-1-andi@firstfloor.org> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Andi Kleen Add decoding for the new lvlx and snoopx field meminfo field added earlier to the kernel so that "perf mem report" and other tools can print it properly. Signed-off-by: Andi Kleen --- tools/include/uapi/linux/perf_event.h | 19 ++++++++++++++-- tools/perf/util/mem-events.c | 41 ++++++++++++++++++++++++++++++++--- 2 files changed, 55 insertions(+), 5 deletions(-) diff --git a/tools/include/uapi/linux/perf_event.h b/tools/include/uapi/linux/perf_event.h index b1c0b187acfe..4b5deeada34b 100644 --- a/tools/include/uapi/linux/perf_event.h +++ b/tools/include/uapi/linux/perf_event.h @@ -931,14 +931,18 @@ union perf_mem_data_src { mem_snoop:5, /* snoop mode */ mem_lock:2, /* lock instr */ mem_dtlb:7, /* tlb access */ - mem_rsvd:31; + mem_lvlx:8, /* memory hierarchy level, ext */ + mem_snoopx:2, /* snoop mode, ext */ + mem_rsvd:21; }; }; #elif defined(__BIG_ENDIAN_BITFIELD) union perf_mem_data_src { __u64 val; struct { - __u64 mem_rsvd:31, + __u64 mem_rsvd:21, + mem_snoopx:2, /* snoop mode, ext */ + mem_lvlx:8, /* memory hierarchy level, ext */ mem_dtlb:7, /* tlb access */ mem_lock:2, /* lock instr */ mem_snoop:5, /* snoop mode */ @@ -975,6 +979,13 @@ union perf_mem_data_src { #define PERF_MEM_LVL_UNC 0x2000 /* Uncached memory */ #define PERF_MEM_LVL_SHIFT 5 +#define PERF_MEM_LVLX_REMOTE 0x01 /* Remote */ +#define PERF_MEM_LVLX_L4 0x02 /* L4 */ +#define PERF_MEM_LVLX_RAM 0x04 /* Ram */ +/* 5 free */ + +#define PERF_MEM_LVLX_SHIFT 33 + /* snoop mode */ #define PERF_MEM_SNOOP_NA 0x01 /* not available */ #define PERF_MEM_SNOOP_NONE 0x02 /* no snoop */ @@ -983,6 +994,10 @@ union perf_mem_data_src { #define PERF_MEM_SNOOP_HITM 0x10 /* snoop hit modified */ #define PERF_MEM_SNOOP_SHIFT 19 +#define PERF_MEM_SNOOPX_FWD 0x01 /* forward */ +/* 1 free */ +#define PERF_MEM_SNOOPX_SHIFT 41 + /* locked instruction */ #define PERF_MEM_LOCK_NA 0x01 /* not available */ #define PERF_MEM_LOCK_LOCKED 0x02 /* locked transaction */ diff --git a/tools/perf/util/mem-events.c b/tools/perf/util/mem-events.c index 06f5a3a4295c..0ebce5be5724 100644 --- a/tools/perf/util/mem-events.c +++ b/tools/perf/util/mem-events.c @@ -166,11 +166,18 @@ static const char * const mem_lvl[] = { "Uncached", }; +static const char * const mem_lvlx[] = { + NULL, + "L4", + "RAM", +}; + int perf_mem__lvl_scnprintf(char *out, size_t sz, struct mem_info *mem_info) { size_t i, l = 0; u64 m = PERF_MEM_LVL_NA; u64 hit, miss; + int printed; if (mem_info) m = mem_info->data_src.mem_lvl; @@ -184,17 +191,37 @@ int perf_mem__lvl_scnprintf(char *out, size_t sz, struct mem_info *mem_info) /* already taken care of */ m &= ~(PERF_MEM_LVL_HIT|PERF_MEM_LVL_MISS); + if (mem_info && + (mem_info->data_src.mem_lvlx & PERF_MEM_LVLX_REMOTE)) + l += scnprintf(out + l, sz - l, "Remote "); + + printed = 0; for (i = 0; m && i < ARRAY_SIZE(mem_lvl); i++, m >>= 1) { if (!(m & 0x1)) continue; - if (l) { + if (printed++) { strcat(out, " or "); l += 4; } l += scnprintf(out + l, sz - l, mem_lvl[i]); } - if (*out == '\0') - l += scnprintf(out, sz - l, "N/A"); + + m = 0; + if (mem_info) + m = mem_info->data_src.mem_lvlx; + + for (i = 0; m && i < ARRAY_SIZE(mem_lvlx); i++, m >>= 1) { + if (!(m & 0x1) || !mem_lvlx[i]) + continue; + if (printed++) { + strcat(out, " or "); + l += 4; + } + l += scnprintf(out + l, sz - l, mem_lvlx[i]); + } + + if (l == 0) + l += scnprintf(out + l, sz - l, "N/A"); if (hit) l += scnprintf(out + l, sz - l, " hit"); if (miss) @@ -231,6 +258,14 @@ int perf_mem__snp_scnprintf(char *out, size_t sz, struct mem_info *mem_info) } l += scnprintf(out + l, sz - l, snoop_access[i]); } + if (mem_info && + (mem_info->data_src.mem_snoopx & PERF_MEM_SNOOPX_FWD)) { + if (l) { + strcat(out, " or "); + l += 4; + } + l += scnprintf(out + l, sz - l, "Fwd"); + } if (*out == '\0') l += scnprintf(out, sz - l, "N/A"); -- 2.9.4