OSDN Git Service

Raise A2DP threat priority to avoid music breaks
authorMattias Agren <magren@broadcom.com>
Thu, 2 Oct 2014 07:43:04 +0000 (09:43 +0200)
committerAndre Eisenbach <eisenbach@google.com>
Mon, 6 Oct 2014 01:17:07 +0000 (18:17 -0700)
* 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

hci/src/bt_hci_bdroid.c
stack/btu/btu_task.c
udrv/ulinux/uipc.c
utils/include/bt_utils.h
utils/src/bt_utils.c

index 4038424..74a315b 100644 (file)
@@ -357,14 +357,17 @@ static int init(const bt_hc_callbacks_t* p_cb, unsigned char *local_bdaddr)
         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;
 }
 
index 3db8d7e..24a1194 100644 (file)
@@ -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 @@ 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);
 
+    prctl(PR_SET_NAME, (unsigned long)"BTU TASK", 0, 0, 0);
+
     raise_priority_a2dp(TASK_HIGH_BTU);
 
     /* Wait for, and process, events */
index a876076..b9caa1b 100644 (file)
@@ -480,6 +480,8 @@ static void uipc_read_task(void *arg)
 
     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;
index 512e1b5..47f0e30 100644 (file)
@@ -29,6 +29,7 @@ typedef enum {
     TASK_HIGH_BTU,
     TASK_HIGH_HCI_WORKER,
     TASK_HIGH_USERIAL_READ,
+    TASK_UIPC_READ,
     TASK_HIGH_MAX
 } tHIGH_PRIORITY_TASK;
 
index df1fd04..ab618b0 100644 (file)
@@ -120,6 +120,7 @@ static void check_do_scheduling_group(void) {
 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 @@ void raise_priority_a2dp(tHIGH_PRIORITY_TASK high_task) {
         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 @@ void adjust_priority_a2dp(int start) {
     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)