Raise A2DP threat priority to avoid music breaks
* Ensure all a2dp audiopath threads are configured to high
priority when actively streaming.
* For now set bt hc worker thread always to URGENT_AUDIO
until new thread api can adjust thread priority dynamically.
Bug: 17520043
Change-Id: I10e314085329278bcfcc4e8bc5ce899b03d22e2b
diff --git a/hci/src/bt_hci_bdroid.c b/hci/src/bt_hci_bdroid.c
index 4038424..74a315b 100644
--- a/hci/src/bt_hci_bdroid.c
+++ b/hci/src/bt_hci_bdroid.c
@@ -357,14 +357,17 @@
ALOGW("init has been called repeatedly without calling cleanup ?");
}
+ // Set prio here and let hci worker thread inherit prio
+ // remove once new thread api (thread_set_priority() ?)
+ // can switch prio
+ raise_priority_a2dp(TASK_HIGH_HCI_WORKER);
+
hc_cb.worker_thread = thread_new("bt_hc_worker");
if (!hc_cb.worker_thread) {
ALOGE("%s unable to create worker thread.", __func__);
return BT_HC_STATUS_FAIL;
}
- // TODO(sharvil): increase thread priority (raise_priority_a2dp)
-
return BT_HC_STATUS_SUCCESS;
}
diff --git a/stack/btu/btu_task.c b/stack/btu/btu_task.c
index 3db8d7e..24a1194 100644
--- a/stack/btu/btu_task.c
+++ b/stack/btu/btu_task.c
@@ -39,6 +39,7 @@
#include "l2c_int.h"
#include "btu.h"
#include "bt_utils.h"
+#include <sys/prctl.h>
#include "sdpint.h"
@@ -221,6 +222,8 @@
/* Send a startup evt message to BTIF_TASK to kickstart the init procedure */
GKI_send_event(BTIF_TASK, BT_EVT_TRIGGER_STACK_INIT);
+ prctl(PR_SET_NAME, (unsigned long)"BTU TASK", 0, 0, 0);
+
raise_priority_a2dp(TASK_HIGH_BTU);
/* Wait for, and process, events */
diff --git a/udrv/ulinux/uipc.c b/udrv/ulinux/uipc.c
index a876076..b9caa1b 100644
--- a/udrv/ulinux/uipc.c
+++ b/udrv/ulinux/uipc.c
@@ -480,6 +480,8 @@
prctl(PR_SET_NAME, (unsigned long)"uipc-main", 0, 0, 0);
+ raise_priority_a2dp(TASK_UIPC_READ);
+
while (uipc_main.running)
{
uipc_main.read_set = uipc_main.active_set;
diff --git a/utils/include/bt_utils.h b/utils/include/bt_utils.h
index 512e1b5..47f0e30 100644
--- a/utils/include/bt_utils.h
+++ b/utils/include/bt_utils.h
@@ -29,6 +29,7 @@
TASK_HIGH_BTU,
TASK_HIGH_HCI_WORKER,
TASK_HIGH_USERIAL_READ,
+ TASK_UIPC_READ,
TASK_HIGH_MAX
} tHIGH_PRIORITY_TASK;
diff --git a/utils/src/bt_utils.c b/utils/src/bt_utils.c
index df1fd04..ab618b0 100644
--- a/utils/src/bt_utils.c
+++ b/utils/src/bt_utils.c
@@ -120,6 +120,7 @@
void raise_priority_a2dp(tHIGH_PRIORITY_TASK high_task) {
int rc = 0;
int tid = gettid();
+ int priority = ANDROID_PRIORITY_AUDIO;
pthread_mutex_lock(&gIdxLock);
g_TaskIdx = high_task;
@@ -136,8 +137,15 @@
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);
+ // always use urgent priority for HCI worker thread until we can adjust
+ // its prio individually. All other threads can be dynamically adjusted voa
+ // adjust_priority_a2dp()
+
+ if (high_task == TASK_HIGH_HCI_WORKER)
+ priority = ANDROID_PRIORITY_URGENT_AUDIO;
+
+ if (setpriority(PRIO_PROCESS, tid, priority) < 0) {
+ ALOGW("failed to change priority tid: %d to %d", tid, priority);
}
}
@@ -157,7 +165,7 @@
int tid;
int i;
- for (i = TASK_HIGH_GKI_TIMER; i < TASK_HIGH_MAX; i++)
+ for (i = 0; i < TASK_HIGH_MAX; i++)
{
tid = g_TaskIDs[i];
if (tid != INVALID_TASK_ID)