Skip to contentSkip to conversation

perf script: Fix perf script -F +metric

PATCH Superseded Andi Kleen 3 participants 9 messages Jun 25, 2024 – Jul 1, 2024 perf events

v1 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Andi Kleen

author
#0 lore raw

PATCH 1/2 perf script: Fix perf script -F +metric

This fixes a regression with perf script -F +metric originally caused by :

commit 37cc8ad77cf81f3ffd226856c367b0e15333a738

Author: Ian Rogers <[email protected]>
Date:   Sun Feb 19 01:28:46 2023 -0800

perf metric: Directly use counts rather than saved_value

In the perf script environment the evsel wouldn't allocate an aggr values array, which led to a -1 reference because the metric evaluation would try to reference NULL - 1 (for aggr_idx)

Give the perf script evsels a single CPU aggr setup. That's enough because the groups are always contiguous, so no need to store more than one CPU's worth of values.

Before

% perf record -e '{cycles,instructions}:S' perf bench mem memcpy % perf script -F +metric
Segmentation fault (core dumped)

After:

% perf record -e '{cycles,instructions}:S' perf bench mem memcpy
...
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.028 MB perf.data (90 samples) ] % perf script -F +metric

       perf-exec 1847557 264658.180789:       3009       cycles:  ffffffff990a579a native_write_msr+0xa ([kernel.kallsyms])
       perf-exec 1847557 264658.180789:        382 instructions:  ffffffff990a579a native_write_msr+0xa ([kernel.kallsyms])
       perf-exec 1847557 264658.180789:         metric:    0.13  insn per cycle

...

Fixes 37cc8ad77cf8 ("perf metric: Directly use counts rather ...")
---
 tools/perf/builtin-script.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
tools/perf/builtin-script.c +4 -2
index c16224b1fef3..4aab194b4b1a 100644
@@ -84,7 +84,7 @@ static bool			system_wide;
 static bool			print_flags;
 static const char		*cpu_list;
 static DECLARE_BITMAP(cpu_bitmap, MAX_NR_CPUS);
-static struct perf_stat_config	stat_config;
+static struct perf_stat_config	stat_config = { .aggr_map = &(struct cpu_aggr_map){ .nr = 1 } };
 static int			max_blocks;
 static bool			native_arch;
 static struct dlfilter		*dlfilter;
@@ -2133,12 +2133,14 @@ static void perf_sample__fprint_metric(struct perf_script *script,
 	if (evsel_script(leader)->gnum++ == 0)
 		perf_stat__reset_shadow_stats();
 	val = sample->period * evsel->scale;
+	/* Always use CPU 0 storage because the groups are contiguous. */
+	evsel->stats->aggr[0].counts.val = val;
 	evsel_script(evsel)->val = val;
 	if (evsel_script(leader)->gnum == leader->core.nr_members) {
 		for_each_group_member (ev2, leader) {
 			perf_stat__print_shadow_stats(&stat_config, ev2,
 						      evsel_script(ev2)->val,
-						      sample->cpu,
+						      0,
 						      &ctx,
 						      NULL);
 		}
Signature · 1 line
2.45.2
author
#1 lore raw

PATCH 2/2 Add a test case for perf script -F +metric

Just a simple test

---
 tools/perf/tests/shell/script.sh | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)
tools/perf/tests/shell/script.sh +15 -1
index c1a603653662..cd9d41734021 100755
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!/bin/bash
 # perf script tests
 # SPDX-License-Identifier: GPL-2.0
 
@@ -7,6 +7,7 @@ set -e
 temp_dir=$(mktemp -d /tmp/perf-test-script.XXXXXXXXXX)
 
 perfdatafile="${temp_dir}/perf.data"
+scriptoutput="${temp_dir}/script"
 db_test="${temp_dir}/db_test.py"
 
 err=0
@@ -88,8 +89,21 @@ test_parallel_perf()
 	echo "parallel-perf test [Success]"
 }
 
