hal: add perf lock to reduce the time for audio route init
Add performance lock before audio_route_init is called
to reduce total initialization time of ahal.
Change-Id: I96bddffa8dc9e05af27873a518185c4e743ee190
diff --git a/hal/audio_hw.c b/hal/audio_hw.c
index 8fbd3dc..fa60f4d 100644
--- a/hal/audio_hw.c
+++ b/hal/audio_hw.c
@@ -9669,6 +9669,8 @@
adev->use_old_pspd_mix_ctrl = false;
adev->adm_routing_changed = false;
+ audio_extn_perf_lock_init();
+
/* Loads platform specific libraries dynamically */
adev->platform = platform_init(adev);
if (!adev->platform) {
@@ -9861,7 +9863,6 @@
adev->adm_data = adev->adm_init();
qahwi_init(*device);
- audio_extn_perf_lock_init();
audio_extn_adsp_hdlr_init(adev->mixer);
audio_extn_snd_mon_init();
diff --git a/hal/msm8974/platform.c b/hal/msm8974/platform.c
index 0c4b8d3..f81fbba 100644
--- a/hal/msm8974/platform.c
+++ b/hal/msm8974/platform.c
@@ -2972,79 +2972,6 @@
return NULL;
}
- if (platform_is_i2s_ext_modem(snd_card_name, my_data) &&
- !is_auto_snd_card(snd_card_name)) {
- ALOGD("%s: Call MIXER_XML_PATH_I2S", __func__);
-
- adev->audio_route = audio_route_init(adev->snd_card,
- MIXER_XML_PATH_I2S);
- } else {
- /* Get the codec internal name from the sound card name
- * and form the mixer paths file name dynamically. This
- * is generic way of picking any codec name based mixer
- * files in future with no code change. This code
- * assumes mixer files are formed with format as
- * mixer_paths_internalcodecname.xml
-
- * If this dynamically read mixer files fails to open then it
- * falls back to default mixer file i.e mixer_paths.xml. This is
- * done to preserve backward compatibility but not mandatory as
- * long as the mixer files are named as per above assumption.
- */
- snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s_%s.xml",
- MIXER_XML_BASE_STRING, snd_split_handle->snd_card,
- snd_split_handle->form_factor);
- if (!audio_extn_utils_resolve_config_file(mixer_xml_file)) {
- memset(mixer_xml_file, 0, sizeof(mixer_xml_file));
- snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s.xml",
- MIXER_XML_BASE_STRING, snd_split_handle->variant);
-
- if (!audio_extn_utils_resolve_config_file(mixer_xml_file)) {
- memset(mixer_xml_file, 0, sizeof(mixer_xml_file));
- snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s.xml",
- MIXER_XML_BASE_STRING, snd_split_handle->snd_card);
-
- if (!audio_extn_utils_resolve_config_file(mixer_xml_file)) {
- memset(mixer_xml_file, 0, sizeof(mixer_xml_file));
- strlcpy(mixer_xml_file, MIXER_XML_DEFAULT_PATH, MIXER_PATH_MAX_LENGTH);
- audio_extn_utils_resolve_config_file(mixer_xml_file);
- }
- }
- }
-
- ALOGD("%s: Loading mixer file: %s", __func__, mixer_xml_file);
- if (audio_extn_read_xml(adev, adev->snd_card, mixer_xml_file,
- MIXER_XML_PATH_AUXPCM) == -ENOSYS) {
- adev->audio_route = audio_route_init(adev->snd_card, mixer_xml_file);
- update_codec_type_and_interface(my_data, snd_card_name);
- }
- }
-
-#if defined (PLATFORM_MSMFALCON) || defined (PLATFORM_MSM8937)
- if (my_data->is_internal_codec == true) {
- msm_device_to_be_id = msm_device_to_be_id_internal_codec;
- msm_be_id_array_len =
- sizeof(msm_device_to_be_id_internal_codec) /
- sizeof(msm_device_to_be_id_internal_codec[0]);
- } else {
- msm_device_to_be_id = msm_device_to_be_id_external_codec;
- msm_be_id_array_len =
- sizeof(msm_device_to_be_id_external_codec) /
- sizeof(msm_device_to_be_id_external_codec[0]);
- }
-#endif
-
- if (!adev->audio_route) {
- ALOGE("%s: Failed to init audio route controls, aborting.",
- __func__);
- if (my_data)
- free(my_data);
- if (snd_card_name)
- free(snd_card_name);
- audio_extn_utils_close_snd_mixer(adev->mixer);
- return NULL;
- }
-
adev->dp_allowed_for_voice =
property_get_bool("vendor.audio.enable.dp.for.voice", false);
@@ -3245,6 +3172,84 @@
platform_info_init(platform_info_file, my_data, PLATFORM);
}
+ // acquire perf lock to reduce the time for audio route init
+ audio_extn_perf_lock_acquire(&adev->perf_lock_handle, 0,
+ adev->perf_lock_opts,
+ adev->perf_lock_opts_size);
+ if (platform_is_i2s_ext_modem(snd_card_name, my_data) &&
+ !is_auto_snd_card(snd_card_name)) {
+ ALOGD("%s: Call MIXER_XML_PATH_I2S", __func__);
+
+ adev->audio_route = audio_route_init(adev->snd_card,
+ MIXER_XML_PATH_I2S);
+ } else {
+ /* Get the codec internal name from the sound card name
+ * and form the mixer paths file name dynamically. This
+ * is generic way of picking any codec name based mixer
+ * files in future with no code change. This code
+ * assumes mixer files are formed with format as
+ * mixer_paths_internalcodecname.xml
+
+ * If this dynamically read mixer files fails to open then it
+ * falls back to default mixer file i.e mixer_paths.xml. This is
+ * done to preserve backward compatibility but not mandatory as
+ * long as the mixer files are named as per above assumption.
+ */
+ snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s_%s.xml",
+ MIXER_XML_BASE_STRING, snd_split_handle->snd_card,
+ snd_split_handle->form_factor);
+ if (!audio_extn_utils_resolve_config_file(mixer_xml_file)) {
+ memset(mixer_xml_file, 0, sizeof(mixer_xml_file));
+ snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s.xml",
+ MIXER_XML_BASE_STRING, snd_split_handle->variant);
+
+ if (!audio_extn_utils_resolve_config_file(mixer_xml_file)) {
+ memset(mixer_xml_file, 0, sizeof(mixer_xml_file));
+ snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s.xml",
+ MIXER_XML_BASE_STRING, snd_split_handle->snd_card);
+
+ if (!audio_extn_utils_resolve_config_file(mixer_xml_file)) {
+ memset(mixer_xml_file, 0, sizeof(mixer_xml_file));
+ strlcpy(mixer_xml_file, MIXER_XML_DEFAULT_PATH, MIXER_PATH_MAX_LENGTH);
+ audio_extn_utils_resolve_config_file(mixer_xml_file);
+ }
+ }
+ }
+
+ ALOGD("%s: Loading mixer file: %s", __func__, mixer_xml_file);
+ if (audio_extn_read_xml(adev, adev->snd_card, mixer_xml_file,
+ MIXER_XML_PATH_AUXPCM) == -ENOSYS) {
+ adev->audio_route = audio_route_init(adev->snd_card, mixer_xml_file);
+ update_codec_type_and_interface(my_data, snd_card_name);
+ }
+ }
+ audio_extn_perf_lock_release(&adev->perf_lock_handle);
+
+ if (!adev->audio_route) {
+ ALOGE("%s: Failed to init audio route controls, aborting.",
+ __func__);
+ if (my_data)
+ free(my_data);
+ if (snd_card_name)
+ free(snd_card_name);
+ audio_extn_utils_close_snd_mixer(adev->mixer);
+ return NULL;
+ }
+
+#if defined (PLATFORM_MSMFALCON) || defined (PLATFORM_MSM8937)
+ if (my_data->is_internal_codec == true) {
+ msm_device_to_be_id = msm_device_to_be_id_internal_codec;
+ msm_be_id_array_len =
+ sizeof(msm_device_to_be_id_internal_codec) /
+ sizeof(msm_device_to_be_id_internal_codec[0]);
+ } else {
+ msm_device_to_be_id = msm_device_to_be_id_external_codec;
+ msm_be_id_array_len =
+ sizeof(msm_device_to_be_id_external_codec) /
+ sizeof(msm_device_to_be_id_external_codec[0]);
+ }
+#endif
+
/* CSRA devices support multiple sample rates via I2S at spkr out */
if (!strncmp(snd_card_name, "qcs405-csra", strlen("qcs405-csra"))) {
ALOGE("%s: soundcard: %s supports multiple sample rates", __func__, snd_card_name);