Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3132f061 authored by Emilian Peev's avatar Emilian Peev
Browse files

Camera: Bump the preview frame spacer thread priority

The preview frame spacer thread is part of the camera
critical path and any scheduling delays could contribute
to frame drops and poor UX.
Increase the respective thread priority to avoid potential
delays during buffer IPC.

Bug: 355665306
Flag: com.android.internal.camera.flags.bump_preview_frame_space_priority
Test: Camera CTS
Change-Id: Id9501f7132e8b534244ab4042e42387038177ab5
parent 2ec03470
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -257,3 +257,13 @@ flag {
        purpose: PURPOSE_BUGFIX
    }
}

flag {
    namespace: "camera_platform"
    name: "bump_preview_frame_space_priority"
    description: "Increase the PreviewFrameSpacer thread priority"
    bug: "355665306"
    metadata {
        purpose: PURPOSE_BUGFIX
    }
}
+24 −0
Original line number Diff line number Diff line
@@ -18,10 +18,16 @@
#define ATRACE_TAG ATRACE_TAG_CAMERA
//#define LOG_NDEBUG 0

#include <com_android_internal_camera_flags.h>

#include <utils/Log.h>

#include "PreviewFrameSpacer.h"
#include "Camera3OutputStream.h"
#include "utils/SchedulingPolicyUtils.h"
#include "utils/Utils.h"

namespace flags = com::android::internal::camera::flags;

namespace android {

@@ -129,6 +135,24 @@ void PreviewFrameSpacer::queueBufferToClientLocked(
    mLastCameraReadoutTime = bufferHolder.readoutTimestamp;
}

status_t PreviewFrameSpacer::run(const char* name, int32_t priority, size_t stack) {
    auto ret = Thread::run(name, priority, stack);
    if (flags::bump_preview_frame_space_priority()) {
        // Boost priority of the preview frame spacer thread to SCHED_FIFO.
        pid_t previewFrameSpacerTid = getTid();
        auto res = SchedulingPolicyUtils::requestPriorityDirect(getpid(), previewFrameSpacerTid,
                RunThreadWithRealtimePriority::kRequestThreadPriority);
        if (res != OK) {
            ALOGW("Can't set realtime priority for preview frame spacer thread: %s (%d)",
                    strerror(-res), res);
        } else {
            ALOGV("Set real time priority for preview frame spacer thread (tid %d)",
                    previewFrameSpacerTid);
        }
    }
    return ret;
}

}; // namespace camera3

}; // namespace android
+1 −0
Original line number Diff line number Diff line
@@ -58,6 +58,7 @@ class PreviewFrameSpacer : public Thread {

    bool threadLoop() override;
    void requestExit() override;
    status_t run(const char* name, int32_t priority = PRIORITY_DEFAULT, size_t stack = 0) override;

  private:
    // structure holding cached preview buffer info