+test_metric()
+{
+	echo "script metric test"
+	if ! perf list | grep -q cycles ; then return ; fi
+	if ! perf list | grep -q instructions ; then return ; fi
+	perf record -e '{cycles,instructions}' -o "${perfdatafile}" bash -c 'for i in `seq 1000` ; do true ; done'
+	perf script -i "${perfdatafile}" -F +metric  > $scriptoutput
+	test $(grep -c metric $scriptoutput) -gt 5
+	grep metric $scriptoutput | head
+	echo "script metric test [Success]"
+}
+
 test_db
 test_parallel_perf
+test_metric
 
 cleanup
 
Signature · 1 line
2.45.2
#3 lore raw
In reply to Andi Kleen
Quoted 29 lines · Andi Kleen

This fixes a regression with perf script -F +metric originally caused by :

commit 37cc8ad77cf81f3ffd226856c367b0e15333a738

Author: Ian Rogers <[email protected]>
Date:   Sun Feb 19 01:28:46 2023 -0800

perf metric: Directly use counts rather than saved_value

In the perf script environment the evsel wouldn't allocate an aggr values array, which led to a -1 reference because the metric evaluation would try to reference NULL - 1 (for aggr_idx)

Give the perf script evsels a single CPU aggr setup. That's enough because the groups are always contiguous, so no need to store more than one CPU's worth of values.

Before

% perf record -e '{cycles,instructions}:S' perf bench mem memcpy % perf script -F +metric
Segmentation fault (core dumped)

After:

% perf record -e '{cycles,instructions}:S' perf bench mem memcpy
...
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.028 MB perf.data (90 samples) ] % perf script -F +metric

Quoted 7 lines
       perf-exec 1847557 264658.180789:       3009       cycles:  ffffffff990a579a native_write_msr+0xa ([kernel.kallsyms])
       perf-exec 1847557 264658.180789:        382 instructions:  ffffffff990a579a native_write_msr+0xa ([kernel.kallsyms])
       perf-exec 1847557 264658.180789:         metric:    0.13  insn per cycle

...

Fixes 37cc8ad77cf8 ("perf metric: Directly use counts rather ...")

This works, however there seems to be yet another issue on perf-tools-next branch that breaks script metrics.

617824a7f0f73 (perf parse-events: Prefer sysfs/JSON hardware events over legacy, 2024-04-15) changes event priority so on my host "instructions" have type PERF_TYPE_RAW instead of PERF_TYPE_HARDWARE.

# event : name = instructions, , id = { 190969, 190970, 190971, 190972, 190973, 190974, 190975, 190976 }, type = 4 (cpu), size = 136, config = 0xc0 (instructions), sample_type = IP|TID|TIME|READ|CPU|PERIOD|IDENTIFIER, read_format = ID|GROUP|LOST, sample_id_all = 1, exclude_guest = 1

This results in evsel__stat_type no longer recognizing these as STAT_INSTRUCTIONS.

Quoted 34 lines
---
 tools/perf/builtin-script.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
tools/perf/builtin-script.c +4 -3
index c16224b1fef3..4aab194b4b1a 100644
@@ -84,7 +84,7 @@ static bool			system_wide;
 static bool			print_flags;
 static const char		*cpu_list;
 static DECLARE_BITMAP(cpu_bitmap, MAX_NR_CPUS);
-static struct perf_stat_config	stat_config;
+static struct perf_stat_config	stat_config = { .aggr_map = &(struct cpu_aggr_map){ .nr = 1 } };
 static int			max_blocks;
 static bool			native_arch;
 static struct dlfilter		*dlfilter;
