1 2 /* 3 * Copyright (c) 2022 Huawei Device Co., Ltd. 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 #ifndef CGROUP_SCHED_FRAMEWORK_PROCESS_GROUP_INCLUDE_CGROUP_CONTROLLER_H_ 18 #define CGROUP_SCHED_FRAMEWORK_PROCESS_GROUP_INCLUDE_CGROUP_CONTROLLER_H_ 19 20 #include <map> // for map 21 #include <string> // for basic_string 22 #include <functional> // for less 23 #include <iosfwd> // for string 24 #include "sched_policy.h" // for SchedPolicy 25 26 namespace OHOS { 27 namespace ResourceSchedule { 28 namespace CgroupSetting { 29 class CgroupController { 30 public: 31 CgroupController(const std::string& name, const std::string& path); 32 ~CgroupController(); 33 34 CgroupController(const CgroupController& controller) = delete; 35 CgroupController& operator=(const CgroupController& controller) = delete; 36 CgroupController(CgroupController&& controller); 37 CgroupController& operator=(CgroupController&& controller); 38 GetName()39 const inline std::string GetName() const 40 { 41 return name_; 42 } 43 GetPath()44 const inline std::string GetPath() const 45 { 46 return path_; 47 } 48 bool IsEnabled(); 49 bool SetThreadSchedPolicy(int tid, SchedPolicy policy, bool isSetThreadGroup); 50 bool AddSchedPolicy(SchedPolicy policy, const std::string& subgroup); 51 bool GetTaskGroup(int tid, std::string& group); 52 53 private: 54 std::string name_; 55 std::string path_; 56 std::map<SchedPolicy, int> policyToTaskFd_; 57 std::map<SchedPolicy, int> policyToProcFd_; 58 59 bool AddThreadSchedPolicy(SchedPolicy policy, const std::string& subgroup); 60 bool AddThreadGroupSchedPolicy(SchedPolicy policy, const std::string& subgroup); 61 static bool AddTidToCgroup(int tid, int fd); 62 }; 63 } // namespace CgroupSetting 64 } // namespace ResourceSchedule 65 } // namespace OHOS 66 #endif // CGROUP_SCHED_FRAMEWORK_PROCESS_GROUP_INCLUDE_CGROUP_CONTROLLER_H_ 67