Add perf support for HiSilicon PCIe Tune and Trace device
Subsystems (5)
v12 cover Add perf support for HiSilicon PCIe Tune and Trace device
From: Yicong Yang <[email protected]>
This patchset adds the perf tool support for HiSilicon PCIe Tune and Trace device [1]. The device driver makes use of perf AUX trace for tracing TLP (Transaction Layer Packet) headers of PCIe. The trace can be used by perf record and the traced data can be decoded by perf report with this patchset. The detailed usage is documented in [1].
This is split from the v11 series as suggested to send driver part and perf tool part separately. The perf tool part has no change since v11. The whole changelog can be found at [2].
Wish to have perf support along with the PTT driver to enable the full support.
[1] https://lore.kernel.org/lkml/[email protected]/
[2] https://lore.kernel.org/lkml/[email protected]/
Qi Liu (3):
perf tool: arm: Refactor event list iteration in
auxtrace_record__init()
perf tool: Add support for HiSilicon PCIe Tune and Trace device driver perf tool: Add support for parsing HiSilicon PCIe Trace packet
tools/perf/arch/arm/util/auxtrace.c | 116 +++++++++-- tools/perf/arch/arm/util/pmu.c | 3 + tools/perf/arch/arm64/util/Build | 2 +- tools/perf/arch/arm64/util/hisi-ptt.c | 188 +++++++++++++++++ tools/perf/util/Build | 2 + tools/perf/util/auxtrace.c | 4 + tools/perf/util/auxtrace.h | 1 + tools/perf/util/hisi-ptt-decoder/Build | 1 + .../hisi-ptt-decoder/hisi-ptt-pkt-decoder.c | 164 +++++++++++++++ .../hisi-ptt-decoder/hisi-ptt-pkt-decoder.h | 31 +++ tools/perf/util/hisi-ptt.c | 192 ++++++++++++++++++ tools/perf/util/hisi-ptt.h | 19 ++ 12 files changed, 703 insertions(+), 20 deletions(-) create mode 100644 tools/perf/arch/arm64/util/hisi-ptt.c create mode 100644 tools/perf/util/hisi-ptt-decoder/Build create mode 100644 tools/perf/util/hisi-ptt-decoder/hisi-ptt-pkt-decoder.c create mode 100644 tools/perf/util/hisi-ptt-decoder/hisi-ptt-pkt-decoder.h create mode 100644 tools/perf/util/hisi-ptt.c create mode 100644 tools/perf/util/hisi-ptt.h
Signature · 1 line
2.24.0
PATCH RESEND v12 1/3 perf tool: arm: Refactor event list iteration in auxtrace_record__init()
From: Qi Liu <[email protected]>
Add find_pmu_for_event() and use to simplify logic in auxtrace_record_init(). find_pmu_for_event() will be reused in subsequent patches.
--- tools/perf/arch/arm/util/auxtrace.c | 53 ++++++++++++++++++----------- 1 file changed, 34 insertions(+), 19 deletions(-)
tools/perf/arch/arm/util/auxtrace.c +34 -19
@@ -50,16 +50,32 @@ static struct perf_pmu **find_all_arm_spe_pmus(int *nr_spes, int *err)return arm_spe_pmus; } +static struct perf_pmu *find_pmu_for_event (struct perf_pmu **pmus, +int pmu_nr,struct evsel *evsel) +{ +int i; + +if (!pmus) +return NULL ; + +for (i =0 ; i < pmu_nr; i++) { +if (evsel->core.attr.type == pmus[i]->type) +return pmus[i]; + } + +return NULL ; +} +struct auxtrace_record *auxtrace_record__init (struct evlist *evlist,int *err) { -struct perf_pmu *cs_etm_pmu; +struct perf_pmu *cs_etm_pmu =NULL ; +struct perf_pmu **arm_spe_pmus =NULL ;struct evsel *evsel; -bool found_etm = false; +struct perf_pmu *found_etm =NULL ;struct perf_pmu *found_spe =NULL ; -struct perf_pmu **arm_spe_pmus =NULL ; +int auxtrace_event_cnt =0 ;int nr_spes =0 ; -int i =0 ;if (!evlist)return NULL ;
@@ -68,24 +84,23 @@ struct auxtrace_record arm_spe_pmus =find_all_arm_spe_pmus (&nr_spes, err);evlist__for_each_entry (evlist, evsel) { -if (cs_etm_pmu && - evsel->core.attr.type == cs_etm_pmu->type) - found_etm = true; - -if (!nr_spes || found_spe) -continue ; - -for (i =0 ; i < nr_spes; i++) { -if (evsel->core.attr.type == arm_spe_pmus[i]->type) { - found_spe = arm_spe_pmus[i]; -break ; - } - } +if (cs_etm_pmu && !found_etm) + found_etm =find_pmu_for_event (&cs_etm_pmu,1 , evsel); + +if (arm_spe_pmus && !found_spe) + found_spe =find_pmu_for_event (arm_spe_pmus, nr_spes, evsel); } +free (arm_spe_pmus); -if (found_etm && found_spe) { -pr_err ("Concurrent ARM Coresight ETM and SPE operation not currently supported\n" ); +if (found_etm) + auxtrace_event_cnt++; + +if (found_spe) + auxtrace_event_cnt++; + +if (auxtrace_event_cnt >1 ) { +pr_err ("Concurrent AUX trace operation not currently supported\n" ); *err = -EOPNOTSUPP ;return NULL ; }
Signature · 1 line
2.24.0
Re: [RESEND PATCH v12 1/3] perf tool: arm: Refactor event list iteration in auxtrace_record__init()
Quoted 67 lines · Yicong Yang
From: Qi Liu <[email protected]>
Add
find_pmu_for_event()and use to simplify logic inauxtrace_record_init().find_pmu_for_event()will be reused in subsequent patches.Reviewed-by Leo Yan <[email protected]>Reviewed-by Jonathan Cameron <[email protected]>Signed-off-by Qi Liu <[email protected]>Signed-off-by Yicong Yang <[email protected]>--- tools/perf/arch/arm/util/auxtrace.c | 53 ++++++++++++++++++----------- 1 file changed, 34 insertions(+), 19 deletions(-)tools/perf/arch/arm/util/auxtrace.c +20
-12@@ -50,16 +50,32 @@ static struct perf_pmu **find_all_arm_spe_pmus(int *nr_spes, int *err)return arm_spe_pmus; } +static struct perf_pmu *find_pmu_for_event (struct perf_pmu **pmus, +int pmu_nr,struct evsel *evsel) +{ +int i; + +if (!pmus) +return NULL ; + +for (i =0 ; i < pmu_nr; i++) { +if (evsel->core.attr.type == pmus[i]->type) +return pmus[i]; + } + +return NULL ; +} +struct auxtrace_record *auxtrace_record__init (struct evlist *evlist,int *err) { -struct perf_pmu *cs_etm_pmu; +struct perf_pmu *cs_etm_pmu =NULL ; +struct perf_pmu **arm_spe_pmus =NULL ;struct evsel *evsel; -bool found_etm = false; +struct perf_pmu *found_etm =NULL ;struct perf_pmu *found_spe =NULL ; -struct perf_pmu **arm_spe_pmus =NULL ; +int auxtrace_event_cnt =0 ;int nr_spes =0 ; -int i =0 ;if (!evlist)return NULL ;@@ -68,24 +84,23 @@ struct auxtrace_record arm_spe_pmus =find_all_arm_spe_pmus (&nr_spes, err);evlist__for_each_entry (evlist, evsel) { -if (cs_etm_pmu && - evsel->core.attr.type == cs_etm_pmu->type) - found_etm = true; - -if (!nr_spes || found_spe) -continue ; - -for (i =0 ; i < nr_spes; i++) {
tools/perf/arch/arm/util/auxtrace.c struct auxtrace_record · line 91
Quoted 10 lines
tools/perf/arch/arm/util/auxtrace.c +5
-5-if (evsel->core.attr.type == arm_spe_pmus[i]->type) { - found_spe = arm_spe_pmus[i]; -break ; - } - } +if (cs_etm_pmu && !found_etm) + found_etm =find_pmu_for_event (&cs_etm_pmu,1 , evsel); + +if (arm_spe_pmus && !found_spe) + found_spe =find_pmu_for_event (arm_spe_pmus, nr_spes, evsel);
should you break if found_etm and found_spe are set? Or, indeed, error and return directly as we do below? Indeed, I am not sure why you even require auxtrace_event_cnt
Quoted 17 lines
tools/perf/arch/arm/util/auxtrace.c +9
-2} +free (arm_spe_pmus); -if (found_etm && found_spe) { -pr_err ("Concurrent ARM Coresight ETM and SPE operation not currently supported\n" ); +if (found_etm) + auxtrace_event_cnt++; + +if (found_spe) + auxtrace_event_cnt++; + +if (auxtrace_event_cnt >1 ) { +pr_err ("Concurrent AUX trace operation not currently supported\n" ); *err = -EOPNOTSUPP ;return NULL ; }
Re: [RESEND PATCH v12 1/3] perf tool: arm: Refactor event list iteration in auxtrace_record__init()
On Wed, Sep 14, 2022 at 02:47:43PM +0100, John Garry wrote:
[...]
Quoted 33 lines
Quoted 33 lines
struct auxtrace_record *auxtrace_record__init(struct evlist *evlist, int *err) {tools/perf/arch/arm/util/auxtrace.c +5
-17-struct perf_pmu *cs_etm_pmu; +struct perf_pmu *cs_etm_pmu =NULL ; +struct perf_pmu **arm_spe_pmus =NULL ;struct evsel *evsel; -bool found_etm = false; +struct perf_pmu *found_etm =NULL ;struct perf_pmu *found_spe =NULL ; -struct perf_pmu **arm_spe_pmus =NULL ; +int auxtrace_event_cnt =0 ;int nr_spes =0 ; -int i =0 ;if (!evlist)return NULL ;@@ -68,24 +84,23 @@ struct auxtrace_record arm_spe_pmus =find_all_arm_spe_pmus (&nr_spes, err);evlist__for_each_entry (evlist, evsel) { -if (cs_etm_pmu && - evsel->core.attr.type == cs_etm_pmu->type) - found_etm = true; - -if (!nr_spes || found_spe) -continue ; - -for (i =0 ; i < nr_spes; i++) { -if (evsel->core.attr.type == arm_spe_pmus[i]->type) { - found_spe = arm_spe_pmus[i]; -break ; - } - } + if (cs_etm_pmu && !found_etm) + found_etm =
Quoted 8 lines
tools/perf/arch/arm/util/auxtrace.c struct auxtrace_record · line 91
Quoted 4 lines
tools/perf/arch/arm/util/auxtrace.c +3
-0find_pmu_for_event (&cs_etm_pmu,1 , evsel); + +if (arm_spe_pmus && !found_spe) + found_spe =find_pmu_for_event (arm_spe_pmus, nr_spes, evsel);should you break if
found_etmandfound_speare set? Or, indeed, error and return directly as we do below? Indeed, I am not sure why you even requireauxtrace_event_cnt
I think this was my suggestion :)
We can check if both 'found_etm' and 'found_spe' are set and directly break (and bail out) for this case. But it would introduce more complex checking if we connect with patch 2 with new flag 'found_ptt', something like:
if ((found_etm && found_spe) ||
(found_etm && found_ptt) ||
(found_spe && found_ptt))
break;This is hard for later's extension if we need to support a new auxtrace event, so using auxtrace_event_cnt would be easier to extend more auxtrace event on Arm platforms.
Thanks,
Leo
Quoted 17 lines
Quoted 16 lines
tools/perf/arch/arm/util/auxtrace.c +9
-2} +free (arm_spe_pmus); -if (found_etm && found_spe) { -pr_err ("Concurrent ARM Coresight ETM and SPE operation not currently supported\n" ); +if (found_etm) + auxtrace_event_cnt++; + +if (found_spe) + auxtrace_event_cnt++; + +if (auxtrace_event_cnt >1 ) { +pr_err ("Concurrent AUX trace operation not currently supported\n" ); *err = -EOPNOTSUPP ;return NULL ; }
Re: [RESEND PATCH v12 1/3] perf tool: arm: Refactor event list iteration in auxtrace_record__init()
Quoted 46 lines · Leo Yan
On Wed, Sep 14, 2022 at 02:47:43PM +0100, John Garry wrote:
[...]
Quoted 33 lines
Quoted 33 lines
struct auxtrace_record *auxtrace_record__init(struct evlist *evlist, int *err) {tools/perf/arch/arm/util/auxtrace.c +5
-17-struct perf_pmu *cs_etm_pmu; +struct perf_pmu *cs_etm_pmu =NULL ; +struct perf_pmu **arm_spe_pmus =NULL ;struct evsel *evsel; -bool found_etm = false; +struct perf_pmu *found_etm =NULL ;struct perf_pmu *found_spe =NULL ; -struct perf_pmu **arm_spe_pmus =NULL ; +int auxtrace_event_cnt =0 ;int nr_spes =0 ; -int i =0 ;if (!evlist)return NULL ;@@ -68,24 +84,23 @@ struct auxtrace_record arm_spe_pmus =find_all_arm_spe_pmus (&nr_spes, err);evlist__for_each_entry (evlist, evsel) { -if (cs_etm_pmu && - evsel->core.attr.type == cs_etm_pmu->type) - found_etm = true; - -if (!nr_spes || found_spe) -continue ; - -for (i =0 ; i < nr_spes; i++) { -if (evsel->core.attr.type == arm_spe_pmus[i]->type) { - found_spe = arm_spe_pmus[i]; -break ; - } - } + if (cs_etm_pmu && !found_etm) + found_etm =Quoted 8 lines
tools/perf/arch/arm/util/auxtrace.c struct auxtrace_record · line 91
Quoted 4 lines
tools/perf/arch/arm/util/auxtrace.c +3
-0find_pmu_for_event (&cs_etm_pmu,1 , evsel); + +if (arm_spe_pmus && !found_spe) + found_spe =find_pmu_for_event (arm_spe_pmus, nr_spes, evsel);should you break if
found_etmandfound_speare set? Or, indeed, error and return directly as we do below? Indeed, I am not sure why you even requireauxtrace_event_cnt
Quoted 2 lines
I think this was my suggestion :)
yes. thanks :). It's dicussed in v7 and for more information:
https://lore.kernel.org/lkml/20220430073411.GA657977@leoy-ThinkPad-X240s/
Quoted 36 lines
We can check if both '
found_etm' and 'found_spe' are set and directly break (and bail out) for this case. But it would introduce more complex checking if we connect with patch 2 with new flag 'found_ptt', something like:if ((found_etm && found_spe) || (found_etm && found_ptt) || (found_spe && found_ptt)) break;This is hard for later's extension if we need to support a new auxtrace event, so using
auxtrace_event_cntwould be easier to extend more auxtrace event on Arm platforms.Thanks,
LeoQuoted 8 lines
Quoted 8 lines
tools/perf/arch/arm/util/auxtrace.c +4
-2} +free (arm_spe_pmus); -if (found_etm && found_spe) { -pr_err ("Concurrent ARM Coresight ETM and SPE operation not currently supported\n" ); +if (found_etm) + auxtrace_event_cnt++; +Quoted 9 lines
tools/perf/arch/arm/util/auxtrace.c struct auxtrace_record · line 106
Quoted 8 lines
tools/perf/arch/arm/util/auxtrace.c +5
-0+if (found_spe) + auxtrace_event_cnt++; + +if (auxtrace_event_cnt >1 ) { +pr_err ("Concurrent AUX trace operation not currently supported\n" ); *err = -EOPNOTSUPP ;return NULL ; }.
PATCH RESEND v12 2/3 perf tool: Add support for HiSilicon PCIe Tune and Trace device driver
In reply to Yicong YangFrom: Qi Liu <[email protected]>
HiSilicon PCIe tune and trace device (PTT) could dynamically tune the PCIe link's events, and trace the TLP headers).
This patch add support for PTT device in perf tool, so users could use 'perf record' to get TLP headers trace data.
--- tools/perf/arch/arm/util/auxtrace.c | 63 +++++++++ tools/perf/arch/arm/util/pmu.c | 3 + tools/perf/arch/arm64/util/Build | 2 +- tools/perf/arch/arm64/util/hisi-ptt.c | 188 ++++++++++++++++++++++++++ tools/perf/util/auxtrace.c | 1 + tools/perf/util/auxtrace.h | 1 + tools/perf/util/hisi-ptt.h | 16 +++ 7 files changed, 273 insertions(+), 1 deletion(-) create mode 100644 tools/perf/arch/arm64/util/hisi-ptt.c create mode 100644 tools/perf/util/hisi-ptt.h
tools/perf/arch/arm/util/auxtrace.c +63 -0
@@ -4,9 +4,11 @@* Author: Mathieu Poirier <[email protected]> */ +#include <dirent.h> #include <stdbool.h> #include <linux/coresight-pmu.h> #include <linux/zalloc.h> +#include <api/fs/fs.h> #include "../../../util/auxtrace.h" #include "../../../util/debug.h"
@@ -14,6 +16,7 @@#include "../../../util/pmu.h" #include "cs-etm.h" #include "arm-spe.h" +#include "hisi-ptt.h" static struct perf_pmu **find_all_arm_spe_pmus (int *nr_spes,int *err) {
@@ -50,6 +53,52 @@ static struct perf_pmu **find_all_arm_spe_pmus(int *nr_spes, int *err)return arm_spe_pmus; } +static struct perf_pmu **find_all_hisi_ptt_pmus (int *nr_ptts,int *err) +{ +const char *sysfs =sysfs__mountpoint (); +struct perf_pmu **hisi_ptt_pmus =NULL ; +struct dirent *dent; +char path[PATH_MAX ]; +DIR *dir =NULL ; +int idx =0 ; + +snprintf (path,PATH_MAX ,"%s" EVENT_SOURCE_DEVICE_PATH , sysfs); + dir =opendir (path); +if (!dir) { +pr_err ("can't read directory '%s'\n" ,EVENT_SOURCE_DEVICE_PATH ); + *err = -EINVAL ; + goto out; + } + +while ((dent =readdir (dir))) { +if (strstr (dent->d_name,HISI_PTT_PMU_NAME )) + (*nr_ptts)++; + } + +if (!(*nr_ptts)) + goto out; + + hisi_ptt_pmus =zalloc (sizeof (struct perf_pmu *) * (*nr_ptts)); +if (!hisi_ptt_pmus) { +pr_err ("hisi_ptt alloc failed\n" ); + *err = -ENOMEM ; + goto out; + } + +rewinddir (dir); +while ((dent =readdir (dir))) { +if (strstr (dent->d_name,HISI_PTT_PMU_NAME ) && idx < (*nr_ptts)) { + hisi_ptt_pmus[idx] =perf_pmu__find (dent->d_name); +if (hisi_ptt_pmus[idx]) + idx++; + } + } + +out: +closedir (dir); +return hisi_ptt_pmus; +} +static struct perf_pmu *find_pmu_for_event (struct perf_pmu **pmus,int pmu_nr,struct evsel *evsel) {
@@ -71,17 +120,21 @@ struct auxtrace_record {struct perf_pmu *cs_etm_pmu =NULL ;struct perf_pmu **arm_spe_pmus =NULL ; +struct perf_pmu **hisi_ptt_pmus =NULL ;struct evsel *evsel;struct perf_pmu *found_etm =NULL ;struct perf_pmu *found_spe =NULL ; +struct perf_pmu *found_ptt =NULL ;int auxtrace_event_cnt =0 ;int nr_spes =0 ; +int nr_ptts =0 ;if (!evlist)return NULL ; cs_etm_pmu =perf_pmu__find (CORESIGHT_ETM_PMU_NAME ); arm_spe_pmus =find_all_arm_spe_pmus (&nr_spes, err); + hisi_ptt_pmus =find_all_hisi_ptt_pmus (&nr_ptts, err);evlist__for_each_entry (evlist, evsel) {if (cs_etm_pmu && !found_etm)
@@ -89,9 +142,13 @@ struct auxtrace_recordif (arm_spe_pmus && !found_spe) found_spe =find_pmu_for_event (arm_spe_pmus, nr_spes, evsel); + +if (hisi_ptt_pmus && !found_ptt) + found_ptt =find_pmu_for_event (hisi_ptt_pmus, nr_ptts, evsel); }free (arm_spe_pmus); +free (hisi_ptt_pmus);if (found_etm) auxtrace_event_cnt++;
@@ -99,6 +156,9 @@ struct auxtrace_recordif (found_spe) auxtrace_event_cnt++; +if (found_ptt) + auxtrace_event_cnt++; +if (auxtrace_event_cnt >1 ) {pr_err ("Concurrent AUX trace operation not currently supported\n" ); *err = -EOPNOTSUPP ;
@@ -111,6 +171,9 @@ struct auxtrace_record#if defined(__aarch64__)if (found_spe)return arm_spe_recording_init (err, found_spe); + +if (found_ptt) +return hisi_ptt_recording_init (err, found_ptt);#endif /*
tools/perf/arch/arm/util/pmu.c +3 -0
@@ -10,6 +10,7 @@#include <linux/string.h> #include "arm-spe.h" +#include "hisi-ptt.h" #include "../../../util/pmu.h" struct perf_event_attr
@@ -22,6 +23,8 @@ struct perf_event_attr#if defined(__aarch64__) } else if (strstarts(pmu->name, ARM_SPE_PMU_NAME)) {return arm_spe_pmu_default_config (pmu); + }else if (strstarts (pmu->name,HISI_PTT_PMU_NAME )) { + pmu->selectable = true;#endif }
tools/perf/arch/arm64/util/Build +1 -1
@@ -11,4 +11,4 @@ perf-$(CONFIG_LIBDW_DWARF_UNWIND) += unwind-libdw.o perf-$(CONFIG_AUXTRACE) += ../../arm/util/pmu.o \ ../../arm/util/auxtrace.o \ ../../arm/util/cs-etm.o \ - arm-spe.o mem-events.o + arm-spe.o mem-events.o hisi-ptt.o
tools/perf/arch/arm64/util/hisi-ptt.c new file +188 -0
188 lines not on this page · raw message
tools/perf/util/auxtrace.c +1 -0
@@ -1319,6 +1319,7 @@ int perf_event__process_auxtrace_info(struct perf_session *session,case PERF_AUXTRACE_S390_CPUMSF : err =s390_cpumsf_process_auxtrace_info (event, session);break ; +case PERF_AUXTRACE_HISI_PTT :case PERF_AUXTRACE_UNKNOWN :default :return -EINVAL ;
tools/perf/util/auxtrace.h +1 -0
@@ -48,6 +48,7 @@ enum auxtrace_type {PERF_AUXTRACE_CS_ETM ,PERF_AUXTRACE_ARM_SPE ,PERF_AUXTRACE_S390_CPUMSF , + PERF_AUXTRACE_HISI_PTT, }; enum itrace_period_type {
tools/perf/util/hisi-ptt.h new file +16 -0
@@ -0,0 +1,16 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* HiSilicon PCIe Trace and Tuning (PTT) support +* Copyright (c) 2022 HiSilicon Technologies Co., Ltd. +*/ + +#ifndef INCLUDE__PERF_HISI_PTT_H__ +#define INCLUDE__PERF_HISI_PTT_H__ + +#define HISI_PTT_PMU_NAME "hisi_ptt" +#define HISI_PTT_AUXTRACE_PRIV_SIZE sizeof(u64) + +struct auxtrace_record *hisi_ptt_recording_init (int *err, +struct perf_pmu *hisi_ptt_pmu); + +#endif
Signature · 1 line
2.24.0
PATCH RESEND v12 3/3 perf tool: Add support for parsing HiSilicon PCIe Trace packet
In reply to Yicong YangFrom: Qi Liu <[email protected]>
Add support for using 'perf report --dump-raw-trace' to parse PTT packet.
Example usage:
Output will contain raw PTT data and its textual representation, such as:
0 0 0x5810 [0x30]: PERF_RECORD_AUXTRACE size: 0x400000 offset: 0
ref: 0xa5d50c725 idx: 0 tid: -1 cpu: 0
.
. ... HISI PTT data: size 4194304 bytes
. 00000000: 00 00 00 00 Prefix . 00000004: 08 20 00 60 Header DW0 . 00000008: ff 02 00 01 Header DW1 . 0000000c: 20 08 00 00 Header DW2 . 00000010: 10 e7 44 ab Header DW3 . 00000014: 2a a8 1e 01 Time . 00000020: 00 00 00 00 Prefix . 00000024: 01 00 00 60 Header DW0 . 00000028: 0f 1e 00 01 Header DW1 . 0000002c: 04 00 00 00 Header DW2 . 00000030: 40 00 81 02 Header DW3 . 00000034: ee 02 00 00 Time
....
--- tools/perf/util/Build | 2 + tools/perf/util/auxtrace.c | 3 + tools/perf/util/hisi-ptt-decoder/Build | 1 + .../hisi-ptt-decoder/hisi-ptt-pkt-decoder.c | 164 +++++++++++++++ .../hisi-ptt-decoder/hisi-ptt-pkt-decoder.h | 31 +++ tools/perf/util/hisi-ptt.c | 192 ++++++++++++++++++ tools/perf/util/hisi-ptt.h | 3 + 7 files changed, 396 insertions(+) create mode 100644 tools/perf/util/hisi-ptt-decoder/Build create mode 100644 tools/perf/util/hisi-ptt-decoder/hisi-ptt-pkt-decoder.c create mode 100644 tools/perf/util/hisi-ptt-decoder/hisi-ptt-pkt-decoder.h create mode 100644 tools/perf/util/hisi-ptt.c
tools/perf/util/Build +2 -0
@@ -118,6 +118,8 @@ perf-$(CONFIG_AUXTRACE) += intel-pt.o perf-$(CONFIG_AUXTRACE) += intel-bts.o perf-$(CONFIG_AUXTRACE) += arm-spe.o perf-$(CONFIG_AUXTRACE) += arm-spe-decoder/ +perf-$(CONFIG_AUXTRACE) += hisi-ptt.o +perf-$(CONFIG_AUXTRACE) += hisi-ptt-decoder/ perf-$(CONFIG_AUXTRACE) += s390-cpumsf.o ifdef CONFIG_LIBOPENCSD
tools/perf/util/auxtrace.c +3 -0
@@ -51,6 +51,7 @@#include "intel-pt.h" #include "intel-bts.h" #include "arm-spe.h" +#include "hisi-ptt.h" #include "s390-cpumsf.h" #include "util/mmap.h"
@@ -1320,6 +1321,8 @@ int perf_event__process_auxtrace_info(struct perf_session *session, err =s390_cpumsf_process_auxtrace_info (event, session);break ;case PERF_AUXTRACE_HISI_PTT : + err =hisi_ptt_process_auxtrace_info (event, session); +break ;case PERF_AUXTRACE_UNKNOWN :default :return -EINVAL ;
tools/perf/util/hisi-ptt-decoder/Build new file +1 -0
@@ -0,0 +1 @@ +perf-$(CONFIG_AUXTRACE) += hisi-ptt-pkt-decoder.o
tools/perf/util/hisi-ptt-decoder/hisi-ptt-pkt-decoder.c new file +164 -0
164 lines not on this page · raw message
tools/perf/util/hisi-ptt-decoder/hisi-ptt-pkt-decoder.h new file +31 -0
@@ -0,0 +1,31 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* HiSilicon PCIe Trace and Tuning (PTT) support +* Copyright (c) 2022 HiSilicon Technologies Co., Ltd. +*/ + +#ifndef INCLUDE__HISI_PTT_PKT_DECODER_H__ +#define INCLUDE__HISI_PTT_PKT_DECODER_H__ + +#include <stddef.h> +#include <stdint.h> + +#define HISI_PTT_8DW_CHECK_MASK GENMASK(31, 11) +#define HISI_PTT_IS_8DW_PKT GENMASK(31, 11) +#define HISI_PTT_MAX_SPACE_LEN 10 +#define HISI_PTT_FIELD_LENTH 4 + +enum hisi_ptt_pkt_type { +HISI_PTT_4DW_PKT , +HISI_PTT_8DW_PKT , +HISI_PTT_PKT_MAX +}; + +static int hisi_ptt_pkt_size[] = { + [HISI_PTT_4DW_PKT ] =16 , + [HISI_PTT_8DW_PKT ] =32 , +}; + +int hisi_ptt_pkt_desc (const unsigned char *buf,int pos,enum hisi_ptt_pkt_type type); + +#endif
tools/perf/util/hisi-ptt.c new file +192 -0
192 lines not on this page · raw message
tools/perf/util/hisi-ptt.h +3 -0
@@ -13,4 +13,7 @@struct auxtrace_record *hisi_ptt_recording_init (int *err,struct perf_pmu *hisi_ptt_pmu); +int hisi_ptt_process_auxtrace_info (union perf_event *event, +struct perf_session *session); +#endif
Signature · 1 line
2.24.0
Re: [RESEND PATCH v12 3/3] perf tool: Add support for parsing HiSilicon PCIe Trace packet
Quoted 123 lines · Yicong Yang
From: Qi Liu <[email protected]>
Add support for using 'perf report --dump-raw-trace' to parse PTT packet.
Example usage:
Output will contain raw PTT data and its textual representation, such as:
0 0
0x5810[0x30]:PERF_RECORD_AUXTRACEsize:0x400000offset: 0
ref:0xa5d50c725idx: 0 tid: -1 cpu: 0
.
. ... HISI PTT data: size 4194304 bytes. 00000000: 00 00 00 00 Prefix . 00000004: 08 20 00 60 Header DW0 . 00000008: ff 02 00 01 Header DW1 . 0000000c: 20 08 00 00 Header DW2 . 00000010: 10 e7 44 ab Header DW3 . 00000014: 2a a8 1e 01 Time . 00000020: 00 00 00 00 Prefix . 00000024: 01 00 00 60 Header DW0 . 00000028: 0f 1e 00 01 Header DW1 . 0000002c: 04 00 00 00 Header DW2 . 00000030: 40 00 81 02 Header DW3 . 00000034: ee 02 00 00 Time....
Signed-off-by Qi Liu <[email protected]>Signed-off-by Yicong Yang <[email protected]>--- tools/perf/util/Build | 2 + tools/perf/util/auxtrace.c | 3 + tools/perf/util/hisi-ptt-decoder/Build | 1 + .../hisi-ptt-decoder/hisi-ptt-pkt-decoder.c | 164 +++++++++++++++ .../hisi-ptt-decoder/hisi-ptt-pkt-decoder.h | 31 +++ tools/perf/util/hisi-ptt.c | 192 ++++++++++++++++++ tools/perf/util/hisi-ptt.h | 3 + 7 files changed, 396 insertions(+)create mode 100644
tools/perf/util/hisi-ptt-decoder/Buildcreate mode 100644tools/perf/util/hisi-ptt-decoder/hisi-ptt-pkt-decoder.ccreate mode 100644tools/perf/util/hisi-ptt-decoder/hisi-ptt-pkt-decoder.hcreate mode 100644tools/perf/util/hisi-ptt.ctools/perf/util/Build +2
-0@@ -118,6 +118,8 @@ perf-$(CONFIG_AUXTRACE) += intel-pt.o perf-$(CONFIG_AUXTRACE) += intel-bts.o perf-$(CONFIG_AUXTRACE) += arm-spe.o perf-$(CONFIG_AUXTRACE) += arm-spe-decoder/ +perf-$(CONFIG_AUXTRACE) += hisi-ptt.o +perf-$(CONFIG_AUXTRACE) += hisi-ptt-decoder/ perf-$(CONFIG_AUXTRACE) += s390-cpumsf.o ifdef CONFIG_LIBOPENCSDtools/perf/util/auxtrace.c +3
-0@@ -51,6 +51,7 @@#include "intel-pt.h" #include "intel-bts.h" #include "arm-spe.h" +#include "hisi-ptt.h" #include "s390-cpumsf.h" #include "util/mmap.h" @@ -1320,6 +1321,8 @@ int perf_event__process_auxtrace_info(struct perf_session *session, err =s390_cpumsf_process_auxtrace_info (event, session);break ;case PERF_AUXTRACE_HISI_PTT : + err =hisi_ptt_process_auxtrace_info (event, session); +break ;case PERF_AUXTRACE_UNKNOWN :default :return -EINVAL ;tools/perf/util/hisi-ptt-decoder/Build new file +1
-0@@ -0,0 +1 @@ +perf-$(CONFIG_AUXTRACE) += hisi-ptt-pkt-decoder.otools/perf/util/hisi-ptt-decoder/hisi-ptt-pkt-decoder.c new file +33
-0@@ -0,0 +1,164 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* HiSilicon PCIe Trace and Tuning (PTT) support +* Copyright (c) 2022 HiSilicon Technologies Co., Ltd. +*/ + +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <endian.h> +#include <byteswap.h> +#include <linux/bitops.h> +#include <stdarg.h> + +#include "../color.h" +#include "hisi-ptt-pkt-decoder.h" + +/* +* For 8DW format, the bit[31:11] of DW0 is always 0x1fffff, which can be +* used to distinguish the data format. +* 8DW format is like: +* bits [ 31:11 ][ 10:0 ] +* |---------------------------------------|-------------------| +* DW0 [ 0x1fffff ][ Reserved (0x7ff) ] +* DW1 [ Prefix ] +* DW2 [ Header DW0 ] +* DW3 [ Header DW1 ] +* DW4 [ Header DW2 ] +* DW5 [ Header DW3 ] +* DW6 [ Reserved (0x0) ] +* DW7 [ Time ] +* +* 4DW format is like:
tools/perf/util/hisi-ptt-decoder/hisi-ptt-pkt-decoder.c line 43
Quoted 10 lines
tools/perf/util/hisi-ptt-decoder/hisi-ptt-pkt-decoder.c new file +10
-0+* bits [31:30] [ 29:25 ][24][23][22][21][ 20:11 ][ 10:0 ] +* |-----|---------|---|---|---|---|-------------|-------------| +* DW0 [ Fmt ][ Type ][T9][T8][TH][SO][ Length ][ Time ] +* DW1 [ Header DW1 ] +* DW2 [ Header DW2 ] +* DW3 [ Header DW3 ] +*/ + +enum hisi_ptt_8dw_pkt_field_type { +HISI_PTT_8DW_RSV0 ,
if this is defined according to HW value then better be explicit and declare the value
Quoted 56 lines
tools/perf/util/hisi-ptt-decoder/hisi-ptt-pkt-decoder.c new file +56
-0+HISI_PTT_8DW_PREFIX , +HISI_PTT_8DW_HEAD0 , +HISI_PTT_8DW_HEAD1 , +HISI_PTT_8DW_HEAD2 , +HISI_PTT_8DW_HEAD3 , +HISI_PTT_8DW_RSV1 , +HISI_PTT_8DW_TIME , +HISI_PTT_8DW_TYPE_MAX +}; + +enum hisi_ptt_4dw_pkt_field_type { +HISI_PTT_4DW_HEAD1 , +HISI_PTT_4DW_HEAD2 , +HISI_PTT_4DW_HEAD3 , +HISI_PTT_4DW_TYPE_MAX +}; + +static const char *const hisi_ptt_8dw_pkt_field_name[] = { + [HISI_PTT_8DW_PREFIX ] ="Prefix" , + [HISI_PTT_8DW_HEAD0 ] ="Header DW0" , + [HISI_PTT_8DW_HEAD1 ] ="Header DW1" , + [HISI_PTT_8DW_HEAD2 ] ="Header DW2" , + [HISI_PTT_8DW_HEAD3 ] ="Header DW3" , + [HISI_PTT_8DW_TIME ] ="Time" +}; + +static const char *const hisi_ptt_4dw_pkt_field_name[] = { + [HISI_PTT_4DW_HEAD1 ] ="Header DW1" , + [HISI_PTT_4DW_HEAD2 ] ="Header DW2" , + [HISI_PTT_4DW_HEAD3 ] ="Header DW3" , +}; + +union hisi_ptt_4dw { +struct { +uint32_t format :2 ; +uint32_t type :5 ; +uint32_t t9 :1 ; +uint32_t t8 :1 ; +uint32_t th :1 ; +uint32_t so :1 ; +uint32_t len :10 ; +uint32_t time :11 ; + }; +uint32_t value; +}; + +static void hisi_ptt_print_pkt (const unsigned char *buf,int pos,const char *desc) +{ +const char *color =PERF_COLOR_BLUE ; +int i; + +printf ("." ); +color_fprintf (stdout, color," %08x: " , pos); +for (i =0 ; i <HISI_PTT_FIELD_LENTH ; i++) +color_fprintf (stdout, color,"%02x " , buf[pos + i]); +for (i =0 ; i <HISI_PTT_MAX_SPACE_LEN ; i++)
tools/perf/util/hisi-ptt-decoder/hisi-ptt-pkt-decoder.c line 109
Quoted 10 lines
tools/perf/util/hisi-ptt-decoder/hisi-ptt-pkt-decoder.c new file +10
-0+color_fprintf (stdout, color," " ); +color_fprintf (stdout, color," %s\n" , desc); +} + +static int hisi_ptt_8dw_kpt_desc (const unsigned char *buf,int pos) +{ +int i; + +for (i =0 ; i <HISI_PTT_8DW_TYPE_MAX ; i++) { +/* Do not show reserved filed */
fields
Quoted 119 lines
tools/perf/util/hisi-ptt-decoder/hisi-ptt-pkt-decoder.c new file +55
-0+if (i ==HISI_PTT_8DW_RSV0 || i ==HISI_PTT_8DW_RSV1 ) { + pos +=HISI_PTT_FIELD_LENTH ; +continue ; + } + +hisi_ptt_print_pkt (buf, pos, hisi_ptt_8dw_pkt_field_name[i]); + pos +=HISI_PTT_FIELD_LENTH ; + } + +return hisi_ptt_pkt_size[HISI_PTT_8DW_PKT ]; +} + +static void hisi_ptt_4dw_print_dw0 (const unsigned char *buf,int pos) +{ +const char *color =PERF_COLOR_BLUE ; +union hisi_ptt_4dw dw0; +int i; + + dw0.value = *(uint32_t *)(buf + pos); +printf ("." ); +color_fprintf (stdout, color," %08x: " , pos); +for (i =0 ; i <HISI_PTT_FIELD_LENTH ; i++) +color_fprintf (stdout, color,"%02x " , buf[pos + i]); +for (i =0 ; i <HISI_PTT_MAX_SPACE_LEN ; i++) +color_fprintf (stdout, color," " ); + +color_fprintf (stdout, color, +" %s %x %s %x %s %x %s %x %s %x %s %x %s %x %s %x\n" , +"Format" , dw0.format,"Type" , dw0.type,"T9" , dw0.t9, +"T8" , dw0.t8,"TH" , dw0.th,"SO" , dw0.so,"Length" , + dw0.len,"Time" , dw0.time); +} + +static int hisi_ptt_4dw_kpt_desc (const unsigned char *buf,int pos) +{ +int i; + +hisi_ptt_4dw_print_dw0 (buf, pos); + pos +=HISI_PTT_FIELD_LENTH ; + +for (i =0 ; i <HISI_PTT_4DW_TYPE_MAX ; i++) { +hisi_ptt_print_pkt (buf, pos, hisi_ptt_4dw_pkt_field_name[i]); + pos +=HISI_PTT_FIELD_LENTH ; + } + +return hisi_ptt_pkt_size[HISI_PTT_4DW_PKT ]; +} + +int hisi_ptt_pkt_desc (const unsigned char *buf,int pos,enum hisi_ptt_pkt_type type) +{ +if (type ==HISI_PTT_8DW_PKT ) +return hisi_ptt_8dw_kpt_desc (buf, pos); + +return hisi_ptt_4dw_kpt_desc (buf, pos); +}tools/perf/util/hisi-ptt-decoder/hisi-ptt-pkt-decoder.h new file +31
-0@@ -0,0 +1,31 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* HiSilicon PCIe Trace and Tuning (PTT) support +* Copyright (c) 2022 HiSilicon Technologies Co., Ltd. +*/ + +#ifndef INCLUDE__HISI_PTT_PKT_DECODER_H__ +#define INCLUDE__HISI_PTT_PKT_DECODER_H__ + +#include <stddef.h> +#include <stdint.h> + +#define HISI_PTT_8DW_CHECK_MASK GENMASK(31, 11) +#define HISI_PTT_IS_8DW_PKT GENMASK(31, 11) +#define HISI_PTT_MAX_SPACE_LEN 10 +#define HISI_PTT_FIELD_LENTH 4 + +enum hisi_ptt_pkt_type { +HISI_PTT_4DW_PKT , +HISI_PTT_8DW_PKT , +HISI_PTT_PKT_MAX +}; + +static int hisi_ptt_pkt_size[] = { + [HISI_PTT_4DW_PKT ] =16 , + [HISI_PTT_8DW_PKT ] =32 , +}; + +int hisi_ptt_pkt_desc (const unsigned char *buf,int pos,enum hisi_ptt_pkt_type type); + +#endif tools/perf/util/hisi-ptt.c new file +21
-0@@ -0,0 +1,192 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* HiSilicon PCIe Trace and Tuning (PTT) support +* Copyright (c) 2022 HiSilicon Technologies Co., Ltd. +*/ + +#include <byteswap.h> +#include <endian.h> +#include <errno.h> +#include <inttypes.h> +#include <linux/bitops.h> +#include <linux/kernel.h> +#include <linux/log2.h> +#include <linux/types.h> +#include <linux/zalloc.h> +#include <stdlib.h> +#include <unistd.h> + +#include "auxtrace.h" +#include "color.h" +#include "debug.h"
tools/perf/util/hisi-ptt.c line 31
Quoted 10 lines
tools/perf/util/hisi-ptt.c new file +10
-0+#include "evlist.h" +#include "evsel.h" +#include "hisi-ptt.h" +#include "hisi-ptt-decoder/hisi-ptt-pkt-decoder.h" +#include "machine.h" +#include "session.h" +#include "symbol.h" +#include "tool.h" +#include "util/synthetic-events.h" +#include <internal/lib.h>
that's a lot of includes for such a small c file ...
Quoted 62 lines
tools/perf/util/hisi-ptt.c new file +62
-0+ +struct hisi_ptt { +struct auxtrace auxtrace; +u32 auxtrace_type; +struct perf_session *session; +struct machine *machine; +u32 pmu_type; +}; + +struct hisi_ptt_queue { +struct hisi_ptt *ptt; +struct auxtrace_buffer *buffer; +}; + +static enum hisi_ptt_pkt_type hisi_ptt_check_packet_type (unsigned char *buf) +{ +uint32_t head = *(uint32_t *)buf; + +if ((HISI_PTT_8DW_CHECK_MASK & head) ==HISI_PTT_IS_8DW_PKT ) +return HISI_PTT_8DW_PKT ; + +return HISI_PTT_4DW_PKT ; +} + +static void hisi_ptt_dump (struct hisi_ptt *ptt__maybe_unused , +unsigned char *buf,size_t len) +{ +const char *color =PERF_COLOR_BLUE ; +enum hisi_ptt_pkt_type type; +size_t pos =0 ; +int pkt_len; + + type =hisi_ptt_check_packet_type (buf); + len =round_down (len, hisi_ptt_pkt_size[type]); +color_fprintf (stdout, color,". ... HISI PTT data: size %zu bytes\n" , + len); + +while (len >0 ) { + pkt_len =hisi_ptt_pkt_desc (buf, pos, type); +if (!pkt_len) +color_fprintf (stdout, color," Bad packet!\n" ); + + pos += pkt_len; + len -= pkt_len; + } +} + +static void hisi_ptt_dump_event (struct hisi_ptt *ptt,unsigned char *buf, +size_t len) +{ +printf (".\n" ); + +hisi_ptt_dump (ptt, buf, len); +} + +static int hisi_ptt_process_event (struct perf_session *session__maybe_unused , +union perf_event *event__maybe_unused , +struct perf_sample *sample__maybe_unused , +struct perf_tool *tool__maybe_unused ) +{ +return 0 ; +}
tools/perf/util/hisi-ptt.c line 103
Quoted 10 lines
tools/perf/util/hisi-ptt.c new file +10
-0+ +static int hisi_ptt_process_auxtrace_event (struct perf_session *session, +union perf_event *event, +struct perf_tool *tool__maybe_unused ) +{ + struct hisi_ptt *ptt = container_of(session->auxtrace, struct hisi_ptt, + auxtrace); +int fd =perf_data__fd (session->data); +int size = event->auxtrace.size; +void *data =malloc (size);
no check for data == NULL
Quoted 15 lines
tools/perf/util/hisi-ptt.c new file +15
-0+off_t data_offset; +int err; + +if (perf_data__is_pipe (session->data)) { + data_offset =0 ; + }else { + data_offset =lseek (fd,0 ,SEEK_CUR ); +if (data_offset ==-1 ) +return -errno; + } + + err =readn (fd, data, size); +if (err != (ssize_t )size) { +free (data); +return -errno;
tools/perf/util/hisi-ptt.c line 128
Quoted 10 lines
tools/perf/util/hisi-ptt.c new file +10
-0+ } + +if (dump_trace) +hisi_ptt_dump_event (ptt, data, size); + +return 0 ; +} + +static int hisi_ptt_flush (struct perf_session *session__maybe_unused , +struct perf_tool *tool__maybe_unused )
if it's valid to stub this function - s390-cpumsf.c does this also - then can we have it such that auxtrace__flush_events() can handle !flush_events (and avoid stubs)?
tools/perf/util/hisi-ptt.c line 135
Quoted 7 lines
tools/perf/util/hisi-ptt.c new file +7
-0+{ +return 0 ; +} + +static void hisi_ptt_free_events (struct perf_session *session__maybe_unused ) +{ +}
As above, maybe we can avoid such stubs
Quoted 69 lines
tools/perf/util/hisi-ptt.c new file +57
-0+ +static void hisi_ptt_free (struct perf_session *session) +{ + struct hisi_ptt *ptt = container_of(session->auxtrace, struct hisi_ptt, + auxtrace); + + session->auxtrace =NULL ; +free (ptt); +} + +static bool hisi_ptt_evsel_is_auxtrace (struct perf_session *session, +struct evsel *evsel) +{ + struct hisi_ptt *ptt = container_of(session->auxtrace, struct hisi_ptt, auxtrace); + +return evsel->core.attr.type == ptt->pmu_type; +} + +static void hisi_ptt_print_info (__u64 type) +{ +if (!dump_trace) +return ; + +fprintf (stdout," PMU Type %" PRId64"\n" , (s64 ) type); +} + +int hisi_ptt_process_auxtrace_info (union perf_event *event, +struct perf_session *session) +{ +struct perf_record_auxtrace_info *auxtrace_info = &event->auxtrace_info; +struct hisi_ptt *ptt; + +if (auxtrace_info->header.size <HISI_PTT_AUXTRACE_PRIV_SIZE + +sizeof (struct perf_record_auxtrace_info )) +return -EINVAL ; + + ptt =zalloc (sizeof (*ptt)); +if (!ptt) +return -ENOMEM ; + + ptt->session = session; + ptt->machine = &session->machines.host;/* No kvm support */ + ptt->auxtrace_type = auxtrace_info->type; + ptt->pmu_type = auxtrace_info->priv[0 ]; + + ptt->auxtrace.process_event = hisi_ptt_process_event; + ptt->auxtrace.process_auxtrace_event = hisi_ptt_process_auxtrace_event; + ptt->auxtrace.flush_events = hisi_ptt_flush; + ptt->auxtrace.free_events = hisi_ptt_free_events; + ptt->auxtrace.free = hisi_ptt_free; + ptt->auxtrace.evsel_is_auxtrace = hisi_ptt_evsel_is_auxtrace; + session->auxtrace = &ptt->auxtrace; + +hisi_ptt_print_info (auxtrace_info->priv[0 ]); + +return 0 ; +}tools/perf/util/hisi-ptt.h +3
-0@@ -13,4 +13,7 @@struct auxtrace_record *hisi_ptt_recording_init (int *err,struct perf_pmu *hisi_ptt_pmu); +int hisi_ptt_process_auxtrace_info (union perf_event *event, +struct perf_session *session); +#endif
Re: [RESEND PATCH v12 3/3] perf tool: Add support for parsing HiSilicon PCIe Trace packet
Quoted 126 lines · John Garry
Quoted 125 lines · Yicong Yang
From: Qi Liu <[email protected]>
Add support for using 'perf report --dump-raw-trace' to parse PTT packet.
Example usage:
Output will contain raw PTT data and its textual representation, such as:
0 0
0x5810[0x30]:PERF_RECORD_AUXTRACEsize: 0x400000 offset: 0
ref: 0xa5d50c725 idx: 0 tid: -1 cpu: 0
.
. ... HISI PTT data: size 4194304 bytes
. 00000000: 00 00 00 00 Prefix . 00000004: 08 20 00 60 Header DW0 . 00000008: ff 02 00 01 Header DW1 .0000000c: 20 08 00 00 Header DW2 . 00000010: 10 e7 44 ab Header DW3 . 00000014: 2a a8 1e 01 Time . 00000020: 00 00 00 00 Prefix . 00000024: 01 00 00 60 Header DW0 . 00000028: 0f 1e 00 01 Header DW1 .0000002c: 04 00 00 00 Header DW2 . 00000030: 40 00 81 02 Header DW3 . 00000034: ee 02 00 00 Time
....Signed-off-by Qi Liu <[email protected]>Signed-off-by Yicong Yang <[email protected]>---
tools/perf/util/Build | 2 + tools/perf/util/auxtrace.c | 3 + tools/perf/util/hisi-ptt-decoder/Build | 1 + .../hisi-ptt-decoder/hisi-ptt-pkt-decoder.c | 164 +++++++++++++++ .../hisi-ptt-decoder/hisi-ptt-pkt-decoder.h | 31 +++ tools/perf/util/hisi-ptt.c | 192 ++++++++++++++++++ tools/perf/util/hisi-ptt.h | 3 +7 files changed, 396 insertions(+)create mode 100644
tools/perf/util/hisi-ptt-decoder/Buildcreate mode 100644tools/perf/util/hisi-ptt-decoder/hisi-ptt-pkt-decoder.ccreate mode 100644tools/perf/util/hisi-ptt-decoder/hisi-ptt-pkt-decoder.hcreate mode 100644tools/perf/util/hisi-ptt.ctools/perf/util/Build +0
-0@@ -118,6 +118,8 @@ perf-$(CONFIG_AUXTRACE) += intel-pt.operf-$(CONFIG_AUXTRACE) += intel-bts.o
perf-$(CONFIG_AUXTRACE) += arm-spe.o
perf-$(CONFIG_AUXTRACE) += arm-spe-decoder/tools/perf/util/Build +2
-0+perf-$(CONFIG_AUXTRACE) += hisi-ptt.o +perf-$(CONFIG_AUXTRACE) += hisi-ptt-decoder/perf-$(CONFIG_AUXTRACE) += s390-cpumsf.o
ifdefCONFIG_LIBOPENCSDtools/perf/util/auxtrace.c +1
-0@@ -51,6 +51,7 @@ #include "intel-pt.h" #include "intel-bts.h" #include "arm-spe.h" +#include "hisi-ptt.h" #include "s390-cpumsf.h" #include "util/mmap.h" @@ -1320,6 +1321,8 @@ int perf_event__process_auxtrace_info(struct perf_session *session,err =
s390_cpumsf_process_auxtrace_info(event, session); break;
casePERF_AUXTRACE_HISI_PTT:
+ err =hisi_ptt_process_auxtrace_info(event, session); + break;
casePERF_AUXTRACE_UNKNOWN:
default:
return-EINVAL;tools/perf/util/hisi-ptt-decoder/Build new file +1
-0@@ -0,0 +1 @@ +perf-$(CONFIG_AUXTRACE) += hisi-ptt-pkt-decoder.otools/perf/util/hisi-ptt-decoder/hisi-ptt-pkt-decoder.c new file +37
-0@@ -0,0 +1,164 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* HiSilicon PCIe Trace and Tuning (PTT) support +* Copyright (c) 2022 HiSilicon Technologies Co., Ltd. +*/ + +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <endian.h> +#include <byteswap.h> +#include <linux/bitops.h> +#include <stdarg.h> + +#include "../color.h" +#include "hisi-ptt-pkt-decoder.h" + +/* +* For 8DW format, the bit[31:11] of DW0 is always 0x1fffff, which can be +* used to distinguish the data format. +* 8DW format is like: +* bits [ 31:11 ][ 10:0 ] +* |---------------------------------------|-------------------| +* DW0 [ 0x1fffff ][ Reserved (0x7ff) ] +* DW1 [ Prefix ] +* DW2 [ Header DW0 ] +* DW3 [ Header DW1 ] +* DW4 [ Header DW2 ] +* DW5 [ Header DW3 ] +* DW6 [ Reserved (0x0) ] +* DW7 [ Time ] +* +* 4DW format is like: +* bits [31:30] [ 29:25 ][24][23][22][21][ 20:11 ][ 10:0 ] +* |-----|---------|---|---|---|---|-------------|-------------| +* DW0 [ Fmt ][ Type ][T9][T8][TH][SO][ Length ][ Time ] +* DW1 [ Header DW1 ]
Quoted 9 lines
tools/perf/util/hisi-ptt-decoder/hisi-ptt-pkt-decoder.c line 43
Quoted 6 lines
tools/perf/util/hisi-ptt-decoder/hisi-ptt-pkt-decoder.c new file +6
-0+* DW2 [ Header DW2 ] +* DW3 [ Header DW3 ] +*/ + +enum hisi_ptt_8dw_pkt_field_type { + HISI_PTT_8DW_RSV0,if this is defined according to HW value then better be explicit and declare the value
We use these enums to distinguish each DWords of the data, as defined above in the comments.
Do you mean the REV0 here is not accurate according to the above doc?
Quoted 10 lines
Quoted 10 lines
tools/perf/util/hisi-ptt-decoder/hisi-ptt-pkt-decoder.c new file +10
-0+ HISI_PTT_8DW_PREFIX, + HISI_PTT_8DW_HEAD0, + HISI_PTT_8DW_HEAD1, + HISI_PTT_8DW_HEAD2, + HISI_PTT_8DW_HEAD3, + HISI_PTT_8DW_RSV1, + HISI_PTT_8DW_TIME, + HISI_PTT_8DW_TYPE_MAX +}; +
[...]
Quoted 31 lines
Quoted 31 lines
tools/perf/util/hisi-ptt.c new file +25
-0@@ -0,0 +1,192 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* HiSilicon PCIe Trace and Tuning (PTT) support +* Copyright (c) 2022 HiSilicon Technologies Co., Ltd. +*/ + +#include <byteswap.h> +#include <endian.h> +#include <errno.h> +#include <inttypes.h> +#include <linux/bitops.h> +#include <linux/kernel.h> +#include <linux/log2.h> +#include <linux/types.h> +#include <linux/zalloc.h> +#include <stdlib.h> +#include <unistd.h> + +#include "auxtrace.h" +#include "color.h" +#include "debug.h" +#include "evlist.h" +#include "evsel.h" +#include "hisi-ptt.h" +#include "hisi-ptt-decoder/hisi-ptt-pkt-decoder.h"
Quoted 9 lines
tools/perf/util/hisi-ptt.c line 31
Quoted 6 lines
tools/perf/util/hisi-ptt.c new file +6
-0+#include "machine.h" +#include "session.h" +#include "symbol.h" +#include "tool.h" +#include "util/synthetic-events.h" +#include <internal/lib.h> that's a lot of includes for such a small c file ...
They're necessary I think. Since you point it out I'll do a check and git rid of the unnecessary including if there is.
Quoted 8 lines
Quoted 8 lines
tools/perf/util/hisi-ptt.c new file +8
-0+ +struct hisi_ptt { + struct auxtrace auxtrace; + u32 auxtrace_type; + struct perf_session *session; + struct machine *machine; + u32 pmu_type; +};
[...]
Quoted 6 lines
tools/perf/util/hisi-ptt.c line 128
Quoted 3 lines
tools/perf/util/hisi-ptt.c new file +3
-0+ +static int hisi_ptt_flush (struct perf_session *session__maybe_unused , + struct perf_tool *tool __maybe_unused)if it's valid to stub this function -
s390-cpumsf.cdoes this also - then can we have it such thatauxtrace__flush_events()can handle !flush_events (and avoid stubs)?
Quoted 10 lines
tools/perf/util/hisi-ptt.c line 135
Quoted 7 lines
tools/perf/util/hisi-ptt.c new file +7
-0+{ + return 0; +} + +static void hisi_ptt_free_events (struct perf_session *session__maybe_unused ) +{ +}As above, maybe we can avoid such stubs
ok. But I'd prefer to do it in a separate patch after this series to ease the review, considering we have only 2 cases here and we already have a refactor in this series, if you don't object.
Will fix the reset comments.
Thanks,
Yicong