I use this way to calculate the CPU usage in our firmware.
I am not sure this way is correct or not.
from this way, I found the percentage is very high when I only do the playback alone with tdm8 mode.
almost 95% CPU usage.
that is the reason I send this RFC.
please give me the feedback whether this way to calculate the CPU usage is correct or not.
thanks
~zhigang
On 2018年06月21日 17:57, Wu Zhigang wrote:
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@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) {