linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Michael Petlan <mpetlan@redhat.com>
To: linux-perf-users@vger.kernel.org, acme@redhat.com,
	irogers@google.com, namhyung@kernel.org
Cc: jmario@redhat.com, jolsa@kernel.org
Subject: [PATCH 2/4] perf c2c: Add shared mem flag
Date: Mon,  6 Oct 2025 19:57:08 +0200	[thread overview]
Message-ID: <20251006175710.1179040-3-mpetlan@redhat.com> (raw)
In-Reply-To: <20251006175710.1179040-1-mpetlan@redhat.com>

In perf-c2c report, it was impossible to detect shared memory. That
may hide important facts about the cache-line usage.

Add an "S" flag to the Shared Data Cache Line Table marking entries
using shared memory.

Suggested-by: Joe Mario <jmario@redhat.com>
Suggested-by: Jiri Olsa <jolsa@kernel.org>

Signed-off-by: Michael Petlan <mpetlan@redhat.com>
---
 tools/perf/builtin-c2c.c | 49 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 49 insertions(+)

diff --git a/tools/perf/builtin-c2c.c b/tools/perf/builtin-c2c.c
index 9e9ff471ddd1..ab77ea7b188c 100644
--- a/tools/perf/builtin-c2c.c
+++ b/tools/perf/builtin-c2c.c
@@ -19,6 +19,7 @@
 #include <linux/zalloc.h>
 #include <asm/bug.h>
 #include <sys/param.h>
+#include <sys/mman.h>
 #include "debug.h"
 #include "builtin.h"
 #include <perf/cpumap.h>
@@ -45,6 +46,14 @@
 #include "pmus.h"
 #include "string2.h"
 #include "util/util.h"
+#include "dso.h"
+#include "map.h"
+
+enum shared_mem {
+	SHARED_MEM__UNKNOWN	= -1,
+	SHARED_MEM__NO		=  0,
+	SHARED_MEM__YES		=  1,
+};
 
 struct c2c_hists {
 	struct hists		hists;
@@ -74,6 +83,7 @@ struct c2c_hist_entry {
 	unsigned long		 paddr_cnt;
 	bool			 paddr_zero;
 	char			*nodestr;
+	enum shared_mem		 shared_mem;
 
 	/*
 	 * must be at the end,
@@ -275,6 +285,12 @@ static void compute_stats(struct c2c_hist_entry *c2c_he,
 		update_stats(&cstats->load, weight);
 }
 
+static bool map_is_shared_memory(struct map *map)
+{
+	return map && map->flags & MAP_SHARED && map->dso &&
+		!strncmp(map->dso->name, "/SYSV", sizeof("/SYSV") - 1);
+}
+
 static int process_sample_event(const struct perf_tool *tool __maybe_unused,
 				union perf_event *event,
 				struct perf_sample *sample,
@@ -1330,6 +1346,28 @@ cl_idx_empty_entry(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
 	return scnprintf(hpp->buf, hpp->size, "%*s", width, "");
 }
 
+static void
+c2c_he__resolve_shared_mem(struct c2c_hist_entry *c2c_he)
+{
+	if (c2c_he->shared_mem != SHARED_MEM__UNKNOWN)
+		c2c_he->shared_mem = map_is_shared_memory(c2c_he->he.mem_info->daddr.ms.map);
+}
+
+static int
+cl_shared_entry(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
+				struct hist_entry *he)
+{
+	struct c2c_hist_entry *c2c_he;
+	int width = c2c_width(fmt, hpp, he->hists);
+	char buf[10];
+
+	c2c_he = container_of(he, struct c2c_hist_entry, he);
+	c2c_he__resolve_shared_mem(c2c_he);
+
+	scnprintf(buf, 10, c2c_he->shared_mem == SHARED_MEM__YES ? "S" : " ");
+	return scnprintf(hpp->buf, hpp->size, "%*s", width, buf);
+}
+
 #define HEADER_LOW(__h)			\
 	{				\
 		.line[1] = {		\
@@ -1810,6 +1848,14 @@ static struct c2c_dimension dim_dcacheline_num_empty = {
 	.width		= 5,
 };
 
+static struct c2c_dimension dim_dcacheline_shared = {
+	.header		= HEADER_LOW(""),
+	.name		= "cl_shared",
+	.cmp		= empty_cmp,
+	.entry		= cl_shared_entry,
+	.width		= 1,
+};
+
 static struct c2c_dimension *dimensions[] = {
 	&dim_dcacheline,
 	&dim_dcacheline_node,
@@ -1866,6 +1912,7 @@ static struct c2c_dimension *dimensions[] = {
 	&dim_dcacheline_idx,
 	&dim_dcacheline_num,
 	&dim_dcacheline_num_empty,
+	&dim_dcacheline_shared,
 	NULL,
 };
 
@@ -3150,6 +3197,7 @@ static int perf_c2c__report(int argc, const char **argv)
 
 	if (c2c.display != DISPLAY_SNP_PEER)
 		output_str = "cl_idx,"
+			     "cl_shared,"
 			     "dcacheline,"
 			     "dcacheline_node,"
 			     "dcacheline_count,"
@@ -3165,6 +3213,7 @@ static int perf_c2c__report(int argc, const char **argv)
 			     "dram_lcl,dram_rmt";
 	else
 		output_str = "cl_idx,"
+			     "cl_shared,"
 			     "dcacheline,"
 			     "dcacheline_node,"
 			     "dcacheline_count,"
-- 
2.47.3


  parent reply	other threads:[~2025-10-06 17:57 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-06 17:57 [PATCH 0/4] perf c2c: Detect shared memory cachelines Michael Petlan
2025-10-06 17:57 ` [PATCH 1/4] perf tools: Remove /SYSV from no_dso maps Michael Petlan
2025-10-06 18:01   ` Ian Rogers
2025-10-06 18:28     ` Joe Mario
2025-10-06 19:21       ` Ian Rogers
2025-10-06 17:57 ` Michael Petlan [this message]
2025-10-06 17:57 ` [PATCH 3/4] perf c2c: Add map name for cacheline Michael Petlan
2025-10-06 17:57 ` [PATCH 4/4] perf c2c report: Add --detect-shm option Michael Petlan
2025-10-07  8:16 ` [PATCH 0/4] perf c2c: Detect shared memory cachelines Namhyung Kim
2025-10-07 14:38   ` Arnaldo Carvalho de Melo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20251006175710.1179040-3-mpetlan@redhat.com \
    --to=mpetlan@redhat.com \
    --cc=acme@redhat.com \
    --cc=irogers@google.com \
    --cc=jmario@redhat.com \
    --cc=jolsa@kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=namhyung@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).