From: Athira Rajeev <atrajeev@linux.ibm.com>
To: acme@kernel.org, jolsa@kernel.org, adrian.hunter@intel.com,
maddy@linux.ibm.com, irogers@google.com, namhyung@kernel.org
Cc: linux-perf-users@vger.kernel.org, linuxppc-dev@lists.ozlabs.org,
atrajeev@linux.ibm.com, hbathini@linux.vnet.ibm.com,
tejas05@linux.ibm.com, tshah@linux.ibm.com,
venkat88@linux.ibm.com
Subject: [PATCH 9/9] tools/perf/powerpc: Add logical address in decoded traces
Date: Wed, 1 Jul 2026 14:11:15 +0530 [thread overview]
Message-ID: <20260701084115.80383-10-atrajeev@linux.ibm.com> (raw)
In-Reply-To: <20260701084115.80383-1-atrajeev@linux.ibm.com>
Enhance the post processing to translate physical addresses to logical
addresses in the decoded output. This improves debuggability by
allowing direct correlation with source code and debug symbols.
The decoder now creates a .l output file with logical addresses,
making it easier to analyze traces using symbol tables and debuggers.
LP index filtering is made optional when dumping traces to show all
addresses.
Add logical address translation in the post-processing step of
process_trace_file(). For each physical address found in the decoded
trace, find_logical_addr() is used to look up the corresponding
logical address from the mem_entries array. The translated output is
written to a new file with a ".l" suffix alongside the original
decoded trace file.
LP index filtering in find_logical_addr() is made optional via a
new 'filter' parameter. When running with dump_trace (perf script -D),
filtering is disabled so all addresses are translated regardless of
LP index. This ensures complete coverage when dumping traces for
analysis.
Example output files after decoding:
htm.bin.n0.p2.c0.out - decoded trace with physical addresses
htm.bin.n0.p2.c0.out.l - decoded trace with logical addresses
Signed-off-by: Athira Rajeev <atrajeev@linux.ibm.com>
---
tools/perf/util/powerpc-htm.c | 81 ++++++++++++++++++++++++++++++++---
1 file changed, 74 insertions(+), 7 deletions(-)
diff --git a/tools/perf/util/powerpc-htm.c b/tools/perf/util/powerpc-htm.c
index 050fbceac71e..1bd2664453c6 100644
--- a/tools/perf/util/powerpc-htm.c
+++ b/tools/perf/util/powerpc-htm.c
@@ -202,7 +202,7 @@ static int add_map_entry(struct addr_map **arr, size_t *count, size_t *cap, stru
static unsigned long find_logical_addr(unsigned long long given_addr,
struct mem_entries *mem_entries_array,
size_t n_entries,
- u32 lp_filter)
+ u32 lp_filter, int filter)
{
for (size_t i = 0; i < n_entries; i++) {
unsigned long long start = mem_entries_array[i].phy_addr & PHYS_ADDR_MASK;
@@ -221,11 +221,13 @@ static unsigned long find_logical_addr(unsigned long long given_addr,
* If so, calculate:
* 'offset' and the 'logical address
*/
- if (start <= given_addr && given_addr < end &&
- mem_entries_array[i].lp_index == lp_filter) {
+ if (start <= given_addr && given_addr < end) {
unsigned long long offset = given_addr - start;
unsigned long logical = mem_entries_array[i].logical_addr + offset;
+ if (filter && (mem_entries_array[i].lp_index != lp_filter))
+ continue;
+
pr_debug("DEBUG: Condition hit at i=%zu given_addr=0x%llx start=0x%llx end=0x%llx lp_index=%u\n",
i, given_addr,
start, end,
@@ -259,36 +261,60 @@ static struct addr_map *process_trace_file(const char *trace_file,
unsigned long logical_addr;
size_t total_phys = 0;
size_t total_phys_to_logical = 0;
-
FILE *fp = fopen(trace_file, "r");
+ size_t prefix_len;
+ int found_match = 0;
+ FILE *fout;
+ int filter_lp = 1;
+ char *output = malloc(strlen(trace_file) + 3); /* +3 for ".l" and null */
+
+ if (!output) {
+ pr_err("Failed to allocate memory for output filename\n");
+ fclose(fp);
+ return NULL;
+ }
if (!fp) {
pr_err("Failed to open trace file %s: %s\n", trace_file, strerror(errno));
return NULL;
}
+ snprintf(output, strlen(trace_file) + 3, "%s.l", trace_file);
+ fout = fopen(output, "w");
+ if (!fout) {
+ pr_err("Failed to open trace output file: %s\n", output);
+ fclose(fp);
+ return NULL;
+ }
+
if (regcomp(&addr_regex, "addr:0x[0-9A-Fa-f]+", REG_EXTENDED) != 0) {
pr_err("Failed to compile addr_regex\n");
- return NULL;
+ goto out;
}
if (regcomp(&label_regex,
"^[[:space:]]*[0-9A-Fa-f]+ : [^[:space:]]+[[:space:]]+([^[:space:]]+)",
REG_EXTENDED) != 0) {
pr_err("Failed to compile label_regex\n");
- return NULL;
+ regfree(&addr_regex);
+ goto out;
}
maps = NULL;
count = 0;
cap = 0;
+ /* When dumping traces, show all addresses regardless of LP index */
+ if (dump_trace)
+ filter_lp = 0;
+
while (getline(&line, &len, fp) != -1) {
if (regexec(&label_regex, line, 2, pmatch, 0) == 0) {
char label[64] = {0};
int start = pmatch[1].rm_so;
int end = pmatch[1].rm_eo;
int line_len = end - start;
+ found_match = 0;
if (line_len < 0)
line_len = 0;
@@ -303,6 +329,10 @@ static struct addr_map *process_trace_file(const char *trace_file,
while (regexec(&addr_regex, ptr, 1, pmatch, 0) == 0) {
unsigned long long phys_addr = 0;
struct addr_map entry = {0};
+ char *hex_start = strstr(line, "addr:0x");
+ const char *target = "addr:0x";
+ char *old_val_ptr;
+ size_t written;
if (sscanf(ptr + pmatch[0].rm_so + strlen("addr:"),
"%llx", &phys_addr) != 1) {
@@ -315,7 +345,30 @@ static struct addr_map *process_trace_file(const char *trace_file,
logical_addr = find_logical_addr(phys_addr,
mem_entries_array,
n_entries,
- lp_filter);
+ lp_filter, filter_lp);
+ /* create output.txt with logical address */
+ if (dump_trace && hex_start) {
+ old_val_ptr = hex_start + strlen(target);
+ prefix_len = hex_start - line;
+ written = fwrite(line, 1, prefix_len, fout);
+ if (written != prefix_len) {
+ pr_err("Failed to write prefix to output file\n");
+ continue;
+ }
+ if (fprintf(fout, "addr:0x%llx\t", (unsigned long long)logical_addr) < 0) {
+ pr_err("Failed to write to output file\n");
+ continue;
+ }
+ while (*old_val_ptr != ' ' && *old_val_ptr != '\n' && *old_val_ptr != '\0') {
+ old_val_ptr++;
+ }
+ if (fprintf(fout, "%s", old_val_ptr) < 0) {
+ pr_err("Failed to write suffix to output file\n");
+ continue;
+ }
+ found_match = 1;
+ }
+
if (logical_addr == 0) {
ptr += pmatch[0].rm_eo;
continue;
@@ -335,6 +388,12 @@ static struct addr_map *process_trace_file(const char *trace_file,
ptr += pmatch[0].rm_eo;
}
+ if (dump_trace && (!found_match) && line) {
+ if (fprintf(fout, "%s", line) < 0) {
+ pr_err("Failed to write line to output file\n");
+ continue;
+ }
+ }
}
}
@@ -342,9 +401,17 @@ static struct addr_map *process_trace_file(const char *trace_file,
fclose(fp);
regfree(&addr_regex);
regfree(&label_regex);
+ fclose(fout);
+ free(output);
*count_out = count;
return maps;
+
+out:
+ fclose(fp);
+ fclose(fout);
+ free(output);
+ return NULL;
}
static int create_mem_maps(struct perf_session *session, struct powerpc_htm *htm)
--
2.52.0
next prev parent reply other threads:[~2026-07-01 8:42 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-01 8:41 [PATCH 0/9] tools/perf: Add interface to expose HTM trace data via perf Athira Rajeev
2026-07-01 8:41 ` [PATCH 1/9] tool/perf: Move auxtrace_record__init for powerpc-vpadtl as separate utility Athira Rajeev
2026-07-01 8:56 ` sashiko-bot
2026-07-01 8:41 ` [PATCH 2/9] tools/perf: Add CONFIG_AUXTRACE support for HTM pmu on powerpc Athira Rajeev
2026-07-01 8:55 ` sashiko-bot
2026-07-01 8:41 ` [PATCH 3/9] tools/perf: Add arch_record__collect_final_data to collect additional data before closing the event Athira Rajeev
2026-07-01 8:54 ` sashiko-bot
2026-07-01 8:41 ` [PATCH 4/9] tools/perf: Add powerpc callback support for arch_record__collect_final_data Athira Rajeev
2026-07-01 8:55 ` sashiko-bot
2026-07-01 8:41 ` [PATCH 5/9] tools/perf: process htm auxtrace events and display in perf report -D Athira Rajeev
2026-07-01 9:05 ` sashiko-bot
2026-07-01 8:41 ` [PATCH 6/9] perf tools powerpc: Add HTM trace data processing and decoding support Athira Rajeev
2026-07-01 9:06 ` sashiko-bot
2026-07-01 8:41 ` [PATCH 7/9] perf tools powerpc: Add physical to logical address mapping for HTM traces Athira Rajeev
2026-07-01 9:07 ` sashiko-bot
2026-07-01 8:41 ` [PATCH 8/9] tools/perf/powerpc: Add event name as htm of PERF_TYPE_SYNTH type to present htm samples Athira Rajeev
2026-07-01 9:12 ` sashiko-bot
2026-07-01 8:41 ` Athira Rajeev [this message]
2026-07-01 9:13 ` [PATCH 9/9] tools/perf/powerpc: Add logical address in decoded traces sashiko-bot
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=20260701084115.80383-10-atrajeev@linux.ibm.com \
--to=atrajeev@linux.ibm.com \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=hbathini@linux.vnet.ibm.com \
--cc=irogers@google.com \
--cc=jolsa@kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=maddy@linux.ibm.com \
--cc=namhyung@kernel.org \
--cc=tejas05@linux.ibm.com \
--cc=tshah@linux.ibm.com \
--cc=venkat88@linux.ibm.com \
/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