Merge "PlaybackThread: Request real-time priority on ARC" into main
diff --git a/services/audioflinger/Threads.cpp b/services/audioflinger/Threads.cpp
index 3fdd5cb..767c502 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,
@@ -3954,6 +3956,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;