2 * Copyright (c) 2013, TOYOTA MOTOR CORPORATION.
4 * This program is licensed under the terms and conditions of the
5 * Apache License, version 2.0. The full text of the Apache License is at
6 * http://www.apache.org/licenses/LICENSE-2.0
10 * @brief CicoSCSysResourceController
11 * SystemController resource watcher
12 * CPU/FreeMemory monitoring
14 * @date Aug-05-2013 create start
17 #ifndef CICOSCSYSRESOURCECONTROLLER_H
18 #define CICOSCSYSRESOURCECONTROLLER_H
21 #include "CicoStateAction.h"
23 #ifndef CICOSTATEMACHINE_H
24 class CicoStateMachine;
27 #ifndef CICOSCSYSRESOURCEMONITOR_H
28 class CicoSCSysResourceMonitor;
31 #ifndef __CICO_SC_CONF_H__
32 class CicoSCResourceConf;
35 #define D_STRtasks "tasks"
36 #define D_STRcpushares "cpu.shares"
38 class CicoSCSysResourceController;
41 * @brief Class ico System Resource Controller CPU LOW level
43 class CicoSRCCPU_LOW : public CicoStateAction
45 public: // member method
46 CicoSRCCPU_LOW(CicoSCSysResourceController* obj);
47 virtual ~CicoSRCCPU_LOW();
49 virtual void onEntry(const CicoEvent& ev, const CicoState* stt, int addval);
50 virtual void onDo(const CicoEvent& ev, const CicoState* stt, int addval);
51 virtual void onExit(const CicoEvent& ev, const CicoState* stt,
53 protected: // member Variable
54 int m_val; // cpu or memory usage value
55 int m_baseVal; // cpu or memory base usage value
57 CicoSCSysResourceController* m_cntlr;
58 const CicoSCResourceConf* m_rConf;
62 * @brief Class ico System Resource Controller CPU HIGH level
64 class CicoSRCCPU_HIGH : public CicoSRCCPU_LOW
66 public: // member method
67 CicoSRCCPU_HIGH(CicoSCSysResourceController* obj);
68 virtual ~CicoSRCCPU_HIGH();
69 void onDo(const CicoEvent& ev, const CicoState* stt, int addval);
71 protected: // member Variable
75 * @brief Class ico System Resource Controller MEMory LOW level
77 class CicoSRCMEM_LOW : public CicoSRCCPU_LOW
79 public: // member method
80 CicoSRCMEM_LOW(CicoSCSysResourceController* obj);
81 virtual ~CicoSRCMEM_LOW();
82 void onDo(const CicoEvent& ev, const CicoState* stt, int addval);
83 protected: // member Variable
87 * @brief Class ico System Resource Controller MEMory HIGH level
89 class CicoSRCMEM_HIGH : public CicoSRCCPU_LOW
91 public: // member method
92 CicoSRCMEM_HIGH(CicoSCSysResourceController* obj);
93 virtual ~CicoSRCMEM_HIGH();
94 void onDo(const CicoEvent& ev, const CicoState* stt, int addval);
95 protected: // member Variable
99 * @brief System Controller System Resource Controller class
101 class CicoSCSysResourceController
104 CicoSCSysResourceController();
105 ~CicoSCSysResourceController();
107 bool isWactchAllReady() const;
109 bool startSysResource(); // start cgroup controll
111 bool watch(); // watch request (please interval call)
112 const CicoSCSysResourceMonitor& getMonitor() const;
113 int getCpuUsge() const;
114 int getMemoryUsge() const;
116 void resourceControlCPUShares(bool bHight);
117 void resourceControlMemLimit(bool bHight);
118 bool entryCgroupCPU(int pid, int grpNo);
121 void init_cgroup_cpu();
122 void init_cgroup_memory();
123 void make_directorys(std::vector<std::string> dir);
124 bool replaceCgroupFile(const std::string& tgt, int val);
125 bool replaceCgroupFile(const std::string& tgt, const char* val);
128 CicoSCSysResourceMonitor* m_monitor;
129 const CicoSCResourceConf* m_rConf;
130 std::vector<std::string> m_RCCpuTasks;
131 std::vector<std::string> m_RCCpuShares;
134 CicoStateMachine* m_stt;
136 CicoSRCCPU_LOW* m_SRCCPU_LOW;
137 CicoSRCCPU_HIGH* m_SRCCPU_HIGH;
138 CicoSRCMEM_LOW* m_SRCMEM_LOW;
139 CicoSRCMEM_HIGH* m_SRCMEM_HIGH;
152 bool CicoSCSysResourceController::isWactchAllReady() const
154 if ((-1 != m_cpu) && (-1 != m_mem)) {
161 * @brief get monitor class
162 * return monitor class
164 inline const CicoSCSysResourceMonitor&
165 CicoSCSysResourceController::getMonitor() const
171 * @brief get CPU usage
174 inline int CicoSCSysResourceController::getCpuUsge() const
180 * @brief get CPU usage
183 inline int CicoSCSysResourceController::getMemoryUsge() const
188 #endif // CICOSCSYSRESOURCECONTROLLER_H