blob: 4e9792fc7b32f8ada145741eaa0a7ba911532206 [file] [log] [blame]
Glenn Kasten1dc28b72012-04-24 10:01:03 -07001/*
2 * Copyright (C) 2012 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
Eric Laurentf59a4b32013-07-02 11:15:41 -070017#define LOG_TAG "SchedulingPolicyService"
18//#define LOG_NDEBUG 0
19
Glenn Kasten1dc28b72012-04-24 10:01:03 -070020#include <binder/IServiceManager.h>
21#include <utils/Mutex.h>
22#include "ISchedulingPolicyService.h"
Eino-Ville Talvalaf99498e2015-09-25 16:52:55 -070023#include "mediautils/SchedulingPolicyService.h"
Glenn Kasten1dc28b72012-04-24 10:01:03 -070024
25namespace android {
26
27static sp<ISchedulingPolicyService> sSchedulingPolicyService;
28static const String16 _scheduling_policy("scheduling_policy");
29static Mutex sMutex;
30
Mikhail Naganov83f04272017-02-07 10:45:09 -080031int requestPriority(pid_t pid, pid_t tid, int32_t prio, bool isForApp, bool asynchronous)
Glenn Kasten1dc28b72012-04-24 10:01:03 -070032{
33 // FIXME merge duplicated code related to service lookup, caching, and error recovery
Eric Laurentf59a4b32013-07-02 11:15:41 -070034 int ret;
Glenn Kasten1dc28b72012-04-24 10:01:03 -070035 for (;;) {
36 sMutex.lock();
Eric Laurentf59a4b32013-07-02 11:15:41 -070037 sp<ISchedulingPolicyService> sps = sSchedulingPolicyService;
Glenn Kasten1dc28b72012-04-24 10:01:03 -070038 sMutex.unlock();
Eric Laurentf59a4b32013-07-02 11:15:41 -070039 if (sps == 0) {
40 sp<IBinder> binder = defaultServiceManager()->checkService(_scheduling_policy);
41 if (binder == 0) {
42 sleep(1);
43 continue;
44 }
Glenn Kasten1dc28b72012-04-24 10:01:03 -070045 sps = interface_cast<ISchedulingPolicyService>(binder);
46 sMutex.lock();
47 sSchedulingPolicyService = sps;
48 sMutex.unlock();
Eric Laurentf59a4b32013-07-02 11:15:41 -070049 }
Mikhail Naganov83f04272017-02-07 10:45:09 -080050 ret = sps->requestPriority(pid, tid, prio, isForApp, asynchronous);
Eric Laurentf59a4b32013-07-02 11:15:41 -070051 if (ret != DEAD_OBJECT) {
Glenn Kasten1dc28b72012-04-24 10:01:03 -070052 break;
53 }
Eric Laurentf59a4b32013-07-02 11:15:41 -070054 ALOGW("SchedulingPolicyService died");
55 sMutex.lock();
56 sSchedulingPolicyService.clear();
57 sMutex.unlock();
Glenn Kasten1dc28b72012-04-24 10:01:03 -070058 }
Eric Laurentf59a4b32013-07-02 11:15:41 -070059 return ret;
Glenn Kasten1dc28b72012-04-24 10:01:03 -070060}
61
Chong Zhang79d2b282018-04-17 14:14:31 -070062int requestCpusetBoost(bool enable, const sp<IInterface> &client)
63{
64 int ret;
65 sMutex.lock();
66 sp<ISchedulingPolicyService> sps = sSchedulingPolicyService;
67 sMutex.unlock();
68 if (sps == 0) {
69 sp<IBinder> binder = defaultServiceManager()->checkService(_scheduling_policy);
70 if (binder == 0) {
71 return DEAD_OBJECT;
72 }
73 sps = interface_cast<ISchedulingPolicyService>(binder);
74 sMutex.lock();
75 sSchedulingPolicyService = sps;
76 sMutex.unlock();
77 }
78 ret = sps->requestCpusetBoost(enable, client);
79 if (ret != DEAD_OBJECT) {
80 return ret;
81 }
82 ALOGW("SchedulingPolicyService died");
83 sMutex.lock();
84 sSchedulingPolicyService.clear();
85 sMutex.unlock();
86 return ret;
87}
88
Glenn Kasten1dc28b72012-04-24 10:01:03 -070089} // namespace android