[Sound-open-firmware] [PATCH] [RFC]platform: calculate the percentage of cpu cycle
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) {
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) {
Hi Zhigang,
I think, that correct value for 400MHz clock is:
*#define CPU_CYCLE_PER_MS 400000000*
* *
Tomek **
On 21.06.2018 11:59, zhigangw wrote:
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) {
Sound-open-firmware mailing list Sound-open-firmware@alsa-project.org http://mailman.alsa-project.org/mailman/listinfo/sound-open-firmware
On Thu, 2018-06-21 at 12:04 +0200, Lauda, Tomasz wrote:
Hi Zhigang,
I think, that correct value for 400MHz clock is:
*#define CPU_CYCLE_PER_MS 400000000*
Tomek **
On 21.06.2018 11:59, zhigangw wrote:
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.
This is broken, you are just timing DMA interrupts. Please enable verbose trace and you should see all the calls time stamped.
Liam
On 2018年06月21日 18:10, Liam Girdwood wrote:
On Thu, 2018-06-21 at 12:04 +0200, Lauda, Tomasz wrote:
Hi Zhigang,
I think, that correct value for 400MHz clock is:
*#define CPU_CYCLE_PER_MS 400000000*
Tomek **
On 21.06.2018 11:59, zhigangw wrote:
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.
This is broken, you are just timing DMA interrupts. Please enable verbose trace and you should see all the calls time stamped.
Liam
I want to estimate the CPU usage. How to estimate this with the verbose trace. Do you have any idea? Thanks ~zhigang
Sound-open-firmware mailing list Sound-open-firmware@alsa-project.org http://mailman.alsa-project.org/mailman/listinfo/sound-open-firmware
On Fri, 2018-06-22 at 16:46 +0800, zhigangw wrote:
Liam
I want to estimate the CPU usage. How to estimate this with the verbose trace. Do you have any idea?
The pipeline work can be timed by looking at the pipeline schedule start and finish trace messages and the time delta between them.
e.g. consider a pipeline with a 1ms scheduling tick that takes 200uS to run from start to finish. The pipeline CPU utilisation is 20%
Liam
On 2018年06月22日 18:13, Liam Girdwood wrote:
On Fri, 2018-06-22 at 16:46 +0800, zhigangw wrote:
Liam
I want to estimate the CPU usage. How to estimate this with the verbose trace. Do you have any idea?
The pipeline work can be timed by looking at the pipeline schedule start and finish trace messages and the time delta between them.
e.g. consider a pipeline with a 1ms scheduling tick that takes 200uS to run from start to finish. The pipeline CPU utilisation is 20%
Liam
Hmm, this way would not take the scheduler period into account. And using the timestamp, I am not sure whether it is accurate than using the CCOUNT register. I will give another RFC later. please check it. Thanks ~Zhigang
On Mon, 2018-06-25 at 11:20 +0800, zhigangw wrote:
On 2018年06月22日 18:13, Liam Girdwood wrote:
On Fri, 2018-06-22 at 16:46 +0800, zhigangw wrote:
Liam
I want to estimate the CPU usage. How to estimate this with the verbose trace. Do you have any idea?
The pipeline work can be timed by looking at the pipeline schedule start and finish trace messages and the time delta between them.
e.g. consider a pipeline with a 1ms scheduling tick that takes 200uS to run from start to finish. The pipeline CPU utilisation is 20%
Liam
Hmm, this way would not take the scheduler period into account. And using the timestamp, I am not sure whether it is accurate than using the CCOUNT register. I will give another RFC later. please check it. Thanks ~Zhigang
Trace takes all parts of the scheduler/pipeline into account. You can enable/disable any trace message you like in order to time events. Please use trace and move on.
Liam
On 2018年06月25日 14:28, Liam Girdwood wrote:
On Mon, 2018-06-25 at 11:20 +0800, zhigangw wrote:
On 2018年06月22日 18:13, Liam Girdwood wrote:
On Fri, 2018-06-22 at 16:46 +0800, zhigangw wrote:
Liam
I want to estimate the CPU usage. How to estimate this with the verbose trace. Do you have any idea?
The pipeline work can be timed by looking at the pipeline schedule start and finish trace messages and the time delta between them.
e.g. consider a pipeline with a 1ms scheduling tick that takes 200uS to run from start to finish. The pipeline CPU utilisation is 20%
Liam
Hmm, this way would not take the scheduler period into account. And using the timestamp, I am not sure whether it is accurate than using the CCOUNT register. I will give another RFC later. please check it. Thanks ~Zhigang
Trace takes all parts of the scheduler/pipeline into account. You can enable/disable any trace message you like in order to time events. Please use trace and move on.
Liam
Hello Liam: Maybe my question is stupid, I think the pipeline's start point is over here in dai_dma_cb() function:
if (dev->state == COMP_STATE_ACTIVE) { /* I will add the trace code here to print as pipeline start point */ pipeline_schedule_copy(dev->pipeline, 0); }
Where is the finish point of the pipeline? :-
Thanks ~zhigang
On Mon, 2018-06-25 at 17:16 +0800, zhigangw wrote:
Maybe my question is stupid, I think the pipeline's start point is over here in dai_dma_cb() function:
if (dev->state == COMP_STATE_ACTIVE) { /* I will add the trace code here to print as pipeline start
point */ pipeline_schedule_copy(dev->pipeline, 0); }
Where is the finish point of the pipeline? :-
Your pipeline is scheduled by the DMA callback and will run immediately atm.
Please look at pipeline_task() for start and finish trace messages.
Liam
On 2018年06月21日 18:04, Lauda, Tomasz wrote:
Hi Zhigang,
I think, that correct value for 400MHz clock is:
*#define CPU_CYCLE_PER_MS 400000000*
Tomek
I used the 1ms as the base interval, so it should be 400000. Thanks ~zhigang
On 21.06.2018 11:59, zhigangw wrote:
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) {
Sound-open-firmware mailing list Sound-open-firmware@alsa-project.org http://mailman.alsa-project.org/mailman/listinfo/sound-open-firmware
-----Original Message----- From: sound-open-firmware-bounces@alsa-project.org [mailto:sound-open- firmware-bounces@alsa-project.org] On Behalf Of Wu Zhigang Sent: Thursday, June 21, 2018 5:57 PM To: sound-open-firmware@alsa-project.org Cc: Wu Zhigang zhigang.wu@linux.intel.com Subject: [Sound-open-firmware] [PATCH] [RFC]platform: calculate the percentage of cpu cycle
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");
I think you should use ICOUNT, not CCOUNT.
Thanks, ~Keyon
- 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
Sound-open-firmware mailing list Sound-open-firmware@alsa-project.org http://mailman.alsa-project.org/mailman/listinfo/sound-open-firmware
participants (5)
-
Jie, Yang
-
Lauda, Tomasz
-
Liam Girdwood
-
Wu Zhigang
-
zhigangw