[PATCH v3 16/20] perf arm-spe: Add new function arm_spe_pkt_desc_op_type()

From: Leo Yan
Date: Thu Oct 22 2020 - 10:59:15 EST


The operation type packet is complex and contains subclass; the parsing
flow causes deep indentation; for more readable, this patch introduces
a new function arm_spe_pkt_desc_op_type() which is used for operation
type parsing.

Signed-off-by: Leo Yan <leo.yan@xxxxxxxxxx>
---
.../arm-spe-decoder/arm-spe-pkt-decoder.c | 122 ++++++++++--------
1 file changed, 66 insertions(+), 56 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 2cb019999016..19d05d9734ab 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
@@ -336,6 +336,70 @@ static int arm_spe_pkt_desc_event(const struct arm_spe_pkt *packet,
return buf_len - blen;
}

+static int arm_spe_pkt_desc_op_type(const struct arm_spe_pkt *packet,
+ char *buf, size_t buf_len)
+{
+ int ret, idx = packet->index;
+ unsigned long long payload = packet->payload;
+ size_t blen = buf_len;
+
+ switch (idx) {
+ case 0:
+ return arm_spe_pkt_snprintf(&buf, &blen,
+ payload & 0x1 ? "COND-SELECT" : "INSN-OTHER");
+ case 1:
+ ret = arm_spe_pkt_snprintf(&buf, &blen,
+ payload & 0x1 ? "ST" : "LD");
+ if (ret < 0)
+ return ret;
+
+ if (payload & 0x2) {
+ if (payload & 0x4) {
+ ret = arm_spe_pkt_snprintf(&buf, &blen, " AT");
+ if (ret < 0)
+ return ret;
+ }
+ if (payload & 0x8) {
+ ret = arm_spe_pkt_snprintf(&buf, &blen, " EXCL");
+ if (ret < 0)
+ return ret;
+ }
+ if (payload & 0x10) {
+ ret = arm_spe_pkt_snprintf(&buf, &blen, " AR");
+ if (ret < 0)
+ return ret;
+ }
+ } else if (payload & 0x4) {
+ ret = arm_spe_pkt_snprintf(&buf, &blen, " SIMD-FP");
+ if (ret < 0)
+ return ret;
+ }
+
+ return buf_len - blen;
+
+ case 2:
+ ret = arm_spe_pkt_snprintf(&buf, &blen, "B");
+ if (ret < 0)
+ return ret;
+
+ if (payload & 0x1) {
+ ret = arm_spe_pkt_snprintf(&buf, &blen, " COND");
+ if (ret < 0)
+ return ret;
+ }
+ if (payload & 0x2) {
+ ret = arm_spe_pkt_snprintf(&buf, &blen, " IND");
+ if (ret < 0)
+ return ret;
+ }
+
+ return buf_len - blen;
+
+ default:
+ return 0;
+ }
+}
+
static int arm_spe_pkt_desc_addr(const struct arm_spe_pkt *packet,
char *buf, size_t buf_len)
{
@@ -403,7 +467,7 @@ static int arm_spe_pkt_desc_counter(const struct arm_spe_pkt *packet,
int arm_spe_pkt_desc(const struct arm_spe_pkt *packet, char *buf,
size_t buf_len)
{
- int ret, idx = packet->index;
+ int idx = packet->index;
unsigned long long payload = packet->payload;
const char *name = arm_spe_pkt_name(packet->type);
size_t blen = buf_len;
@@ -416,61 +480,7 @@ int arm_spe_pkt_desc(const struct arm_spe_pkt *packet, char *buf,
case ARM_SPE_EVENTS:
return arm_spe_pkt_desc_event(packet, buf, buf_len);
case ARM_SPE_OP_TYPE:
- switch (idx) {
- case 0:
- return arm_spe_pkt_snprintf(&buf, &blen,
- payload & 0x1 ? "COND-SELECT" : "INSN-OTHER");
- case 1:
- ret = arm_spe_pkt_snprintf(&buf, &blen,
- payload & 0x1 ? "ST" : "LD");
- if (ret < 0)
- return ret;
-
- if (payload & 0x2) {
- if (payload & 0x4) {
- ret = arm_spe_pkt_snprintf(&buf, &blen, " AT");
- if (ret < 0)
- return ret;
- }
- if (payload & 0x8) {
- ret = arm_spe_pkt_snprintf(&buf, &blen, " EXCL");
- if (ret < 0)
- return ret;
- }
- if (payload & 0x10) {
- ret = arm_spe_pkt_snprintf(&buf, &blen, " AR");
- if (ret < 0)
- return ret;
- }
- } else if (payload & 0x4) {
- ret = arm_spe_pkt_snprintf(&buf, &blen, " SIMD-FP");
- if (ret < 0)
- return ret;
- }
-
- return buf_len - blen;
-
- case 2:
- ret = arm_spe_pkt_snprintf(&buf, &blen, "B");
- if (ret < 0)
- return ret;
-
- if (payload & 0x1) {
- ret = arm_spe_pkt_snprintf(&buf, &blen, " COND");
- if (ret < 0)
- return ret;
- }
- if (payload & 0x2) {
- ret = arm_spe_pkt_snprintf(&buf, &blen, " IND");
- if (ret < 0)
- return ret;
- }
-
- return buf_len - blen;
-
- default:
- return 0;
- }
+ return arm_spe_pkt_desc_op_type(packet, buf, buf_len);
case ARM_SPE_DATA_SOURCE:
case ARM_SPE_TIMESTAMP:
return arm_spe_pkt_snprintf(&buf, &blen, "%s %lld", name, payload);
--
2.17.1