return false;
}
-void SetComm() {
- pid_t tid = syscall(__NR_gettid);
+void DoBoost(pid_t tid) {
+ if (tid < 1)
+ return;
+
+ resource_pid_t res_pid = {
+ .pid = 0,
+ .tid = &tid,
+ .tid_count = 1,
+ };
+
+ int ret = resource_set_cpu_boosting(res_pid, CPU_BOOSTING_LEVEL_MEDIUM,
+ static_cast<cpu_boosting_flag_e>(0), -1);
+ if (ret != 0) {
+ _E("resource_set_cpu_boosting() is failed. error: %d", ret);
+ return;
+ }
+
+ _D("resource_set_cpu_boosting() is successful. tid(%d)", tid);
+}
+
+void ClearBoost(pid_t tid) {
+ if (tid < 1)
+ return;
+
+ resource_pid_t res_pid = {
+ .pid = 0,
+ .tid = &tid,
+ .tid_count = 1,
+ };
+
+ int ret = resource_clear_cpu_boosting(res_pid);
+ if (ret!= 0) {
+ _E("resource_clear_cpu_boosting() is failed. error: %d", ret);
+ return;
+ }
+
+ _D("resource_clear_cpu_boosting() is successful. tid(%d)", tid);
+}
+
+void SetComm(pid_t tid) {
std::string path = "/proc/" + std::to_string(tid) + "/comm";
int fd = open(path.c_str(), O_WRONLY);
if (fd < 0) {
if (disposed_)
return;
+ UnsetBoostingTimer();
SendRequest(std::make_shared<CynaraRequest>(true));
thread_.join();
disposed_ = true;
Dispose();
}
+void CynaraManager::SetBoostingTimer() {
+ if (boosting_timer_ == 0)
+ DoBoost(tid_);
+ else
+ g_source_remove(boosting_timer_);
+
+ boosting_timer_ = g_timeout_add(5000,
+ [](gpointer user_data) {
+ auto* cynara_manager = static_cast<CynaraManager*>(user_data);
+ cynara_manager->boosting_timer_ = 0;
+ ClearBoost(cynara_manager->tid_);
+ return G_SOURCE_REMOVE;
+ }, this);
+}
+
+void CynaraManager::UnsetBoostingTimer() {
+ if (boosting_timer_ != 0) {
+ g_source_remove(boosting_timer_);
+ boosting_timer_ = 0;
+ }
+}
+
void CynaraManager::SendRequest(std::shared_ptr<CynaraRequest> request) {
+ SetBoostingTimer();
queue_.Push(std::move(request));
}
void CynaraManager::CynaraThread() {
_W("BEGIN");
- SetComm();
+ tid_ = syscall(__NR_gettid);
+ SetComm(tid_);
char err_buf[128];
cynara* cynara = nullptr;
#define CYNARA_MANAGER_HH_
#include <glib.h>
+#include <sys/types.h>
+#include <unistd.h>
#include <list>
#include <memory>
void CynaraThread();
static gboolean RequestCb(gpointer user_data);
static gboolean ResponseCb(gpointer user_data);
+ void SetBoostingTimer();
+ void UnsetBoostingTimer();
private:
bool disposed_ = true;
std::unordered_map<unsigned int, std::shared_ptr<CynaraResponseCb>> res_cbs_;
std::unordered_map<int, std::shared_ptr<CynaraChecker>> checkers_;
std::list<std::shared_ptr<CynaraSubChecker>> sub_checkers_;
+ pid_t tid_ = 0;
+ guint boosting_timer_ = 0;
};
} // namespace cynara_core