1 /* 2 * Copyright (c) 2023 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 #ifndef OS_ATTR_MANAGER_H 17 #define OS_ATTR_MANAGER_H 18 #include "ffrt_inner.h" 19 #include "sched/qos.h" 20 21 namespace ffrt { 22 const std::string cpuctlGroupIvePath = "/dev/cpuctl/cam2stage"; 23 const std::string cpusetGroupIvePath = "/dev/cpuset/cam2stage"; 24 const std::string cpuThreadNode = "/tasks"; 25 const std::string cpuSharesNode = "/cpu.shares"; 26 const std::string cpuLatencyniceNode = "/cpu.latency.nice"; 27 const std::string cpuUclampminNode = "/cpu.uclamp.min"; 28 const std::string cpuUclampmaxNode = "/cpu.uclamp.max"; 29 const std::string cpuvipprioNode = "/cpu.vip_prio"; 30 const std::string cpuMapNode = "/cpus"; 31 const int PATH_MAX_LENS = 4096; 32 const int CGROUP_SHARES_MIN = 2; 33 const int CGROUP_SHARES_MAX = 262144; 34 const int CGROUP_LAT_NICE_MIN = -20; 35 const int CGROUP_LAT_NICE_MAX = 19; 36 const int CGROUP_UCLAMP_MIN = 0; 37 const int CGROUP_UCLAMP_MAX = 100; 38 const int CGROUP_VIPPRIO_MIN = 0; 39 const int CGROUP_VIPPRIO_MAX = 10; 40 class OSAttrManager { 41 public: OSAttrManager()42 OSAttrManager() {} ~OSAttrManager()43 ~OSAttrManager() {} 44 Instance()45 static inline OSAttrManager* Instance() 46 { 47 static OSAttrManager instance; 48 return &instance; 49 } 50 51 bool CheckSchedAttrPara(const std::string &name, int min, int max, int paraValue); 52 int UpdateSchedAttr(const QoS& qos, ffrt_os_sched_attr *attr); 53 void SetCGroupCtlPara(const std::string &name, int32_t value); 54 void SetCGroupSetPara(const std::string &name, const std::string &value); 55 void SetTidToCGroup(int32_t pid); 56 void SetTidToCGroupPrivate(const std::string &filename, int32_t pid); 57 template <typename T> 58 void SetCGroupPara(const std::string &filename, T& value); 59 }; 60 } // namespace ffrt 61 62 #endif /* OS_ATTR_MANAGER_H */