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 class CicoSCSysResourceController;
38 * @brief Class ico System Resource Controller CPU LOW level
40 class CicoSRCCPU_LOW : public CicoStateAction
42 public: // member method
43 CicoSRCCPU_LOW(CicoSCSysResourceController* obj);
44 virtual ~CicoSRCCPU_LOW();
46 virtual void onEntry(const CicoEvent& ev, const CicoState* stt, int addval);
47 virtual void onDo(const CicoEvent& ev, const CicoState* stt, int addval);
48 virtual void onExit(const CicoEvent& ev, const CicoState* stt,
50 protected: // member Variable
51 int m_val; // cpu or memory usage value
52 int m_baseVal; // cpu or memory base usage value
54 CicoSCSysResourceController* m_cntlr;
55 const CicoSCResourceConf* m_rConf;
59 * @brief Class ico System Resource Controller CPU HIGH level
61 class CicoSRCCPU_HIGH : public CicoSRCCPU_LOW
63 public: // member method
64 CicoSRCCPU_HIGH(CicoSCSysResourceController* obj);
65 virtual ~CicoSRCCPU_HIGH();
66 void onDo(const CicoEvent& ev, const CicoState* stt, int addval);
68 protected: // member Variable
72 * @brief Class ico System Resource Controller MEMory LOW level
74 class CicoSRCMEM_LOW : public CicoSRCCPU_LOW
76 public: // member method
77 CicoSRCMEM_LOW(CicoSCSysResourceController* obj);
78 virtual ~CicoSRCMEM_LOW();
79 void onDo(const CicoEvent& ev, const CicoState* stt, int addval);
80 protected: // member Variable
84 * @brief Class ico System Resource Controller MEMory HIGH level
86 class CicoSRCMEM_HIGH : public CicoSRCCPU_LOW
88 public: // member method
89 CicoSRCMEM_HIGH(CicoSCSysResourceController* obj);
90 virtual ~CicoSRCMEM_HIGH();
91 void onDo(const CicoEvent& ev, const CicoState* stt, int addval);
92 protected: // member Variable
96 * @brief System Controller System Resource Controller class
98 class CicoSCSysResourceController
101 CicoSCSysResourceController();
102 ~CicoSCSysResourceController();
104 bool isWactchAllReady() const;
106 bool watch(); // watch request (please interval call)
107 const CicoSCSysResourceMonitor& getMonitor() const;
108 int getCpuUsge() const;
109 int getMemoryUsge() const;
111 void resourceControlCPUShares(bool bHight);
112 void resourceControlMemLimit(bool bHight);
113 bool entryCgroupCPU(int pid, int grpNo);
116 void init_cgroup_cpu();
117 void init_cgroup_memory();
118 void make_directorys(std::vector<std::string> dir);
119 bool replaceCgroupFile(const std::string& tgt, int val);
120 bool replaceCgroupFile(const std::string& tgt, const char* val);
123 CicoSCSysResourceMonitor* m_monitor;
124 const CicoSCResourceConf* m_rConf;
125 CicoStateMachine* m_stt;
127 CicoSRCCPU_LOW* m_SRCCPU_LOW;
128 CicoSRCCPU_HIGH* m_SRCCPU_HIGH;
129 CicoSRCMEM_LOW* m_SRCMEM_LOW;
130 CicoSRCMEM_HIGH* m_SRCMEM_HIGH;
134 std::vector<std::string> m_RCCpuTasks;
135 std::vector<std::string> m_RCCpuShares;
146 bool CicoSCSysResourceController::isWactchAllReady() const
148 if ((-1 != m_cpu) && (-1 != m_mem)) {
155 * @brief get monitor class
156 * return monitor class
158 inline const CicoSCSysResourceMonitor&
159 CicoSCSysResourceController::getMonitor() const
165 * @brief get CPU usage
168 inline int CicoSCSysResourceController::getCpuUsge() const
174 * @brief get CPU usage
177 inline int CicoSCSysResourceController::getMemoryUsge() const
182 #endif // CICOSCSYSRESOURCECONTROLLER_H