summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSrinu Jella <sjella@codeaurora.org>2015-11-04 21:01:30 +0530
committerGerrit - the friendly Code Review server <code-review@localhost>2015-12-18 02:23:26 -0800
commita69b205e21329391537fbefd4994fa8549f5eca4 (patch)
tree47ad2b1c061fda56db49826afe1e796b5b0a144b
parentcb2450e7e002a1383d594e02bd97058b6e96cf1b (diff)
downloadandroid_system_bt-a69b205e21329391537fbefd4994fa8549f5eca4.tar.gz
android_system_bt-a69b205e21329391537fbefd4994fa8549f5eca4.tar.bz2
android_system_bt-a69b205e21329391537fbefd4994fa8549f5eca4.zip
Bluetooth: Boost timer callback thread priority to high
- Boost timer callback thread priority to high for getting alarm callback with priority during a2dp music playback. - Media task/btu/hci/event threads are all high priority but actual callback thread is remaining normal which mean it's possible not to schedule alarm callback in-time if system is busy. CRs-Fixed: 935097 Change-Id: I10dff46af800d55f0e816353a0f39cfe3150d22f
-rw-r--r--osi/include/thread.h8
-rw-r--r--osi/src/alarm.c7
-rw-r--r--osi/src/thread.c15
3 files changed, 30 insertions, 0 deletions
diff --git a/osi/include/thread.h b/osi/include/thread.h
index def4aa509..9e5602a41 100644
--- a/osi/include/thread.h
+++ b/osi/include/thread.h
@@ -23,6 +23,9 @@
#define THREAD_NAME_MAX 16
+// Increase callback thread priority to high
+#define TIMER_CALLBACK_THREAD_PRIORITY -19
+
typedef struct reactor_t reactor_t;
typedef struct thread_t thread_t;
typedef void (*thread_fn)(void *context);
@@ -58,6 +61,11 @@ bool thread_post(thread_t *thread, thread_fn func, void *context);
// |thread| may not be NULL.
void thread_stop(thread_t *thread);
+// Attempts to sets the |priority| of a given |thread|.
+// The |thread| has to be running for this call to succeed.
+// Returns true on success.
+bool thread_set_priority(thread_t *thread, int priority);
+
// Returns true if the current thread is the same as the one represented by |thread|.
// |thread| may not be NULL.
bool thread_is_self(const thread_t *thread);
diff --git a/osi/src/alarm.c b/osi/src/alarm.c
index 761c6f315..ff168297c 100644
--- a/osi/src/alarm.c
+++ b/osi/src/alarm.c
@@ -35,6 +35,7 @@
#include "osi/include/semaphore.h"
#include "osi/include/thread.h"
+
struct alarm_t {
// The lock is held while the callback for this alarm is being executed.
// It allows us to release the coarse-grained monitor lock while a potentially
@@ -241,6 +242,12 @@ static bool lazy_initialize(void) {
return false;
}
+ // boost timer thread to high for getting alarm callback with priority
+ // during a2dp music playback, media task/btu/hci/event threads are all high priority
+ // but actual callback thread is remaining normal which mean it's possible not to
+ // schedule alarm callback in-time if system is busy
+ thread_set_priority(callback_thread, TIMER_CALLBACK_THREAD_PRIORITY);
+
thread_post(callback_thread, callback_dispatch, NULL);
return true;
}
diff --git a/osi/src/thread.c b/osi/src/thread.c
index d0824436e..9e4b6a4e4 100644
--- a/osi/src/thread.c
+++ b/osi/src/thread.c
@@ -24,6 +24,7 @@
#include <pthread.h>
#include <string.h>
#include <sys/prctl.h>
+#include <sys/resource.h>
#include <sys/types.h>
#include "osi/include/allocator.h"
@@ -122,6 +123,20 @@ void thread_free(thread_t *thread) {
osi_free(thread);
}
+bool thread_set_priority(thread_t *thread, int priority) {
+ if (!thread)
+ return false;
+
+ const int rc = setpriority(PRIO_PROCESS, thread->tid, priority);
+ if (rc < 0) {
+ LOG_ERROR("%s unable to set thread priority %d for tid %d, error %d",
+ __func__, priority, thread->tid, rc);
+ return false;
+ }
+
+ return true;
+}
+
void thread_join(thread_t *thread) {
assert(thread != NULL);