@@ -2133,12 +2133,14 @@ static void perf_sample__fprint_metric(struct perf_script *script,
 	if (evsel_script(leader)->gnum++ == 0)
 		perf_stat__reset_shadow_stats();
 	val = sample->period * evsel->scale;
+	/* Always use CPU 0 storage because the groups are contiguous. */
+	evsel->stats->aggr[0].counts.val = val;
 	evsel_script(evsel)->val = val;
 	if (evsel_script(leader)->gnum == leader->core.nr_members) {
 		for_each_group_member (ev2, leader) {
 			perf_stat__print_shadow_stats(&stat_config, ev2,
 						      evsel_script(ev2)->val,
-						      sample->cpu,
+						      0,
 						      &ctx,
 						      NULL);
 		}
--
Quoted 2 lines

2.45.2

--
Artem

maintainer
#8 lore raw
In reply to Andi Kleen

Hi Andi,

Quoted 29 lines · Andi Kleen

This fixes a regression with perf script -F +metric originally caused by :

commit 37cc8ad77cf81f3ffd226856c367b0e15333a738

Author: Ian Rogers <[email protected]>
Date:   Sun Feb 19 01:28:46 2023 -0800

perf metric: Directly use counts rather than saved_value

In the perf script environment the evsel wouldn't allocate an aggr values array, which led to a -1 reference because the metric evaluation would try to reference NULL - 1 (for aggr_idx)

Give the perf script evsels a single CPU aggr setup. That's enough because the groups are always contiguous, so no need to store more than one CPU's worth of values.

Before

% perf record -e '{cycles,instructions}:S' perf bench mem memcpy % perf script -F +metric
Segmentation fault (core dumped)

After:

% perf record -e '{cycles,instructions}:S' perf bench mem memcpy
...
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.028 MB perf.data (90 samples) ] % perf script -F +metric

Quoted 4 lines
       perf-exec 1847557 264658.180789:       3009       cycles:  ffffffff990a579a native_write_msr+0xa ([kernel.kallsyms])
       perf-exec 1847557 264658.180789:        382 instructions:  ffffffff990a579a native_write_msr+0xa ([kernel.kallsyms])
       perf-exec 1847557 264658.180789:         metric:    0.13  insn per cycle

...

Thanks for the fix!

Quoted 12 lines
Fixes 37cc8ad77cf8 ("perf metric: Directly use counts rather ...")
---
 tools/perf/builtin-script.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
tools/perf/builtin-script.c +0 -0
index c16224b1fef3..4aab194b4b1a 100644

tools/perf/builtin-script.c static bool system_wide; · line 87

Quoted 5 lines
tools/perf/builtin-script.c +1 -1
@@ -84,7 +84,7 @@ static bool			system_wide;
 static bool			print_flags;
 static const char		*cpu_list;
 static DECLARE_BITMAP(cpu_bitmap, MAX_NR_CPUS);
-static struct perf_stat_config	stat_config;
+static struct perf_stat_config	stat_config = { .aggr_map = &(struct cpu_aggr_map){ .nr = 1 } };

Can you please follow the coding style and properly put the code?

Thanks,
Namhyung

Quoted 22 lines
tools/perf/builtin-script.c +3 -1
 static int			max_blocks;
 static bool			native_arch;
 static struct dlfilter		*dlfilter;
@@ -2133,12 +2133,14 @@ static void perf_sample__fprint_metric(struct perf_script *script,
 	if (evsel_script(leader)->gnum++ == 0)
 		perf_stat__reset_shadow_stats();
 	val = sample->period * evsel->scale;
+	/* Always use CPU 0 storage because the groups are contiguous. */
+	evsel->stats->aggr[0].counts.val = val;
 	evsel_script(evsel)->val = val;
 	if (evsel_script(leader)->gnum == leader->core.nr_members) {
 		for_each_group_member (ev2, leader) {
 			perf_stat__print_shadow_stats(&stat_config, ev2,
 						      evsel_script(ev2)->val,
-						      sample->cpu,
+						      0,
 						      &ctx,
 						      NULL);
 		}
Signature · 1 line
2.45.2
maintainer
#4 lore raw
In reply to Artem Savkov
Quoted 46 lines · Artem Savkov
Quoted 29 lines · Andi Kleen

This fixes a regression with perf script -F +metric originally caused by :

commit 37cc8ad77cf81f3ffd226856c367b0e15333a738

Author: Ian Rogers <[email protected]>
Date:   Sun Feb 19 01:28:46 2023 -0800

perf metric: Directly use counts rather than saved_value

In the perf script environment the evsel wouldn't allocate an aggr values array, which led to a -1 reference because the metric evaluation would try to reference NULL - 1 (for aggr_idx)

Give the perf script evsels a single CPU aggr setup. That's enough because the groups are always contiguous, so no need to store more than one CPU's worth of values.

Before

% perf record -e '{cycles,instructions}:S' perf bench mem memcpy % perf script -F +metric
Segmentation fault (core dumped)

After:

% perf record -e '{cycles,instructions}:S' perf bench mem memcpy
...
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.028 MB perf.data (90 samples) ] % perf script -F +metric

Quoted 7 lines
       perf-exec 1847557 264658.180789:       3009       cycles:  ffffffff990a579a native_write_msr+0xa ([kernel.kallsyms])
       perf-exec 1847557 264658.180789:        382 instructions:  ffffffff990a579a native_write_msr+0xa ([kernel.kallsyms])
       perf-exec 1847557 264658.180789:         metric:    0.13  insn per cycle

...

Fixes 37cc8ad77cf8 ("perf metric: Directly use counts rather ...")

This works, however there seems to be yet another issue on perf-tools-next branch that breaks script metrics.

617824a7f0f73 (perf parse-events: Prefer sysfs/JSON hardware events over legacy, 2024-04-15) changes event priority so on my host "instructions" have type PERF_TYPE_RAW instead of PERF_TYPE_HARDWARE.

Quoted 4 lines
# event : name = instructions, , id = { 190969, 190970, 190971, 190972, 190973, 190974, 190975, 190976 }, type = 4 (cpu), size = 136, config = 0xc0 (instructions), sample_type = IP|TID|TIME|READ|CPU|PERIOD|IDENTIFIER, read_format = ID|GROUP|LOST, sample_id_all = 1, exclude_guest = 1

This results in evsel__stat_type no longer recognizing these as STAT_INSTRUCTIONS.

Hmm.. sounds like a problem. Ian, did you notice this?

Thanks,
Namhyung

Quoted 41 lines
Quoted 35 lines
---
 tools/perf/builtin-script.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
tools/perf/builtin-script.c +4 -3
index c16224b1fef3..4aab194b4b1a 100644
@@ -84,7 +84,7 @@ static bool			system_wide;
 static bool			print_flags;
 static const char		*cpu_list;
 static DECLARE_BITMAP(cpu_bitmap, MAX_NR_CPUS);
-static struct perf_stat_config	stat_config;
+static struct perf_stat_config	stat_config = { .aggr_map = &(struct cpu_aggr_map){ .nr = 1 } };
 static int			max_blocks;
 static bool			native_arch;
 static struct dlfilter		*dlfilter;
@@ -2133,12 +2133,14 @@ static void perf_sample__fprint_metric(struct perf_script *script,
 	if (evsel_script(leader)->gnum++ == 0)
 		perf_stat__reset_shadow_stats();
 	val = sample->period * evsel->scale;
+	/* Always use CPU 0 storage because the groups are contiguous. */
+	evsel->stats->aggr[0].counts.val = val;
 	evsel_script(evsel)->val = val;
 	if (evsel_script(leader)->gnum == leader->core.nr_members) {
 		for_each_group_member (ev2, leader) {
 			perf_stat__print_shadow_stats(&stat_config, ev2,
 						      evsel_script(ev2)->val,
-						      sample->cpu,
+						      0,
 						      &ctx,
 						      NULL);
 		}
--
Quoted 2 lines

2.45.2

--
Artem

maintainer
#2 lore raw

Re: [PATCH 2/2] Add a test case for perf script -F +metric

In reply to Andi Kleen
Quoted 12 lines · Andi Kleen

Just a simple test

---
 tools/perf/tests/shell/script.sh | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)
tools/perf/tests/shell/script.sh +0 -0
index c1a603653662..cd9d41734021 100755

tools/perf/tests/shell/script.sh line 1

Quoted 2 lines
tools/perf/tests/shell/script.sh +1 -1
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!/bin/bash

Do we really need this?

Quoted 12 lines
tools/perf/tests/shell/script.sh +1 -0
 # perf script tests
 # SPDX-License-Identifier: GPL-2.0
 
@@ -7,6 +7,7 @@ set -e
 temp_dir=$(mktemp -d /tmp/perf-test-script.XXXXXXXXXX)
 
 perfdatafile="${temp_dir}/perf.data"
+scriptoutput="${temp_dir}/script"
 db_test="${temp_dir}/db_test.py"
 
 err=0

tools/perf/tests/shell/script.sh test_parallel_perf() · line 97

Quoted 9 lines
tools/perf/tests/shell/script.sh +6 -0
@@ -88,8 +89,21 @@ test_parallel_perf()
 	echo "parallel-perf test [Success]"
 }
 
+test_metric()
+{
+	echo "script metric test"
+	if ! perf list | grep -q cycles ; then return ; fi
+	if ! perf list | grep -q instructions ; then return ; fi
+	perf record -e '{cycles,instructions}' -o "${perfdatafile}" bash -c 'for i in `seq 1000` ; do true ; done'

You can use built-in workloads like noploop or so instead of running an external command.

  $ perf record -- perf test -w noploop

Thanks,
Namhyung

Quoted 15 lines
tools/perf/tests/shell/script.sh +7 -0
+	perf script -i "${perfdatafile}" -F +metric  > $scriptoutput
+	test $(grep -c metric $scriptoutput) -gt 5
+	grep metric $scriptoutput | head
+	echo "script metric test [Success]"
+}
+
 test_db
 test_parallel_perf
+test_metric
 
 cleanup
 
Signature · 1 line
2.45.2
author
#5 lore raw
In reply to Artem Savkov
Quoted 7 lines

This works, however there seems to be yet another issue on perf-tools-next branch that breaks script metrics.

617824a7f0f73 (perf parse-events: Prefer sysfs/JSON hardware events over legacy, 2024-04-15) changes event priority so on my host "instructions" have type PERF_TYPE_RAW instead of PERF_TYPE_HARDWARE.

FWIW I don't see this on my build on Intel, even with that commit.

Quoted 2 lines

This results in evsel__stat_type no longer recognizing these as STAT_INSTRUCTIONS.

I guess we could just fix evsel__stat_type to handle that case

Does this patch work?

perf: Workaround event priority problems

When instructions is not of HARDWARE types anymore, but raw, which breaks the shadow stat metrics detection for IPC.

Fixes 617824a7f0f73 (perf parse-events: Prefer sysfs/JSON hardware
tools/perf/util/stat-shadow.c +4 -2
index 3466aa952442..87a503e47ff0 100644
@@ -97,9 +97,11 @@ static enum stat_type evsel__stat_type(const struct evsel *evsel)
 
 	if (evsel__is_clock(evsel))
 		return STAT_NSECS;
-	else if (evsel__match(evsel, HARDWARE, HW_CPU_CYCLES))
+	else if (evsel__match(evsel, HARDWARE, HW_CPU_CYCLES) ||
+			!strcmp(evsel__name((struct evsel *)evsel), "cycles"))
 		return STAT_CYCLES;
-	else if (evsel__match(evsel, HARDWARE, HW_INSTRUCTIONS))
+	else if (evsel__match(evsel, HARDWARE, HW_INSTRUCTIONS) ||
+			!strcmp(evsel__name((struct evsel *)evsel), "instructions"))
 		return STAT_INSTRUCTIONS;
 	else if (evsel__match(evsel, HARDWARE, HW_STALLED_CYCLES_FRONTEND))
 		return STAT_STALLED_CYCLES_FRONT;
#6 lore raw
Quoted 8 lines · Andi Kleen
Quoted 7 lines

This works, however there seems to be yet another issue on perf-tools-next branch that breaks script metrics.

617824a7f0f73 (perf parse-events: Prefer sysfs/JSON hardware events over legacy, 2024-04-15) changes event priority so on my host "instructions" have type PERF_TYPE_RAW instead of PERF_TYPE_HARDWARE.

Quoted 8 lines

FWIW I don't see this on my build on Intel, even with that commit.

Quoted 2 lines

This results in evsel__stat_type no longer recognizing these as STAT_INSTRUCTIONS.

I guess we could just fix evsel__stat_type to handle that case

Does this patch work?

It does for this specific example, but there are other events as well. From arch/x86/events/intel/core.c:

        static u64 intel_perfmon_event_map[PERF_COUNT_HW_MAX] __read_mostly =
        {
                [PERF_COUNT_HW_CPU_CYCLES]		= 0x003c,
                [PERF_COUNT_HW_INSTRUCTIONS]		= 0x00c0,
                [PERF_COUNT_HW_CACHE_REFERENCES]	= 0x4f2e,
                [PERF_COUNT_HW_CACHE_MISSES]		= 0x412e,
                [PERF_COUNT_HW_BRANCH_INSTRUCTIONS]	= 0x00c4,
                [PERF_COUNT_HW_BRANCH_MISSES]		= 0x00c5,
                [PERF_COUNT_HW_BUS_CYCLES]		= 0x013c,
                [PERF_COUNT_HW_REF_CPU_CYCLES]		= 0x0300, /* pseudo-encoding */
        };

The list is probably different on other arches.

Quoted 14 lines

perf: Workaround event priority problems

When instructions is not of HARDWARE types anymore, but raw, which breaks the shadow stat metrics detection for IPC.

Fixes 617824a7f0f73 (perf parse-events: Prefer sysfs/JSON hardware
tools/perf/util/stat-shadow.c +0 -0
index 3466aa952442..87a503e47ff0 100644

tools/perf/util/stat-shadow.c static enum stat_type evsel__stat_type(const struct evsel *evsel) · line 101

Quoted 6 lines
tools/perf/util/stat-shadow.c +2 -1
@@ -97,9 +97,11 @@ static enum stat_type evsel__stat_type(const struct evsel *evsel)
 
 	if (evsel__is_clock(evsel))
 		return STAT_NSECS;
-	else if (evsel__match(evsel, HARDWARE, HW_CPU_CYCLES))
+	else if (evsel__match(evsel, HARDWARE, HW_CPU_CYCLES) ||
+			!strcmp(evsel__name((struct evsel *)evsel), "cycles"))

It is also probably worth to add a PERF_TYPE_RAW check.

tools/perf/util/stat-shadow.c static enum stat_type evsel__stat_type(const struct evsel *evsel) · line 107

Quoted 8 lines
tools/perf/util/stat-shadow.c +2 -1
 		return STAT_CYCLES;
-	else if (evsel__match(evsel, HARDWARE, HW_INSTRUCTIONS))
+	else if (evsel__match(evsel, HARDWARE, HW_INSTRUCTIONS) ||
+			!strcmp(evsel__name((struct evsel *)evsel), "instructions"))
 		return STAT_INSTRUCTIONS;
 	else if (evsel__match(evsel, HARDWARE, HW_STALLED_CYCLES_FRONTEND))
 		return STAT_STALLED_CYCLES_FRONT;

--
Artem

author
#7 lore raw
Quoted 33 lines · Artem Savkov
Quoted 8 lines · Andi Kleen
Quoted 7 lines

This works, however there seems to be yet another issue on perf-tools-next branch that breaks script metrics.

617824a7f0f73 (perf parse-events: Prefer sysfs/JSON hardware events over legacy, 2024-04-15) changes event priority so on my host "instructions" have type PERF_TYPE_RAW instead of PERF_TYPE_HARDWARE.

Quoted 8 lines

FWIW I don't see this on my build on Intel, even with that commit.

Quoted 2 lines

This results in evsel__stat_type no longer recognizing these as STAT_INSTRUCTIONS.

I guess we could just fix evsel__stat_type to handle that case

Does this patch work?

It does for this specific example, but there are other events as well. From arch/x86/events/intel/core.c:

        static u64 intel_perfmon_event_map[PERF_COUNT_HW_MAX] __read_mostly =
        {
                [PERF_COUNT_HW_CPU_CYCLES]		= 0x003c,
                [PERF_COUNT_HW_INSTRUCTIONS]		= 0x00c0,
                [PERF_COUNT_HW_CACHE_REFERENCES]	= 0x4f2e,
                [PERF_COUNT_HW_CACHE_MISSES]		= 0x412e,
                [PERF_COUNT_HW_BRANCH_INSTRUCTIONS]	= 0x00c4,
                [PERF_COUNT_HW_BRANCH_MISSES]		= 0x00c5,
                [PERF_COUNT_HW_BUS_CYCLES]		= 0x013c,
                [PERF_COUNT_HW_REF_CPU_CYCLES]		= 0x0300, /* pseudo-encoding */
        };
Quoted 1 line

The list is probably different on other arches.

Most of them only use the fallback "xxx per second" metric, which should work even for raw I think. But yes some would be needed (like cache and branches)

Probably it needs a more generic solution then, it was somewhat of a hack anyways.

My proposal would be to revert the original patch. Clearly it was a bad idea.

-Andi