2023-10-14 07:42:56

by Leo Yan

[permalink] [raw]
Subject: [PATCH v1 RESEND 0/2] perf cs-etm: Improve timestamp tracing

This patch series is to improve timestamp handling in per-thread mode.

The current code doesn't validate timestamp and always return success for
per-thread mode, for a sane implementation, the first patch is to allow
validation timestamp tracing in per-thread mode.

The second patch is to respect timestamp option "--timestamp" or "-T",
when users set this option, the tool will automatically enable hardware
timestamp tracing in Arm CoreSight.

This patch set is rebased on the latest perf-tools-next branch, and
tested on Arm Juno board. And added James Clark's review tags.


Leo Yan (2):
perf cs-etm: Validate timestamp tracing in per-thread mode
perf cs-etm: Respect timestamp option

tools/perf/arch/arm/util/cs-etm.c | 22 ++++++++++++++++++++--
1 file changed, 20 insertions(+), 2 deletions(-)

--
2.34.1


2023-10-14 07:42:57

by Leo Yan

[permalink] [raw]
Subject: [PATCH v1 RESEND 2/2] perf cs-etm: Respect timestamp option

When users pass the option '--timestamp' or '-T' in the record command,
all events will set the PERF_SAMPLE_TIME bit in the attribution. In
this case, the AUX event will record the kernel timestamp, but it
doesn't mean Arm CoreSight enables timestamp packets in its hardware
tracing.

If the option '--timestamp' or '-T' is set, this patch always enables
Arm CoreSight timestamp, as a result, the bit 28 in event's config is to
be set.

Before:

# perf record -e cs_etm// --per-thread --timestamp -- ls
# perf script --header-only
...
# event : name = cs_etm//, , id = { 69 }, type = 12, size = 136,
config = 0, { sample_period, sample_freq } = 1,
sample_type = IP|TID|TIME|CPU|IDENTIFIER, read_format = ID|LOST,
disabled = 1, enable_on_exec = 1, sample_id_all = 1, exclude_guest = 1
...

After:

# perf record -e cs_etm// --per-thread --timestamp -- ls
# perf script --header-only
...
# event : name = cs_etm//, , id = { 49 }, type = 12, size = 136,
config = 0x10000000, { sample_period, sample_freq } = 1,
sample_type = IP|TID|TIME|CPU|IDENTIFIER, read_format = ID|LOST,
disabled = 1, enable_on_exec = 1, sample_id_all = 1, exclude_guest = 1
...

Signed-off-by: Leo Yan <[email protected]>
Reviewed-by: James Clark <[email protected]>
---
tools/perf/arch/arm/util/cs-etm.c | 9 +++++++++
1 file changed, 9 insertions(+)

diff --git a/tools/perf/arch/arm/util/cs-etm.c b/tools/perf/arch/arm/util/cs-etm.c
index cf9ef9ba800b..58c506e9788d 100644
--- a/tools/perf/arch/arm/util/cs-etm.c
+++ b/tools/perf/arch/arm/util/cs-etm.c
@@ -442,6 +442,15 @@ static int cs_etm_recording_options(struct auxtrace_record *itr,
"contextid", 1);
}

+ /*
+ * When the option '--timestamp' or '-T' is enabled, the PERF_SAMPLE_TIME
+ * bit is set for all events. In this case, always enable Arm CoreSight
+ * timestamp tracing.
+ */
+ if (opts->sample_time_set)
+ evsel__set_config_if_unset(cs_etm_pmu, cs_etm_evsel,
+ "timestamp", 1);
+
/* Add dummy event to keep tracking */
err = parse_event(evlist, "dummy:u");
if (err)
--
2.34.1

2023-10-16 08:42:29

by Suzuki K Poulose

[permalink] [raw]
Subject: Re: [PATCH v1 RESEND 2/2] perf cs-etm: Respect timestamp option

On 14/10/2023 08:41, Leo Yan wrote:
> When users pass the option '--timestamp' or '-T' in the record command,
> all events will set the PERF_SAMPLE_TIME bit in the attribution. In
> this case, the AUX event will record the kernel timestamp, but it
> doesn't mean Arm CoreSight enables timestamp packets in its hardware
> tracing.
>
> If the option '--timestamp' or '-T' is set, this patch always enables
> Arm CoreSight timestamp, as a result, the bit 28 in event's config is to
> be set.
>
> Before:
>
> # perf record -e cs_etm// --per-thread --timestamp -- ls
> # perf script --header-only
> ...
> # event : name = cs_etm//, , id = { 69 }, type = 12, size = 136,
> config = 0, { sample_period, sample_freq } = 1,
> sample_type = IP|TID|TIME|CPU|IDENTIFIER, read_format = ID|LOST,
> disabled = 1, enable_on_exec = 1, sample_id_all = 1, exclude_guest = 1
> ...
>
> After:
>
> # perf record -e cs_etm// --per-thread --timestamp -- ls
> # perf script --header-only
> ...
> # event : name = cs_etm//, , id = { 49 }, type = 12, size = 136,
> config = 0x10000000, { sample_period, sample_freq } = 1,
> sample_type = IP|TID|TIME|CPU|IDENTIFIER, read_format = ID|LOST,
> disabled = 1, enable_on_exec = 1, sample_id_all = 1, exclude_guest = 1
> ...
>
> Signed-off-by: Leo Yan <[email protected]>
> Reviewed-by: James Clark <[email protected]>

Acked-by: Suzuki K Poulose <[email protected]>

> ---
> tools/perf/arch/arm/util/cs-etm.c | 9 +++++++++
> 1 file changed, 9 insertions(+)
>
> diff --git a/tools/perf/arch/arm/util/cs-etm.c b/tools/perf/arch/arm/util/cs-etm.c
> index cf9ef9ba800b..58c506e9788d 100644
> --- a/tools/perf/arch/arm/util/cs-etm.c
> +++ b/tools/perf/arch/arm/util/cs-etm.c
> @@ -442,6 +442,15 @@ static int cs_etm_recording_options(struct auxtrace_record *itr,
> "contextid", 1);
> }
>
> + /*
> + * When the option '--timestamp' or '-T' is enabled, the PERF_SAMPLE_TIME
> + * bit is set for all events. In this case, always enable Arm CoreSight
> + * timestamp tracing.
> + */
> + if (opts->sample_time_set)
> + evsel__set_config_if_unset(cs_etm_pmu, cs_etm_evsel,
> + "timestamp", 1);
> +
> /* Add dummy event to keep tracking */
> err = parse_event(evlist, "dummy:u");
> if (err)

2023-10-17 19:56:42

by Namhyung Kim

[permalink] [raw]
Subject: Re: [PATCH v1 RESEND 0/2] perf cs-etm: Improve timestamp tracing

On Sat, 14 Oct 2023 15:41:57 +0800, Leo Yan wrote:
> This patch series is to improve timestamp handling in per-thread mode.
>
> The current code doesn't validate timestamp and always return success for
> per-thread mode, for a sane implementation, the first patch is to allow
> validation timestamp tracing in per-thread mode.
>
> The second patch is to respect timestamp option "--timestamp" or "-T",
> when users set this option, the tool will automatically enable hardware
> timestamp tracing in Arm CoreSight.
>
> [...]

Applied to perf-tools-next, thanks!