diff options
author | Mathieu Poirier <mathieu.poirier@linaro.org> | 2019-02-12 12:16:17 -0500 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2019-02-14 13:18:07 -0500 |
commit | 3fa0e83e29488547b39f321fd5a239f08f129c72 (patch) | |
tree | 69af5d41eeee13ade29d22a974ec35d74b241d9f | |
parent | f74f349c211e3e62bc7fe35a132918c7f2c0fafb (diff) |
perf cs-etm: Modularize main packet processing loop
Making the main packet processing loop modular so that it can be called
from different decoding context (timeless vs. non-timless), avoiding to
repeat code.
Signed-off-by: Mathieu Poirier <mathieu.poirier@linaro.org>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Suzuki K Poulouse <suzuki.poulose@arm.com>
Cc: linux-arm-kernel@lists.infradead.org
Link: http://lkml.kernel.org/r/20190212171618.25355-13-mathieu.poirier@linaro.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r-- | tools/perf/util/cs-etm.c | 129 |
1 files changed, 72 insertions, 57 deletions
diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c index cfa686fe223e..f607bc58bd03 100644 --- a/tools/perf/util/cs-etm.c +++ b/tools/perf/util/cs-etm.c | |||
@@ -1519,6 +1519,72 @@ out: | |||
1519 | return ret; | 1519 | return ret; |
1520 | } | 1520 | } |
1521 | 1521 | ||
1522 | static int cs_etm__process_decoder_queue(struct cs_etm_queue *etmq) | ||
1523 | { | ||
1524 | int ret; | ||
1525 | |||
1526 | /* Process each packet in this chunk */ | ||
1527 | while (1) { | ||
1528 | ret = cs_etm_decoder__get_packet(etmq->decoder, | ||
1529 | etmq->packet); | ||
1530 | if (ret <= 0) | ||
1531 | /* | ||
1532 | * Stop processing this chunk on | ||
1533 | * end of data or error | ||
1534 | */ | ||
1535 | break; | ||
1536 | |||
1537 | /* | ||
1538 | * Since packet addresses are swapped in packet | ||
1539 | * handling within below switch() statements, | ||
1540 | * thus setting sample flags must be called | ||
1541 | * prior to switch() statement to use address | ||
1542 | * information before packets swapping. | ||
1543 | */ | ||
1544 | ret = cs_etm__set_sample_flags(etmq); | ||
1545 | if (ret < 0) | ||
1546 | break; | ||
1547 | |||
1548 | switch (etmq->packet->sample_type) { | ||
1549 | case CS_ETM_RANGE: | ||
1550 | /* | ||
1551 | * If the packet contains an instruction | ||
1552 | * range, generate instruction sequence | ||
1553 | * events. | ||
1554 | */ | ||
1555 | cs_etm__sample(etmq); | ||
1556 | break; | ||
1557 | case CS_ETM_EXCEPTION: | ||
1558 | case CS_ETM_EXCEPTION_RET: | ||
1559 | /* | ||
1560 | * If the exception packet is coming, | ||
1561 | * make sure the previous instruction | ||
1562 | * range packet to be handled properly. | ||
1563 | */ | ||
1564 | cs_etm__exception(etmq); | ||
1565 | break; | ||
1566 | case CS_ETM_DISCONTINUITY: | ||
1567 | /* | ||
1568 | * Discontinuity in trace, flush | ||
1569 | * previous branch stack | ||
1570 | */ | ||
1571 | cs_etm__flush(etmq); | ||
1572 | break; | ||
1573 | case CS_ETM_EMPTY: | ||
1574 | /* | ||
1575 | * Should not receive empty packet, | ||
1576 | * report error. | ||
1577 | */ | ||
1578 | pr_err("CS ETM Trace: empty packet\n"); | ||
1579 | return -EINVAL; | ||
1580 | default: | ||
1581 | break; | ||
1582 | } | ||
1583 | } | ||
1584 | |||
1585 | return ret; | ||
1586 | } | ||
1587 | |||
1522 | static int cs_etm__run_decoder(struct cs_etm_queue *etmq) | 1588 | static int cs_etm__run_decoder(struct cs_etm_queue *etmq) |
1523 | { | 1589 | { |
1524 | int err = 0; | 1590 | int err = 0; |
@@ -1544,64 +1610,13 @@ static int cs_etm__run_decoder(struct cs_etm_queue *etmq) | |||
1544 | if (err) | 1610 | if (err) |
1545 | return err; | 1611 | return err; |
1546 | 1612 | ||
1547 | /* Process each packet in this chunk */ | 1613 | /* |
1548 | while (1) { | 1614 | * Process each packet in this chunk, nothing to do if |
1549 | err = cs_etm_decoder__get_packet(etmq->decoder, | 1615 | * an error occurs other than hoping the next one will |
1550 | etmq->packet); | 1616 | * be better. |
1551 | if (err <= 0) | 1617 | */ |
1552 | /* | 1618 | err = cs_etm__process_decoder_queue(etmq); |
1553 | * Stop processing this chunk on | ||
1554 | * end of data or error | ||
1555 | */ | ||
1556 | break; | ||
1557 | 1619 | ||
1558 | /* | ||
1559 | * Since packet addresses are swapped in packet | ||
1560 | * handling within below switch() statements, | ||
1561 | * thus setting sample flags must be called | ||
1562 | * prior to switch() statement to use address | ||
1563 | * information before packets swapping. | ||
1564 | */ | ||
1565 | err = cs_etm__set_sample_flags(etmq); | ||
1566 | if (err < 0) | ||
1567 | break; | ||
1568 | |||
1569 | switch (etmq->packet->sample_type) { | ||
1570 | case CS_ETM_RANGE: | ||
1571 | /* | ||
1572 | * If the packet contains an instruction | ||
1573 | * range, generate instruction sequence | ||
1574 | * events. | ||
1575 | */ | ||
1576 | cs_etm__sample(etmq); | ||
1577 | break; | ||
1578 | case CS_ETM_EXCEPTION: | ||
1579 | case CS_ETM_EXCEPTION_RET: | ||
1580 | /* | ||
1581 | * If the exception packet is coming, | ||
1582 | * make sure the previous instruction | ||
1583 | * range packet to be handled properly. | ||
1584 | */ | ||
1585 | cs_etm__exception(etmq); | ||
1586 | break; | ||
1587 | case CS_ETM_DISCONTINUITY: | ||
1588 | /* | ||
1589 | * Discontinuity in trace, flush | ||
1590 | * previous branch stack | ||
1591 | */ | ||
1592 | cs_etm__flush(etmq); | ||
1593 | break; | ||
1594 | case CS_ETM_EMPTY: | ||
1595 | /* | ||
1596 | * Should not receive empty packet, | ||
1597 | * report error. | ||
1598 | */ | ||
1599 | pr_err("CS ETM Trace: empty packet\n"); | ||
1600 | return -EINVAL; | ||
1601 | default: | ||
1602 | break; | ||
1603 | } | ||
1604 | } | ||
1605 | } while (etmq->buf_len); | 1620 | } while (etmq->buf_len); |
1606 | 1621 | ||
1607 | if (err == 0) | 1622 | if (err == 0) |