From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by dpdk.org (Postfix) with ESMTP id 8B7885F21 for ; Fri, 28 Dec 2018 12:33:05 +0100 (CET) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 28 Dec 2018 03:33:04 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,409,1539673200"; d="scan'208";a="122292237" Received: from irvmail001.ir.intel.com ([163.33.26.43]) by orsmga001.jf.intel.com with ESMTP; 28 Dec 2018 03:33:03 -0800 Received: from sivswdev09.ir.intel.com (sivswdev09.ir.intel.com [10.237.217.48]) by irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id wBSBX2ct012466; Fri, 28 Dec 2018 11:33:02 GMT Received: from sivswdev09.ir.intel.com (localhost [127.0.0.1]) by sivswdev09.ir.intel.com with ESMTP id wBSBX2hn004174; Fri, 28 Dec 2018 11:33:02 GMT Received: (from lma25@localhost) by sivswdev09.ir.intel.com with LOCAL id wBSBX20x004170; Fri, 28 Dec 2018 11:33:02 GMT From: Liang Ma To: david.hunt@intel.com Cc: dev@dpdk.org, anatoly.burakov@intel.com, lei.a.yao@intel.com, Liang Ma Date: Fri, 28 Dec 2018 11:32:59 +0000 Message-Id: <1545996779-4098-1-git-send-email-liang.j.ma@intel.com> X-Mailer: git-send-email 1.7.7.4 Subject: [dpdk-dev] [PATCH] libs/power: fix the resource leaking issue X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 28 Dec 2018 11:33:05 -0000 Fixes: e6c6dc0f96c8 ("power: add p-state driver compatibility") Coverity issue: 328528 Also add the missing functionality of enable/disable turbo Signed-off-by: Liang Ma --- lib/librte_power/power_pstate_cpufreq.c | 34 ++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/lib/librte_power/power_pstate_cpufreq.c b/lib/librte_power/power_pstate_cpufreq.c index 411d0eb..cb226a5 100644 --- a/lib/librte_power/power_pstate_cpufreq.c +++ b/lib/librte_power/power_pstate_cpufreq.c @@ -160,6 +160,10 @@ power_init_for_setting_freq(struct pstate_power_info *pi) pi->lcore_id); f_max = fopen(fullpath_max, "rw+"); + + if (f_max == NULL) + fclose(f_min); + FOPEN_OR_ERR_RET(f_max, -1); pi->f_cur_min = f_min; @@ -214,7 +218,13 @@ set_freq_internal(struct pstate_power_info *pi, uint32_t idx) /* Turbo is available and enabled, first freq bucket is sys max freq */ if (pi->turbo_available && pi->turbo_enable && (idx == 0)) target_freq = pi->sys_max_freq; - else + else if (pi->turbo_available && (!pi->turbo_enable) && (idx == 0)) { + + RTE_LOG(ERR, POWER, "Turbo is off, frequency can't be scaled up more %u\n", + pi->lcore_id); + return -1; + + } else target_freq = pi->freqs[idx]; /* Decrease freq, the min freq should be updated first */ @@ -394,6 +404,10 @@ power_get_available_freqs(struct pstate_power_info *pi) FOPEN_OR_ERR_RET(f_min, ret); f_max = fopen(fullpath_max, "r"); + + if (f_max == NULL) + fclose(f_min); + FOPEN_OR_ERR_RET(f_max, ret); s_min = fgets(buf_min, sizeof(buf_min), f_min); @@ -726,6 +740,14 @@ power_pstate_enable_turbo(unsigned int lcore_id) return -1; } + /* Max may have changed, so call to max function */ + if (power_pstate_cpufreq_freq_max(lcore_id) < 0) { + RTE_LOG(ERR, POWER, + "Failed to set frequency of lcore %u to max\n", + lcore_id); + return -1; + } + return 0; } @@ -744,6 +766,16 @@ power_pstate_disable_turbo(unsigned int lcore_id) pi->turbo_enable = 0; + if ((pi->turbo_available) && (pi->curr_idx <= 1)) { + /* Try to set freq to max by default coming out of turbo */ + if (power_pstate_cpufreq_freq_max(lcore_id) < 0) { + RTE_LOG(ERR, POWER, + "Failed to set frequency of lcore %u to max\n", + lcore_id); + return -1; + } + } + return 0; } -- 2.7.5