diff options
author | Matthew Xie <mattx@google.com> | 2012-10-26 12:29:29 -0700 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2012-10-26 12:29:30 -0700 |
commit | 23ad5920f8c2dfdbd2bac8c4d7b244226a77c644 (patch) | |
tree | 21f8de49ed14d3f69c4c19438f22c3c5f46f9545 | |
parent | 9ab1946281916b06df6cb2e5eb37ad12cd4dce4a (diff) | |
parent | 520b756328dcf4a54cf25f5d16177aa17fdbce31 (diff) | |
download | external_bluetooth_bluedroid-23ad5920f8c2dfdbd2bac8c4d7b244226a77c644.zip external_bluetooth_bluedroid-23ad5920f8c2dfdbd2bac8c4d7b244226a77c644.tar.gz external_bluetooth_bluedroid-23ad5920f8c2dfdbd2bac8c4d7b244226a77c644.tar.bz2 |
Merge "Bump up priority of a few tasks that could affect a2dp" into jb-mr1-dev
-rw-r--r-- | btif/src/bluetooth.c | 4 | ||||
-rwxr-xr-x | btif/src/btif_media_task.c | 3 | ||||
-rw-r--r-- | gki/Android.mk | 1 | ||||
-rwxr-xr-x | gki/ulinux/gki_ulinux.c | 7 | ||||
-rw-r--r-- | hci/Android.mk | 6 | ||||
-rw-r--r-- | hci/src/bt_hci_bdroid.c | 3 | ||||
-rw-r--r-- | main/Android.mk | 4 | ||||
-rw-r--r-- | stack/Android.mk | 1 | ||||
-rw-r--r-- | stack/btu/btu_task.c | 3 | ||||
-rw-r--r-- | utils/Android.mk | 20 | ||||
-rw-r--r-- | utils/include/bt_utils.h | 42 | ||||
-rw-r--r-- | utils/src/bt_utils.c | 139 |
12 files changed, 228 insertions, 5 deletions
diff --git a/btif/src/bluetooth.c b/btif/src/bluetooth.c index 18e706f..20d6a07 100644 --- a/btif/src/bluetooth.c +++ b/btif/src/bluetooth.c @@ -40,6 +40,7 @@ #define LOG_TAG "bluedroid" #include "btif_api.h" +#include "bt_utils.h" /************************************************************************************ ** Constants & Macros @@ -113,6 +114,8 @@ static int init(bt_callbacks_t* callbacks ) /* add checks for individual callbacks ? */ + bt_utils_init(); + /* init btif */ btif_init_bluetooth(); @@ -146,6 +149,7 @@ static void cleanup( void ) return; btif_shutdown_bluetooth(); + bt_utils_cleanup(); /* hal callbacks reset upon shutdown complete callback */ diff --git a/btif/src/btif_media_task.c b/btif/src/btif_media_task.c index 6975154..c615751 100755 --- a/btif/src/btif_media_task.c +++ b/btif/src/btif_media_task.c @@ -67,6 +67,7 @@ #include "btif_av.h" #include "btif_sm.h" #include "btif_util.h" +#include "bt_utils.h" /***************************************************************************** ** Constants @@ -1209,6 +1210,8 @@ int btif_media_task(void *p) media_task_running = MEDIA_TASK_STATE_ON; + raise_priority_a2dp(TASK_HIGH_MEDIA); + while (1) { event = GKI_wait(0xffff, 0); diff --git a/gki/Android.mk b/gki/Android.mk index c76c237..0ece25b 100644 --- a/gki/Android.mk +++ b/gki/Android.mk @@ -8,6 +8,7 @@ LOCAL_C_INCLUDES:= $(LOCAL_PATH)/common \ $(LOCAL_PATH)/ulinux \ $(LOCAL_PATH)/../include \ $(LOCAL_PATH)/../stack/include \ + $(LOCAL_PATH)/../utils/include \ $(bdroid_C_INCLUDES) \ LOCAL_CFLAGS += -Werror $(bdroid_CFLAGS) diff --git a/gki/ulinux/gki_ulinux.c b/gki/ulinux/gki_ulinux.c index 97a7f41..57ff7bb 100755 --- a/gki/ulinux/gki_ulinux.c +++ b/gki/ulinux/gki_ulinux.c @@ -33,6 +33,7 @@ #include <pthread.h> /* must be 1st header defined */ #include <time.h> #include "gki_int.h" +#include "bt_utils.h" #define LOG_TAG "GKI_LINUX" @@ -618,6 +619,10 @@ void* timer_thread(void *arg) /* Indicate that tick is just starting */ restart = 1; + prctl(PR_SET_NAME, (unsigned long)"gki timer", 0, 0, 0); + + raise_priority_a2dp(TASK_HIGH_GKI_TIMER); + while(!shutdown_timer) { /* If the timer has been stopped (no SW timer running) */ @@ -807,8 +812,6 @@ void GKI_run (void *p_task_id) return; } - prctl(PR_SET_NAME, (unsigned long)"gki timer", 0, 0, 0); - #else GKI_TRACE("GKI_run "); for (;;) diff --git a/hci/Android.mk b/hci/Android.mk index 875197c..f2a63e5 100644 --- a/hci/Android.mk +++ b/hci/Android.mk @@ -26,11 +26,13 @@ LOCAL_SRC_FILES += \ endif LOCAL_C_INCLUDES += \ - $(LOCAL_PATH)/include + $(LOCAL_PATH)/include \ + $(LOCAL_PATH)/../utils/include LOCAL_SHARED_LIBRARIES := \ libcutils \ - libdl + libdl \ + libbt-utils LOCAL_MODULE := libbt-hci LOCAL_MODULE_TAGS := optional diff --git a/hci/src/bt_hci_bdroid.c b/hci/src/bt_hci_bdroid.c index 27d190e..7b14eb3 100644 --- a/hci/src/bt_hci_bdroid.c +++ b/hci/src/bt_hci_bdroid.c @@ -34,6 +34,7 @@ #include "utils.h" #include "hci.h" #include "userial.h" +#include "bt_utils.h" #include <sys/prctl.h> #ifndef BTHC_DBG @@ -344,6 +345,8 @@ static void *bt_hc_worker_thread(void *arg) prctl(PR_SET_NAME, (unsigned long)"bt_hc_worker", 0, 0, 0); tx_cmd_pkts_pending = FALSE; + raise_priority_a2dp(TASK_HIGH_HCI_WORKER); + while (lib_running) { pthread_mutex_lock(&hc_cb.mutex); diff --git a/main/Android.mk b/main/Android.mk index 2a5ed93..8ecb3c3 100644 --- a/main/Android.mk +++ b/main/Android.mk @@ -88,6 +88,7 @@ LOCAL_C_INCLUDES+= . \ $(LOCAL_PATH)/../brcm/include \ $(LOCAL_PATH)/../embdrv/sbc/encoder/include \ $(LOCAL_PATH)/../audio_a2dp_hw \ + $(LOCAL_PATH)/../utils/include \ $(bdroid_C_INCLUDES) \ external/tinyxml2 @@ -113,7 +114,8 @@ endif LOCAL_SHARED_LIBRARIES := \ libcutils \ libpower \ - libbt-hci + libbt-hci \ + libbt-utils #LOCAL_WHOLE_STATIC_LIBRARIES := libbt-brcm_gki libbt-brcm_stack libbt-brcm_bta LOCAL_STATIC_LIBRARIES := libbt-brcm_gki libbt-brcm_bta libbt-brcm_stack libtinyxml2 diff --git a/stack/Android.mk b/stack/Android.mk index 968cfdb..0c24805 100644 --- a/stack/Android.mk +++ b/stack/Android.mk @@ -28,6 +28,7 @@ LOCAL_C_INCLUDES:= . \ $(LOCAL_PATH)/../bta/include \ $(LOCAL_PATH)/../bta/sys \ $(LOCAL_PATH)/../brcm/include \ + $(LOCAL_PATH)/../utils/include \ $(bdroid_C_INCLUDES) \ LOCAL_CFLAGS += $(bdroid_CFLAGS) diff --git a/stack/btu/btu_task.c b/stack/btu/btu_task.c index 1041307..48ce489 100644 --- a/stack/btu/btu_task.c +++ b/stack/btu/btu_task.c @@ -38,6 +38,7 @@ #include "hcimsgs.h" #include "l2c_int.h" #include "btu.h" +#include "bt_utils.h" #include "sdpint.h" @@ -192,6 +193,8 @@ BTU_API UINT32 btu_task (UINT32 param) /* Send a startup evt message to BTIF_TASK to kickstart the init procedure */ GKI_send_event(BTIF_TASK, BT_EVT_TRIGGER_STACK_INIT); + raise_priority_a2dp(TASK_HIGH_BTU); + /* Wait for, and process, events */ for (;;) { diff --git a/utils/Android.mk b/utils/Android.mk new file mode 100644 index 0000000..4e66705 --- /dev/null +++ b/utils/Android.mk @@ -0,0 +1,20 @@ +LOCAL_PATH:= $(call my-dir) + +include $(CLEAR_VARS) + +LOCAL_C_INCLUDES:= $(LOCAL_PATH)/include \ + $(LOCAL_PATH)/../gki/ulinux \ + $(bdroid_C_INCLUDES) + +LOCAL_CFLAGS += -Werror $(bdroid_CFLAGS) + +LOCAL_PRELINK_MODULE:=false +LOCAL_SRC_FILES:= \ + ./src/bt_utils.c + +LOCAL_MODULE := libbt-utils +LOCAL_MODULE_TAGS := optional +LOCAL_SHARED_LIBRARIES := libcutils libc +LOCAL_MODULE_CLASS := SHARED_LIBRARIES + +include $(BUILD_SHARED_LIBRARY) diff --git a/utils/include/bt_utils.h b/utils/include/bt_utils.h new file mode 100644 index 0000000..ef4fc18 --- /dev/null +++ b/utils/include/bt_utils.h @@ -0,0 +1,42 @@ +/****************************************************************************** + * + * Copyright (C) 2009-2012 Broadcom Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************************/ + +#ifndef BT_UTILS_H +#define BT_UTILS_H + +/******************************************************************************* +** Type definitions +********************************************************************************/ + +typedef enum { + TASK_HIGH_MEDIA = 0, + TASK_HIGH_GKI_TIMER, + TASK_HIGH_BTU, + TASK_HIGH_HCI_WORKER, + TASK_HIGH_MAX +} tHIGH_PRIORITY_TASK; + +/******************************************************************************* +** Functions +********************************************************************************/ + +void bt_utils_init(); +void bt_utils_cleanup(); +void raise_priority_a2dp(tHIGH_PRIORITY_TASK high_task); + +#endif /* BT_UTILS_H */ diff --git a/utils/src/bt_utils.c b/utils/src/bt_utils.c new file mode 100644 index 0000000..aeb9292 --- /dev/null +++ b/utils/src/bt_utils.c @@ -0,0 +1,139 @@ +/****************************************************************************** + * + * Copyright (C) 2012 Broadcom Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************************/ + +/************************************************************************************ + * + * Filename: bt_utils.c + * + * Description: Miscellaneous helper functions + * + * + ***********************************************************************************/ + +#include <cutils/properties.h> +#include <cutils/sched_policy.h> +#include <errno.h> +#include <pthread.h> +#include <sys/resource.h> +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <utils/ThreadDefs.h> + +#define LOG_TAG "BT_UTILS" + +#include <utils/Log.h> + +#include "data_types.h" +#include "bt_utils.h" + + +/******************************************************************************* +** Type definitions for callback functions +********************************************************************************/ +static pthread_once_t g_DoSchedulingGroupOnce[TASK_HIGH_MAX]; +static BOOLEAN g_DoSchedulingGroup[TASK_HIGH_MAX]; +static pthread_mutex_t gIdxLock; +static int g_TaskIdx; + +/***************************************************************************** +** +** Function bt_utils_init +** +** Description Initialize bluedroid util +** +** Returns void +** +*******************************************************************************/ +void bt_utils_init() { + int i; + pthread_mutexattr_t lock_attr; + + for(i = 0; i < TASK_HIGH_MAX; i++) { + g_DoSchedulingGroupOnce[i] = PTHREAD_ONCE_INIT; + g_DoSchedulingGroup[i] = TRUE; + } + pthread_mutexattr_init(&lock_attr); + pthread_mutex_init(&gIdxLock, &lock_attr); +} + +/***************************************************************************** +** +** Function bt_utils_cleanup +** +** Description Clean up bluedroid util +** +** Returns void +** +*******************************************************************************/ +void bt_utils_cleanup() { + pthread_mutex_destroy(&gIdxLock); +} + +/***************************************************************************** +** +** Function check_do_scheduling_group +** +** Description check if it is ok to change schedule group +** +** Returns void +** +*******************************************************************************/ +static void check_do_scheduling_group(void) { + char buf[PROPERTY_VALUE_MAX]; + int len = property_get("debug.sys.noschedgroups", buf, ""); + if (len > 0) { + int temp; + if (sscanf(buf, "%d", &temp) == 1) { + g_DoSchedulingGroup[g_TaskIdx] = temp == 0; + } + } +} + +/***************************************************************************** +** +** Function raise_priority_a2dp +** +** Description Raise task priority for A2DP streaming +** +** Returns void +** +*******************************************************************************/ +void raise_priority_a2dp(tHIGH_PRIORITY_TASK high_task) { + int rc = 0; + int tid = gettid(); + + pthread_mutex_lock(&gIdxLock); + g_TaskIdx = high_task; + + pthread_once(&g_DoSchedulingGroupOnce[g_TaskIdx], check_do_scheduling_group); + if (g_DoSchedulingGroup[g_TaskIdx]) { + // set_sched_policy does not support tid == 0 + rc = set_sched_policy(tid, SP_FOREGROUND); + } + pthread_mutex_unlock(&gIdxLock); + + if (rc) { + ALOGW("failed to change sched policy, tid %d, err: %d", tid, errno); + } + + if (setpriority(PRIO_PROCESS, tid, ANDROID_PRIORITY_AUDIO) < 0) { + ALOGW("failed to change priority tid: %d to %d", tid, ANDROID_PRIORITY_AUDIO); + } +} + |