From 606cafa745df096c8c83156d6a4e62d970592383 Mon Sep 17 00:00:00 2001 From: heppen Date: Wed, 29 May 2024 17:11:41 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9E=20fix(procservice):=20=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2=E7=93=A6=E7=89=B9=E8=B0=83=E5=BA=A6=E5=BC=80=E5=85=B3?= =?UTF-8?q?=E7=AC=AC=E4=B8=80=E6=AC=A1=E8=B0=83=E7=94=A8=E4=BC=9A=E5=87=BA?= =?UTF-8?q?=E7=8E=B0=E6=9F=A5=E8=AF=A2=E5=A4=B1=E8=B4=A5=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pwrapis/src/procservice.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/pwrapis/src/procservice.c b/pwrapis/src/procservice.c index ba06632..2a2467f 100644 --- a/pwrapis/src/procservice.c +++ b/pwrapis/src/procservice.c @@ -187,6 +187,12 @@ static int QueryProcs(const char *keyWords, pid_t procs[], int maxNum, int *proc static inline int ReadWattState(int *state) { char buff[PWR_STATE_LEN] = {0}; + + // already check whether watt scheduler is supported + if (access(WATT_CGROUP_PATH, F_OK) != 0 && MkDirs(WATT_CGROUP_PATH, CRT_DIR_MODE) != PWR_SUCCESS) { + return PWR_ERR_SYS_EXCEPTION; + } + int ret = ReadFile(WATT_STATE_PATH, buff, PWR_STATE_LEN); if (ret == PWR_SUCCESS) { *state = atoi(buff); @@ -451,8 +457,8 @@ void ProcGetWattState(PwrMsg *req) return; } *state = PWR_DISABLE; - int ret = ReadWattState(state); - SendRspToClient(req, ret, (char *)state, sizeof(int)); + (void)ReadWattState(state); + SendRspToClient(req, PWR_SUCCESS, (char *)state, sizeof(int)); } void ProcSetWattState(PwrMsg *req) @@ -501,7 +507,7 @@ void ProcSetWattFirstDomain(PwrMsg *req) SendRspToClient(req, PWR_ERR_INVALIDE_PARAM, NULL, 0); return; } - + int *cpuId = (int *)req->data; if (*cpuId < 0 || GetCpuCoreNumber() <= *cpuId || !checkIfCpuOnline(*cpuId)) { SendRspToClient(req, PWR_ERR_INVALIDE_PARAM, NULL, 0); @@ -515,9 +521,7 @@ void ProcSetWattFirstDomain(PwrMsg *req) int state = PWR_DISABLE; int ret = ReadWattState(&state); - if (ret != PWR_SUCCESS) { - return SendRspToClient(req, ret, NULL, 0); - } else if (state == PWR_ENABLE) { // could set watt first domain only when watt is disabled + if (state == PWR_ENABLE) { // could set watt first domain only when watt is disabled return SendRspToClient(req, PWR_ERR_WATT_NEED_DISABLE_TO_SET_DOMAIN, NULL, 0); } -- Gitee