tools headers UAPI: Add new macros for mem_hops field to perf_event.h
authorKajol Jain <kjain@linux.ibm.com>
Mon, 6 Dec 2021 09:17:47 +0000 (14:47 +0530)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Wed, 22 Dec 2021 12:34:43 +0000 (09:34 -0300)
Add new macros for mem_hops field which can be used to represent
remote-node, socket and board level details.

Currently the code had macro for HOPS_0 which, corresponds to data
coming from another core but same node.  Add new macros for HOPS_1 to
HOPS_3 to represent remote-node, socket and board level data.

Also add corresponding strings in the mem_hops array to represent
mem_hop field data in perf_mem__lvl_scnprintf function

Incase mem_hops field is used, PERF_MEM_LVLNUM field also need to be set
inorder to represent the data source. Hence printing data source via
PERF_MEM_LVL field can be skip in that scenario.

For ex: Encodings for mem_hops fields with L2 cache:

  L2                      - local L2
  L2 | REMOTE | HOPS_0    - remote core, same node L2
  L2 | REMOTE | HOPS_1    - remote node, same socket L2
  L2 | REMOTE | HOPS_2    - remote socket, same board L2
  L2 | REMOTE | HOPS_3    - remote board L2

Signed-off-by: Kajol Jain <kjain@linux.ibm.com>
Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Athira Jajeev <atrajeev@linux.vnet.ibm.com>
Cc: Daniel Borkmann <daniel@iogearbox.net>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Madhavan Srinivasan <maddy@linux.ibm.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Nageswara R Sastry <rnsastry@linux.ibm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Song Liu <songliubraving@fb.com>
Cc: linuxppc-dev@lists.ozlabs.org
Link: http://lore.kernel.org/lkml/20211206091749.87585-3-kjain@linux.ibm.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/include/uapi/linux/perf_event.h
tools/perf/util/mem-events.c

index bd8860eeb291b18f225e8c6d76be1293ec31d853..4cd39aaccbe7b90491137ec2d9381b8b042ba5f4 100644 (file)
@@ -1332,7 +1332,10 @@ union perf_mem_data_src {
 
 /* hop level */
 #define PERF_MEM_HOPS_0                0x01 /* remote core, same node */
-/* 2-7 available */
+#define PERF_MEM_HOPS_1         0x02 /* remote node, same socket */
+#define PERF_MEM_HOPS_2         0x03 /* remote socket, same board */
+#define PERF_MEM_HOPS_3         0x04 /* remote board */
+/* 5-7 available */
 #define PERF_MEM_HOPS_SHIFT    43
 
 #define PERF_MEM_S(a, s) \
index 3167b4628b6d0717ef3e27a9ecfbc15f8d2457e6..ed0ab838bcc5dc7ff7dbc93c7b182831bbdcb716 100644 (file)
@@ -309,6 +309,9 @@ static const char * const mem_hops[] = {
         * to be set with mem_hops field.
         */
        "core, same node",
+       "node, same socket",
+       "socket, same board",
+       "board",
 };
 
 int perf_mem__lvl_scnprintf(char *out, size_t sz, struct mem_info *mem_info)
@@ -316,7 +319,7 @@ 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;
+       int printed = 0;
 
        if (mem_info)
                m  = mem_info->data_src.mem_lvl;
@@ -335,18 +338,22 @@ int perf_mem__lvl_scnprintf(char *out, size_t sz, struct mem_info *mem_info)
                l += 7;
        }
 
-       if (mem_info && mem_info->data_src.mem_hops)
+       /*
+        * Incase mem_hops field is set, we can skip printing data source via
+        * PERF_MEM_LVL namespace.
+        */
+       if (mem_info && mem_info->data_src.mem_hops) {
                l += scnprintf(out + l, sz - l, "%s ", mem_hops[mem_info->data_src.mem_hops]);
-
-       printed = 0;
-       for (i = 0; m && i < ARRAY_SIZE(mem_lvl); i++, m >>= 1) {
-               if (!(m & 0x1))
-                       continue;
-               if (printed++) {
-                       strcat(out, " or ");
-                       l += 4;
+       } else {
+               for (i = 0; m && i < ARRAY_SIZE(mem_lvl); i++, m >>= 1) {
+                       if (!(m & 0x1))
+                               continue;
+                       if (printed++) {
+                               strcat(out, " or ");
+                               l += 4;
+                       }
+                       l += scnprintf(out + l, sz - l, mem_lvl[i]);
                }
-               l += scnprintf(out + l, sz - l, mem_lvl[i]);
        }
 
        if (mem_info && mem_info->data_src.mem_lvl_num) {