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

Commit 3128fda9 authored by Jyoti Bhayana's avatar Jyoti Bhayana
Browse files

Do not use scheduling service in cameraservice.

Since the cameraserver sets the RLIMIT_RTPRIO as 10 in it's
init.rc file, cameraservice can boost the priority of camera
request thread using direct calls till that limit instead of
using scheduling service.

Bug: 231557017
Test: Test using a simple camera2 ndk program which opens the camera and
capture a still image.

Change-Id: Iedba796f9a74e87f9d93f243617ec4895206a3cb
parent 5a1f004d
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -66,6 +66,8 @@ cc_defaults {
        "libmedia_codeclist",
        "libmedia_omx",
        "libmemunreachable",
        "libprocessgroup",
        "libprocinfo",
        "libsensorprivacy",
        "libstagefright",
        "libstagefright_foundation",
@@ -185,6 +187,7 @@ cc_library {
        "utils/CameraThreadState.cpp",
        "utils/CameraTraces.cpp",
        "utils/AutoConditionLock.cpp",
        "utils/SchedulingPolicyUtils.cpp",
        "utils/SessionConfigurationUtils.cpp",
        "utils/SessionConfigurationUtilsHidl.cpp",
        "utils/SessionStatsBuilder.cpp",
+3 −3
Original line number Diff line number Diff line
@@ -60,9 +60,9 @@
#include "device3/Camera3InputStream.h"
#include "device3/Camera3OutputStream.h"
#include "device3/Camera3SharedOutputStream.h"
#include "mediautils/SchedulingPolicyService.h"
#include "utils/CameraThreadState.h"
#include "utils/CameraTraces.h"
#include "utils/SchedulingPolicyUtils.h"
#include "utils/SessionConfigurationUtils.h"
#include "utils/TraceHFR.h"

@@ -2616,8 +2616,8 @@ status_t Camera3Device::configureStreamsLocked(int operatingMode,
    if (disableFifo != 1) {
        // Boost priority of request thread to SCHED_FIFO.
        pid_t requestThreadTid = mRequestThread->getTid();
        res = requestPriority(getpid(), requestThreadTid,
                kRequestThreadPriority, /*isForApp*/ false, /*asynchronous*/ false);
        res = SchedulingPolicyUtils::requestPriorityDirect(getpid(), requestThreadTid,
                kRequestThreadPriority);
        if (res != OK) {
            ALOGW("Can't set realtime priority for request processing thread: %s (%d)",
                    strerror(-res), res);
+66 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2023 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "SchedulingPolicyUtils.h"

#include <errno.h>
#include <pthread.h>
#include <sched.h>

#include "CameraThreadState.h"
#include <private/android_filesystem_config.h>
#include <processgroup/processgroup.h>
#include <processgroup/sched_policy.h>
#include <procinfo/process.h>
#include <utils/Log.h>

namespace android {
namespace camera3 {
namespace SchedulingPolicyUtils {

int requestPriorityDirect(int pid, int tid, int prio) {
    android::procinfo::ProcessInfo processInfo;
    static const int kMinPrio = 1;
    static const int kMaxPrio = 3;

    if (!android::procinfo::GetProcessInfo(tid, &processInfo)) {
       ALOGE("%s: Error getting process info", __FUNCTION__);
       return -EPERM;
    }

    if (prio < kMinPrio || prio > kMaxPrio || processInfo.pid != pid) {
        ALOGE("%s: Invalid parameter prio=%d pid=%d procinfo.pid=%d", __FUNCTION__, prio, pid,
                processInfo.pid);
        return -EPERM;
    }

    // Set the thread group as audio system thread group in consistent with the
    // implementation in SchedulingPolicyService.java when isApp is false in
    // requestPriority method.
    if (!SetTaskProfiles(tid, {get_sched_policy_profile_name(SP_AUDIO_SYS)},
            /*use_fd_cache*/ true)) {
        ALOGE("%s:Error in  SetTaskProfiles", __FUNCTION__);
        return -EPERM;
    }

    struct sched_param param;
    param.sched_priority = prio;
    return sched_setscheduler(tid, SCHED_FIFO | SCHED_RESET_ON_FORK, &param);
}

} // namespace SchedulingPolicyUtils
} // namespace camera3
} // namespace android
+35 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2023 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
#ifndef ANDROID_SERVICE_CAMERA_SCHEDULING_POLICY_UTILS_H
#define ANDROID_SERVICE_CAMERA_SCHEDULING_POLICY_UTILS_H

namespace android {
namespace camera3 {
namespace SchedulingPolicyUtils {

/**
 * Request elevated priority for thread tid, whose thread group leader must be pid.
 * Instead of using scheduling policy service, this method uses direct system calls.
 * The priority parameter is currently restricted from 1 to 3 matching
 * scheduling policy service implementation.
 */
int requestPriorityDirect(int pid, int tid, int prio);

} // SchedulingPolicyUtils
} // camera3
} // android

#endif