New issue
Advanced search Search tips
Note: Color blocks (like or ) mean that a user may not be available. Tooltip shows the reason.

Issue 719812 link

Starred by 2 users

Issue metadata

Status: Fixed
Owner:
Last visit > 30 days ago
Closed: Oct 2017
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: Chrome
Pri: 2
Type: Bug



Sign in to add a comment

Reduce init device latency

Project Member Reported by chinyue@chromium.org, May 9 2017

Issue description

When a device is being used, CRAS calls init_device if it is not opened yet.

For output device, the init_device first calls cras_iodev_set_format()  and then calls cras_iodev_open() to open the device.

- cras_iodev_set_format() calls update_channel_layout(), which involves a call to snd_pcm_hw_params()
- cras_iodev_open() calls open_dev(), which also involves a call to snd_pcm_hw_params()

To init a device, 2 snd_pcm_hw_params() calls are invoked with similar params.
The snd_pcm_hw_params() call is one of the most expensive snd operations (takes 16 ms to open Elm speaker)
So if we could reduce the snd_pcm_hw_params() call to only 1 time, that could help reduce device open latency (about 30-35% reduction)

 
Status: Started (was: Untriaged)
Another call we want to de-duplicate is the snd_pcm_open() call.

The snd_pcm_open() is called twice currently when CRAS opens a device. The first time is when CRAS queries device properties, and the second time is when CRAS really opens the device.
The first call takes 21ms and second call takes 33ms on reef to open internal speakers, and they totally takes 54ms out of the 64ms of init_device (84% of time)

Since we're really going to open the device, we don't have to close it after queried the properties and can save the second snd_pcm_open() call. And that could potentially reduce 50% of time to init a device.

Project Member

Comment 2 by bugdroid1@chromium.org, May 12 2017

The following revision refers to this bug:
  https://chromium.googlesource.com/chromiumos/third_party/adhd/+/3615ecbae09a43a52ddc716a0c038729fe24f5fd

commit 3615ecbae09a43a52ddc716a0c038729fe24f5fd
Author: Chinyue Chen <chinyue@google.com>
Date: Fri May 12 10:25:35 2017

CRAS: iodev - Skip update_channel_layout for 2-channel output.

If the requested channel count when opening an output device <= 2
then we can skip the update channel layout call and reduce the time
spent to init a device.

BUG= chromium:719812 
TEST=Tested on reef.

Change-Id: I46cba552751440a2043b0778b8b22a51a6113e3e
Reviewed-on: https://chromium-review.googlesource.com/499910
Commit-Ready: Chinyue Chen <chinyue@chromium.org>
Tested-by: Chinyue Chen <chinyue@chromium.org>
Reviewed-by: Hsinyu Chao <hychao@chromium.org>

[modify] https://crrev.com/3615ecbae09a43a52ddc716a0c038729fe24f5fd/cras/src/server/cras_iodev.c

The following CLs are also merged:

https://chromium-review.googlesource.com/#/c/503947/
https://chromium-review.googlesource.com/#/c/505974/


The time it takes to open speakers on reef is now 42ms (was 122ms before the reduction CLs)

Cc: ka...@chromium.org
Hi Chinyue

https://chromium-review.googlesource.com/c/505974/ broke the external mic on cyan and celes.

This was found in https://wmatrix.googleplex.com/platform/unfiltered?platforms=celes&suites=chameleon_audio_perbuild&days_back=20&releases=60&hide_missing=True and https://wmatrix.googleplex.com/platform/unfiltered?platforms=celes&suites=chameleon_audio_perbuild&days_back=20&releases=60&hide_missing=True

Could you please revert it first ?
Moja and I will be in MTV this week and we are trying to make test lab as stable as possible.
Thanks!
For example, on celes R60-9576.0.0

localhost ~ # cras_test_client --capture_f /tmp/c
Stream error -107
cras_test_client: cras_client: error removing stream from server

And see /var/log/messages:

2017-05-23T01:56:34.320333+00:00 ERR cras_server[24008]: No chmap queried!
2017-05-23T01:56:34.321449+00:00 ERR cras_server[24008]: hw_params: Invalid argument: rate: 48000, ret_rate: 48000, channel: 2, format: 2
2017-05-23T01:56:34.339102+00:00 ERR cras_server[24008]: Init chtrt5650: :1,0 failed, rc = -22
2017-05-23T01:56:35.362590+00:00 ERR cras_server[24008]: No chmap queried!
2017-05-23T01:56:35.363791+00:00 ERR cras_server[24008]: hw_params: Invalid argument: rate: 48000, ret_rate: 48000, channel: 2, format: 2
2017-05-23T01:56:35.381754+00:00 ERR cras_server[24008]: Enable chtrt5650: :1,0 failed, rc = -22
2017-05-23T01:56:35.381775+00:00 ERR cras_server[24008]: Init device retry failed

Comment 7 by chinyue@google.com, May 23 2017

I'll try it on cyan and fix it, sorry for the inconvenience!

Thanks! The test start passing from 9581.
Project Member

Comment 9 by bugdroid1@chromium.org, May 29 2017

Labels: merge-merged-release-R59-9460.B
The following revision refers to this bug:
  https://chromium.googlesource.com/chromiumos/third_party/adhd/+/85e70ffda3f2b47a6665adca0fd4e885ab032a9c

commit 85e70ffda3f2b47a6665adca0fd4e885ab032a9c
Author: Chinyue Chen <chinyue@google.com>
Date: Mon May 29 03:58:46 2017

CRAS: iodev - Skip update_channel_layout for 2-channel output.

If the requested channel count when opening an output device <= 2
then we can skip the update channel layout call and reduce the time
spent to init a device.

BUG= chromium:719812 
TEST=Tested on reef.

Change-Id: I46cba552751440a2043b0778b8b22a51a6113e3e
Reviewed-on: https://chromium-review.googlesource.com/499910
Commit-Ready: Chinyue Chen <chinyue@chromium.org>
Tested-by: Chinyue Chen <chinyue@chromium.org>
Reviewed-by: Hsinyu Chao <hychao@chromium.org>
(cherry picked from commit 3615ecbae09a43a52ddc716a0c038729fe24f5fd)
Reviewed-on: https://chromium-review.googlesource.com/517464
Reviewed-by: Chinyue Chen <chinyue@chromium.org>
Commit-Queue: Chinyue Chen <chinyue@chromium.org>

[modify] https://crrev.com/85e70ffda3f2b47a6665adca0fd4e885ab032a9c/cras/src/server/cras_iodev.c

Status: Fixed (was: Started)
The deduplicate CL has been re-laneded: https://chromium-review.googlesource.com/572447

Comment 11 by dchan@chromium.org, Jan 22 2018

Status: Archived (was: Fixed)

Comment 12 by dchan@chromium.org, Jan 23 2018

Status: Fixed (was: Archived)

Sign in to add a comment