2020-10-22 17:52:43

by Leo Yan

[permalink] [raw]
Subject: [PATCH v3 11/20] perf arm-spe: Add new function arm_spe_pkt_desc_counter()

This patch moves out the counter packet parsing code from
arm_spe_pkt_desc() to the new function arm_spe_pkt_desc_counter().

Signed-off-by: Leo Yan <[email protected]>
---
.../arm-spe-decoder/arm-spe-pkt-decoder.c | 64 +++++++++++--------
1 file changed, 37 insertions(+), 27 deletions(-)

diff --git a/tools/perf/util/arm-spe-decoder/arm-spe-pkt-decoder.c b/tools/perf/util/arm-spe-decoder/arm-spe-pkt-decoder.c
index 1fc07c693640..023bcc9be3cc 100644
--- a/tools/perf/util/arm-spe-decoder/arm-spe-pkt-decoder.c
+++ b/tools/perf/util/arm-spe-decoder/arm-spe-pkt-decoder.c
@@ -293,6 +293,42 @@ static int arm_spe_pkt_desc_addr(const struct arm_spe_pkt *packet,
}
}

+static int arm_spe_pkt_desc_counter(const struct arm_spe_pkt *packet,
+ char *buf, size_t buf_len)
+{
+ u64 payload = packet->payload;
+ const char *name = arm_spe_pkt_name(packet->type);
+ size_t blen = buf_len;
+ int ret;
+
+ ret = arm_spe_pkt_snprintf(&buf, &blen, "%s %d ", name,
+ (unsigned short)payload);
+ if (ret < 0)
+ return ret;
+
+ switch (packet->index) {
+ case 0:
+ ret = arm_spe_pkt_snprintf(&buf, &blen, "TOT");
+ if (ret < 0)
+ return ret;
+ break;
+ case 1:
+ ret = arm_spe_pkt_snprintf(&buf, &blen, "ISSUE");
+ if (ret < 0)
+ return ret;
+ break;
+ case 2:
+ ret = arm_spe_pkt_snprintf(&buf, &blen, "XLAT");
+ if (ret < 0)
+ return ret;
+ break;
+ default:
+ break;
+ }
+
+ return buf_len - blen;
+}
+
int arm_spe_pkt_desc(const struct arm_spe_pkt *packet, char *buf,
size_t buf_len)
{
@@ -435,33 +471,7 @@ int arm_spe_pkt_desc(const struct arm_spe_pkt *packet, char *buf,
return arm_spe_pkt_snprintf(&buf, &blen, "%s 0x%lx el%d",
name, (unsigned long)payload, idx + 1);
case ARM_SPE_COUNTER:
- ret = arm_spe_pkt_snprintf(&buf, &blen, "%s %d ", name,
- (unsigned short)payload);
- if (ret < 0)
- return ret;
-
- switch (idx) {
- case 0:
- ret = arm_spe_pkt_snprintf(&buf, &blen, "TOT");
- if (ret < 0)
- return ret;
- break;
- case 1:
- ret = arm_spe_pkt_snprintf(&buf, &blen, "ISSUE");
- if (ret < 0)
- return ret;
- break;
- case 2:
- ret = arm_spe_pkt_snprintf(&buf, &blen, "XLAT");
- if (ret < 0)
- return ret;
- break;
- default:
- break;
- }
-
- return buf_len - blen;
-
+ return arm_spe_pkt_desc_counter(packet, buf, buf_len);
default:
break;
}
--
2.17.1


2020-10-23 18:57:50

by Andre Przywara

[permalink] [raw]
Subject: Re: [PATCH v3 11/20] perf arm-spe: Add new function arm_spe_pkt_desc_counter()

On 22/10/2020 15:58, Leo Yan wrote:
> This patch moves out the counter packet parsing code from
> arm_spe_pkt_desc() to the new function arm_spe_pkt_desc_counter().
>
> Signed-off-by: Leo Yan <[email protected]>

Confirmed by diff'ing '-' vs. '+' to not introduce an actual change.

Reviewed-by: Andre Przywara <[email protected]>

Cheers,
Andre

> ---
> .../arm-spe-decoder/arm-spe-pkt-decoder.c | 64 +++++++++++--------
> 1 file changed, 37 insertions(+), 27 deletions(-)
>
> diff --git a/tools/perf/util/arm-spe-decoder/arm-spe-pkt-decoder.c b/tools/perf/util/arm-spe-decoder/arm-spe-pkt-decoder.c
> index 1fc07c693640..023bcc9be3cc 100644
> --- a/tools/perf/util/arm-spe-decoder/arm-spe-pkt-decoder.c
> +++ b/tools/perf/util/arm-spe-decoder/arm-spe-pkt-decoder.c
> @@ -293,6 +293,42 @@ static int arm_spe_pkt_desc_addr(const struct arm_spe_pkt *packet,
> }
> }
>
> +static int arm_spe_pkt_desc_counter(const struct arm_spe_pkt *packet,
> + char *buf, size_t buf_len)
> +{
> + u64 payload = packet->payload;
> + const char *name = arm_spe_pkt_name(packet->type);
> + size_t blen = buf_len;
> + int ret;
> +
> + ret = arm_spe_pkt_snprintf(&buf, &blen, "%s %d ", name,
> + (unsigned short)payload);
> + if (ret < 0)
> + return ret;
> +
> + switch (packet->index) {
> + case 0:
> + ret = arm_spe_pkt_snprintf(&buf, &blen, "TOT");
> + if (ret < 0)
> + return ret;
> + break;
> + case 1:
> + ret = arm_spe_pkt_snprintf(&buf, &blen, "ISSUE");
> + if (ret < 0)
> + return ret;
> + break;
> + case 2:
> + ret = arm_spe_pkt_snprintf(&buf, &blen, "XLAT");
> + if (ret < 0)
> + return ret;
> + break;
> + default:
> + break;
> + }
> +
> + return buf_len - blen;
> +}
> +
> int arm_spe_pkt_desc(const struct arm_spe_pkt *packet, char *buf,
> size_t buf_len)
> {
> @@ -435,33 +471,7 @@ int arm_spe_pkt_desc(const struct arm_spe_pkt *packet, char *buf,
> return arm_spe_pkt_snprintf(&buf, &blen, "%s 0x%lx el%d",
> name, (unsigned long)payload, idx + 1);
> case ARM_SPE_COUNTER:
> - ret = arm_spe_pkt_snprintf(&buf, &blen, "%s %d ", name,
> - (unsigned short)payload);
> - if (ret < 0)
> - return ret;
> -
> - switch (idx) {
> - case 0:
> - ret = arm_spe_pkt_snprintf(&buf, &blen, "TOT");
> - if (ret < 0)
> - return ret;
> - break;
> - case 1:
> - ret = arm_spe_pkt_snprintf(&buf, &blen, "ISSUE");
> - if (ret < 0)
> - return ret;
> - break;
> - case 2:
> - ret = arm_spe_pkt_snprintf(&buf, &blen, "XLAT");
> - if (ret < 0)
> - return ret;
> - break;
> - default:
> - break;
> - }
> -
> - return buf_len - blen;
> -
> + return arm_spe_pkt_desc_counter(packet, buf, buf_len);
> default:
> break;
> }
>