[Sound-open-firmware] [PATCH] [RFC]platform: calculate the percentage of cpu cycle
Wu Zhigang
zhigang.wu at linux.intel.com
Thu Jun 21 11:57:01 CEST 2018
calculate the percentage of cpu cyle based on
the CCOUNT register. which can tell the percentage
of cpu cycle usage.
Signed-off-by: Wu Zhigang <zhigang.wu at linux.intel.com>
---
src/audio/dai.c | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
diff --git a/src/audio/dai.c b/src/audio/dai.c
index 99749d1..7811e38 100644
--- a/src/audio/dai.c
+++ b/src/audio/dai.c
@@ -72,6 +72,21 @@ struct dai_data {
uint64_t wallclock; /* wall clock at stream start */
};
+/* for apollolake, it is 400MHz per 1s */
+#define CPU_CYCLE_PER_MS 400000
+
+static void calc_mcps(struct pipeline *p)
+{
+ uint32_t cpu_cycle = 0;
+ uint32_t deta = 0;
+
+ __asm__ __volatile__ ("rsr %0, CCOUNT" : "=a" (cpu_cycle) : : "memory");
+ deta = cpu_cycle - p->cpu_cycle;
+ p->cpu_cycle = cpu_cycle;
+ deta = (deta * 100) / CPU_CYCLE_PER_MS;
+ trace_error_value(deta); /* the percentage of the cpu cycle in 1ms */
+}
+
/* this is called by DMA driver every time descriptor has completed */
static void dai_dma_cb(void *data, uint32_t type, struct dma_sg_elem *next)
{
@@ -81,6 +96,8 @@ static void dai_dma_cb(void *data, uint32_t type, struct dma_sg_elem *next)
tracev_dai("irq");
+ calc_mcps(dev->pipeline);
+
/* stop dma copy for pause/stop/xrun */
if (dev->state != COMP_STATE_ACTIVE || dd->xrun) {
--
2.17.1
More information about the Sound-open-firmware
mailing list