blob: f3afc69e758757a579515f5ee209a175b9ef46fd [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
Jyoti Bhayana3128fda2023-04-27 18:27:56 -070023#include <private/android_filesystem_config.h>
24#include <processgroup/processgroup.h>
25#include <processgroup/sched_policy.h>
26#include <procinfo/process.h>
27#include <utils/Log.h>
28
29namespace android {
30namespace camera3 {
31namespace SchedulingPolicyUtils {
32
33int requestPriorityDirect(int pid, int tid, int prio) {
34 android::procinfo::ProcessInfo processInfo;
35 static const int kMinPrio = 1;
36 static const int kMaxPrio = 3;
37
38 if (!android::procinfo::GetProcessInfo(tid, &processInfo)) {
39 ALOGE("%s: Error getting process info", __FUNCTION__);
40 return -EPERM;
41 }
42
43 if (prio < kMinPrio || prio > kMaxPrio || processInfo.pid != pid) {
44 ALOGE("%s: Invalid parameter prio=%d pid=%d procinfo.pid=%d", __FUNCTION__, prio, pid,
45 processInfo.pid);
46 return -EPERM;
47 }
48
49 // Set the thread group as audio system thread group in consistent with the
50 // implementation in SchedulingPolicyService.java when isApp is false in
51 // requestPriority method.
52 if (!SetTaskProfiles(tid, {get_sched_policy_profile_name(SP_AUDIO_SYS)},
53 /*use_fd_cache*/ true)) {
54 ALOGE("%s:Error in SetTaskProfiles", __FUNCTION__);
55 return -EPERM;
56 }
57
58 struct sched_param param;
59 param.sched_priority = prio;
60 return sched_setscheduler(tid, SCHED_FIFO | SCHED_RESET_ON_FORK, &param);
61}
62
63} // namespace SchedulingPolicyUtils
64} // namespace camera3
65} // namespace android