1 /* 2 * Copyright (c) 2025-2025 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #include "res_sa_init.h" 17 18 #include "res_sched_client.h" 19 #include "res_sched_log.h" 20 21 namespace OHOS { 22 namespace ResourceSchedule { 23 GetInstance()24ResSchedSaInit& ResSchedSaInit::GetInstance() 25 { 26 static ResSchedSaInit instance; 27 return instance; 28 } 29 GetInstance()30ResSchedIpcThread& ResSchedIpcThread::GetInstance() 31 { 32 static ResSchedIpcThread instance; 33 return instance; 34 } 35 SetQos(uint32_t pid)36void ResSchedIpcThread::SetQos(uint32_t pid) 37 { 38 if (!isInit_.load()) { 39 return; 40 } 41 42 if (pid == selfPid_) { 43 return; 44 } 45 46 uint32_t tid = gettid(); 47 std::unique_lock<std::mutex> lock(ipcThreadSetQosMutex_); 48 if (ipcThreadTids_.find(tid) != ipcThreadTids_.end()) { 49 lock.unlock(); 50 return; 51 } 52 if (ipcThreadTids_.size() > MAX_IPC_THREAD_NUM) { 53 RESSCHED_LOGI("ResSchedIpcThread SetQos Thread size EXCEEDS LIMIT."); 54 ipcThreadTids_.clear(); 55 } 56 ipcThreadTids_.insert(tid); 57 lock.unlock(); 58 59 std::string strTid = std::to_string(tid); 60 std::unordered_map<std::string, std::string> mapPayload; 61 mapPayload["pid"] = std::to_string(selfPid_); 62 mapPayload[strTid] = std::to_string(RSS_IPC_QOS_LEVEL); 63 mapPayload["bundleName"] = RSS_BUNDLE_NAME; 64 RESSCHED_LOGI("ResSchedIpcThread SetQos Thread tid=%{public}u.", tid); 65 OHOS::ResourceSchedule::ResSchedClient::GetInstance().ReportData( 66 OHOS::ResourceSchedule::ResType::RES_TYPE_THREAD_QOS_CHANGE, 0, mapPayload); 67 } 68 SetInitFlag(bool flag)69void ResSchedIpcThread::SetInitFlag(bool flag) 70 { 71 selfPid_ = getpid(); 72 isInit_ = flag; 73 } 74 75 } // namespace ResourceSchedule 76 } // namespace OHOS 77