diff options
author | Srinu Jella <sjella@codeaurora.org> | 2015-11-04 21:01:30 +0530 |
---|---|---|
committer | Gerrit - the friendly Code Review server <code-review@localhost> | 2015-12-04 01:52:31 -0800 |
commit | 74a2952e414d75028bf1078ddd314dbe4cc9c0c8 (patch) | |
tree | 4e5938f30bbe2323fe9d6b090fafe069f0851c00 | |
parent | f5e2a388f82a0efbc03a32a1e595cbd78b5f2b37 (diff) | |
download | android_system_bt-74a2952e414d75028bf1078ddd314dbe4cc9c0c8.tar.gz android_system_bt-74a2952e414d75028bf1078ddd314dbe4cc9c0c8.tar.bz2 android_system_bt-74a2952e414d75028bf1078ddd314dbe4cc9c0c8.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.h | 8 | ||||
-rw-r--r-- | osi/src/alarm.c | 7 | ||||
-rw-r--r-- | osi/src/thread.c | 15 |
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); |