PlaybackThread: Request real-time priority on ARC
MixerThread handles audio mixing and it implements PlaybackThread.
1. In ARC++, nice value of a thread will be divided by 2 so
THREAD_PRIORITY_URGENT_AUDIO is not enough for PlaybackThread.
2. In our experiments, the threads density per core in ChromeOS
are generally more than normal Android. The latency under using CFS
scheduler with any priority is not enough for MixerThread to process
audio data in time.
We request the lowest real-time priority, SCHED_FIFO=1, for
PlaybackThread in ARC++.
This is to upstream ARC-only CL ag/24624964, by checking
ro.boot.container and only requesting the real-time priority on ARC.
For the context of the original CL, see ag/5604522.
Bug: 301627581
Test: 1. Build this CL on main-arc-dev branch and flash to ARCVM
2. `ps -AT -eo rtprio,comm,name`, check AudioOut rtprio is 1
Change-Id: If9aece940fce31722a188a8629f3d167813d4205
diff --git a/services/audioflinger/Threads.cpp b/services/audioflinger/Threads.cpp
index 671e27f..f9f6b40 100644
--- a/services/audioflinger/Threads.cpp
+++ b/services/audioflinger/Threads.cpp
@@ -223,6 +223,8 @@
static const int kPriorityAudioApp = 2;
static const int kPriorityFastMixer = 3;
static const int kPriorityFastCapture = 3;
+// Request real-time priority for PlaybackThread in ARC
+static const int kPriorityPlaybackThreadArc = 1;
// IAudioFlinger::createTrack() has an in/out parameter 'pFrameCount' for the total size of the
// track buffer in shared memory. Zero on input means to use a default value. For fast tracks,
@@ -3949,6 +3951,27 @@
stream()->setHalThreadPriority(priorityBoost);
}
}
+ } else if (property_get_bool("ro.boot.container", false /* default_value */)) {
+ // In ARC experiments (b/73091832), the latency under using CFS scheduler with any priority
+ // is not enough for PlaybackThread to process audio data in time. We request the lowest
+ // real-time priority, SCHED_FIFO=1, for PlaybackThread in ARC. ro.boot.container is true
+ // only on ARC.
+ const pid_t tid = getTid();
+ if (tid == -1) {
+ ALOGW("%s: Cannot update PlaybackThread priority for ARC, no tid", __func__);
+ } else {
+ const status_t status = requestPriority(getpid(),
+ tid,
+ kPriorityPlaybackThreadArc,
+ false /* isForApp */,
+ true /* asynchronous */);
+ if (status != OK) {
+ ALOGW("%s: Cannot update PlaybackThread priority for ARC, status %d", __func__,
+ status);
+ } else {
+ stream()->setHalThreadPriority(kPriorityPlaybackThreadArc);
+ }
+ }
}
Vector<sp<IAfTrack>> tracksToRemove;