blob: 92a1030a10e6a2f66b9ab951eb79bff26cce063c [file] [log] [blame]
Jyoti Bhayana3128fda2023-04-27 18:27:56 -07001/*
2 * Copyright (C) 2023 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "SchedulingPolicyUtils.h"
18
19#include <errno.h>
20#include <pthread.h>
21#include <sched.h>
22
23#include "CameraThreadState.h"
24#include <private/android_filesystem_config.h>
25#include <processgroup/processgroup.h>
26#include <processgroup/sched_policy.h>
27#include <procinfo/process.h>
28#include <utils/Log.h>
29
30namespace android {
31namespace camera3 {
32namespace SchedulingPolicyUtils {
33
34int requestPriorityDirect(int pid, int tid, int prio) {
35 android::procinfo::ProcessInfo processInfo;
36 static const int kMinPrio = 1;
37 static const int kMaxPrio = 3;
38
39 if (!android::procinfo::GetProcessInfo(tid, &processInfo)) {
40 ALOGE("%s: Error getting process info", __FUNCTION__);
41 return -EPERM;
42 }
43
44 if (prio < kMinPrio || prio > kMaxPrio || processInfo.pid != pid) {
45 ALOGE("%s: Invalid parameter prio=%d pid=%d procinfo.pid=%d", __FUNCTION__, prio, pid,
46 processInfo.pid);
47 return -EPERM;
48 }
49
50 // Set the thread group as audio system thread group in consistent with the
51 // implementation in SchedulingPolicyService.java when isApp is false in
52 // requestPriority method.
53 if (!SetTaskProfiles(tid, {get_sched_policy_profile_name(SP_AUDIO_SYS)},
54 /*use_fd_cache*/ true)) {
55 ALOGE("%s:Error in SetTaskProfiles", __FUNCTION__);
56 return -EPERM;
57 }
58
59 struct sched_param param;
60 param.sched_priority = prio;
61 return sched_setscheduler(tid, SCHED_FIFO | SCHED_RESET_ON_FORK, &param);
62}
63
64} // namespace SchedulingPolicyUtils
65} // namespace camera3
66} // namespace android