• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 CGROUP_SCHED_FRAMEWORK_PROCESS_GROUP_INCLUDE_CGROUP_MAP_H_
17 #define CGROUP_SCHED_FRAMEWORK_PROCESS_GROUP_INCLUDE_CGROUP_MAP_H_
18 
19 #include <map>                  // for map
20 #include <string>               // for basic_string, operator<
21 #include <functional>           // for less
22 #include <iosfwd>               // for string
23 #include "cgroup_controller.h"  // for CgroupController
24 #include "nlohmann/json.hpp"         // for Value
25 #include "sched_policy.h"       // for SchedPolicy
26 
27 namespace OHOS {
28 namespace ResourceSchedule {
29 namespace CgroupSetting {
30 class CgroupMap {
31 public:
32     static CgroupMap& GetInstance();
33 
34     bool SetThreadSchedPolicy(int tid, SchedPolicy policy, bool isSetThreadGroup);
35     bool LoadConfigFromJsonObj(const nlohmann::json& jsonObj);
36     bool FindFristEnableCgroupController(CgroupController** p);
37 
38 private:
39     CgroupMap() = default;
40     ~CgroupMap() = default;
41 
42     CgroupMap(const CgroupMap&) = delete;
43     CgroupMap& operator=(const CgroupMap &) = delete;
44     CgroupMap(CgroupMap&&) = delete;
45     CgroupMap& operator=(CgroupMap&&) = delete;
46 
47     std::map<std::string, CgroupController> controllers_;
48 
49     bool CheckCgroupConfigFormat(const nlohmann::json& cgroupObj);
50     void AddCgroupController(const std::string& name, CgroupController& controller);
51     bool LoadSchedPolicyConfig(CgroupController& controller, const nlohmann::json& policyObj);
52 };
53 } // namespace CgroupSetting
54 } // namespace ResourceSchedule
55 } // namespace OHOS
56 #endif // CGROUP_SCHED_FRAMEWORK_PROCESS_GROUP_INCLUDE_CGROUP_MAP_H_
57