Glenn Kasten | 1dc28b7 | 2012-04-24 10:01:03 -0700 | [diff] [blame] | 1 | /* |
| 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 Laurent | f59a4b3 | 2013-07-02 11:15:41 -0700 | [diff] [blame] | 17 | #define LOG_TAG "SchedulingPolicyService" |
| 18 | //#define LOG_NDEBUG 0 |
| 19 | |
Glenn Kasten | 1dc28b7 | 2012-04-24 10:01:03 -0700 | [diff] [blame] | 20 | #include <binder/IServiceManager.h> |
| 21 | #include <utils/Mutex.h> |
| 22 | #include "ISchedulingPolicyService.h" |
Eino-Ville Talvala | f99498e | 2015-09-25 16:52:55 -0700 | [diff] [blame] | 23 | #include "mediautils/SchedulingPolicyService.h" |
Glenn Kasten | 1dc28b7 | 2012-04-24 10:01:03 -0700 | [diff] [blame] | 24 | |
| 25 | namespace android { |
| 26 | |
| 27 | static sp<ISchedulingPolicyService> sSchedulingPolicyService; |
| 28 | static const String16 _scheduling_policy("scheduling_policy"); |
| 29 | static Mutex sMutex; |
| 30 | |
Mikhail Naganov | 83f0427 | 2017-02-07 10:45:09 -0800 | [diff] [blame] | 31 | int requestPriority(pid_t pid, pid_t tid, int32_t prio, bool isForApp, bool asynchronous) |
Glenn Kasten | 1dc28b7 | 2012-04-24 10:01:03 -0700 | [diff] [blame] | 32 | { |
| 33 | // FIXME merge duplicated code related to service lookup, caching, and error recovery |
Eric Laurent | f59a4b3 | 2013-07-02 11:15:41 -0700 | [diff] [blame] | 34 | int ret; |
Glenn Kasten | 1dc28b7 | 2012-04-24 10:01:03 -0700 | [diff] [blame] | 35 | for (;;) { |
| 36 | sMutex.lock(); |
Eric Laurent | f59a4b3 | 2013-07-02 11:15:41 -0700 | [diff] [blame] | 37 | sp<ISchedulingPolicyService> sps = sSchedulingPolicyService; |
Glenn Kasten | 1dc28b7 | 2012-04-24 10:01:03 -0700 | [diff] [blame] | 38 | sMutex.unlock(); |
Eric Laurent | f59a4b3 | 2013-07-02 11:15:41 -0700 | [diff] [blame] | 39 | if (sps == 0) { |
| 40 | sp<IBinder> binder = defaultServiceManager()->checkService(_scheduling_policy); |
| 41 | if (binder == 0) { |
| 42 | sleep(1); |
| 43 | continue; |
| 44 | } |
Glenn Kasten | 1dc28b7 | 2012-04-24 10:01:03 -0700 | [diff] [blame] | 45 | sps = interface_cast<ISchedulingPolicyService>(binder); |
| 46 | sMutex.lock(); |
| 47 | sSchedulingPolicyService = sps; |
| 48 | sMutex.unlock(); |
Eric Laurent | f59a4b3 | 2013-07-02 11:15:41 -0700 | [diff] [blame] | 49 | } |
Mikhail Naganov | 83f0427 | 2017-02-07 10:45:09 -0800 | [diff] [blame] | 50 | ret = sps->requestPriority(pid, tid, prio, isForApp, asynchronous); |
Eric Laurent | f59a4b3 | 2013-07-02 11:15:41 -0700 | [diff] [blame] | 51 | if (ret != DEAD_OBJECT) { |
Glenn Kasten | 1dc28b7 | 2012-04-24 10:01:03 -0700 | [diff] [blame] | 52 | break; |
| 53 | } |
Eric Laurent | f59a4b3 | 2013-07-02 11:15:41 -0700 | [diff] [blame] | 54 | ALOGW("SchedulingPolicyService died"); |
| 55 | sMutex.lock(); |
| 56 | sSchedulingPolicyService.clear(); |
| 57 | sMutex.unlock(); |
Glenn Kasten | 1dc28b7 | 2012-04-24 10:01:03 -0700 | [diff] [blame] | 58 | } |
Eric Laurent | f59a4b3 | 2013-07-02 11:15:41 -0700 | [diff] [blame] | 59 | return ret; |
Glenn Kasten | 1dc28b7 | 2012-04-24 10:01:03 -0700 | [diff] [blame] | 60 | } |
| 61 | |
Chong Zhang | 79d2b28 | 2018-04-17 14:14:31 -0700 | [diff] [blame] | 62 | int 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 Kasten | 1dc28b7 | 2012-04-24 10:01:03 -0700 | [diff] [blame] | 89 | } // namespace android |