• 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 <vector>               // for getAllCgroupController
24 #include "cgroup_controller.h"  // for CgroupController
25 #include "nlohmann/json.hpp"         // for Value
26 #include "sched_policy.h"       // for SchedPolicy
27 
28 namespace OHOS {
29 namespace ResourceSchedule {
30 namespace CgroupSetting {
31 class CgroupMap {
32 public:
33     static CgroupMap& GetInstance();
34 
35     bool SetThreadSchedPolicy(int tid, SchedPolicy policy, bool isSetThreadGroup);
36     bool LoadConfigFromJsonObj(const nlohmann::json& jsonObj);
37     bool FindAllEnableCgroupControllers(std::vector<CgroupController *> &controllers);
38 
39 private:
40     CgroupMap() = default;
41     ~CgroupMap() = default;
42 
43     CgroupMap(const CgroupMap&) = delete;
44     CgroupMap& operator=(const CgroupMap &) = delete;
45     CgroupMap(CgroupMap&&) = delete;
46     CgroupMap& operator=(CgroupMap&&) = delete;
47 
48     std::map<std::string, CgroupController> controllers_;
49 
50     bool CheckCgroupConfigFormat(const nlohmann::json& cgroupObj);
51     void AddCgroupController(const std::string& name, CgroupController& controller);
52     bool LoadSchedPolicyConfig(CgroupController& controller, const nlohmann::json& policyObj);
53 };
54 } // namespace CgroupSetting
55 } // namespace ResourceSchedule
56 } // namespace OHOS
57 #endif // CGROUP_SCHED_FRAMEWORK_PROCESS_GROUP_INCLUDE_CGROUP_MAP_H_
58