zephyrproject-rtos / zephyr

Primary Git Repository for the Zephyr Project. Zephyr is a new generation, scalable, optimized, secure RTOS for multiple hardware architectures.
https://docs.zephyrproject.org
Apache License 2.0
10.44k stars 6.4k forks source link

usb: audio: high CPU load when running headphones_microphone sample #26857

Open koffes opened 4 years ago

koffes commented 4 years ago

Is your enhancement proposal related to a problem? Please describe. Running the mentioned sample on the nRF52840. Vanilla setup, no changes to config.

The CPU loads are: Idle: 4 % Playback 33 % Paused playback: 33 %. Goes down to 26 % after a while Play and record: 52 %

Describe the solution you'd like Please try to enable DMA. This will likely reduce CPU load significantly.

@emob-nordic @alexsven

alexsven commented 3 years ago

I have done some testing on the headset sample with a nRF5340.

I have tested two set ups, one with stereo hp + stereo mic (vanilla sample) and another where I remove one channel from both hp and mic from the overlay file, thus creating a mono device.

The starting CPU load before any audio has been played is 10%, then I start the audio and I see that the CPU load goes up to 40% for stereo hp and 37% for mono hp. When I at the same time sink the mic line by recording with Audacity I get 63% for stereo and 57% for mono. When stopping audio and stopping sink I get 33% for both usecases after a while.

EDIT: CPU load was measured using CONFIG_TRACING=y CONFIG_TRACING_CPU_STATS=y CONFIG_TRACING_CPU_STATS_LOG=y CONFIG_TRACING_CPU_STATS_INTERVAL=5000

alexsven commented 3 years ago

Ran one more test: Headphones only Starting CPU load: 7% Playing audio: 28% Paused: 21%

ddavidebor commented 3 years ago

@koffes I see this has been opened for a long time. Is there an update on this?

koffes commented 3 years ago

@ddavidebor We are waiting for this issue to be resolved as part of #26935

alexsven commented 2 years ago

Testing again with v3.0.0-rc1 and nRF5340 Stereo headphones: 19% CPU, Stereo headset: 22%, 10% is consumed by sysworkq.

This was run on an nRF5340

alexsven commented 2 years ago

Testing on nRF52840 I get: Stereo headphones : 21% Stereo headset: 24% for USB thread, 11% for sysworkq

tmon-nordic commented 10 months ago

64174 makes rather significant amount of cpu time available to application because it eliminates busy loop inside interrupt while waiting for DMA to finish.