• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
Keine Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

system/bt


Commit MetaInfo

Revisionfeb2d84f4b69392b5f37ae1ec9d53ac728514275 (tree)
Zeit2017-04-28 10:27:09
AutorPhilip Cuadra <philipcuadra@goog...>
CommiterPhilip Cuadra

Log Message

Revert "Make Bluetooth audio threads use RT scheduling"

This reverts commit eaa42774f393eb3ccaee91a958e8df6a8fb09b91.

http://b/37733903
Test: confirmed switching users does not hang.

Change-Id: Ic54e4ed2dda057e681df225a37a574c221cd8fc3

Ändern Zusammenfassung

Diff

--- a/btif/src/btif_av.cc
+++ b/btif/src/btif_av.cc
@@ -929,9 +929,17 @@ static bool btif_av_state_started_handler(btif_sm_event_t event, void* p_data) {
929929 * see update_audio_focus_state()
930930 */
931931 btif_report_audio_state(BTAV_AUDIO_STATE_STARTED, &(btif_av_cb.peer_bda));
932+
933+ /* increase the a2dp consumer task priority temporarily when start
934+ ** audio playing, to avoid overflow the audio packet queue. */
935+ adjust_priority_a2dp(true);
936+
932937 break;
933938
934939 case BTIF_SM_EXIT_EVT:
940+ /* restore the a2dp consumer task priority when stop audio playing. */
941+ adjust_priority_a2dp(false);
942+
935943 break;
936944
937945 case BTIF_AV_START_STREAM_REQ_EVT:
--- a/hci/src/hci_layer.cc
+++ b/hci/src/hci_layer.cc
@@ -63,9 +63,6 @@ typedef struct {
6363 #define DEFAULT_STARTUP_TIMEOUT_MS 8000
6464 #define STRING_VALUE_OF(x) #x
6565
66-// RT priority for HCI thread
67-static const int BT_HCI_RT_PRIORITY = 1;
68-
6966 // Abort if there is no response to an HCI command.
7067 static const uint32_t COMMAND_PENDING_TIMEOUT_MS = 2000;
7168
@@ -191,9 +188,6 @@ static future_t* hci_module_start_up(void) {
191188 LOG_ERROR(LOG_TAG, "%s unable to create thread.", __func__);
192189 goto error;
193190 }
194- if (!thread_set_rt_priority(thread, BT_HCI_RT_PRIORITY)) {
195- LOG_ERROR(LOG_TAG, "%s unable to make thread RT.", __func__);
196- }
197191
198192 commands_pending_response = list_new(NULL);
199193 if (!commands_pending_response) {
--- a/osi/include/thread.h
+++ b/osi/include/thread.h
@@ -65,13 +65,6 @@ void thread_stop(thread_t* thread);
6565 // Returns true on success.
6666 bool thread_set_priority(thread_t* thread, int priority);
6767
68-// Attempts to set |thread| to the real-time SCHED_FIFO |priority|.
69-// The |thread| has to be running for this call to succeed.
70-// Priority values are valid in the range sched_get_priority_max(SCHED_FIFO)
71-// to sched_get_priority_min(SCHED_FIFO). Larger values are higher priority.
72-// Returns true on success.
73-bool thread_set_rt_priority(thread_t* thread, int priority);
74-
7568 // Returns true if the current thread is the same as the one represented by
7669 // |thread|.
7770 // |thread| may not be NULL.
--- a/osi/src/alarm.cc
+++ b/osi/src/alarm.cc
@@ -27,7 +27,6 @@
2727 #include <fcntl.h>
2828 #include <inttypes.h>
2929 #include <malloc.h>
30-#include <pthread.h>
3130 #include <signal.h>
3231 #include <string.h>
3332 #include <time.h>
@@ -45,9 +44,12 @@
4544 #include "osi/include/thread.h"
4645 #include "osi/include/wakelock.h"
4746
48-// Callback and timer threads should run at RT priority in order to ensure they
49-// meet audio deadlines. Use this priority for all audio/timer related thread.
50-static const int THREAD_RT_PRIORITY = 1;
47+// Make callbacks run at high thread priority. Some callbacks are used for audio
48+// related timer tasks as well as re-transmissions etc. Since we at this point
49+// cannot differentiate what callback we are dealing with, assume high priority
50+// for now.
51+// TODO(eisenbach): Determine correct thread priority (from parent?/per alarm?)
52+static const int CALLBACK_THREAD_PRIORITY_HIGH = -19;
5153
5254 typedef struct {
5355 size_t count;
@@ -312,7 +314,7 @@ static bool lazy_initialize(void) {
312314 __func__);
313315 goto error;
314316 }
315- thread_set_rt_priority(default_callback_thread, THREAD_RT_PRIORITY);
317+ thread_set_priority(default_callback_thread, CALLBACK_THREAD_PRIORITY_HIGH);
316318 default_callback_queue = fixed_queue_new(SIZE_MAX);
317319 if (default_callback_queue == NULL) {
318320 LOG_ERROR(LOG_TAG, "%s unable to create default alarm callbacks queue.",
@@ -328,7 +330,8 @@ static bool lazy_initialize(void) {
328330 LOG_ERROR(LOG_TAG, "%s unable to create alarm callback thread.", __func__);
329331 goto error;
330332 }
331- thread_set_rt_priority(dispatcher_thread, THREAD_RT_PRIORITY);
333+
334+ thread_set_priority(dispatcher_thread, CALLBACK_THREAD_PRIORITY_HIGH);
332335 thread_post(dispatcher_thread, callback_dispatch, NULL);
333336 return true;
334337
@@ -622,18 +625,9 @@ static bool timer_create_internal(const clockid_t clock_id, timer_t* timer) {
622625 CHECK(timer != NULL);
623626
624627 struct sigevent sigevent;
625- // create timer with RT priority thread
626- pthread_attr_t thread_attr;
627- pthread_attr_init(&thread_attr);
628- pthread_attr_setschedpolicy(&thread_attr, SCHED_FIFO);
629- struct sched_param param;
630- param.sched_priority = THREAD_RT_PRIORITY;
631- pthread_attr_setschedparam(&thread_attr, &param);
632-
633628 memset(&sigevent, 0, sizeof(sigevent));
634629 sigevent.sigev_notify = SIGEV_THREAD;
635630 sigevent.sigev_notify_function = (void (*)(union sigval))timer_callback;
636- sigevent.sigev_notify_attributes = (void*)(&thread_attr);
637631 if (timer_create(clock_id, &sigevent, timer) == -1) {
638632 LOG_ERROR(LOG_TAG, "%s unable to create timer with clock %d: %s", __func__,
639633 clock_id, strerror(errno));
--- a/osi/src/thread.cc
+++ b/osi/src/thread.cc
@@ -159,23 +159,6 @@ bool thread_set_priority(thread_t* thread, int priority) {
159159 return true;
160160 }
161161
162-bool thread_set_rt_priority(thread_t* thread, int priority) {
163- if (!thread) return false;
164-
165- struct sched_param rt_params;
166- rt_params.sched_priority = priority;
167-
168- const int rc = sched_setscheduler(thread->tid, SCHED_FIFO, &rt_params);
169- if (rc != 0) {
170- LOG_ERROR(LOG_TAG,
171- "%s unable to set SCHED_FIFO priority %d for tid %d, error %s",
172- __func__, priority, thread->tid, strerror(errno));
173- return false;
174- }
175-
176- return true;
177-}
178-
179162 bool thread_is_self(const thread_t* thread) {
180163 CHECK(thread != NULL);
181164 return !!pthread_equal(pthread_self(), thread->pthread);
--- a/stack/btu/btu_init.cc
+++ b/stack/btu/btu_init.cc
@@ -36,8 +36,9 @@
3636 #include "sdpint.h"
3737 #include "smp_int.h"
3838
39-// RT priority for audio-related tasks
40-#define BTU_TASK_RT_PRIORITY 1
39+// Increase BTU task thread priority to avoid pre-emption
40+// of audio realated tasks.
41+#define BTU_TASK_THREAD_PRIORITY (-19)
4142
4243 extern fixed_queue_t* btif_msg_queue;
4344
@@ -129,7 +130,7 @@ void BTU_StartUp(void) {
129130 bt_workqueue_thread = thread_new(BT_WORKQUEUE_NAME);
130131 if (bt_workqueue_thread == NULL) goto error_exit;
131132
132- thread_set_rt_priority(bt_workqueue_thread, BTU_TASK_RT_PRIORITY);
133+ thread_set_priority(bt_workqueue_thread, BTU_TASK_THREAD_PRIORITY);
133134
134135 // Continue startup on bt workqueue thread.
135136 thread_post(bt_workqueue_thread, btu_task_start_up, NULL);
--- a/utils/include/bt_utils.h
+++ b/utils/include/bt_utils.h
@@ -36,5 +36,6 @@ typedef enum {
3636 ******************************************************************************/
3737
3838 void raise_priority_a2dp(tHIGH_PRIORITY_TASK high_task);
39+void adjust_priority_a2dp(int start);
3940
4041 #endif /* BT_UTILS_H */
--- a/utils/src/bt_utils.cc
+++ b/utils/src/bt_utils.cc
@@ -37,9 +37,12 @@
3737 #include <unistd.h>
3838 #include <mutex>
3939
40-#define A2DP_RT_PRIORITY 1
41-#ifndef OS_GENERIC
40+#ifdef OS_GENERIC
41+#define ANDROID_PRIORITY_AUDIO -16
42+#define ANDROID_PRIORITY_URGENT_AUDIO -19
43+#else
4244 #include <cutils/sched_policy.h>
45+#include <utils/ThreadDefs.h>
4346 #endif
4447
4548 #include "bt_types.h"
@@ -113,6 +116,7 @@ static void check_do_scheduling_group(void) {
113116 void raise_priority_a2dp(tHIGH_PRIORITY_TASK high_task) {
114117 int rc = 0;
115118 int tid = gettid();
119+ int priority = ANDROID_PRIORITY_AUDIO;
116120
117121 {
118122 std::lock_guard<std::mutex> lock(gIdxLock);
@@ -139,17 +143,41 @@ void raise_priority_a2dp(tHIGH_PRIORITY_TASK high_task) {
139143 errno);
140144 }
141145
142- // make A2DP threads use RT scheduling policy since they are part of the
143- // audio pipeline
144- {
145- struct sched_param rt_params;
146- rt_params.sched_priority = A2DP_RT_PRIORITY;
147-
148- const int rc = sched_setscheduler(tid, SCHED_FIFO, &rt_params);
149- if (rc != 0) {
150- LOG_ERROR(LOG_TAG,
151- "%s unable to set SCHED_FIFO priority %d for tid %d, error %s",
152- __func__, A2DP_RT_PRIORITY, tid, strerror(errno));
146+ // always use urgent priority for HCI worker thread until we can adjust
147+ // its prio individually. All other threads can be dynamically adjusted voa
148+ // adjust_priority_a2dp()
149+
150+ priority = ANDROID_PRIORITY_URGENT_AUDIO;
151+
152+ if (setpriority(PRIO_PROCESS, tid, priority) < 0) {
153+ LOG_WARN(LOG_TAG, "failed to change priority tid: %d to %d", tid, priority);
154+ }
155+}
156+
157+/*****************************************************************************
158+ *
159+ * Function adjust_priority_a2dp
160+ *
161+ * Description Increase the a2dp consumer task priority temporarily when
162+ * audio starts playing to avoid overflowing the audio packet
163+ * queue. Restore the a2dp consumer task priority when audio
164+ * is not playing.
165+ *
166+ * Returns void
167+ *
168+ ******************************************************************************/
169+void adjust_priority_a2dp(int start) {
170+ int priority = start ? ANDROID_PRIORITY_URGENT_AUDIO : ANDROID_PRIORITY_AUDIO;
171+ int tid;
172+ int i;
173+
174+ for (i = 0; i < TASK_HIGH_MAX; i++) {
175+ tid = g_TaskIDs[i];
176+ if (tid != INVALID_TASK_ID) {
177+ if (setpriority(PRIO_PROCESS, tid, priority) < 0) {
178+ LOG_WARN(LOG_TAG, "failed to change priority tid: %d to %d", tid,
179+ priority);
180+ }
153181 }
154182 }
155183 }